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 /** Devicetree bus type */
73 #define BUS_TYPE_DT 11
74 
75 /** A hardware device */
76 struct device {
77  /** Name */
78  char name[40];
79  /** Driver name */
80  const char *driver_name;
81  /** Device description */
83  /** Devices on the same bus */
85  /** Devices attached to this device */
87  /** Bus device */
88  struct device *parent;
89 };
90 
91 /**
92  * A root device
93  *
94  * Root devices are system buses such as PCI, EISA, etc.
95  *
96  */
97 struct root_device {
98  /** Device chain
99  *
100  * A root device has a NULL parent field.
101  */
102  struct device dev;
103  /** Root device driver */
105  /** Driver-private data */
106  void *priv;
107 };
108 
109 /** A root device driver */
110 struct root_driver {
111  /**
112  * Add root device
113  *
114  * @v rootdev Root device
115  * @ret rc Return status code
116  *
117  * Called from probe_devices() for all root devices in the build.
118  */
119  int ( * probe ) ( struct root_device *rootdev );
120  /**
121  * Remove root device
122  *
123  * @v rootdev Root device
124  *
125  * Called from remove_device() for all successfully-probed
126  * root devices.
127  */
128  void ( * remove ) ( struct root_device *rootdev );
129 };
130 
131 /** Root device table */
132 #define ROOT_DEVICES __table ( struct root_device, "root_devices" )
133 
134 /** Declare a root device */
135 #define __root_device __table_entry ( ROOT_DEVICES, 01 )
136 
137 /**
138  * Set root device driver-private data
139  *
140  * @v rootdev Root device
141  * @v priv Private data
142  */
143 static inline void rootdev_set_drvdata ( struct root_device *rootdev,
144  void *priv ){
145  rootdev->priv = priv;
146 }
147 
148 /**
149  * Get root device driver-private data
150  *
151  * @v rootdev Root device
152  * @ret priv Private data
153  */
154 static inline void * rootdev_get_drvdata ( struct root_device *rootdev ) {
155  return rootdev->priv;
156 }
157 
158 extern int device_keep_count;
159 
160 /**
161  * Prevent devices from being removed on shutdown
162  *
163  */
164 static inline void devices_get ( void ) {
166 }
167 
168 /**
169  * Allow devices to be removed on shutdown
170  *
171  */
172 static inline void devices_put ( void ) {
174 }
175 
176 extern struct device * identify_device ( struct interface *intf );
177 #define identify_device_TYPE( object_type ) \
178  typeof ( struct device * ( object_type ) )
179 
180 #endif /* _IPXE_DEVICE_H */
static void rootdev_set_drvdata(struct root_device *rootdev, void *priv)
Set root device driver-private data.
Definition: device.h:143
static void devices_put(void)
Allow devices to be removed on shutdown.
Definition: device.h:172
unsigned long ioaddr
I/O address.
Definition: device.h:37
void(* remove)(struct root_device *rootdev)
Remove root device.
Definition: device.h:128
char name[40]
Name.
Definition: device.h:78
A root device.
Definition: device.h:97
struct device dev
Device chain.
Definition: device.h:102
void * priv
Driver-private data.
Definition: device.h:106
unsigned int vendor
Vendor ID.
Definition: device.h:31
struct device * parent
Bus device.
Definition: device.h:88
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:76
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
An object interface.
Definition: interface.h:124
unsigned int irq
IRQ.
Definition: device.h:39
struct root_driver * driver
Root device driver.
Definition: device.h:104
static void devices_get(void)
Prevent devices from being removed on shutdown.
Definition: device.h:164
const char * driver_name
Driver name.
Definition: device.h:80
unsigned int location
Location.
Definition: device.h:29
Linked lists.
struct list_head siblings
Devices on the same bus.
Definition: device.h:84
A root device driver.
Definition: device.h:110
int(* probe)(struct root_device *rootdev)
Add root device.
Definition: device.h:119
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:154
static struct tlan_private * priv
Definition: tlan.c:225
unsigned int device
Device ID.
Definition: device.h:33
struct list_head children
Devices attached to this device.
Definition: device.h:86
struct device_description desc
Device description.
Definition: device.h:82
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