1#ifndef _ASM_POWERPC_PCI_BRIDGE_H
2#define _ASM_POWERPC_PCI_BRIDGE_H
3#ifdef __KERNEL__
4
5
6
7
8
9
10#include <linux/pci.h>
11#include <linux/list.h>
12#include <linux/ioport.h>
13
14struct device_node;
15
16enum {
17
18
19
20 PPC_PCI_REASSIGN_ALL_RSRC = 0x00000001,
21
22
23 PPC_PCI_REASSIGN_ALL_BUS = 0x00000002,
24
25
26 PPC_PCI_PROBE_ONLY = 0x00000004,
27
28
29
30
31 PPC_PCI_CAN_SKIP_ISA_ALIGN = 0x00000008,
32
33
34 PPC_PCI_ENABLE_PROC_DOMAINS = 0x00000010,
35
36 PPC_PCI_COMPAT_DOMAIN_0 = 0x00000020,
37};
38#ifdef CONFIG_PCI
39extern unsigned int ppc_pci_flags;
40
41static inline void ppc_pci_set_flags(int flags)
42{
43 ppc_pci_flags = flags;
44}
45
46static inline void ppc_pci_add_flags(int flags)
47{
48 ppc_pci_flags |= flags;
49}
50
51static inline int ppc_pci_has_flag(int flag)
52{
53 return (ppc_pci_flags & flag);
54}
55#else
56static inline void ppc_pci_set_flags(int flags) { }
57static inline void ppc_pci_add_flags(int flags) { }
58static inline int ppc_pci_has_flag(int flag)
59{
60 return 0;
61}
62#endif
63
64
65
66
67
68struct pci_controller {
69 struct pci_bus *bus;
70 char is_dynamic;
71#ifdef CONFIG_PPC64
72 int node;
73#endif
74 struct device_node *dn;
75 struct list_head list_node;
76 struct device *parent;
77
78 int first_busno;
79 int last_busno;
80#ifndef CONFIG_PPC64
81 int self_busno;
82#endif
83
84 void __iomem *io_base_virt;
85#ifdef CONFIG_PPC64
86 void *io_base_alloc;
87#endif
88 resource_size_t io_base_phys;
89#ifndef CONFIG_PPC64
90 resource_size_t pci_io_size;
91#endif
92
93
94
95
96 resource_size_t pci_mem_offset;
97#ifdef CONFIG_PPC64
98 unsigned long pci_io_size;
99#endif
100
101
102
103
104
105 resource_size_t isa_mem_phys;
106 resource_size_t isa_mem_size;
107
108 struct pci_ops *ops;
109 unsigned int __iomem *cfg_addr;
110 void __iomem *cfg_data;
111
112#ifndef CONFIG_PPC64
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129#define PPC_INDIRECT_TYPE_SET_CFG_TYPE 0x00000001
130#define PPC_INDIRECT_TYPE_EXT_REG 0x00000002
131#define PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS 0x00000004
132#define PPC_INDIRECT_TYPE_NO_PCIE_LINK 0x00000008
133#define PPC_INDIRECT_TYPE_BIG_ENDIAN 0x00000010
134#define PPC_INDIRECT_TYPE_BROKEN_MRM 0x00000020
135 u32 indirect_type;
136#endif
137
138
139
140 struct resource io_resource;
141 struct resource mem_resources[3];
142 int global_number;
143#ifdef CONFIG_PPC64
144 unsigned long buid;
145 unsigned long dma_window_base_cur;
146 unsigned long dma_window_size;
147
148 void *private_data;
149#endif
150};
151
152#ifndef CONFIG_PPC64
153
154static inline struct pci_controller *pci_bus_to_host(const struct pci_bus *bus)
155{
156 return bus->sysdata;
157}
158
159static inline int isa_vaddr_is_ioport(void __iomem *address)
160{
161
162
163
164 return 0;
165}
166
167
168
169extern int early_read_config_byte(struct pci_controller *hose, int bus,
170 int dev_fn, int where, u8 *val);
171extern int early_read_config_word(struct pci_controller *hose, int bus,
172 int dev_fn, int where, u16 *val);
173extern int early_read_config_dword(struct pci_controller *hose, int bus,
174 int dev_fn, int where, u32 *val);
175extern int early_write_config_byte(struct pci_controller *hose, int bus,
176 int dev_fn, int where, u8 val);
177extern int early_write_config_word(struct pci_controller *hose, int bus,
178 int dev_fn, int where, u16 val);
179extern int early_write_config_dword(struct pci_controller *hose, int bus,
180 int dev_fn, int where, u32 val);
181
182extern int early_find_capability(struct pci_controller *hose, int bus,
183 int dev_fn, int cap);
184
185extern void setup_indirect_pci(struct pci_controller* hose,
186 resource_size_t cfg_addr,
187 resource_size_t cfg_data, u32 flags);
188extern void setup_grackle(struct pci_controller *hose);
189#else
190
191
192
193
194
195struct iommu_table;
196
197struct pci_dn {
198 int busno;
199 int devfn;
200
201 struct pci_controller *phb;
202 struct iommu_table *iommu_table;
203 struct device_node *node;
204
205 int pci_ext_config_space;
206
207#ifdef CONFIG_EEH
208 struct pci_dev *pcidev;
209 int class_code;
210 int eeh_mode;
211 int eeh_config_addr;
212 int eeh_pe_config_addr;
213 int eeh_check_count;
214 int eeh_freeze_count;
215 int eeh_false_positives;
216 u32 config_space[16];
217#endif
218};
219
220
221#define PCI_DN(dn) ((struct pci_dn *) (dn)->data)
222
223extern struct device_node *fetch_dev_dn(struct pci_dev *dev);
224
225
226
227
228
229
230
231
232static inline struct device_node *pci_device_to_OF_node(struct pci_dev *dev)
233{
234 struct device_node *dn = dev->sysdata;
235 struct pci_dn *pdn = dn->data;
236
237 if (pdn && pdn->devfn == dev->devfn && pdn->busno == dev->bus->number)
238 return dn;
239 return fetch_dev_dn(dev);
240}
241
242static inline int pci_device_from_OF_node(struct device_node *np,
243 u8 *bus, u8 *devfn)
244{
245 if (!PCI_DN(np))
246 return -ENODEV;
247 *bus = PCI_DN(np)->busno;
248 *devfn = PCI_DN(np)->devfn;
249 return 0;
250}
251
252static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus)
253{
254 if (bus->self)
255 return pci_device_to_OF_node(bus->self);
256 else
257 return bus->sysdata;
258}
259
260
261extern struct pci_bus *pcibios_find_pci_bus(struct device_node *dn);
262
263
264extern void pcibios_remove_pci_devices(struct pci_bus *bus);
265
266
267extern void pcibios_add_pci_devices(struct pci_bus *bus);
268
269static inline struct pci_controller *pci_bus_to_host(const struct pci_bus *bus)
270{
271 struct device_node *busdn = bus->sysdata;
272
273 BUG_ON(busdn == NULL);
274 return PCI_DN(busdn)->phb;
275}
276
277
278extern void isa_bridge_find_early(struct pci_controller *hose);
279
280static inline int isa_vaddr_is_ioport(void __iomem *address)
281{
282
283 unsigned long ea = (unsigned long)address;
284 return ea >= ISA_IO_BASE && ea < ISA_IO_END;
285}
286
287extern int pcibios_unmap_io_space(struct pci_bus *bus);
288extern int pcibios_map_io_space(struct pci_bus *bus);
289
290
291#define PCI_PROBE_NONE -1
292#define PCI_PROBE_NORMAL 0
293#define PCI_PROBE_DEVTREE 1
294
295#ifdef CONFIG_NUMA
296#define PHB_SET_NODE(PHB, NODE) ((PHB)->node = (NODE))
297#else
298#define PHB_SET_NODE(PHB, NODE) ((PHB)->node = -1)
299#endif
300
301#endif
302
303
304extern struct pci_controller *pci_find_hose_for_OF_device(
305 struct device_node* node);
306
307
308extern void pci_process_bridge_OF_ranges(struct pci_controller *hose,
309 struct device_node *dev, int primary);
310
311
312extern struct pci_controller *pcibios_alloc_controller(struct device_node *dev);
313extern void pcibios_free_controller(struct pci_controller *phb);
314extern void pcibios_setup_phb_resources(struct pci_controller *hose);
315
316#ifdef CONFIG_PCI
317extern unsigned long pci_address_to_pio(phys_addr_t address);
318extern int pcibios_vaddr_is_ioport(void __iomem *address);
319#else
320static inline unsigned long pci_address_to_pio(phys_addr_t address)
321{
322 return (unsigned long)-1;
323}
324static inline int pcibios_vaddr_is_ioport(void __iomem *address)
325{
326 return 0;
327}
328#endif
329
330#endif
331#endif
332