xref: /openbmc/linux/arch/powerpc/include/asm/pci-bridge.h (revision 89c2dd62a389c5fed07c4b13c906c43214fc7491)
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>
13b8b572e1SStephen Rothwell 
14b8b572e1SStephen Rothwell struct device_node;
15b8b572e1SStephen Rothwell 
16b8b572e1SStephen Rothwell enum {
17b8b572e1SStephen Rothwell 	/* Force re-assigning all resources (ignore firmware
18b8b572e1SStephen Rothwell 	 * setup completely)
19b8b572e1SStephen Rothwell 	 */
20b8b572e1SStephen Rothwell 	PPC_PCI_REASSIGN_ALL_RSRC	= 0x00000001,
21b8b572e1SStephen Rothwell 
22b8b572e1SStephen Rothwell 	/* Re-assign all bus numbers */
23b8b572e1SStephen Rothwell 	PPC_PCI_REASSIGN_ALL_BUS	= 0x00000002,
24b8b572e1SStephen Rothwell 
25b8b572e1SStephen Rothwell 	/* Do not try to assign, just use existing setup */
26b8b572e1SStephen Rothwell 	PPC_PCI_PROBE_ONLY		= 0x00000004,
27b8b572e1SStephen Rothwell 
28b8b572e1SStephen Rothwell 	/* Don't bother with ISA alignment unless the bridge has
29b8b572e1SStephen Rothwell 	 * ISA forwarding enabled
30b8b572e1SStephen Rothwell 	 */
31b8b572e1SStephen Rothwell 	PPC_PCI_CAN_SKIP_ISA_ALIGN	= 0x00000008,
32b8b572e1SStephen Rothwell 
33b8b572e1SStephen Rothwell 	/* Enable domain numbers in /proc */
34b8b572e1SStephen Rothwell 	PPC_PCI_ENABLE_PROC_DOMAINS	= 0x00000010,
35b8b572e1SStephen Rothwell 	/* ... except for domain 0 */
36b8b572e1SStephen Rothwell 	PPC_PCI_COMPAT_DOMAIN_0		= 0x00000020,
37b8b572e1SStephen Rothwell };
387fe519c2SJosh Boyer #ifdef CONFIG_PCI
397fe519c2SJosh Boyer extern unsigned int ppc_pci_flags;
407fe519c2SJosh Boyer 
417fe519c2SJosh Boyer static inline void ppc_pci_set_flags(int flags)
427fe519c2SJosh Boyer {
437fe519c2SJosh Boyer 	ppc_pci_flags = flags;
447fe519c2SJosh Boyer }
457fe519c2SJosh Boyer 
467fe519c2SJosh Boyer static inline void ppc_pci_add_flags(int flags)
477fe519c2SJosh Boyer {
487fe519c2SJosh Boyer 	ppc_pci_flags |= flags;
497fe519c2SJosh Boyer }
507fe519c2SJosh Boyer 
517fe519c2SJosh Boyer static inline int ppc_pci_has_flag(int flag)
527fe519c2SJosh Boyer {
537fe519c2SJosh Boyer 	return (ppc_pci_flags & flag);
547fe519c2SJosh Boyer }
557fe519c2SJosh Boyer #else
567fe519c2SJosh Boyer static inline void ppc_pci_set_flags(int flags) { }
577fe519c2SJosh Boyer static inline void ppc_pci_add_flags(int flags) { }
587fe519c2SJosh Boyer static inline int ppc_pci_has_flag(int flag)
597fe519c2SJosh Boyer {
607fe519c2SJosh Boyer 	return 0;
617fe519c2SJosh Boyer }
627fe519c2SJosh Boyer #endif
63b8b572e1SStephen Rothwell 
64b8b572e1SStephen Rothwell 
65b8b572e1SStephen Rothwell /*
66b8b572e1SStephen Rothwell  * Structure of a PCI controller (host bridge)
67b8b572e1SStephen Rothwell  */
68b8b572e1SStephen Rothwell struct pci_controller {
69b8b572e1SStephen Rothwell 	struct pci_bus *bus;
70b8b572e1SStephen Rothwell 	char is_dynamic;
71b8b572e1SStephen Rothwell #ifdef CONFIG_PPC64
72b8b572e1SStephen Rothwell 	int node;
73b8b572e1SStephen Rothwell #endif
74b8b572e1SStephen Rothwell 	struct device_node *dn;
75b8b572e1SStephen Rothwell 	struct list_head list_node;
76b8b572e1SStephen Rothwell 	struct device *parent;
77b8b572e1SStephen Rothwell 
78b8b572e1SStephen Rothwell 	int first_busno;
79b8b572e1SStephen Rothwell 	int last_busno;
80b8b572e1SStephen Rothwell 	int self_busno;
81b8b572e1SStephen Rothwell 
82b8b572e1SStephen Rothwell 	void __iomem *io_base_virt;
83b8b572e1SStephen Rothwell #ifdef CONFIG_PPC64
84b8b572e1SStephen Rothwell 	void *io_base_alloc;
85b8b572e1SStephen Rothwell #endif
86b8b572e1SStephen Rothwell 	resource_size_t io_base_phys;
87b8b572e1SStephen Rothwell 	resource_size_t pci_io_size;
88b8b572e1SStephen Rothwell 
89b8b572e1SStephen Rothwell 	/* Some machines (PReP) have a non 1:1 mapping of
90b8b572e1SStephen Rothwell 	 * the PCI memory space in the CPU bus space
91b8b572e1SStephen Rothwell 	 */
92b8b572e1SStephen Rothwell 	resource_size_t pci_mem_offset;
93b8b572e1SStephen Rothwell 
94e9f82cb7SBenjamin Herrenschmidt 	/* Some machines have a special region to forward the ISA
95e9f82cb7SBenjamin Herrenschmidt 	 * "memory" cycles such as VGA memory regions. Left to 0
96e9f82cb7SBenjamin Herrenschmidt 	 * if unsupported
97e9f82cb7SBenjamin Herrenschmidt 	 */
98e9f82cb7SBenjamin Herrenschmidt 	resource_size_t	isa_mem_phys;
99e9f82cb7SBenjamin Herrenschmidt 	resource_size_t	isa_mem_size;
100e9f82cb7SBenjamin Herrenschmidt 
101b8b572e1SStephen Rothwell 	struct pci_ops *ops;
102b8b572e1SStephen Rothwell 	unsigned int __iomem *cfg_addr;
103b8b572e1SStephen Rothwell 	void __iomem *cfg_data;
104b8b572e1SStephen Rothwell 
105b8b572e1SStephen Rothwell 	/*
106b8b572e1SStephen Rothwell 	 * Used for variants of PCI indirect handling and possible quirks:
107b8b572e1SStephen Rothwell 	 *  SET_CFG_TYPE - used on 4xx or any PHB that does explicit type0/1
108b8b572e1SStephen Rothwell 	 *  EXT_REG - provides access to PCI-e extended registers
109b8b572e1SStephen Rothwell 	 *  SURPRESS_PRIMARY_BUS - we surpress the setting of PCI_PRIMARY_BUS
110b8b572e1SStephen Rothwell 	 *   on Freescale PCI-e controllers since they used the PCI_PRIMARY_BUS
111b8b572e1SStephen Rothwell 	 *   to determine which bus number to match on when generating type0
112b8b572e1SStephen Rothwell 	 *   config cycles
113b8b572e1SStephen Rothwell 	 *  NO_PCIE_LINK - the Freescale PCI-e controllers have issues with
114b8b572e1SStephen Rothwell 	 *   hanging if we don't have link and try to do config cycles to
115b8b572e1SStephen Rothwell 	 *   anything but the PHB.  Only allow talking to the PHB if this is
116b8b572e1SStephen Rothwell 	 *   set.
117b8b572e1SStephen Rothwell 	 *  BIG_ENDIAN - cfg_addr is a big endian register
118b8b572e1SStephen Rothwell 	 *  BROKEN_MRM - the 440EPx/GRx chips have an errata that causes hangs on
119b8b572e1SStephen Rothwell 	 *   the PLB4.  Effectively disable MRM commands by setting this.
120b8b572e1SStephen Rothwell 	 */
121b8b572e1SStephen Rothwell #define PPC_INDIRECT_TYPE_SET_CFG_TYPE		0x00000001
122b8b572e1SStephen Rothwell #define PPC_INDIRECT_TYPE_EXT_REG		0x00000002
123b8b572e1SStephen Rothwell #define PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS	0x00000004
124b8b572e1SStephen Rothwell #define PPC_INDIRECT_TYPE_NO_PCIE_LINK		0x00000008
125b8b572e1SStephen Rothwell #define PPC_INDIRECT_TYPE_BIG_ENDIAN		0x00000010
126b8b572e1SStephen Rothwell #define PPC_INDIRECT_TYPE_BROKEN_MRM		0x00000020
127b8b572e1SStephen Rothwell 	u32 indirect_type;
128b8b572e1SStephen Rothwell 	/* Currently, we limit ourselves to 1 IO range and 3 mem
129b8b572e1SStephen Rothwell 	 * ranges since the common pci_bus structure can't handle more
130b8b572e1SStephen Rothwell 	 */
131b8b572e1SStephen Rothwell 	struct resource	io_resource;
132b8b572e1SStephen Rothwell 	struct resource mem_resources[3];
133b8b572e1SStephen Rothwell 	int global_number;		/* PCI domain number */
13489d93347SBecky Bruce 
13589d93347SBecky Bruce 	resource_size_t dma_window_base_cur;
13689d93347SBecky Bruce 	resource_size_t dma_window_size;
13789d93347SBecky Bruce 
138b8b572e1SStephen Rothwell #ifdef CONFIG_PPC64
139b8b572e1SStephen Rothwell 	unsigned long buid;
140b8b572e1SStephen Rothwell 
141b8b572e1SStephen Rothwell 	void *private_data;
142b8b572e1SStephen Rothwell #endif	/* CONFIG_PPC64 */
143b8b572e1SStephen Rothwell };
144b8b572e1SStephen Rothwell 
145b8b572e1SStephen Rothwell /* These are used for config access before all the PCI probing
146b8b572e1SStephen Rothwell    has been done. */
147b8b572e1SStephen Rothwell extern int early_read_config_byte(struct pci_controller *hose, int bus,
148b8b572e1SStephen Rothwell 			int dev_fn, int where, u8 *val);
149b8b572e1SStephen Rothwell extern int early_read_config_word(struct pci_controller *hose, int bus,
150b8b572e1SStephen Rothwell 			int dev_fn, int where, u16 *val);
151b8b572e1SStephen Rothwell extern int early_read_config_dword(struct pci_controller *hose, int bus,
152b8b572e1SStephen Rothwell 			int dev_fn, int where, u32 *val);
153b8b572e1SStephen Rothwell extern int early_write_config_byte(struct pci_controller *hose, int bus,
154b8b572e1SStephen Rothwell 			int dev_fn, int where, u8 val);
155b8b572e1SStephen Rothwell extern int early_write_config_word(struct pci_controller *hose, int bus,
156b8b572e1SStephen Rothwell 			int dev_fn, int where, u16 val);
157b8b572e1SStephen Rothwell extern int early_write_config_dword(struct pci_controller *hose, int bus,
158b8b572e1SStephen Rothwell 			int dev_fn, int where, u32 val);
159b8b572e1SStephen Rothwell 
160b8b572e1SStephen Rothwell extern int early_find_capability(struct pci_controller *hose, int bus,
161b8b572e1SStephen Rothwell 				 int dev_fn, int cap);
162b8b572e1SStephen Rothwell 
163b8b572e1SStephen Rothwell extern void setup_indirect_pci(struct pci_controller* hose,
164b8b572e1SStephen Rothwell 			       resource_size_t cfg_addr,
165b8b572e1SStephen Rothwell 			       resource_size_t cfg_data, u32 flags);
166*89c2dd62SKumar Gala 
167*89c2dd62SKumar Gala #ifndef CONFIG_PPC64
168*89c2dd62SKumar Gala 
169*89c2dd62SKumar Gala static inline struct pci_controller *pci_bus_to_host(const struct pci_bus *bus)
170*89c2dd62SKumar Gala {
171*89c2dd62SKumar Gala 	return bus->sysdata;
172*89c2dd62SKumar Gala }
173*89c2dd62SKumar Gala 
174*89c2dd62SKumar Gala static inline int isa_vaddr_is_ioport(void __iomem *address)
175*89c2dd62SKumar Gala {
176*89c2dd62SKumar Gala 	/* No specific ISA handling on ppc32 at this stage, it
177*89c2dd62SKumar Gala 	 * all goes through PCI
178*89c2dd62SKumar Gala 	 */
179*89c2dd62SKumar Gala 	return 0;
180*89c2dd62SKumar Gala }
181*89c2dd62SKumar Gala 
182b8b572e1SStephen Rothwell #else	/* CONFIG_PPC64 */
183b8b572e1SStephen Rothwell 
184b8b572e1SStephen Rothwell /*
185b8b572e1SStephen Rothwell  * PCI stuff, for nodes representing PCI devices, pointed to
186b8b572e1SStephen Rothwell  * by device_node->data.
187b8b572e1SStephen Rothwell  */
188b8b572e1SStephen Rothwell struct iommu_table;
189b8b572e1SStephen Rothwell 
190b8b572e1SStephen Rothwell struct pci_dn {
191b8b572e1SStephen Rothwell 	int	busno;			/* pci bus number */
192b8b572e1SStephen Rothwell 	int	devfn;			/* pci device and function number */
193b8b572e1SStephen Rothwell 
194b8b572e1SStephen Rothwell 	struct  pci_controller *phb;	/* for pci devices */
195b8b572e1SStephen Rothwell 	struct	iommu_table *iommu_table;	/* for phb's or bridges */
196b8b572e1SStephen Rothwell 	struct	device_node *node;	/* back-pointer to the device_node */
197b8b572e1SStephen Rothwell 
198b8b572e1SStephen Rothwell 	int	pci_ext_config_space;	/* for pci devices */
199b8b572e1SStephen Rothwell 
200b8b572e1SStephen Rothwell #ifdef CONFIG_EEH
201b8b572e1SStephen Rothwell 	struct	pci_dev *pcidev;	/* back-pointer to the pci device */
202b8b572e1SStephen Rothwell 	int	class_code;		/* pci device class */
203b8b572e1SStephen Rothwell 	int	eeh_mode;		/* See eeh.h for possible EEH_MODEs */
204b8b572e1SStephen Rothwell 	int	eeh_config_addr;
205b8b572e1SStephen Rothwell 	int	eeh_pe_config_addr; /* new-style partition endpoint address */
206b8b572e1SStephen Rothwell 	int	eeh_check_count;	/* # times driver ignored error */
207b8b572e1SStephen Rothwell 	int	eeh_freeze_count;	/* # times this device froze up. */
208b8b572e1SStephen Rothwell 	int	eeh_false_positives;	/* # times this device reported #ff's */
209b8b572e1SStephen Rothwell 	u32	config_space[16];	/* saved PCI config space */
210b8b572e1SStephen Rothwell #endif
211b8b572e1SStephen Rothwell };
212b8b572e1SStephen Rothwell 
213b8b572e1SStephen Rothwell /* Get the pointer to a device_node's pci_dn */
214b8b572e1SStephen Rothwell #define PCI_DN(dn)	((struct pci_dn *) (dn)->data)
215b8b572e1SStephen Rothwell 
216b8b572e1SStephen Rothwell extern struct device_node *fetch_dev_dn(struct pci_dev *dev);
2172eb4afb6SKumar Gala extern void * update_dn_pci_info(struct device_node *dn, void *data);
218b8b572e1SStephen Rothwell 
219b8b572e1SStephen Rothwell /* Get a device_node from a pci_dev.  This code must be fast except
220b8b572e1SStephen Rothwell  * in the case where the sysdata is incorrect and needs to be fixed
221b8b572e1SStephen Rothwell  * up (this will only happen once).
222b8b572e1SStephen Rothwell  * In this case the sysdata will have been inherited from a PCI host
223b8b572e1SStephen Rothwell  * bridge or a PCI-PCI bridge further up the tree, so it will point
224b8b572e1SStephen Rothwell  * to a valid struct pci_dn, just not the one we want.
225b8b572e1SStephen Rothwell  */
226b8b572e1SStephen Rothwell static inline struct device_node *pci_device_to_OF_node(struct pci_dev *dev)
227b8b572e1SStephen Rothwell {
228b8b572e1SStephen Rothwell 	struct device_node *dn = dev->sysdata;
229b8b572e1SStephen Rothwell 	struct pci_dn *pdn = dn->data;
230b8b572e1SStephen Rothwell 
231b8b572e1SStephen Rothwell 	if (pdn && pdn->devfn == dev->devfn && pdn->busno == dev->bus->number)
232b8b572e1SStephen Rothwell 		return dn;	/* fast path.  sysdata is good */
233b8b572e1SStephen Rothwell 	return fetch_dev_dn(dev);
234b8b572e1SStephen Rothwell }
235b8b572e1SStephen Rothwell 
236b8b572e1SStephen Rothwell static inline int pci_device_from_OF_node(struct device_node *np,
237b8b572e1SStephen Rothwell 					  u8 *bus, u8 *devfn)
238b8b572e1SStephen Rothwell {
239b8b572e1SStephen Rothwell 	if (!PCI_DN(np))
240b8b572e1SStephen Rothwell 		return -ENODEV;
241b8b572e1SStephen Rothwell 	*bus = PCI_DN(np)->busno;
242b8b572e1SStephen Rothwell 	*devfn = PCI_DN(np)->devfn;
243b8b572e1SStephen Rothwell 	return 0;
244b8b572e1SStephen Rothwell }
245b8b572e1SStephen Rothwell 
246b8b572e1SStephen Rothwell static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus)
247b8b572e1SStephen Rothwell {
248b8b572e1SStephen Rothwell 	if (bus->self)
249b8b572e1SStephen Rothwell 		return pci_device_to_OF_node(bus->self);
250b8b572e1SStephen Rothwell 	else
251b8b572e1SStephen Rothwell 		return bus->sysdata; /* Must be root bus (PHB) */
252b8b572e1SStephen Rothwell }
253b8b572e1SStephen Rothwell 
254b8b572e1SStephen Rothwell /** Find the bus corresponding to the indicated device node */
255b8b572e1SStephen Rothwell extern struct pci_bus *pcibios_find_pci_bus(struct device_node *dn);
256b8b572e1SStephen Rothwell 
257b8b572e1SStephen Rothwell /** Remove all of the PCI devices under this bus */
258b8b572e1SStephen Rothwell extern void pcibios_remove_pci_devices(struct pci_bus *bus);
259b8b572e1SStephen Rothwell 
260b8b572e1SStephen Rothwell /** Discover new pci devices under this bus, and add them */
261b8b572e1SStephen Rothwell extern void pcibios_add_pci_devices(struct pci_bus *bus);
262b8b572e1SStephen Rothwell 
263b8b572e1SStephen Rothwell static inline struct pci_controller *pci_bus_to_host(const struct pci_bus *bus)
264b8b572e1SStephen Rothwell {
265b8b572e1SStephen Rothwell 	struct device_node *busdn = bus->sysdata;
266b8b572e1SStephen Rothwell 
267b8b572e1SStephen Rothwell 	BUG_ON(busdn == NULL);
268b8b572e1SStephen Rothwell 	return PCI_DN(busdn)->phb;
269b8b572e1SStephen Rothwell }
270b8b572e1SStephen Rothwell 
271b8b572e1SStephen Rothwell 
272b8b572e1SStephen Rothwell extern void isa_bridge_find_early(struct pci_controller *hose);
273b8b572e1SStephen Rothwell 
274b8b572e1SStephen Rothwell static inline int isa_vaddr_is_ioport(void __iomem *address)
275b8b572e1SStephen Rothwell {
276b8b572e1SStephen Rothwell 	/* Check if address hits the reserved legacy IO range */
277b8b572e1SStephen Rothwell 	unsigned long ea = (unsigned long)address;
278b8b572e1SStephen Rothwell 	return ea >= ISA_IO_BASE && ea < ISA_IO_END;
279b8b572e1SStephen Rothwell }
280b8b572e1SStephen Rothwell 
281b8b572e1SStephen Rothwell extern int pcibios_unmap_io_space(struct pci_bus *bus);
282b8b572e1SStephen Rothwell extern int pcibios_map_io_space(struct pci_bus *bus);
283b8b572e1SStephen Rothwell 
284b8b572e1SStephen Rothwell #ifdef CONFIG_NUMA
285b8b572e1SStephen Rothwell #define PHB_SET_NODE(PHB, NODE)		((PHB)->node = (NODE))
286b8b572e1SStephen Rothwell #else
287b8b572e1SStephen Rothwell #define PHB_SET_NODE(PHB, NODE)		((PHB)->node = -1)
288b8b572e1SStephen Rothwell #endif
289b8b572e1SStephen Rothwell 
290b8b572e1SStephen Rothwell #endif	/* CONFIG_PPC64 */
291b8b572e1SStephen Rothwell 
292b8b572e1SStephen Rothwell /* Get the PCI host controller for an OF device */
293b8b572e1SStephen Rothwell extern struct pci_controller *pci_find_hose_for_OF_device(
294b8b572e1SStephen Rothwell 			struct device_node* node);
295b8b572e1SStephen Rothwell 
296b8b572e1SStephen Rothwell /* Fill up host controller resources from the OF node */
297b8b572e1SStephen Rothwell extern void pci_process_bridge_OF_ranges(struct pci_controller *hose,
298b8b572e1SStephen Rothwell 			struct device_node *dev, int primary);
299b8b572e1SStephen Rothwell 
300b8b572e1SStephen Rothwell /* Allocate & free a PCI host bridge structure */
301b8b572e1SStephen Rothwell extern struct pci_controller *pcibios_alloc_controller(struct device_node *dev);
302b8b572e1SStephen Rothwell extern void pcibios_free_controller(struct pci_controller *phb);
30353280323SBenjamin Herrenschmidt extern void pcibios_setup_phb_resources(struct pci_controller *hose);
304b8b572e1SStephen Rothwell 
305b8b572e1SStephen Rothwell #ifdef CONFIG_PCI
306b8b572e1SStephen Rothwell extern unsigned long pci_address_to_pio(phys_addr_t address);
307b8b572e1SStephen Rothwell extern int pcibios_vaddr_is_ioport(void __iomem *address);
308b8b572e1SStephen Rothwell #else
309b8b572e1SStephen Rothwell static inline unsigned long pci_address_to_pio(phys_addr_t address)
310b8b572e1SStephen Rothwell {
311b8b572e1SStephen Rothwell 	return (unsigned long)-1;
312b8b572e1SStephen Rothwell }
313b8b572e1SStephen Rothwell static inline int pcibios_vaddr_is_ioport(void __iomem *address)
314b8b572e1SStephen Rothwell {
315b8b572e1SStephen Rothwell 	return 0;
316b8b572e1SStephen Rothwell }
317b8b572e1SStephen Rothwell #endif	/* CONFIG_PCI */
318b8b572e1SStephen Rothwell 
319b8b572e1SStephen Rothwell #endif	/* __KERNEL__ */
320b8b572e1SStephen Rothwell #endif	/* _ASM_POWERPC_PCI_BRIDGE_H */
321