macio.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #ifndef __MACIO_ASIC_H__
  2. #define __MACIO_ASIC_H__
  3. #ifdef __KERNEL__
  4. #include <asm/of_device.h>
  5. extern struct bus_type macio_bus_type;
  6. /* MacIO device driver is defined later */
  7. struct macio_driver;
  8. struct macio_chip;
  9. #define MACIO_DEV_COUNT_RESOURCES 8
  10. #define MACIO_DEV_COUNT_IRQS 8
  11. /*
  12. * the macio_bus structure is used to describe a "virtual" bus
  13. * within a MacIO ASIC. It's typically provided by a macio_pci_asic
  14. * PCI device, but could be provided differently as well (nubus
  15. * machines using a fake OF tree).
  16. *
  17. * The pdev field can be NULL on non-PCI machines
  18. */
  19. struct macio_bus
  20. {
  21. struct macio_chip *chip; /* macio_chip (private use) */
  22. int index; /* macio chip index in system */
  23. #ifdef CONFIG_PCI
  24. struct pci_dev *pdev; /* PCI device hosting this bus */
  25. #endif
  26. };
  27. /*
  28. * the macio_dev structure is used to describe a device
  29. * within an Apple MacIO ASIC.
  30. */
  31. struct macio_dev
  32. {
  33. struct macio_bus *bus; /* macio bus this device is on */
  34. struct macio_dev *media_bay; /* Device is part of a media bay */
  35. struct of_device ofdev;
  36. int n_resources;
  37. struct resource resource[MACIO_DEV_COUNT_RESOURCES];
  38. int n_interrupts;
  39. struct resource interrupt[MACIO_DEV_COUNT_IRQS];
  40. };
  41. #define to_macio_device(d) container_of(d, struct macio_dev, ofdev.dev)
  42. #define of_to_macio_device(d) container_of(d, struct macio_dev, ofdev)
  43. extern struct macio_dev *macio_dev_get(struct macio_dev *dev);
  44. extern void macio_dev_put(struct macio_dev *dev);
  45. /*
  46. * Accessors to resources & interrupts and other device
  47. * fields
  48. */
  49. static inline int macio_resource_count(struct macio_dev *dev)
  50. {
  51. return dev->n_resources;
  52. }
  53. static inline unsigned long macio_resource_start(struct macio_dev *dev, int resource_no)
  54. {
  55. return dev->resource[resource_no].start;
  56. }
  57. static inline unsigned long macio_resource_end(struct macio_dev *dev, int resource_no)
  58. {
  59. return dev->resource[resource_no].end;
  60. }
  61. static inline unsigned long macio_resource_len(struct macio_dev *dev, int resource_no)
  62. {
  63. struct resource *res = &dev->resource[resource_no];
  64. if (res->start == 0 || res->end == 0 || res->end < res->start)
  65. return 0;
  66. return res->end - res->start + 1;
  67. }
  68. extern int macio_request_resource(struct macio_dev *dev, int resource_no, const char *name);
  69. extern void macio_release_resource(struct macio_dev *dev, int resource_no);
  70. extern int macio_request_resources(struct macio_dev *dev, const char *name);
  71. extern void macio_release_resources(struct macio_dev *dev);
  72. static inline int macio_irq_count(struct macio_dev *dev)
  73. {
  74. return dev->n_interrupts;
  75. }
  76. static inline int macio_irq(struct macio_dev *dev, int irq_no)
  77. {
  78. return dev->interrupt[irq_no].start;
  79. }
  80. static inline void macio_set_drvdata(struct macio_dev *dev, void *data)
  81. {
  82. dev_set_drvdata(&dev->ofdev.dev, data);
  83. }
  84. static inline void* macio_get_drvdata(struct macio_dev *dev)
  85. {
  86. return dev_get_drvdata(&dev->ofdev.dev);
  87. }
  88. static inline struct device_node *macio_get_of_node(struct macio_dev *mdev)
  89. {
  90. return mdev->ofdev.node;
  91. }
  92. #ifdef CONFIG_PCI
  93. static inline struct pci_dev *macio_get_pci_dev(struct macio_dev *mdev)
  94. {
  95. return mdev->bus->pdev;
  96. }
  97. #endif
  98. /*
  99. * A driver for a mac-io chip based device
  100. */
  101. struct macio_driver
  102. {
  103. char *name;
  104. struct of_device_id *match_table;
  105. struct module *owner;
  106. int (*probe)(struct macio_dev* dev, const struct of_device_id *match);
  107. int (*remove)(struct macio_dev* dev);
  108. int (*suspend)(struct macio_dev* dev, pm_message_t state);
  109. int (*resume)(struct macio_dev* dev);
  110. int (*shutdown)(struct macio_dev* dev);
  111. struct device_driver driver;
  112. };
  113. #define to_macio_driver(drv) container_of(drv,struct macio_driver, driver)
  114. extern int macio_register_driver(struct macio_driver *);
  115. extern void macio_unregister_driver(struct macio_driver *);
  116. #endif /* __KERNEL__ */
  117. #endif /* __MACIO_ASIC_H__ */