macio.h 3.7 KB

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