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

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