These changes are the raw update to qemu-2.6.
[kvmfornfv.git] / qemu / roms / ipxe / src / include / ipxe / device.h
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 */
19 struct 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[32];
76         /** Driver name */
77         const char *driver_name;
78         /** Device description */
79         struct device_description desc;
80         /** Devices on the same bus */
81         struct list_head siblings;
82         /** Devices attached to this device */
83         struct list_head children;
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 */
101         struct root_driver *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 ) {
162         device_keep_count++;
163 }
164
165 /**
166  * Allow devices to be removed on shutdown
167  *
168  */
169 static inline void devices_put ( void ) {
170         device_keep_count--;
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 */