iPXE
device.h
Go to the documentation of this file.
00001 #ifndef _IPXE_DEVICE_H
00002 #define _IPXE_DEVICE_H
00003 
00004 /**
00005  * @file
00006  *
00007  * Device model
00008  *
00009  */
00010 
00011 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00012 
00013 #include <ipxe/list.h>
00014 #include <ipxe/tables.h>
00015 
00016 struct interface;
00017 
00018 /** A hardware device description */
00019 struct device_description {
00020         /** Bus type
00021          *
00022          * This must be a BUS_TYPE_XXX constant.
00023          */
00024         unsigned int bus_type;
00025         /** Location
00026          *
00027          * The interpretation of this field is bus-type-specific.
00028          */
00029         unsigned int location;
00030         /** Vendor ID */
00031         unsigned int vendor;
00032         /** Device ID */
00033         unsigned int device;
00034         /** Device class */
00035         unsigned long class;
00036         /** I/O address */
00037         unsigned long ioaddr;
00038         /** IRQ */
00039         unsigned int irq;
00040 };
00041 
00042 /** PCI bus type */
00043 #define BUS_TYPE_PCI 1
00044 
00045 /** ISAPnP bus type */
00046 #define BUS_TYPE_ISAPNP 2
00047 
00048 /** EISA bus type */
00049 #define BUS_TYPE_EISA 3
00050 
00051 /** MCA bus type */
00052 #define BUS_TYPE_MCA 4
00053 
00054 /** ISA bus type */
00055 #define BUS_TYPE_ISA 5
00056 
00057 /** TAP bus type */
00058 #define BUS_TYPE_TAP 6
00059 
00060 /** EFI bus type */
00061 #define BUS_TYPE_EFI 7
00062 
00063 /** Xen bus type */
00064 #define BUS_TYPE_XEN 8
00065 
00066 /** Hyper-V bus type */
00067 #define BUS_TYPE_HV 9
00068 
00069 /** USB bus type */
00070 #define BUS_TYPE_USB 10
00071 
00072 /** A hardware device */
00073 struct device {
00074         /** Name */
00075         char name[40];
00076         /** Driver name */
00077         const char *driver_name;
00078         /** Device description */
00079         struct device_description desc;
00080         /** Devices on the same bus */
00081         struct list_head siblings;
00082         /** Devices attached to this device */
00083         struct list_head children;
00084         /** Bus device */
00085         struct device *parent;
00086 };
00087 
00088 /**
00089  * A root device
00090  *
00091  * Root devices are system buses such as PCI, EISA, etc.
00092  *
00093  */
00094 struct root_device {
00095         /** Device chain
00096          *
00097          * A root device has a NULL parent field.
00098          */
00099         struct device dev;
00100         /** Root device driver */
00101         struct root_driver *driver;
00102         /** Driver-private data */
00103         void *priv;
00104 };
00105 
00106 /** A root device driver */
00107 struct root_driver {
00108         /**
00109          * Add root device
00110          *
00111          * @v rootdev   Root device
00112          * @ret rc      Return status code
00113          *
00114          * Called from probe_devices() for all root devices in the build.
00115          */
00116         int ( * probe ) ( struct root_device *rootdev );
00117         /**
00118          * Remove root device
00119          *
00120          * @v rootdev   Root device
00121          *
00122          * Called from remove_device() for all successfully-probed
00123          * root devices.
00124          */
00125         void ( * remove ) ( struct root_device *rootdev );
00126 };
00127 
00128 /** Root device table */
00129 #define ROOT_DEVICES __table ( struct root_device, "root_devices" )
00130 
00131 /** Declare a root device */
00132 #define __root_device __table_entry ( ROOT_DEVICES, 01 )
00133 
00134 /**
00135  * Set root device driver-private data
00136  *
00137  * @v rootdev           Root device
00138  * @v priv              Private data
00139  */
00140 static inline void rootdev_set_drvdata ( struct root_device *rootdev,
00141                                          void *priv ){
00142         rootdev->priv = priv;
00143 }
00144 
00145 /**
00146  * Get root device driver-private data
00147  *
00148  * @v rootdev           Root device
00149  * @ret priv            Private data
00150  */
00151 static inline void * rootdev_get_drvdata ( struct root_device *rootdev ) {
00152         return rootdev->priv;
00153 }
00154 
00155 extern int device_keep_count;
00156 
00157 /**
00158  * Prevent devices from being removed on shutdown
00159  *
00160  */
00161 static inline void devices_get ( void ) {
00162         device_keep_count++;
00163 }
00164 
00165 /**
00166  * Allow devices to be removed on shutdown
00167  *
00168  */
00169 static inline void devices_put ( void ) {
00170         device_keep_count--;
00171 }
00172 
00173 extern struct device * identify_device ( struct interface *intf );
00174 #define identify_device_TYPE( object_type ) \
00175         typeof ( struct device * ( object_type ) )
00176 
00177 #endif /* _IPXE_DEVICE_H */