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