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