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