Commit aadef0a1bc3db81708471c9d18eb6c756659196f
Committed by
Gerald Van Baren
1 parent
79289c0b5f
Exists in
master
and in
54 other branches
fdt: Add fdtdec_get_uint64 to decode a 64-bit value from a property
It decodes a 64-bit value from a property that is at least 8 bytes long. Signed-off-by: Che-Liang Chiou <clchiou@chromium.org> Signed-off-by: Simon Glass <sjg@chromium.org>
Showing 2 changed files with 28 additions and 0 deletions Side-by-side Diff
include/fdtdec.h
... | ... | @@ -182,6 +182,21 @@ |
182 | 182 | s32 default_val); |
183 | 183 | |
184 | 184 | /** |
185 | + * Look up a 64-bit integer property in a node and return it. The property | |
186 | + * must have at least 8 bytes of data (2 cells). The first two cells are | |
187 | + * concatenated to form a 8 bytes value, where the first cell is top half and | |
188 | + * the second cell is bottom half. | |
189 | + * | |
190 | + * @param blob FDT blob | |
191 | + * @param node node to examine | |
192 | + * @param prop_name name of property to find | |
193 | + * @param default_val default value to return if the property is not found | |
194 | + * @return integer value, if found, or default_val if not | |
195 | + */ | |
196 | +uint64_t fdtdec_get_uint64(const void *blob, int node, const char *prop_name, | |
197 | + uint64_t default_val); | |
198 | + | |
199 | +/** | |
185 | 200 | * Checks whether a node is enabled. |
186 | 201 | * This looks for a 'status' property. If this exists, then returns 1 if |
187 | 202 | * the status is 'ok' and 0 otherwise. If there is no status property, |
lib/fdtdec.c
... | ... | @@ -111,6 +111,19 @@ |
111 | 111 | return default_val; |
112 | 112 | } |
113 | 113 | |
114 | +uint64_t fdtdec_get_uint64(const void *blob, int node, const char *prop_name, | |
115 | + uint64_t default_val) | |
116 | +{ | |
117 | + const uint64_t *cell64; | |
118 | + int length; | |
119 | + | |
120 | + cell64 = fdt_getprop(blob, node, prop_name, &length); | |
121 | + if (!cell64 || length < sizeof(*cell64)) | |
122 | + return default_val; | |
123 | + | |
124 | + return fdt64_to_cpu(*cell64); | |
125 | +} | |
126 | + | |
114 | 127 | int fdtdec_get_is_enabled(const void *blob, int node) |
115 | 128 | { |
116 | 129 | const char *cell; |