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