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.1KB

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