blob: 69ea865c01a41647b752ee5756a583d5668e0592 [file] [log] [blame]
Paul Mackerras047ea782005-11-19 20:17:32 +11001#ifndef _ASM_POWERPC_PCI_BRIDGE_H
2#define _ASM_POWERPC_PCI_BRIDGE_H
Arnd Bergmann88ced032005-12-16 22:43:46 +01003#ifdef __KERNEL__
Linus Torvalds1da177e2005-04-16 15:20:36 -07004
Paul Mackerras047ea782005-11-19 20:17:32 +11005#ifndef CONFIG_PPC64
Kumar Gala5531e412007-06-27 00:16:25 -05006#include <linux/ioport.h>
7#include <linux/pci.h>
8
9struct device_node;
10struct pci_controller;
11
Kumar Gala5531e412007-06-27 00:16:25 -050012/*
13 * Structure of a PCI controller (host bridge)
14 */
15struct pci_controller {
16 struct pci_bus *bus;
17 void *arch_data;
Kumar Gala5531e412007-06-27 00:16:25 -050018 struct pci_controller *next;
19 struct device *parent;
20
21 int first_busno;
22 int last_busno;
23 int self_busno;
24
25 void __iomem *io_base_virt;
26 resource_size_t io_base_phys;
27
28 /* Some machines (PReP) have a non 1:1 mapping of
29 * the PCI memory space in the CPU bus space
30 */
31 resource_size_t pci_mem_offset;
32
33 struct pci_ops *ops;
34 volatile unsigned int __iomem *cfg_addr;
35 volatile void __iomem *cfg_data;
36
37 /*
38 * Used for variants of PCI indirect handling and possible quirks:
39 * SET_CFG_TYPE - used on 4xx or any PHB that does explicit type0/1
40 * EXT_REG - provides access to PCI-e extended registers
41 * SURPRESS_PRIMARY_BUS - we surpress the setting of PCI_PRIMARY_BUS
42 * on Freescale PCI-e controllers since they used the PCI_PRIMARY_BUS
43 * to determine which bus number to match on when generating type0
44 * config cycles
45 */
46#define PPC_INDIRECT_TYPE_SET_CFG_TYPE (0x00000001)
47#define PPC_INDIRECT_TYPE_EXT_REG (0x00000002)
48#define PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS (0x00000004)
49 u32 indirect_type;
50
51 /* Currently, we limit ourselves to 1 IO range and 3 mem
52 * ranges since the common pci_bus structure can't handle more
53 */
54 struct resource io_resource;
55 struct resource mem_resources[3];
Kumar Gala5516b542007-06-27 01:17:57 -050056 int global_number; /* PCI domain number */
Kumar Gala5531e412007-06-27 00:16:25 -050057};
58
59static inline struct pci_controller *pci_bus_to_host(struct pci_bus *bus)
60{
61 return bus->sysdata;
62}
63
64/* These are used for config access before all the PCI probing
65 has been done. */
66int early_read_config_byte(struct pci_controller *hose, int bus, int dev_fn,
67 int where, u8 *val);
68int early_read_config_word(struct pci_controller *hose, int bus, int dev_fn,
69 int where, u16 *val);
70int early_read_config_dword(struct pci_controller *hose, int bus, int dev_fn,
71 int where, u32 *val);
72int early_write_config_byte(struct pci_controller *hose, int bus, int dev_fn,
73 int where, u8 val);
74int early_write_config_word(struct pci_controller *hose, int bus, int dev_fn,
75 int where, u16 val);
76int early_write_config_dword(struct pci_controller *hose, int bus, int dev_fn,
77 int where, u32 val);
78
79extern void setup_indirect_pci_nomap(struct pci_controller* hose,
80 void __iomem *cfg_addr, void __iomem *cfg_data);
81extern void setup_indirect_pci(struct pci_controller* hose,
82 u32 cfg_addr, u32 cfg_data);
83extern void setup_grackle(struct pci_controller *hose);
84
Paul Mackerras047ea782005-11-19 20:17:32 +110085#else
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#include <linux/pci.h>
Paul Mackerras76f9f872005-10-10 22:52:26 +100088#include <linux/list.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90/*
91 * This program is free software; you can redistribute it and/or
92 * modify it under the terms of the GNU General Public License
93 * as published by the Free Software Foundation; either version
94 * 2 of the License, or (at your option) any later version.
95 */
96
97/*
98 * Structure of a PCI controller (host bridge)
99 */
100struct pci_controller {
101 struct pci_bus *bus;
102 char is_dynamic;
Anton Blanchard357518f2006-06-10 20:53:06 +1000103 int node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 void *arch_data;
105 struct list_head list_node;
Benjamin Herrenschmidt803d4572006-11-11 17:25:07 +1100106 struct device *parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108 int first_busno;
109 int last_busno;
110
111 void __iomem *io_base_virt;
Benjamin Herrenschmidt3d5134e2007-06-04 15:15:36 +1000112 void *io_base_alloc;
Benjamin Herrenschmidt396a1a52006-12-08 17:14:33 +1100113 resource_size_t io_base_phys;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115 /* Some machines have a non 1:1 mapping of
116 * the PCI memory space in the CPU bus space
117 */
Benjamin Herrenschmidt396a1a52006-12-08 17:14:33 +1100118 resource_size_t pci_mem_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 unsigned long pci_io_size;
120
121 struct pci_ops *ops;
122 volatile unsigned int __iomem *cfg_addr;
Paul Mackerras17a63922005-10-20 21:10:09 +1000123 volatile void __iomem *cfg_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125 /* Currently, we limit ourselves to 1 IO range and 3 mem
126 * ranges since the common pci_bus structure can't handle more
127 */
128 struct resource io_resource;
129 struct resource mem_resources[3];
Kumar Gala5531e412007-06-27 00:16:25 -0500130 int global_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 unsigned long buid;
132 unsigned long dma_window_base_cur;
133 unsigned long dma_window_size;
Ishizaki Kou5b7c7262007-01-12 09:57:37 +0900134
135 void *private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136};
137
Paul Mackerras16353172005-09-06 13:17:54 +1000138/*
139 * PCI stuff, for nodes representing PCI devices, pointed to
140 * by device_node->data.
141 */
142struct pci_controller;
143struct iommu_table;
144
145struct pci_dn {
Linas Vepstas7684b402005-11-03 18:55:19 -0600146 int busno; /* pci bus number */
147 int bussubno; /* pci subordinate bus number */
148 int devfn; /* pci device and function number */
149 int class_code; /* pci device class */
Benjamin Herrenschmidtb5166cc2005-11-15 16:05:33 +1100150
Linas Vepstasc2e221e2007-05-23 04:18:04 +1000151 struct pci_controller *phb; /* for pci devices */
152 struct iommu_table *iommu_table; /* for phb's or bridges */
153 struct pci_dev *pcidev; /* back-pointer to the pci device */
154 struct device_node *node; /* back-pointer to the device_node */
155
156 int pci_ext_config_space; /* for pci devices */
157
158#ifdef CONFIG_EEH
Paul Mackerras16353172005-09-06 13:17:54 +1000159 int eeh_mode; /* See eeh.h for possible EEH_MODEs */
160 int eeh_config_addr;
Linas Vepstas25e591f2005-11-03 18:53:20 -0600161 int eeh_pe_config_addr; /* new-style partition endpoint address */
Paul Mackerras16353172005-09-06 13:17:54 +1000162 int eeh_check_count; /* # times driver ignored error */
163 int eeh_freeze_count; /* # times this device froze up. */
Linas Vepstas858955b2007-05-24 03:20:51 +1000164 int eeh_false_positives; /* # times this device reported #ff's */
Paul Mackerras16353172005-09-06 13:17:54 +1000165 u32 config_space[16]; /* saved PCI config space */
Linas Vepstasc2e221e2007-05-23 04:18:04 +1000166#endif
Paul Mackerras16353172005-09-06 13:17:54 +1000167};
168
169/* Get the pointer to a device_node's pci_dn */
170#define PCI_DN(dn) ((struct pci_dn *) (dn)->data)
171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172struct device_node *fetch_dev_dn(struct pci_dev *dev);
173
Paul Mackerras16353172005-09-06 13:17:54 +1000174/* Get a device_node from a pci_dev. This code must be fast except
175 * in the case where the sysdata is incorrect and needs to be fixed
176 * up (this will only happen once).
177 * In this case the sysdata will have been inherited from a PCI host
178 * bridge or a PCI-PCI bridge further up the tree, so it will point
179 * to a valid struct pci_dn, just not the one we want.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 */
181static inline struct device_node *pci_device_to_OF_node(struct pci_dev *dev)
182{
183 struct device_node *dn = dev->sysdata;
Paul Mackerras16353172005-09-06 13:17:54 +1000184 struct pci_dn *pdn = dn->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
Paul Mackerras16353172005-09-06 13:17:54 +1000186 if (pdn && pdn->devfn == dev->devfn && pdn->busno == dev->bus->number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 return dn; /* fast path. sysdata is good */
Paul Mackerras16353172005-09-06 13:17:54 +1000188 return fetch_dev_dn(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189}
190
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000191static inline int pci_device_from_OF_node(struct device_node *np,
192 u8 *bus, u8 *devfn)
193{
194 if (!PCI_DN(np))
195 return -ENODEV;
196 *bus = PCI_DN(np)->busno;
197 *devfn = PCI_DN(np)->devfn;
198 return 0;
199}
200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus)
202{
203 if (bus->self)
204 return pci_device_to_OF_node(bus->self);
205 else
206 return bus->sysdata; /* Must be root bus (PHB) */
207}
208
Linas Vepstas2bf6a8f2005-11-03 18:52:16 -0600209/** Find the bus corresponding to the indicated device node */
210struct pci_bus * pcibios_find_pci_bus(struct device_node *dn);
211
Linas Vepstas2bf6a8f2005-11-03 18:52:16 -0600212/** Remove all of the PCI devices under this bus */
213void pcibios_remove_pci_devices(struct pci_bus *bus);
214
215/** Discover new pci devices under this bus, and add them */
216void pcibios_add_pci_devices(struct pci_bus * bus);
linas31087d72005-12-13 13:46:36 -0600217void pcibios_fixup_new_pci_devices(struct pci_bus *bus, int fix_bus);
Linas Vepstas2bf6a8f2005-11-03 18:52:16 -0600218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219extern int pcibios_remove_root_bus(struct pci_controller *phb);
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221static inline struct pci_controller *pci_bus_to_host(struct pci_bus *bus)
222{
223 struct device_node *busdn = bus->sysdata;
224
225 BUG_ON(busdn == NULL);
Paul Mackerras16353172005-09-06 13:17:54 +1000226 return PCI_DN(busdn)->phb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227}
228
Benjamin Herrenschmidtb5166cc2005-11-15 16:05:33 +1100229extern void pcibios_free_controller(struct pci_controller *phb);
230
Benjamin Herrenschmidt3d5134e2007-06-04 15:15:36 +1000231extern void isa_bridge_find_early(struct pci_controller *hose);
232
233extern int pcibios_unmap_io_space(struct pci_bus *bus);
234extern int pcibios_map_io_space(struct pci_bus *bus);
235
Paul Mackerras42672922005-09-12 17:17:36 +1000236/* Return values for ppc_md.pci_probe_mode function */
237#define PCI_PROBE_NONE -1 /* Don't look at this bus at all */
238#define PCI_PROBE_NORMAL 0 /* Do normal PCI probing */
239#define PCI_PROBE_DEVTREE 1 /* Instantiate from device tree */
240
Anton Blanchard357518f2006-06-10 20:53:06 +1000241#ifdef CONFIG_NUMA
242#define PHB_SET_NODE(PHB, NODE) ((PHB)->node = (NODE))
243#else
244#define PHB_SET_NODE(PHB, NODE) ((PHB)->node = -1)
245#endif
246
Paul Mackerras047ea782005-11-19 20:17:32 +1100247#endif /* CONFIG_PPC64 */
Kumar Gala5531e412007-06-27 00:16:25 -0500248
249/* Get the PCI host controller for an OF device */
250extern struct pci_controller*
251pci_find_hose_for_OF_device(struct device_node* node);
252
253/* Fill up host controller resources from the OF node */
254extern void
255pci_process_bridge_OF_ranges(struct pci_controller *hose,
256 struct device_node *dev, int primary);
257
Kumar Galadbf84712007-06-27 01:56:50 -0500258/* Allocate a new PCI host bridge structure */
259extern struct pci_controller *
260pcibios_alloc_controller(struct device_node *dev);
Kumar Gala5531e412007-06-27 00:16:25 -0500261#ifdef CONFIG_PCI
262extern unsigned long pci_address_to_pio(phys_addr_t address);
263#else
264static inline unsigned long pci_address_to_pio(phys_addr_t address)
265{
266 return (unsigned long)-1;
267}
268#endif
269
270
271
Arnd Bergmann88ced032005-12-16 22:43:46 +0100272#endif /* __KERNEL__ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273#endif