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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #ifndef DEV_H
  2. #define DEV_H
  3. #include "stdint.h"
  4. #include "nic.h"
  5. #include "pci.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. } __attribute__ ((packed));
  14. /* Dont use sizeof, that will include the padding */
  15. #define DEV_ID_SIZE 8
  16. struct dev {
  17. struct dev_operations *dev_op;
  18. const char *name;
  19. struct dev_id devid; /* device ID string (sent to DHCP server) */
  20. /* All possible bus types */
  21. union {
  22. struct pci_device pci;
  23. };
  24. /* All possible device types */
  25. union {
  26. struct nic nic;
  27. };
  28. };
  29. struct dev_operations {
  30. void ( *disable ) ( struct dev * );
  31. void ( *print_info ) ( struct dev * );
  32. int ( *load_configuration ) ( struct dev * );
  33. int ( *load ) ( struct dev * );
  34. };
  35. struct boot_driver {
  36. char *name;
  37. int (*probe) ( struct dev * );
  38. };
  39. #define BOOT_DRIVER( driver_name, probe_func ) \
  40. static struct boot_driver boot_driver \
  41. __attribute__ ((used,__section__(".boot_drivers"))) = { \
  42. .name = driver_name, \
  43. .probe = probe_func, \
  44. };
  45. /* Functions in dev.c */
  46. extern void print_drivers ( void );
  47. extern int probe ( struct dev *dev );
  48. extern void disable ( struct dev *dev );
  49. static inline void print_info ( struct dev *dev ) {
  50. dev->dev_op->print_info ( dev );
  51. }
  52. static inline int load_configuration ( struct dev *dev ) {
  53. return dev->dev_op->load_configuration ( dev );
  54. }
  55. static inline int load ( struct dev *dev ) {
  56. return dev->dev_op->load ( dev );
  57. }
  58. #endif /* DEV_H */