You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

device.h 3.2KB

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