[dt] Provide dt_ioremap() to map device registers

Devicetree devices encode register address ranges within the "reg"
property, with the number of cells used for addresses and for sizes
determined by the #address-cells and #size-cells properties of the
immediate parent device.

Record the number of address and size cells for each device, and
provide a dt_ioremap() function to allow drivers to map a specified
range without having to directly handle the "reg" property.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2025-04-15 20:19:17 +01:00
parent 99322fd3b3
commit eeec6442d9
2 changed files with 89 additions and 0 deletions

View File

@@ -21,8 +21,19 @@ struct dt_device {
struct dt_driver *driver;
/** Driver-private data */
void *priv;
/** Number of address cells for child devices */
uint32_t address_cells;
/** Number of size cells for child devices */
uint32_t size_cells;
};
/** Default number of address cells, if not specified */
#define DT_DEFAULT_ADDRESS_CELLS 2
/** Default number of size cells, if not specified */
#define DT_DEFAULT_SIZE_CELLS 1
/** A devicetree driver */
struct dt_driver {
/** Driver name */
@@ -73,4 +84,7 @@ static inline void * dt_get_drvdata ( struct dt_device *dt ) {
return dt->priv;
}
extern void * dt_ioremap ( struct dt_device *dt, unsigned int offset,
unsigned int index, size_t len );
#endif /* _IPXE_DEVTREE_H */