mirror of
https://github.com/ipxe/ipxe
synced 2026-02-07 08:02:49 +03:00
[fdt] Use phandle as device location
Consumption of phandles will be in the form of locating a functional device (e.g. a GPIO device, or an I2C device, or a reset controller) by phandle, rather than locating the device tree node to which the phandle refers. Repurpose fdt_phandle() to obtain the phandle value (instead of searching by phandle), and record this value as the bus location within the generic device structure. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -482,57 +482,6 @@ int fdt_alias ( struct fdt *fdt, const char *name, unsigned int *offset ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find node by package handle (phandle)
|
||||
*
|
||||
* @v fdt Device tree
|
||||
* @v phandle Package handle
|
||||
* @v offset Offset to fill in
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int fdt_phandle ( struct fdt *fdt, uint32_t phandle, unsigned int *offset ) {
|
||||
struct fdt_descriptor desc;
|
||||
uint32_t value;
|
||||
int depth;
|
||||
int rc;
|
||||
|
||||
/* Initialise offset */
|
||||
*offset = 0;
|
||||
|
||||
/* Find node with matching phandle */
|
||||
for ( depth = -1 ; ; depth += desc.depth, *offset = desc.next ) {
|
||||
|
||||
/* Describe token */
|
||||
if ( ( rc = fdt_describe ( fdt, *offset, &desc ) ) != 0 ) {
|
||||
DBGC ( fdt, "FDT +%#04x has malformed node: %s\n",
|
||||
*offset, strerror ( rc ) );
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Terminate when we exit the root node */
|
||||
if ( ( depth == 0 ) && ( desc.depth < 0 ) )
|
||||
break;
|
||||
|
||||
/* Ignore non-nodes */
|
||||
if ( ( ! desc.name ) || desc.data )
|
||||
continue;
|
||||
|
||||
/* Check for matching "phandle" or "linux-phandle" property */
|
||||
if ( ( ( ( rc = fdt_u32 ( fdt, *offset, "phandle",
|
||||
&value ) ) == 0 ) ||
|
||||
( ( rc = fdt_u32 ( fdt, *offset, "linux,phandle",
|
||||
&value ) ) == 0 ) ) &&
|
||||
( value == phandle ) ) {
|
||||
DBGC2 ( fdt, "FDT +%#04x has phandle %#02x\n",
|
||||
*offset, phandle );
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
DBGC ( fdt, "FDT has no phandle %#02x\n", phandle );
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find property
|
||||
*
|
||||
@@ -730,6 +679,28 @@ int fdt_u32 ( struct fdt *fdt, unsigned int offset, const char *name,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get package handle (phandle) property
|
||||
*
|
||||
* @v fdt Device tree
|
||||
* @v offset Starting node offset
|
||||
* @ret phandle Package handle, or 0 on error
|
||||
*/
|
||||
uint32_t fdt_phandle ( struct fdt *fdt, unsigned int offset ) {
|
||||
uint32_t phandle;
|
||||
int rc;
|
||||
|
||||
/* Get "phandle" or "linux,phandle" property */
|
||||
if ( ( ( rc = fdt_u32 ( fdt, offset, "phandle", &phandle ) ) == 0 ) ||
|
||||
( ( rc = fdt_u32 ( fdt, offset, "linux,phandle",
|
||||
&phandle ) ) == 0 ) ) {
|
||||
assert ( phandle != 0 );
|
||||
return phandle;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get region cell size specification
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user