mirror of
https://github.com/ipxe/ipxe
synced 2026-02-14 02:31:26 +03:00
[fdt] Provide fdt_reg() for unsized single-entry regions
Many region types (e.g. I2C bus addresses) can only ever contain a single region with no size cells specified. Provide fdt_reg() to reduce boilerplate in this common use case. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -732,6 +732,29 @@ void fdt_reg_cells ( struct fdt *fdt, unsigned int offset,
|
||||
regs->stride = ( regs->address_cells + regs->size_cells );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get parent region cell size specification
|
||||
*
|
||||
* @v fdt Device tree
|
||||
* @v offset Starting node offset
|
||||
* @v regs Region cell size specification to fill in
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int fdt_parent_reg_cells ( struct fdt *fdt, unsigned int offset,
|
||||
struct fdt_reg_cells *regs ) {
|
||||
unsigned int parent;
|
||||
int rc;
|
||||
|
||||
/* Get parent node */
|
||||
if ( ( rc = fdt_parent ( fdt, offset, &parent ) ) != 0 )
|
||||
return rc;
|
||||
|
||||
/* Read #address-cells and #size-cells, if present */
|
||||
fdt_reg_cells ( fdt, parent, regs );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of regions
|
||||
*
|
||||
@@ -806,6 +829,32 @@ int fdt_reg_size ( struct fdt *fdt, unsigned int offset,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get unsized single-entry region address
|
||||
*
|
||||
* @v fdt Device tree
|
||||
* @v offset Starting node offset
|
||||
* @v address Region address to fill in
|
||||
* @ret rc Return status code
|
||||
*
|
||||
* Many region types (e.g. I2C bus addresses) can only ever contain a
|
||||
* single region with no size cells specified.
|
||||
*/
|
||||
int fdt_reg ( struct fdt *fdt, unsigned int offset, uint64_t *region ) {
|
||||
struct fdt_reg_cells regs;
|
||||
int rc;
|
||||
|
||||
/* Get parent region cell size specification */
|
||||
if ( ( rc = fdt_parent_reg_cells ( fdt, offset, ®s ) ) != 0 )
|
||||
return rc;
|
||||
|
||||
/* Get first region address */
|
||||
if ( ( rc = fdt_reg_address ( fdt, offset, ®s, 0, region ) ) != 0 )
|
||||
return rc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get MAC address from property
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user