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.

dev.h 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #ifndef DEV_H
  2. #define DEV_H
  3. #include "stdint.h"
  4. /* Device types */
  5. #include "nic.h"
  6. /* Need to check the packing of this struct if Etherboot is ported */
  7. struct dev_id {
  8. uint16_t vendor_id;
  9. uint16_t device_id;
  10. uint8_t bus_type;
  11. #define PCI_BUS_TYPE 1
  12. #define ISA_BUS_TYPE 2
  13. #define MCA_BUS_TYPE 3
  14. } __attribute__ ((packed));
  15. /* Dont use sizeof, that will include the padding */
  16. #define DEV_ID_SIZE 8
  17. struct dev {
  18. struct dev_operations *dev_op;
  19. const char *name;
  20. struct dev_id devid; /* device ID string (sent to DHCP server) */
  21. struct boot_driver *driver; /* driver being used for boot */
  22. /* Pointer to bus information for device. Whatever sets up
  23. * the struct dev must make sure that this points to a buffer
  24. * large enough for the required struct <bus>_device.
  25. */
  26. struct bus_device *bus;
  27. /* All possible device types */
  28. union {
  29. struct nic nic;
  30. };
  31. };
  32. /*
  33. * Macro to help create a common symbol with enough space for any
  34. * struct <bus>_device.
  35. *
  36. * Use as e.g. DEV_BUS(struct pci_device);
  37. */
  38. #define DEV_BUS(datatype,symbol) datatype symbol __asm__ ( "_dev_bus" );
  39. struct dev_operations {
  40. void ( *disable ) ( struct dev * );
  41. void ( *print_info ) ( struct dev * );
  42. int ( *load_configuration ) ( struct dev * );
  43. int ( *load ) ( struct dev * );
  44. };
  45. /*
  46. * Table to describe a bootable device driver. See comments in dev.c
  47. * for an explanation.
  48. *
  49. */
  50. struct bus_device {};
  51. struct bus_driver {};
  52. struct boot_driver {
  53. char *name;
  54. struct bus_device * ( *find_bus_boot_device ) ( struct dev *dev,
  55. struct bus_driver *driver );
  56. struct bus_driver *bus_driver;
  57. int ( *probe ) ( struct dev *dev, struct bus_device *bus_device );
  58. };
  59. #define BOOT_DRIVER( _name, _find_bus_boot_device, _bus_driver, _probe ) \
  60. static struct boot_driver boot_ ## _bus_driver \
  61. __attribute__ ((used,__section__(".boot_drivers"))) = { \
  62. .name = _name, \
  63. .find_bus_boot_device = ( void * ) _find_bus_boot_device, \
  64. .bus_driver = ( void * ) &_bus_driver, \
  65. .probe = ( void * ) _probe, \
  66. };
  67. /* Functions in dev.c */
  68. extern void print_drivers ( void );
  69. extern int find_boot_device ( struct dev *dev );
  70. extern int probe ( struct dev *dev );
  71. extern void disable ( struct dev *dev );
  72. static inline void print_info ( struct dev *dev ) {
  73. dev->dev_op->print_info ( dev );
  74. }
  75. static inline int load_configuration ( struct dev *dev ) {
  76. return dev->dev_op->load_configuration ( dev );
  77. }
  78. static inline int load ( struct dev *dev ) {
  79. return dev->dev_op->load ( dev );
  80. }
  81. #endif /* DEV_H */