macio.h 3.9 KB

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