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 2.5KB

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