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