mirror of
https://github.com/ipxe/ipxe
synced 2026-01-24 21:24:47 +03:00
[dt] Add basic concept of a devicetree bus
Add a basic model for devices instantiated by parsing the system flattened device tree, with drivers matched via the "compatible" property for any non-root node. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -69,6 +69,9 @@ struct device_description {
|
||||
/** USB bus type */
|
||||
#define BUS_TYPE_USB 10
|
||||
|
||||
/** Devicetree bus type */
|
||||
#define BUS_TYPE_DT 11
|
||||
|
||||
/** A hardware device */
|
||||
struct device {
|
||||
/** Name */
|
||||
|
||||
76
src/include/ipxe/devtree.h
Normal file
76
src/include/ipxe/devtree.h
Normal file
@@ -0,0 +1,76 @@
|
||||
#ifndef _IPXE_DEVTREE_H
|
||||
#define _IPXE_DEVTREE_H
|
||||
|
||||
/** @file
|
||||
*
|
||||
* Devicetree bus
|
||||
*
|
||||
*/
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
|
||||
#include <ipxe/device.h>
|
||||
|
||||
/** A devicetree device */
|
||||
struct dt_device {
|
||||
/** Generic device */
|
||||
struct device dev;
|
||||
/** Device path */
|
||||
const char *path;
|
||||
/** Driver for this device */
|
||||
struct dt_driver *driver;
|
||||
/** Driver-private data */
|
||||
void *priv;
|
||||
};
|
||||
|
||||
/** A devicetree driver */
|
||||
struct dt_driver {
|
||||
/** Driver name */
|
||||
const char *name;
|
||||
/** Compatible programming model identifiers */
|
||||
const char **ids;
|
||||
/** Number of compatible programming model identifiers */
|
||||
unsigned int id_count;
|
||||
/**
|
||||
* Probe device
|
||||
*
|
||||
* @v dt Devicetree device
|
||||
* @v offset Starting node offset
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int ( * probe ) ( struct dt_device *dt, unsigned int offset );
|
||||
/**
|
||||
* Remove device
|
||||
*
|
||||
* @v dt Devicetree device
|
||||
*/
|
||||
void ( * remove ) ( struct dt_device *dt );
|
||||
};
|
||||
|
||||
/** Devicetree driver table */
|
||||
#define DT_DRIVERS __table ( struct dt_driver, "dt_drivers" )
|
||||
|
||||
/** Declare a devicetree driver */
|
||||
#define __dt_driver __table_entry ( DT_DRIVERS, 01 )
|
||||
|
||||
/**
|
||||
* Set devicetree driver-private data
|
||||
*
|
||||
* @v dt Devicetree device
|
||||
* @v priv Private data
|
||||
*/
|
||||
static inline void dt_set_drvdata ( struct dt_device *dt, void *priv ) {
|
||||
dt->priv = priv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get devicetree driver-private data
|
||||
*
|
||||
* @v dt Devicetree device
|
||||
* @ret priv Private data
|
||||
*/
|
||||
static inline void * dt_get_drvdata ( struct dt_device *dt ) {
|
||||
return dt->priv;
|
||||
}
|
||||
|
||||
#endif /* _IPXE_DEVTREE_H */
|
||||
@@ -231,6 +231,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
#define ERRFILE_aqc1xx ( ERRFILE_DRIVER | 0x00d70000 )
|
||||
#define ERRFILE_atl_hw ( ERRFILE_DRIVER | 0x00d80000 )
|
||||
#define ERRFILE_atl2_hw ( ERRFILE_DRIVER | 0x00d90000 )
|
||||
#define ERRFILE_devtree ( ERRFILE_DRIVER | 0x00da0000 )
|
||||
|
||||
#define ERRFILE_aoe ( ERRFILE_NET | 0x00000000 )
|
||||
#define ERRFILE_arp ( ERRFILE_NET | 0x00010000 )
|
||||
|
||||
Reference in New Issue
Block a user