Changeset View
Changeset View
Standalone View
Standalone View
sys/contrib/libfdt/libfdt.h
Show First 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | #define FDT_ERR_BADPHANDLE 6 | ||||
* not permitted. */ | * not permitted. */ | ||||
#define FDT_ERR_BADSTATE 7 | #define FDT_ERR_BADSTATE 7 | ||||
/* FDT_ERR_BADSTATE: Function was passed an incomplete device | /* FDT_ERR_BADSTATE: Function was passed an incomplete device | ||||
* tree created by the sequential-write functions, which is | * tree created by the sequential-write functions, which is | ||||
* not sufficiently complete for the requested operation. */ | * not sufficiently complete for the requested operation. */ | ||||
/* Error codes: codes for bad device tree blobs */ | /* Error codes: codes for bad device tree blobs */ | ||||
#define FDT_ERR_TRUNCATED 8 | #define FDT_ERR_TRUNCATED 8 | ||||
/* FDT_ERR_TRUNCATED: Structure block of the given device tree | /* FDT_ERR_TRUNCATED: FDT or a sub-block is improperly | ||||
* ends without an FDT_END tag. */ | * terminated (overflows, goes outside allowed bounds, or | ||||
* isn't properly terminated). */ | |||||
#define FDT_ERR_BADMAGIC 9 | #define FDT_ERR_BADMAGIC 9 | ||||
/* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a | /* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a | ||||
* device tree at all - it is missing the flattened device | * device tree at all - it is missing the flattened device | ||||
* tree magic number. */ | * tree magic number. */ | ||||
#define FDT_ERR_BADVERSION 10 | #define FDT_ERR_BADVERSION 10 | ||||
/* FDT_ERR_BADVERSION: Given device tree has a version which | /* FDT_ERR_BADVERSION: Given device tree has a version which | ||||
* can't be handled by the requested operation. For | * can't be handled by the requested operation. For | ||||
* read-write functions, this may mean that fdt_open_into() is | * read-write functions, this may mean that fdt_open_into() is | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
#endif | #endif | ||||
static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen) | static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen) | ||||
{ | { | ||||
return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen); | return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen); | ||||
} | } | ||||
uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset); | uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset); | ||||
/* | |||||
* Alignment helpers: | |||||
* These helpers access words from a device tree blob. They're | |||||
* built to work even with unaligned pointers on platforms (ike | |||||
* ARM) that don't like unaligned loads and stores | |||||
*/ | |||||
static inline uint32_t fdt32_ld(const fdt32_t *p) | |||||
{ | |||||
const uint8_t *bp = (const uint8_t *)p; | |||||
return ((uint32_t)bp[0] << 24) | |||||
| ((uint32_t)bp[1] << 16) | |||||
| ((uint32_t)bp[2] << 8) | |||||
| bp[3]; | |||||
} | |||||
static inline uint64_t fdt64_ld(const fdt64_t *p) | |||||
{ | |||||
const uint8_t *bp = (const uint8_t *)p; | |||||
return ((uint64_t)bp[0] << 56) | |||||
| ((uint64_t)bp[1] << 48) | |||||
| ((uint64_t)bp[2] << 40) | |||||
| ((uint64_t)bp[3] << 32) | |||||
| ((uint64_t)bp[4] << 24) | |||||
| ((uint64_t)bp[5] << 16) | |||||
| ((uint64_t)bp[6] << 8) | |||||
| bp[7]; | |||||
} | |||||
/**********************************************************************/ | /**********************************************************************/ | ||||
/* Traversal functions */ | /* Traversal functions */ | ||||
/**********************************************************************/ | /**********************************************************************/ | ||||
int fdt_next_node(const void *fdt, int offset, int *depth); | int fdt_next_node(const void *fdt, int offset, int *depth); | ||||
/** | /** | ||||
* fdt_first_subnode() - get offset of first direct subnode | * fdt_first_subnode() - get offset of first direct subnode | ||||
Show All 26 Lines | |||||
* | * | ||||
* This is actually a wrapper around a for loop and would be used like so: | * This is actually a wrapper around a for loop and would be used like so: | ||||
* | * | ||||
* fdt_for_each_subnode(node, fdt, parent) { | * fdt_for_each_subnode(node, fdt, parent) { | ||||
* Use node | * Use node | ||||
* ... | * ... | ||||
* } | * } | ||||
* | * | ||||
* if ((node < 0) && (node != -FDT_ERR_NOT_FOUND)) { | * if ((node < 0) && (node != -FDT_ERR_NOTFOUND)) { | ||||
* Error handling | * Error handling | ||||
* } | * } | ||||
* | * | ||||
* Note that this is implemented as a macro and @node is used as | * Note that this is implemented as a macro and @node is used as | ||||
* iterator in the loop. The parent variable be constant or even a | * iterator in the loop. The parent variable be constant or even a | ||||
* literal. | * literal. | ||||
* | * | ||||
*/ | */ | ||||
#define fdt_for_each_subnode(node, fdt, parent) \ | #define fdt_for_each_subnode(node, fdt, parent) \ | ||||
for (node = fdt_first_subnode(fdt, parent); \ | for (node = fdt_first_subnode(fdt, parent); \ | ||||
node >= 0; \ | node >= 0; \ | ||||
node = fdt_next_subnode(fdt, node)) | node = fdt_next_subnode(fdt, node)) | ||||
/**********************************************************************/ | /**********************************************************************/ | ||||
/* General functions */ | /* General functions */ | ||||
/**********************************************************************/ | /**********************************************************************/ | ||||
#define fdt_get_header(fdt, field) \ | #define fdt_get_header(fdt, field) \ | ||||
(fdt32_to_cpu(((const struct fdt_header *)(fdt))->field)) | (fdt32_ld(&((const struct fdt_header *)(fdt))->field)) | ||||
#define fdt_magic(fdt) (fdt_get_header(fdt, magic)) | #define fdt_magic(fdt) (fdt_get_header(fdt, magic)) | ||||
#define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize)) | #define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize)) | ||||
#define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct)) | #define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct)) | ||||
#define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings)) | #define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings)) | ||||
#define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap)) | #define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap)) | ||||
#define fdt_version(fdt) (fdt_get_header(fdt, version)) | #define fdt_version(fdt) (fdt_get_header(fdt, version)) | ||||
#define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version)) | #define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version)) | ||||
#define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys)) | #define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys)) | ||||
Show All 14 Lines | |||||
fdt_set_hdr_(version); | fdt_set_hdr_(version); | ||||
fdt_set_hdr_(last_comp_version); | fdt_set_hdr_(last_comp_version); | ||||
fdt_set_hdr_(boot_cpuid_phys); | fdt_set_hdr_(boot_cpuid_phys); | ||||
fdt_set_hdr_(size_dt_strings); | fdt_set_hdr_(size_dt_strings); | ||||
fdt_set_hdr_(size_dt_struct); | fdt_set_hdr_(size_dt_struct); | ||||
#undef fdt_set_hdr_ | #undef fdt_set_hdr_ | ||||
/** | /** | ||||
* fdt_check_header - sanity check a device tree or possible device tree | * fdt_header_size - return the size of the tree's header | ||||
* @fdt: pointer to a flattened device tree | |||||
*/ | |||||
size_t fdt_header_size_(uint32_t version); | |||||
static inline size_t fdt_header_size(const void *fdt) | |||||
{ | |||||
return fdt_header_size_(fdt_version(fdt)); | |||||
} | |||||
/** | |||||
* fdt_check_header - sanity check a device tree header | |||||
* @fdt: pointer to data which might be a flattened device tree | * @fdt: pointer to data which might be a flattened device tree | ||||
* | * | ||||
* fdt_check_header() checks that the given buffer contains what | * fdt_check_header() checks that the given buffer contains what | ||||
* appears to be a flattened device tree with sane information in its | * appears to be a flattened device tree, and that the header contains | ||||
* header. | * valid information (to the extent that can be determined from the | ||||
* header alone). | |||||
* | * | ||||
* returns: | * returns: | ||||
* 0, if the buffer appears to contain a valid device tree | * 0, if the buffer appears to contain a valid device tree | ||||
* -FDT_ERR_BADMAGIC, | * -FDT_ERR_BADMAGIC, | ||||
* -FDT_ERR_BADVERSION, | * -FDT_ERR_BADVERSION, | ||||
* -FDT_ERR_BADSTATE, standard meanings, as above | * -FDT_ERR_BADSTATE, | ||||
* -FDT_ERR_TRUNCATED, standard meanings, as above | |||||
*/ | */ | ||||
int fdt_check_header(const void *fdt); | int fdt_check_header(const void *fdt); | ||||
/** | /** | ||||
* fdt_move - move a device tree around in memory | * fdt_move - move a device tree around in memory | ||||
* @fdt: pointer to the device tree to move | * @fdt: pointer to the device tree to move | ||||
* @buf: pointer to memory where the device is to be moved | * @buf: pointer to memory where the device is to be moved | ||||
* @bufsize: size of the memory space at buf | * @bufsize: size of the memory space at buf | ||||
Show All 12 Lines | |||||
* -FDT_ERR_BADSTATE, standard meanings | * -FDT_ERR_BADSTATE, standard meanings | ||||
*/ | */ | ||||
int fdt_move(const void *fdt, void *buf, int bufsize); | int fdt_move(const void *fdt, void *buf, int bufsize); | ||||
/**********************************************************************/ | /**********************************************************************/ | ||||
/* Read-only functions */ | /* Read-only functions */ | ||||
/**********************************************************************/ | /**********************************************************************/ | ||||
int fdt_check_full(const void *fdt, size_t bufsize); | |||||
/** | /** | ||||
* fdt_get_string - retrieve a string from the strings block of a device tree | |||||
* @fdt: pointer to the device tree blob | |||||
* @stroffset: offset of the string within the strings block (native endian) | |||||
* @lenp: optional pointer to return the string's length | |||||
* | |||||
* fdt_get_string() retrieves a pointer to a single string from the | |||||
* strings block of the device tree blob at fdt, and optionally also | |||||
* returns the string's length in *lenp. | |||||
* | |||||
* returns: | |||||
* a pointer to the string, on success | |||||
* NULL, if stroffset is out of bounds, or doesn't point to a valid string | |||||
*/ | |||||
const char *fdt_get_string(const void *fdt, int stroffset, int *lenp); | |||||
/** | |||||
* fdt_string - retrieve a string from the strings block of a device tree | * fdt_string - retrieve a string from the strings block of a device tree | ||||
* @fdt: pointer to the device tree blob | * @fdt: pointer to the device tree blob | ||||
* @stroffset: offset of the string within the strings block (native endian) | * @stroffset: offset of the string within the strings block (native endian) | ||||
* | * | ||||
* fdt_string() retrieves a pointer to a single string from the | * fdt_string() retrieves a pointer to a single string from the | ||||
* strings block of the device tree blob at fdt. | * strings block of the device tree blob at fdt. | ||||
* | * | ||||
* returns: | * returns: | ||||
* a pointer to the string, on success | * a pointer to the string, on success | ||||
* NULL, if stroffset is out of bounds | * NULL, if stroffset is out of bounds, or doesn't point to a valid string | ||||
*/ | */ | ||||
const char *fdt_string(const void *fdt, int stroffset); | const char *fdt_string(const void *fdt, int stroffset); | ||||
/** | /** | ||||
* fdt_get_max_phandle - retrieves the highest phandle in a tree | * fdt_get_max_phandle - retrieves the highest phandle in a tree | ||||
* @fdt: pointer to the device tree blob | * @fdt: pointer to the device tree blob | ||||
* | * | ||||
* fdt_get_max_phandle retrieves the highest phandle in the given | * fdt_get_max_phandle retrieves the highest phandle in the given | ||||
▲ Show 20 Lines • Show All 192 Lines • ▼ Show 20 Lines | |||||
* | * | ||||
* This is actually a wrapper around a for loop and would be used like so: | * This is actually a wrapper around a for loop and would be used like so: | ||||
* | * | ||||
* fdt_for_each_property_offset(property, fdt, node) { | * fdt_for_each_property_offset(property, fdt, node) { | ||||
* Use property | * Use property | ||||
* ... | * ... | ||||
* } | * } | ||||
* | * | ||||
* if ((property < 0) && (property != -FDT_ERR_NOT_FOUND)) { | * if ((property < 0) && (property != -FDT_ERR_NOTFOUND)) { | ||||
* Error handling | * Error handling | ||||
* } | * } | ||||
* | * | ||||
* Note that this is implemented as a macro and property is used as | * Note that this is implemented as a macro and property is used as | ||||
* iterator in the loop. The node variable can be constant or even a | * iterator in the loop. The node variable can be constant or even a | ||||
* literal. | * literal. | ||||
*/ | */ | ||||
#define fdt_for_each_property_offset(property, fdt, node) \ | #define fdt_for_each_property_offset(property, fdt, node) \ | ||||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
return (struct fdt_property *)(uintptr_t) | return (struct fdt_property *)(uintptr_t) | ||||
fdt_get_property(fdt, nodeoffset, name, lenp); | fdt_get_property(fdt, nodeoffset, name, lenp); | ||||
} | } | ||||
/** | /** | ||||
* fdt_getprop_by_offset - retrieve the value of a property at a given offset | * fdt_getprop_by_offset - retrieve the value of a property at a given offset | ||||
* @fdt: pointer to the device tree blob | * @fdt: pointer to the device tree blob | ||||
* @ffset: offset of the property to read | * @offset: offset of the property to read | ||||
* @namep: pointer to a string variable (will be overwritten) or NULL | * @namep: pointer to a string variable (will be overwritten) or NULL | ||||
* @lenp: pointer to an integer variable (will be overwritten) or NULL | * @lenp: pointer to an integer variable (will be overwritten) or NULL | ||||
* | * | ||||
* fdt_getprop_by_offset() retrieves a pointer to the value of the | * fdt_getprop_by_offset() retrieves a pointer to the value of the | ||||
* property at structure block offset 'offset' (this will be a pointer | * property at structure block offset 'offset' (this will be a pointer | ||||
* to within the device blob itself, not a copy of the value). If | * to within the device blob itself, not a copy of the value). If | ||||
* lenp is non-NULL, the length of the property value is also | * lenp is non-NULL, the length of the property value is also | ||||
* returned, in the integer pointed to by lenp. If namep is non-NULL, | * returned, in the integer pointed to by lenp. If namep is non-NULL, | ||||
▲ Show 20 Lines • Show All 467 Lines • ▼ Show 20 Lines | |||||
* tree | * tree | ||||
* @fdt: pointer to the device tree blob | * @fdt: pointer to the device tree blob | ||||
* @nodeoffset: offset of the node to find the address range size for | * @nodeoffset: offset of the node to find the address range size for | ||||
* | * | ||||
* When the node has a valid #size-cells property, returns its value. | * When the node has a valid #size-cells property, returns its value. | ||||
* | * | ||||
* returns: | * returns: | ||||
* 0 <= n < FDT_MAX_NCELLS, on success | * 0 <= n < FDT_MAX_NCELLS, on success | ||||
* 2, if the node has no #address-cells property | * 1, if the node has no #size-cells property | ||||
* -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid | * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid | ||||
* #size-cells property | * #size-cells property | ||||
* -FDT_ERR_BADMAGIC, | * -FDT_ERR_BADMAGIC, | ||||
* -FDT_ERR_BADVERSION, | * -FDT_ERR_BADVERSION, | ||||
* -FDT_ERR_BADSTATE, | * -FDT_ERR_BADSTATE, | ||||
* -FDT_ERR_BADSTRUCTURE, | * -FDT_ERR_BADSTRUCTURE, | ||||
* -FDT_ERR_TRUNCATED, standard meanings | * -FDT_ERR_TRUNCATED, standard meanings | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 206 Lines • ▼ Show 20 Lines | static inline int fdt_property_u32(void *fdt, const char *name, uint32_t val) | ||||
fdt32_t tmp = cpu_to_fdt32(val); | fdt32_t tmp = cpu_to_fdt32(val); | ||||
return fdt_property(fdt, name, &tmp, sizeof(tmp)); | return fdt_property(fdt, name, &tmp, sizeof(tmp)); | ||||
} | } | ||||
static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val) | static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val) | ||||
{ | { | ||||
fdt64_t tmp = cpu_to_fdt64(val); | fdt64_t tmp = cpu_to_fdt64(val); | ||||
return fdt_property(fdt, name, &tmp, sizeof(tmp)); | return fdt_property(fdt, name, &tmp, sizeof(tmp)); | ||||
} | } | ||||
#ifndef SWIG /* Not available in Python */ | |||||
static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val) | static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val) | ||||
{ | { | ||||
return fdt_property_u32(fdt, name, val); | return fdt_property_u32(fdt, name, val); | ||||
} | } | ||||
#endif | |||||
/** | /** | ||||
* fdt_property_placeholder - add a new property and return a ptr to its value | * fdt_property_placeholder - add a new property and return a ptr to its value | ||||
* | * | ||||
* @fdt: pointer to the device tree blob | * @fdt: pointer to the device tree blob | ||||
* @name: name of property to add | * @name: name of property to add | ||||
* @len: length of property value in bytes | * @len: length of property value in bytes | ||||
* @valp: returns a pointer to where where the value should be placed | * @valp: returns a pointer to where where the value should be placed | ||||
▲ Show 20 Lines • Show All 575 Lines • Show Last 20 Lines |