Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __MACIO_ASIC_H__
0003 #define __MACIO_ASIC_H__
0004 #ifdef __KERNEL__
0005 
0006 #include <linux/of_device.h>
0007 
0008 extern struct bus_type macio_bus_type;
0009 
0010 /* MacIO device driver is defined later */
0011 struct macio_driver;
0012 struct macio_chip;
0013 
0014 #define MACIO_DEV_COUNT_RESOURCES   8
0015 #define MACIO_DEV_COUNT_IRQS        8
0016 
0017 /*
0018  * the macio_bus structure is used to describe a "virtual" bus
0019  * within a MacIO ASIC. It's typically provided by a macio_pci_asic
0020  * PCI device, but could be provided differently as well (nubus
0021  * machines using a fake OF tree).
0022  *
0023  * The pdev field can be NULL on non-PCI machines
0024  */
0025 struct macio_bus
0026 {
0027     struct macio_chip   *chip;      /* macio_chip (private use) */
0028     int         index;      /* macio chip index in system */
0029 #ifdef CONFIG_PCI
0030     struct pci_dev      *pdev;      /* PCI device hosting this bus */
0031 #endif
0032 };
0033 
0034 /*
0035  * the macio_dev structure is used to describe a device
0036  * within an Apple MacIO ASIC.
0037  */
0038 struct macio_dev
0039 {
0040     struct macio_bus    *bus;       /* macio bus this device is on */
0041     struct macio_dev    *media_bay; /* Device is part of a media bay */
0042     struct platform_device  ofdev;
0043     struct device_dma_parameters dma_parms; /* ide needs that */
0044     int         n_resources;
0045     struct resource     resource[MACIO_DEV_COUNT_RESOURCES];
0046     int         n_interrupts;
0047     struct resource     interrupt[MACIO_DEV_COUNT_IRQS];
0048 };
0049 #define to_macio_device(d) container_of(d, struct macio_dev, ofdev.dev)
0050 #define of_to_macio_device(d) container_of(d, struct macio_dev, ofdev)
0051 
0052 extern struct macio_dev *macio_dev_get(struct macio_dev *dev);
0053 extern void macio_dev_put(struct macio_dev *dev);
0054 
0055 /*
0056  * Accessors to resources & interrupts and other device
0057  * fields
0058  */
0059 
0060 static inline int macio_resource_count(struct macio_dev *dev)
0061 {
0062     return dev->n_resources;
0063 }
0064 
0065 static inline unsigned long macio_resource_start(struct macio_dev *dev, int resource_no)
0066 {
0067     return dev->resource[resource_no].start;
0068 }
0069 
0070 static inline unsigned long macio_resource_end(struct macio_dev *dev, int resource_no)
0071 {
0072     return dev->resource[resource_no].end;
0073 }
0074 
0075 static inline unsigned long macio_resource_len(struct macio_dev *dev, int resource_no)
0076 {
0077     struct resource *res = &dev->resource[resource_no];
0078     if (res->start == 0 || res->end == 0 || res->end < res->start)
0079         return 0;
0080     return resource_size(res);
0081 }
0082 
0083 extern int macio_enable_devres(struct macio_dev *dev);
0084 
0085 extern int macio_request_resource(struct macio_dev *dev, int resource_no, const char *name);
0086 extern void macio_release_resource(struct macio_dev *dev, int resource_no);
0087 extern int macio_request_resources(struct macio_dev *dev, const char *name);
0088 extern void macio_release_resources(struct macio_dev *dev);
0089 
0090 static inline int macio_irq_count(struct macio_dev *dev)
0091 {
0092     return dev->n_interrupts;
0093 }
0094 
0095 static inline int macio_irq(struct macio_dev *dev, int irq_no)
0096 {
0097     return dev->interrupt[irq_no].start;
0098 }
0099 
0100 static inline void macio_set_drvdata(struct macio_dev *dev, void *data)
0101 {
0102     dev_set_drvdata(&dev->ofdev.dev, data);
0103 }
0104 
0105 static inline void* macio_get_drvdata(struct macio_dev *dev)
0106 {
0107     return dev_get_drvdata(&dev->ofdev.dev);
0108 }
0109 
0110 static inline struct device_node *macio_get_of_node(struct macio_dev *mdev)
0111 {
0112     return mdev->ofdev.dev.of_node;
0113 }
0114 
0115 #ifdef CONFIG_PCI
0116 static inline struct pci_dev *macio_get_pci_dev(struct macio_dev *mdev)
0117 {
0118     return mdev->bus->pdev;
0119 }
0120 #endif
0121 
0122 /*
0123  * A driver for a mac-io chip based device
0124  */
0125 struct macio_driver
0126 {
0127     int (*probe)(struct macio_dev* dev, const struct of_device_id *match);
0128     int (*remove)(struct macio_dev* dev);
0129 
0130     int (*suspend)(struct macio_dev* dev, pm_message_t state);
0131     int (*resume)(struct macio_dev* dev);
0132     int (*shutdown)(struct macio_dev* dev);
0133 
0134 #ifdef CONFIG_PMAC_MEDIABAY
0135     void    (*mediabay_event)(struct macio_dev* dev, int mb_state);
0136 #endif
0137     struct device_driver    driver;
0138 };
0139 #define to_macio_driver(drv) container_of(drv,struct macio_driver, driver)
0140 
0141 extern int macio_register_driver(struct macio_driver *);
0142 extern void macio_unregister_driver(struct macio_driver *);
0143 
0144 #endif /* __KERNEL__ */
0145 #endif /* __MACIO_ASIC_H__ */