]>
Commit | Line | Data |
---|---|---|
a9533e7e HP |
1 | /* |
2 | * Copyright (c) 2010 Broadcom Corporation | |
3 | * | |
4 | * Permission to use, copy, modify, and/or distribute this software for any | |
5 | * purpose with or without fee is hereby granted, provided that the above | |
6 | * copyright notice and this permission notice appear in all copies. | |
7 | * | |
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | |
11 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | |
13 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | |
14 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
15 | */ | |
16 | ||
17 | #ifndef _bcmnvram_h_ | |
18 | #define _bcmnvram_h_ | |
19 | ||
20 | #ifndef _LANGUAGE_ASSEMBLY | |
21 | ||
22 | #include <typedefs.h> | |
23 | #include <bcmdefs.h> | |
24 | ||
25 | struct nvram_header { | |
66cbd3ab GKH |
26 | u32 magic; |
27 | u32 len; | |
28 | u32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */ | |
29 | u32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */ | |
30 | u32 config_ncdl; /* ncdl values for memc */ | |
a9533e7e HP |
31 | }; |
32 | ||
33 | struct nvram_tuple { | |
34 | char *name; | |
35 | char *value; | |
36 | struct nvram_tuple *next; | |
37 | }; | |
38 | ||
39 | /* | |
40 | * Get default value for an NVRAM variable | |
41 | */ | |
42 | extern char *nvram_default_get(const char *name); | |
43 | ||
44 | /* | |
45 | * Initialize NVRAM access. May be unnecessary or undefined on certain | |
46 | * platforms. | |
47 | */ | |
48 | extern int nvram_init(void *sih); | |
49 | ||
50 | /* | |
51 | * Append a chunk of nvram variables to the global list | |
52 | */ | |
53 | extern int nvram_append(void *si, char *vars, uint varsz); | |
54 | ||
55 | /* | |
56 | * Check for reset button press for restoring factory defaults. | |
57 | */ | |
58 | extern int nvram_reset(void *sih); | |
59 | ||
60 | /* | |
61 | * Disable NVRAM access. May be unnecessary or undefined on certain | |
62 | * platforms. | |
63 | */ | |
64 | extern void nvram_exit(void *sih); | |
65 | ||
66 | /* | |
67 | * Get the value of an NVRAM variable. The pointer returned may be | |
68 | * invalid after a set. | |
69 | * @param name name of variable to get | |
70 | * @return value of variable or NULL if undefined | |
71 | */ | |
72 | extern char *nvram_get(const char *name); | |
73 | ||
74 | /* | |
75 | * Read the reset GPIO value from the nvram and set the GPIO | |
76 | * as input | |
77 | */ | |
b4f790ee | 78 | extern int nvram_resetgpio_init(void *sih); |
a9533e7e HP |
79 | |
80 | /* | |
81 | * Get the value of an NVRAM variable. | |
82 | * @param name name of variable to get | |
83 | * @return value of variable or NUL if undefined | |
84 | */ | |
85 | #define nvram_safe_get(name) (nvram_get(name) ? : "") | |
86 | ||
87 | /* | |
88 | * Match an NVRAM variable. | |
89 | * @param name name of variable to match | |
90 | * @param match value to compare against value of variable | |
0f0881b0 | 91 | * @return true if variable is defined and its value is string equal |
a9533e7e HP |
92 | * to match or FALSE otherwise |
93 | */ | |
2d956e22 | 94 | static inline int nvram_match(char *name, char *match) |
a9533e7e HP |
95 | { |
96 | const char *value = nvram_get(name); | |
90ea2296 | 97 | return value && !strcmp(value, match); |
a9533e7e HP |
98 | } |
99 | ||
100 | /* | |
101 | * Inversely match an NVRAM variable. | |
102 | * @param name name of variable to match | |
103 | * @param match value to compare against value of variable | |
0f0881b0 | 104 | * @return true if variable is defined and its value is not string |
a9533e7e HP |
105 | * equal to invmatch or FALSE otherwise |
106 | */ | |
2d956e22 | 107 | static inline int nvram_invmatch(char *name, char *invmatch) |
a9533e7e HP |
108 | { |
109 | const char *value = nvram_get(name); | |
90ea2296 | 110 | return value && strcmp(value, invmatch); |
a9533e7e HP |
111 | } |
112 | ||
113 | /* | |
114 | * Set the value of an NVRAM variable. The name and value strings are | |
115 | * copied into private storage. Pointers to previously set values | |
116 | * may become invalid. The new value may be immediately | |
117 | * retrieved but will not be permanently stored until a commit. | |
118 | * @param name name of variable to set | |
119 | * @param value value of variable | |
120 | * @return 0 on success and errno on failure | |
121 | */ | |
122 | extern int nvram_set(const char *name, const char *value); | |
123 | ||
124 | /* | |
125 | * Unset an NVRAM variable. Pointers to previously set values | |
126 | * remain valid until a set. | |
127 | * @param name name of variable to unset | |
128 | * @return 0 on success and errno on failure | |
129 | * NOTE: use nvram_commit to commit this change to flash. | |
130 | */ | |
131 | extern int nvram_unset(const char *name); | |
132 | ||
133 | /* | |
134 | * Commit NVRAM variables to permanent storage. All pointers to values | |
135 | * may be invalid after a commit. | |
136 | * NVRAM values are undefined after a commit. | |
137 | * @return 0 on success and errno on failure | |
138 | */ | |
139 | extern int nvram_commit(void); | |
140 | ||
141 | /* | |
142 | * Get all NVRAM variables (format name=value\0 ... \0\0). | |
143 | * @param buf buffer to store variables | |
144 | * @param count size of buffer in bytes | |
145 | * @return 0 on success and errno on failure | |
146 | */ | |
147 | extern int nvram_getall(char *nvram_buf, int count); | |
148 | ||
149 | /* | |
150 | * returns the crc value of the nvram | |
151 | * @param nvh nvram header pointer | |
152 | */ | |
de9bca63 | 153 | u8 nvram_calc_crc(struct nvram_header *nvh); |
a9533e7e HP |
154 | |
155 | #endif /* _LANGUAGE_ASSEMBLY */ | |
156 | ||
157 | /* The NVRAM version number stored as an NVRAM variable */ | |
158 | #define NVRAM_SOFTWARE_VERSION "1" | |
159 | ||
160 | #define NVRAM_MAGIC 0x48534C46 /* 'FLSH' */ | |
161 | #define NVRAM_CLEAR_MAGIC 0x0 | |
162 | #define NVRAM_INVALID_MAGIC 0xFFFFFFFF | |
163 | #define NVRAM_VERSION 1 | |
164 | #define NVRAM_HEADER_SIZE 20 | |
165 | #define NVRAM_SPACE 0x8000 | |
166 | ||
167 | #define NVRAM_MAX_VALUE_LEN 255 | |
168 | #define NVRAM_MAX_PARAM_LEN 64 | |
169 | ||
170 | #define NVRAM_CRC_START_POSITION 9 /* magic, len, crc8 to be skipped */ | |
171 | #define NVRAM_CRC_VER_MASK 0xffffff00 /* for crc_ver_init */ | |
172 | ||
173 | #endif /* _bcmnvram_h_ */ |