Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

dev.h 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. /* Pointer to bus information for device. Whatever sets up
  22. * the struct dev must make sure that this points to a buffer
  23. * large enough for the required struct <bus>_device.
  24. */
  25. void *bus;
  26. /* All possible device types */
  27. union {
  28. struct nic nic;
  29. };
  30. };
  31. /*
  32. * Macro to help create a common symbol with enough space for any
  33. * struct <bus>_device.
  34. *
  35. * Use as e.g. DEV_BUS(struct pci_device);
  36. */
  37. #define DEV_BUS(datatype,symbol) datatype symbol __asm__ ( "_dev_bus" );
  38. struct dev_operations {
  39. void ( *disable ) ( struct dev * );
  40. void ( *print_info ) ( struct dev * );
  41. int ( *load_configuration ) ( struct dev * );
  42. int ( *load ) ( struct dev * );
  43. };
  44. struct boot_driver {
  45. char *name;
  46. int (*probe) ( struct dev * );
  47. };
  48. #define BOOT_DRIVER( driver_name, probe_func ) \
  49. static struct boot_driver boot_driver \
  50. __attribute__ ((used,__section__(".boot_drivers"))) = { \
  51. .name = driver_name, \
  52. .probe = probe_func, \
  53. };
  54. /* Functions in dev.c */
  55. extern void print_drivers ( void );
  56. extern int probe ( struct dev *dev );
  57. extern void disable ( struct dev *dev );
  58. static inline void print_info ( struct dev *dev ) {
  59. dev->dev_op->print_info ( dev );
  60. }
  61. static inline int load_configuration ( struct dev *dev ) {
  62. return dev->dev_op->load_configuration ( dev );
  63. }
  64. static inline int load ( struct dev *dev ) {
  65. return dev->dev_op->load ( dev );
  66. }
  67. #endif /* DEV_H */