Add qemu 2.4.0
[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 );
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 /** A hardware device */
67 struct device {
68         /** Name */
69         char name[16];
70         /** Driver name */
71         const char *driver_name;
72         /** Device description */
73         struct device_description desc;
74         /** Devices on the same bus */
75         struct list_head siblings;
76         /** Devices attached to this device */
77         struct list_head children;
78         /** Bus device */
79         struct device *parent;
80 };
81
82 /**
83  * A root device
84  *
85  * Root devices are system buses such as PCI, EISA, etc.
86  *
87  */
88 struct root_device {
89         /** Device chain
90          *
91          * A root device has a NULL parent field.
92          */
93         struct device dev;
94         /** Root device driver */
95         struct root_driver *driver;
96 };
97
98 /** A root device driver */
99 struct root_driver {
100         /**
101          * Add root device
102          *
103          * @v rootdev   Root device
104          * @ret rc      Return status code
105          *
106          * Called from probe_devices() for all root devices in the build.
107          */
108         int ( * probe ) ( struct root_device *rootdev );
109         /**
110          * Remove root device
111          *
112          * @v rootdev   Root device
113          *
114          * Called from remove_device() for all successfully-probed
115          * root devices.
116          */
117         void ( * remove ) ( struct root_device *rootdev );
118 };
119
120 /** Root device table */
121 #define ROOT_DEVICES __table ( struct root_device, "root_devices" )
122
123 /** Declare a root device */
124 #define __root_device __table_entry ( ROOT_DEVICES, 01 )
125
126 extern int device_keep_count;
127
128 /**
129  * Prevent devices from being removed on shutdown
130  *
131  */
132 static inline void devices_get ( void ) {
133         device_keep_count++;
134 }
135
136 /**
137  * Allow devices to be removed on shutdown
138  *
139  */
140 static inline void devices_put ( void ) {
141         device_keep_count--;
142 }
143
144 extern struct device * identify_device ( struct interface *intf );
145 #define identify_device_TYPE( object_type ) \
146         typeof ( struct device * ( object_type ) )
147
148 #endif /* _IPXE_DEVICE_H */