iPXE
device.h
Go to the documentation of this file.
1 #ifndef _IPXE_DEVICE_H
2 #define _IPXE_DEVICE_H
3 
4 /**
5  * @file
6  *
7  * Device model
8  *
9  */
10 
11 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
12 
13 #include <ipxe/list.h>
14 #include <ipxe/tables.h>
15 
16 struct interface;
17 
18 /** A hardware device description */
20  /** Bus type
21  *
22  * This must be a BUS_TYPE_XXX constant.
23  */
24  unsigned int bus_type;
25  /** Location
26  *
27  * The interpretation of this field is bus-type-specific.
28  */
29  unsigned int location;
30  /** Vendor ID */
31  unsigned int vendor;
32  /** Device ID */
33  unsigned int device;
34  /** Device class */
35  unsigned long class;
36  /** I/O address */
37  unsigned long ioaddr;
38  /** IRQ */
39  unsigned int irq;
40 };
41 
42 /** PCI bus type */
43 #define BUS_TYPE_PCI 1
44 
45 /** ISAPnP bus type */
46 #define BUS_TYPE_ISAPNP 2
47 
48 /** EISA bus type */
49 #define BUS_TYPE_EISA 3
50 
51 /** MCA bus type */
52 #define BUS_TYPE_MCA 4
53 
54 /** ISA bus type */
55 #define BUS_TYPE_ISA 5
56 
57 /** TAP bus type */
58 #define BUS_TYPE_TAP 6
59 
60 /** EFI bus type */
61 #define BUS_TYPE_EFI 7
62 
63 /** Xen bus type */
64 #define BUS_TYPE_XEN 8
65 
66 /** Hyper-V bus type */
67 #define BUS_TYPE_HV 9
68 
69 /** USB bus type */
70 #define BUS_TYPE_USB 10
71 
72 /** A hardware device */
73 struct device {
74  /** Name */
75  char name[40];
76  /** Driver name */
77  const char *driver_name;
78  /** Device description */
80  /** Devices on the same bus */
82  /** Devices attached to this device */
84  /** Bus device */
85  struct device *parent;
86 };
87 
88 /**
89  * A root device
90  *
91  * Root devices are system buses such as PCI, EISA, etc.
92  *
93  */
94 struct root_device {
95  /** Device chain
96  *
97  * A root device has a NULL parent field.
98  */
99  struct device dev;
100  /** Root device driver */
102  /** Driver-private data */
103  void *priv;
104 };
105 
106 /** A root device driver */
107 struct root_driver {
108  /**
109  * Add root device
110  *
111  * @v rootdev Root device
112  * @ret rc Return status code
113  *
114  * Called from probe_devices() for all root devices in the build.
115  */
116  int ( * probe ) ( struct root_device *rootdev );
117  /**
118  * Remove root device
119  *
120  * @v rootdev Root device
121  *
122  * Called from remove_device() for all successfully-probed
123  * root devices.
124  */
125  void ( * remove ) ( struct root_device *rootdev );
126 };
127 
128 /** Root device table */
129 #define ROOT_DEVICES __table ( struct root_device, "root_devices" )
130 
131 /** Declare a root device */
132 #define __root_device __table_entry ( ROOT_DEVICES, 01 )
133 
134 /**
135  * Set root device driver-private data
136  *
137  * @v rootdev Root device
138  * @v priv Private data
139  */
140 static inline void rootdev_set_drvdata ( struct root_device *rootdev,
141  void *priv ){
142  rootdev->priv = priv;
143 }
144 
145 /**
146  * Get root device driver-private data
147  *
148  * @v rootdev Root device
149  * @ret priv Private data
150  */
151 static inline void * rootdev_get_drvdata ( struct root_device *rootdev ) {
152  return rootdev->priv;
153 }
154 
155 extern int device_keep_count;
156 
157 /**
158  * Prevent devices from being removed on shutdown
159  *
160  */
161 static inline void devices_get ( void ) {
163 }
164 
165 /**
166  * Allow devices to be removed on shutdown
167  *
168  */
169 static inline void devices_put ( void ) {
171 }
172 
173 extern struct device * identify_device ( struct interface *intf );
174 #define identify_device_TYPE( object_type ) \
175  typeof ( struct device * ( object_type ) )
176 
177 #endif /* _IPXE_DEVICE_H */
static void rootdev_set_drvdata(struct root_device *rootdev, void *priv)
Set root device driver-private data.
Definition: device.h:140
static void devices_put(void)
Allow devices to be removed on shutdown.
Definition: device.h:169
unsigned long ioaddr
I/O address.
Definition: device.h:37
void(* remove)(struct root_device *rootdev)
Remove root device.
Definition: device.h:125
char name[40]
Name.
Definition: device.h:75
A root device.
Definition: device.h:94
struct device dev
Device chain.
Definition: device.h:99
void * priv
Driver-private data.
Definition: device.h:103
unsigned int vendor
Vendor ID.
Definition: device.h:31
struct device * parent
Bus device.
Definition: device.h:85
A doubly-linked list entry (or list head)
Definition: list.h:18
A hardware device description.
Definition: device.h:19
A hardware device.
Definition: device.h:73
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
An object interface.
Definition: interface.h:109
unsigned int irq
IRQ.
Definition: device.h:39
struct root_driver * driver
Root device driver.
Definition: device.h:101
static void devices_get(void)
Prevent devices from being removed on shutdown.
Definition: device.h:161
const char * driver_name
Driver name.
Definition: device.h:77
unsigned int location
Location.
Definition: device.h:29
Linked lists.
struct list_head siblings
Devices on the same bus.
Definition: device.h:81
A root device driver.
Definition: device.h:107
int(* probe)(struct root_device *rootdev)
Add root device.
Definition: device.h:116
unsigned int bus_type
Bus type.
Definition: device.h:24
static void * rootdev_get_drvdata(struct root_device *rootdev)
Get root device driver-private data.
Definition: device.h:151
static struct tlan_private * priv
Definition: tlan.c:224
unsigned int device
Device ID.
Definition: device.h:33
struct list_head children
Devices attached to this device.
Definition: device.h:83
struct device_description desc
Device description.
Definition: device.h:79
Linker tables.
struct device * identify_device(struct interface *intf)
Identify a device behind an interface.
Definition: device.c:125
int device_keep_count
Device removal inhibition counter.
Definition: device.c:44