1b8b572e1SStephen Rothwell #ifndef _ASM_POWERPC_PCI_BRIDGE_H
2b8b572e1SStephen Rothwell #define _ASM_POWERPC_PCI_BRIDGE_H
3b8b572e1SStephen Rothwell #ifdef __KERNEL__
4b8b572e1SStephen Rothwell /*
5b8b572e1SStephen Rothwell  * This program is free software; you can redistribute it and/or
6b8b572e1SStephen Rothwell  * modify it under the terms of the GNU General Public License
7b8b572e1SStephen Rothwell  * as published by the Free Software Foundation; either version
8b8b572e1SStephen Rothwell  * 2 of the License, or (at your option) any later version.
9b8b572e1SStephen Rothwell  */
10b8b572e1SStephen Rothwell #include <linux/pci.h>
11b8b572e1SStephen Rothwell #include <linux/list.h>
12b8b572e1SStephen Rothwell #include <linux/ioport.h>
13f4ffd5e5SRob Herring #include <asm-generic/pci-bridge.h>
14b8b572e1SStephen Rothwell 
15b8b572e1SStephen Rothwell struct device_node;
16b8b572e1SStephen Rothwell 
17b8b572e1SStephen Rothwell /*
18b8b572e1SStephen Rothwell  * Structure of a PCI controller (host bridge)
19b8b572e1SStephen Rothwell  */
20b8b572e1SStephen Rothwell struct pci_controller {
21b8b572e1SStephen Rothwell 	struct pci_bus *bus;
22b8b572e1SStephen Rothwell 	char is_dynamic;
23b8b572e1SStephen Rothwell #ifdef CONFIG_PPC64
24b8b572e1SStephen Rothwell 	int node;
25b8b572e1SStephen Rothwell #endif
26b8b572e1SStephen Rothwell 	struct device_node *dn;
27b8b572e1SStephen Rothwell 	struct list_head list_node;
28b8b572e1SStephen Rothwell 	struct device *parent;
29b8b572e1SStephen Rothwell 
30b8b572e1SStephen Rothwell 	int first_busno;
31b8b572e1SStephen Rothwell 	int last_busno;
32b8b572e1SStephen Rothwell 	int self_busno;
33be8e60d8SYinghai Lu 	struct resource busn;
34b8b572e1SStephen Rothwell 
35b8b572e1SStephen Rothwell 	void __iomem *io_base_virt;
36b8b572e1SStephen Rothwell #ifdef CONFIG_PPC64
37b8b572e1SStephen Rothwell 	void *io_base_alloc;
38b8b572e1SStephen Rothwell #endif
39b8b572e1SStephen Rothwell 	resource_size_t io_base_phys;
40b8b572e1SStephen Rothwell 	resource_size_t pci_io_size;
41b8b572e1SStephen Rothwell 
42b8b572e1SStephen Rothwell 	/* Some machines (PReP) have a non 1:1 mapping of
43b8b572e1SStephen Rothwell 	 * the PCI memory space in the CPU bus space
44b8b572e1SStephen Rothwell 	 */
45b8b572e1SStephen Rothwell 	resource_size_t pci_mem_offset;
46b8b572e1SStephen Rothwell 
47e9f82cb7SBenjamin Herrenschmidt 	/* Some machines have a special region to forward the ISA
48e9f82cb7SBenjamin Herrenschmidt 	 * "memory" cycles such as VGA memory regions. Left to 0
49e9f82cb7SBenjamin Herrenschmidt 	 * if unsupported
50e9f82cb7SBenjamin Herrenschmidt 	 */
51e9f82cb7SBenjamin Herrenschmidt 	resource_size_t	isa_mem_phys;
52e9f82cb7SBenjamin Herrenschmidt 	resource_size_t	isa_mem_size;
53e9f82cb7SBenjamin Herrenschmidt 
54b8b572e1SStephen Rothwell 	struct pci_ops *ops;
55b8b572e1SStephen Rothwell 	unsigned int __iomem *cfg_addr;
56b8b572e1SStephen Rothwell 	void __iomem *cfg_data;
57b8b572e1SStephen Rothwell 
58b8b572e1SStephen Rothwell 	/*
59b8b572e1SStephen Rothwell 	 * Used for variants of PCI indirect handling and possible quirks:
60b8b572e1SStephen Rothwell 	 *  SET_CFG_TYPE - used on 4xx or any PHB that does explicit type0/1
61b8b572e1SStephen Rothwell 	 *  EXT_REG - provides access to PCI-e extended registers
6225985edcSLucas De Marchi 	 *  SURPRESS_PRIMARY_BUS - we suppress the setting of PCI_PRIMARY_BUS
63b8b572e1SStephen Rothwell 	 *   on Freescale PCI-e controllers since they used the PCI_PRIMARY_BUS
64b8b572e1SStephen Rothwell 	 *   to determine which bus number to match on when generating type0
65b8b572e1SStephen Rothwell 	 *   config cycles
66b8b572e1SStephen Rothwell 	 *  NO_PCIE_LINK - the Freescale PCI-e controllers have issues with
67b8b572e1SStephen Rothwell 	 *   hanging if we don't have link and try to do config cycles to
68b8b572e1SStephen Rothwell 	 *   anything but the PHB.  Only allow talking to the PHB if this is
69b8b572e1SStephen Rothwell 	 *   set.
70b8b572e1SStephen Rothwell 	 *  BIG_ENDIAN - cfg_addr is a big endian register
71b8b572e1SStephen Rothwell 	 *  BROKEN_MRM - the 440EPx/GRx chips have an errata that causes hangs on
72b8b572e1SStephen Rothwell 	 *   the PLB4.  Effectively disable MRM commands by setting this.
7334642bbbSKumar Gala 	 *  FSL_CFG_REG_LINK - Freescale controller version in which the PCIe
7434642bbbSKumar Gala 	 *   link status is in a RC PCIe cfg register (vs being a SoC register)
75b8b572e1SStephen Rothwell 	 */
76b8b572e1SStephen Rothwell #define PPC_INDIRECT_TYPE_SET_CFG_TYPE		0x00000001
77b8b572e1SStephen Rothwell #define PPC_INDIRECT_TYPE_EXT_REG		0x00000002
78b8b572e1SStephen Rothwell #define PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS	0x00000004
79b8b572e1SStephen Rothwell #define PPC_INDIRECT_TYPE_NO_PCIE_LINK		0x00000008
80b8b572e1SStephen Rothwell #define PPC_INDIRECT_TYPE_BIG_ENDIAN		0x00000010
81b8b572e1SStephen Rothwell #define PPC_INDIRECT_TYPE_BROKEN_MRM		0x00000020
8234642bbbSKumar Gala #define PPC_INDIRECT_TYPE_FSL_CFG_REG_LINK	0x00000040
83b8b572e1SStephen Rothwell 	u32 indirect_type;
84b8b572e1SStephen Rothwell 	/* Currently, we limit ourselves to 1 IO range and 3 mem
85b8b572e1SStephen Rothwell 	 * ranges since the common pci_bus structure can't handle more
86b8b572e1SStephen Rothwell 	 */
87b8b572e1SStephen Rothwell 	struct resource	io_resource;
88b8b572e1SStephen Rothwell 	struct resource mem_resources[3];
89b8b572e1SStephen Rothwell 	int global_number;		/* PCI domain number */
9089d93347SBecky Bruce 
9189d93347SBecky Bruce 	resource_size_t dma_window_base_cur;
9289d93347SBecky Bruce 	resource_size_t dma_window_size;
9389d93347SBecky Bruce 
94b8b572e1SStephen Rothwell #ifdef CONFIG_PPC64
95b8b572e1SStephen Rothwell 	unsigned long buid;
9634642bbbSKumar Gala #endif	/* CONFIG_PPC64 */
97b8b572e1SStephen Rothwell 
98b8b572e1SStephen Rothwell 	void *private_data;
99b8b572e1SStephen Rothwell };
100b8b572e1SStephen Rothwell 
101b8b572e1SStephen Rothwell /* These are used for config access before all the PCI probing
102b8b572e1SStephen Rothwell    has been done. */
103b8b572e1SStephen Rothwell extern int early_read_config_byte(struct pci_controller *hose, int bus,
104b8b572e1SStephen Rothwell 			int dev_fn, int where, u8 *val);
105b8b572e1SStephen Rothwell extern int early_read_config_word(struct pci_controller *hose, int bus,
106b8b572e1SStephen Rothwell 			int dev_fn, int where, u16 *val);
107b8b572e1SStephen Rothwell extern int early_read_config_dword(struct pci_controller *hose, int bus,
108b8b572e1SStephen Rothwell 			int dev_fn, int where, u32 *val);
109b8b572e1SStephen Rothwell extern int early_write_config_byte(struct pci_controller *hose, int bus,
110b8b572e1SStephen Rothwell 			int dev_fn, int where, u8 val);
111b8b572e1SStephen Rothwell extern int early_write_config_word(struct pci_controller *hose, int bus,
112b8b572e1SStephen Rothwell 			int dev_fn, int where, u16 val);
113b8b572e1SStephen Rothwell extern int early_write_config_dword(struct pci_controller *hose, int bus,
114b8b572e1SStephen Rothwell 			int dev_fn, int where, u32 val);
115b8b572e1SStephen Rothwell 
116b8b572e1SStephen Rothwell extern int early_find_capability(struct pci_controller *hose, int bus,
117b8b572e1SStephen Rothwell 				 int dev_fn, int cap);
118b8b572e1SStephen Rothwell 
119b8b572e1SStephen Rothwell extern void setup_indirect_pci(struct pci_controller* hose,
120b8b572e1SStephen Rothwell 			       resource_size_t cfg_addr,
121b8b572e1SStephen Rothwell 			       resource_size_t cfg_data, u32 flags);
12289c2dd62SKumar Gala 
12389c2dd62SKumar Gala static inline struct pci_controller *pci_bus_to_host(const struct pci_bus *bus)
12489c2dd62SKumar Gala {
12589c2dd62SKumar Gala 	return bus->sysdata;
12689c2dd62SKumar Gala }
12789c2dd62SKumar Gala 
12898d9f30cSBenjamin Herrenschmidt #ifndef CONFIG_PPC64
12998d9f30cSBenjamin Herrenschmidt 
13098d9f30cSBenjamin Herrenschmidt extern int pci_device_from_OF_node(struct device_node *node,
13198d9f30cSBenjamin Herrenschmidt 				   u8 *bus, u8 *devfn);
13298d9f30cSBenjamin Herrenschmidt extern void pci_create_OF_bus_map(void);
13398d9f30cSBenjamin Herrenschmidt 
13489c2dd62SKumar Gala static inline int isa_vaddr_is_ioport(void __iomem *address)
13589c2dd62SKumar Gala {
13689c2dd62SKumar Gala 	/* No specific ISA handling on ppc32 at this stage, it
13789c2dd62SKumar Gala 	 * all goes through PCI
13889c2dd62SKumar Gala 	 */
13989c2dd62SKumar Gala 	return 0;
14089c2dd62SKumar Gala }
14189c2dd62SKumar Gala 
142b8b572e1SStephen Rothwell #else	/* CONFIG_PPC64 */
143b8b572e1SStephen Rothwell 
144b8b572e1SStephen Rothwell /*
145b8b572e1SStephen Rothwell  * PCI stuff, for nodes representing PCI devices, pointed to
146b8b572e1SStephen Rothwell  * by device_node->data.
147b8b572e1SStephen Rothwell  */
148b8b572e1SStephen Rothwell struct iommu_table;
149b8b572e1SStephen Rothwell 
150b8b572e1SStephen Rothwell struct pci_dn {
151b8b572e1SStephen Rothwell 	int	busno;			/* pci bus number */
152b8b572e1SStephen Rothwell 	int	devfn;			/* pci device and function number */
153b8b572e1SStephen Rothwell 
154b8b572e1SStephen Rothwell 	struct  pci_controller *phb;	/* for pci devices */
155b8b572e1SStephen Rothwell 	struct	iommu_table *iommu_table;	/* for phb's or bridges */
156b8b572e1SStephen Rothwell 	struct	device_node *node;	/* back-pointer to the device_node */
157b8b572e1SStephen Rothwell 
158b8b572e1SStephen Rothwell 	int	pci_ext_config_space;	/* for pci devices */
159b8b572e1SStephen Rothwell 
160b8b572e1SStephen Rothwell 	struct	pci_dev *pcidev;	/* back-pointer to the pci device */
161184cd4a3SBenjamin Herrenschmidt #ifdef CONFIG_EEH
1622a0352faSGavin Shan 	struct eeh_dev *edev;		/* eeh device */
163b8b572e1SStephen Rothwell #endif
164184cd4a3SBenjamin Herrenschmidt #define IODA_INVALID_PE		(-1)
165184cd4a3SBenjamin Herrenschmidt #ifdef CONFIG_PPC_POWERNV
166184cd4a3SBenjamin Herrenschmidt 	int	pe_number;
167184cd4a3SBenjamin Herrenschmidt #endif
168b8b572e1SStephen Rothwell };
169b8b572e1SStephen Rothwell 
170b8b572e1SStephen Rothwell /* Get the pointer to a device_node's pci_dn */
171b8b572e1SStephen Rothwell #define PCI_DN(dn)	((struct pci_dn *) (dn)->data)
172b8b572e1SStephen Rothwell 
1732eb4afb6SKumar Gala extern void * update_dn_pci_info(struct device_node *dn, void *data);
174b8b572e1SStephen Rothwell 
175b8b572e1SStephen Rothwell static inline int pci_device_from_OF_node(struct device_node *np,
176b8b572e1SStephen Rothwell 					  u8 *bus, u8 *devfn)
177b8b572e1SStephen Rothwell {
178b8b572e1SStephen Rothwell 	if (!PCI_DN(np))
179b8b572e1SStephen Rothwell 		return -ENODEV;
180b8b572e1SStephen Rothwell 	*bus = PCI_DN(np)->busno;
181b8b572e1SStephen Rothwell 	*devfn = PCI_DN(np)->devfn;
182b8b572e1SStephen Rothwell 	return 0;
183b8b572e1SStephen Rothwell }
184b8b572e1SStephen Rothwell 
1852a0352faSGavin Shan #if defined(CONFIG_EEH)
1862a0352faSGavin Shan static inline struct eeh_dev *of_node_to_eeh_dev(struct device_node *dn)
1872a0352faSGavin Shan {
1881e38b714SGavin Shan 	/*
1891e38b714SGavin Shan 	 * For those OF nodes whose parent isn't PCI bridge, they
1901e38b714SGavin Shan 	 * don't have PCI_DN actually. So we have to skip them for
1911e38b714SGavin Shan 	 * any EEH operations.
1921e38b714SGavin Shan 	 */
1931e38b714SGavin Shan 	if (!dn || !PCI_DN(dn))
1941e38b714SGavin Shan 		return NULL;
1951e38b714SGavin Shan 
1962a0352faSGavin Shan 	return PCI_DN(dn)->edev;
1972a0352faSGavin Shan }
198f8f7d63fSGavin Shan #else
199f8f7d63fSGavin Shan #define of_node_to_eeh_dev(x) (NULL)
2002a0352faSGavin Shan #endif
2012a0352faSGavin Shan 
202b8b572e1SStephen Rothwell /** Find the bus corresponding to the indicated device node */
203b8b572e1SStephen Rothwell extern struct pci_bus *pcibios_find_pci_bus(struct device_node *dn);
204b8b572e1SStephen Rothwell 
205b8b572e1SStephen Rothwell /** Remove all of the PCI devices under this bus */
20620ee6a97SGavin Shan extern void __pcibios_remove_pci_devices(struct pci_bus *bus, int purge_pe);
207b8b572e1SStephen Rothwell extern void pcibios_remove_pci_devices(struct pci_bus *bus);
208b8b572e1SStephen Rothwell 
209b8b572e1SStephen Rothwell /** Discover new pci devices under this bus, and add them */
210b8b572e1SStephen Rothwell extern void pcibios_add_pci_devices(struct pci_bus *bus);
211b8b572e1SStephen Rothwell 
212b8b572e1SStephen Rothwell 
213b8b572e1SStephen Rothwell extern void isa_bridge_find_early(struct pci_controller *hose);
214b8b572e1SStephen Rothwell 
215b8b572e1SStephen Rothwell static inline int isa_vaddr_is_ioport(void __iomem *address)
216b8b572e1SStephen Rothwell {
217b8b572e1SStephen Rothwell 	/* Check if address hits the reserved legacy IO range */
218b8b572e1SStephen Rothwell 	unsigned long ea = (unsigned long)address;
219b8b572e1SStephen Rothwell 	return ea >= ISA_IO_BASE && ea < ISA_IO_END;
220b8b572e1SStephen Rothwell }
221b8b572e1SStephen Rothwell 
222b8b572e1SStephen Rothwell extern int pcibios_unmap_io_space(struct pci_bus *bus);
223b8b572e1SStephen Rothwell extern int pcibios_map_io_space(struct pci_bus *bus);
224b8b572e1SStephen Rothwell 
225b8b572e1SStephen Rothwell #ifdef CONFIG_NUMA
226b8b572e1SStephen Rothwell #define PHB_SET_NODE(PHB, NODE)		((PHB)->node = (NODE))
227b8b572e1SStephen Rothwell #else
228b8b572e1SStephen Rothwell #define PHB_SET_NODE(PHB, NODE)		((PHB)->node = -1)
229b8b572e1SStephen Rothwell #endif
230b8b572e1SStephen Rothwell 
231b8b572e1SStephen Rothwell #endif	/* CONFIG_PPC64 */
232b8b572e1SStephen Rothwell 
233b8b572e1SStephen Rothwell /* Get the PCI host controller for an OF device */
234b8b572e1SStephen Rothwell extern struct pci_controller *pci_find_hose_for_OF_device(
235b8b572e1SStephen Rothwell 			struct device_node* node);
236b8b572e1SStephen Rothwell 
237b8b572e1SStephen Rothwell /* Fill up host controller resources from the OF node */
238b8b572e1SStephen Rothwell extern void pci_process_bridge_OF_ranges(struct pci_controller *hose,
239b8b572e1SStephen Rothwell 			struct device_node *dev, int primary);
240b8b572e1SStephen Rothwell 
241b8b572e1SStephen Rothwell /* Allocate & free a PCI host bridge structure */
242b8b572e1SStephen Rothwell extern struct pci_controller *pcibios_alloc_controller(struct device_node *dev);
243b8b572e1SStephen Rothwell extern void pcibios_free_controller(struct pci_controller *phb);
244b8b572e1SStephen Rothwell 
245b8b572e1SStephen Rothwell #ifdef CONFIG_PCI
246b8b572e1SStephen Rothwell extern int pcibios_vaddr_is_ioport(void __iomem *address);
247b8b572e1SStephen Rothwell #else
248b8b572e1SStephen Rothwell static inline int pcibios_vaddr_is_ioport(void __iomem *address)
249b8b572e1SStephen Rothwell {
250b8b572e1SStephen Rothwell 	return 0;
251b8b572e1SStephen Rothwell }
252b8b572e1SStephen Rothwell #endif	/* CONFIG_PCI */
253b8b572e1SStephen Rothwell 
254b8b572e1SStephen Rothwell #endif	/* __KERNEL__ */
255b8b572e1SStephen Rothwell #endif	/* _ASM_POWERPC_PCI_BRIDGE_H */
256