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 42e9f82cb7SBenjamin Herrenschmidt /* Some machines have a special region to forward the ISA 43e9f82cb7SBenjamin Herrenschmidt * "memory" cycles such as VGA memory regions. Left to 0 44e9f82cb7SBenjamin Herrenschmidt * if unsupported 45e9f82cb7SBenjamin Herrenschmidt */ 46e9f82cb7SBenjamin Herrenschmidt resource_size_t isa_mem_phys; 47e9f82cb7SBenjamin Herrenschmidt resource_size_t isa_mem_size; 48e9f82cb7SBenjamin Herrenschmidt 49b8b572e1SStephen Rothwell struct pci_ops *ops; 50b8b572e1SStephen Rothwell unsigned int __iomem *cfg_addr; 51b8b572e1SStephen Rothwell void __iomem *cfg_data; 52b8b572e1SStephen Rothwell 53b8b572e1SStephen Rothwell /* 54b8b572e1SStephen Rothwell * Used for variants of PCI indirect handling and possible quirks: 55b8b572e1SStephen Rothwell * SET_CFG_TYPE - used on 4xx or any PHB that does explicit type0/1 56b8b572e1SStephen Rothwell * EXT_REG - provides access to PCI-e extended registers 5725985edcSLucas De Marchi * SURPRESS_PRIMARY_BUS - we suppress the setting of PCI_PRIMARY_BUS 58b8b572e1SStephen Rothwell * on Freescale PCI-e controllers since they used the PCI_PRIMARY_BUS 59b8b572e1SStephen Rothwell * to determine which bus number to match on when generating type0 60b8b572e1SStephen Rothwell * config cycles 61b8b572e1SStephen Rothwell * NO_PCIE_LINK - the Freescale PCI-e controllers have issues with 62b8b572e1SStephen Rothwell * hanging if we don't have link and try to do config cycles to 63b8b572e1SStephen Rothwell * anything but the PHB. Only allow talking to the PHB if this is 64b8b572e1SStephen Rothwell * set. 65b8b572e1SStephen Rothwell * BIG_ENDIAN - cfg_addr is a big endian register 66b8b572e1SStephen Rothwell * BROKEN_MRM - the 440EPx/GRx chips have an errata that causes hangs on 67b8b572e1SStephen Rothwell * the PLB4. Effectively disable MRM commands by setting this. 6834642bbbSKumar Gala * FSL_CFG_REG_LINK - Freescale controller version in which the PCIe 6934642bbbSKumar Gala * link status is in a RC PCIe cfg register (vs being a SoC register) 70b8b572e1SStephen Rothwell */ 71b8b572e1SStephen Rothwell #define PPC_INDIRECT_TYPE_SET_CFG_TYPE 0x00000001 72b8b572e1SStephen Rothwell #define PPC_INDIRECT_TYPE_EXT_REG 0x00000002 73b8b572e1SStephen Rothwell #define PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS 0x00000004 74b8b572e1SStephen Rothwell #define PPC_INDIRECT_TYPE_NO_PCIE_LINK 0x00000008 75b8b572e1SStephen Rothwell #define PPC_INDIRECT_TYPE_BIG_ENDIAN 0x00000010 76b8b572e1SStephen Rothwell #define PPC_INDIRECT_TYPE_BROKEN_MRM 0x00000020 7734642bbbSKumar Gala #define PPC_INDIRECT_TYPE_FSL_CFG_REG_LINK 0x00000040 78b8b572e1SStephen Rothwell u32 indirect_type; 79b8b572e1SStephen Rothwell /* Currently, we limit ourselves to 1 IO range and 3 mem 80b8b572e1SStephen Rothwell * ranges since the common pci_bus structure can't handle more 81b8b572e1SStephen Rothwell */ 82b8b572e1SStephen Rothwell struct resource io_resource; 83b8b572e1SStephen Rothwell struct resource mem_resources[3]; 843fd47f06SBenjamin Herrenschmidt resource_size_t mem_offset[3]; 85b8b572e1SStephen Rothwell int global_number; /* PCI domain number */ 8689d93347SBecky Bruce 8789d93347SBecky Bruce resource_size_t dma_window_base_cur; 8889d93347SBecky Bruce resource_size_t dma_window_size; 8989d93347SBecky Bruce 90b8b572e1SStephen Rothwell #ifdef CONFIG_PPC64 91b8b572e1SStephen Rothwell unsigned long buid; 92cca87d30SGavin Shan struct pci_dn *pci_data; 9334642bbbSKumar Gala #endif /* CONFIG_PPC64 */ 94b8b572e1SStephen Rothwell 95b8b572e1SStephen Rothwell void *private_data; 96b8b572e1SStephen Rothwell }; 97b8b572e1SStephen Rothwell 98b8b572e1SStephen Rothwell /* These are used for config access before all the PCI probing 99b8b572e1SStephen Rothwell has been done. */ 100b8b572e1SStephen Rothwell extern int early_read_config_byte(struct pci_controller *hose, int bus, 101b8b572e1SStephen Rothwell int dev_fn, int where, u8 *val); 102b8b572e1SStephen Rothwell extern int early_read_config_word(struct pci_controller *hose, int bus, 103b8b572e1SStephen Rothwell int dev_fn, int where, u16 *val); 104b8b572e1SStephen Rothwell extern int early_read_config_dword(struct pci_controller *hose, int bus, 105b8b572e1SStephen Rothwell int dev_fn, int where, u32 *val); 106b8b572e1SStephen Rothwell extern int early_write_config_byte(struct pci_controller *hose, int bus, 107b8b572e1SStephen Rothwell int dev_fn, int where, u8 val); 108b8b572e1SStephen Rothwell extern int early_write_config_word(struct pci_controller *hose, int bus, 109b8b572e1SStephen Rothwell int dev_fn, int where, u16 val); 110b8b572e1SStephen Rothwell extern int early_write_config_dword(struct pci_controller *hose, int bus, 111b8b572e1SStephen Rothwell int dev_fn, int where, u32 val); 112b8b572e1SStephen Rothwell 113b8b572e1SStephen Rothwell extern int early_find_capability(struct pci_controller *hose, int bus, 114b8b572e1SStephen Rothwell int dev_fn, int cap); 115b8b572e1SStephen Rothwell 116b8b572e1SStephen Rothwell extern void setup_indirect_pci(struct pci_controller* hose, 117b8b572e1SStephen Rothwell resource_size_t cfg_addr, 118b8b572e1SStephen Rothwell resource_size_t cfg_data, u32 flags); 11989c2dd62SKumar Gala 12050d8f87dSRojhalat Ibrahim extern int indirect_read_config(struct pci_bus *bus, unsigned int devfn, 12150d8f87dSRojhalat Ibrahim int offset, int len, u32 *val); 12250d8f87dSRojhalat Ibrahim 1236d5f6a0eSKim Phillips extern int __indirect_read_config(struct pci_controller *hose, 1246d5f6a0eSKim Phillips unsigned char bus_number, unsigned int devfn, 1256d5f6a0eSKim Phillips int offset, int len, u32 *val); 1266d5f6a0eSKim Phillips 12750d8f87dSRojhalat Ibrahim extern int indirect_write_config(struct pci_bus *bus, unsigned int devfn, 12850d8f87dSRojhalat Ibrahim int offset, int len, u32 val); 12950d8f87dSRojhalat Ibrahim 13089c2dd62SKumar Gala static inline struct pci_controller *pci_bus_to_host(const struct pci_bus *bus) 13189c2dd62SKumar Gala { 13289c2dd62SKumar Gala return bus->sysdata; 13389c2dd62SKumar Gala } 13489c2dd62SKumar Gala 13598d9f30cSBenjamin Herrenschmidt #ifndef CONFIG_PPC64 13698d9f30cSBenjamin Herrenschmidt 13798d9f30cSBenjamin Herrenschmidt extern int pci_device_from_OF_node(struct device_node *node, 13898d9f30cSBenjamin Herrenschmidt u8 *bus, u8 *devfn); 13998d9f30cSBenjamin Herrenschmidt extern void pci_create_OF_bus_map(void); 14098d9f30cSBenjamin Herrenschmidt 14189c2dd62SKumar Gala static inline int isa_vaddr_is_ioport(void __iomem *address) 14289c2dd62SKumar Gala { 14389c2dd62SKumar Gala /* No specific ISA handling on ppc32 at this stage, it 14489c2dd62SKumar Gala * all goes through PCI 14589c2dd62SKumar Gala */ 14689c2dd62SKumar Gala return 0; 14789c2dd62SKumar Gala } 14889c2dd62SKumar Gala 149b8b572e1SStephen Rothwell #else /* CONFIG_PPC64 */ 150b8b572e1SStephen Rothwell 151b8b572e1SStephen Rothwell /* 152b8b572e1SStephen Rothwell * PCI stuff, for nodes representing PCI devices, pointed to 153b8b572e1SStephen Rothwell * by device_node->data. 154b8b572e1SStephen Rothwell */ 155b8b572e1SStephen Rothwell struct iommu_table; 156b8b572e1SStephen Rothwell 157b8b572e1SStephen Rothwell struct pci_dn { 158cca87d30SGavin Shan int flags; 159cca87d30SGavin Shan 160b8b572e1SStephen Rothwell int busno; /* pci bus number */ 161b8b572e1SStephen Rothwell int devfn; /* pci device and function number */ 162*c035ff1dSGavin Shan int vendor_id; /* Vendor ID */ 163*c035ff1dSGavin Shan int device_id; /* Device ID */ 164*c035ff1dSGavin Shan int class_code; /* Device class code */ 165b8b572e1SStephen Rothwell 166cca87d30SGavin Shan struct pci_dn *parent; 167b8b572e1SStephen Rothwell struct pci_controller *phb; /* for pci devices */ 168b8b572e1SStephen Rothwell struct iommu_table *iommu_table; /* for phb's or bridges */ 169b8b572e1SStephen Rothwell struct device_node *node; /* back-pointer to the device_node */ 170b8b572e1SStephen Rothwell 171b8b572e1SStephen Rothwell int pci_ext_config_space; /* for pci devices */ 172b8b572e1SStephen Rothwell 173b8b572e1SStephen Rothwell struct pci_dev *pcidev; /* back-pointer to the pci device */ 174184cd4a3SBenjamin Herrenschmidt #ifdef CONFIG_EEH 1752a0352faSGavin Shan struct eeh_dev *edev; /* eeh device */ 176b8b572e1SStephen Rothwell #endif 177184cd4a3SBenjamin Herrenschmidt #define IODA_INVALID_PE (-1) 178184cd4a3SBenjamin Herrenschmidt #ifdef CONFIG_PPC_POWERNV 179184cd4a3SBenjamin Herrenschmidt int pe_number; 180184cd4a3SBenjamin Herrenschmidt #endif 181cca87d30SGavin Shan struct list_head child_list; 182cca87d30SGavin Shan struct list_head list; 183b8b572e1SStephen Rothwell }; 184b8b572e1SStephen Rothwell 185b8b572e1SStephen Rothwell /* Get the pointer to a device_node's pci_dn */ 186b8b572e1SStephen Rothwell #define PCI_DN(dn) ((struct pci_dn *) (dn)->data) 187b8b572e1SStephen Rothwell 188cca87d30SGavin Shan extern struct pci_dn *pci_get_pdn_by_devfn(struct pci_bus *bus, 189cca87d30SGavin Shan int devfn); 190b72c1f65SBenjamin Herrenschmidt extern struct pci_dn *pci_get_pdn(struct pci_dev *pdev); 1912eb4afb6SKumar Gala extern void *update_dn_pci_info(struct device_node *dn, void *data); 192b8b572e1SStephen Rothwell 193b8b572e1SStephen Rothwell static inline int pci_device_from_OF_node(struct device_node *np, 194b8b572e1SStephen Rothwell u8 *bus, u8 *devfn) 195b8b572e1SStephen Rothwell { 196b8b572e1SStephen Rothwell if (!PCI_DN(np)) 197b8b572e1SStephen Rothwell return -ENODEV; 198b8b572e1SStephen Rothwell *bus = PCI_DN(np)->busno; 199b8b572e1SStephen Rothwell *devfn = PCI_DN(np)->devfn; 200b8b572e1SStephen Rothwell return 0; 201b8b572e1SStephen Rothwell } 202b8b572e1SStephen Rothwell 2032a0352faSGavin Shan #if defined(CONFIG_EEH) 2042a0352faSGavin Shan static inline struct eeh_dev *of_node_to_eeh_dev(struct device_node *dn) 2052a0352faSGavin Shan { 2061e38b714SGavin Shan /* 2071e38b714SGavin Shan * For those OF nodes whose parent isn't PCI bridge, they 2081e38b714SGavin Shan * don't have PCI_DN actually. So we have to skip them for 2091e38b714SGavin Shan * any EEH operations. 2101e38b714SGavin Shan */ 2111e38b714SGavin Shan if (!dn || !PCI_DN(dn)) 2121e38b714SGavin Shan return NULL; 2131e38b714SGavin Shan 2142a0352faSGavin Shan return PCI_DN(dn)->edev; 2152a0352faSGavin Shan } 216f8f7d63fSGavin Shan #else 217f8f7d63fSGavin Shan #define of_node_to_eeh_dev(x) (NULL) 2182a0352faSGavin Shan #endif 2192a0352faSGavin Shan 220b8b572e1SStephen Rothwell /** Find the bus corresponding to the indicated device node */ 221b8b572e1SStephen Rothwell extern struct pci_bus *pcibios_find_pci_bus(struct device_node *dn); 222b8b572e1SStephen Rothwell 223b8b572e1SStephen Rothwell /** Remove all of the PCI devices under this bus */ 224b8b572e1SStephen Rothwell extern void pcibios_remove_pci_devices(struct pci_bus *bus); 225b8b572e1SStephen Rothwell 226b8b572e1SStephen Rothwell /** Discover new pci devices under this bus, and add them */ 227b8b572e1SStephen Rothwell extern void pcibios_add_pci_devices(struct pci_bus *bus); 228b8b572e1SStephen Rothwell 229b8b572e1SStephen Rothwell 230b8b572e1SStephen Rothwell extern void isa_bridge_find_early(struct pci_controller *hose); 231b8b572e1SStephen Rothwell 232b8b572e1SStephen Rothwell static inline int isa_vaddr_is_ioport(void __iomem *address) 233b8b572e1SStephen Rothwell { 234b8b572e1SStephen Rothwell /* Check if address hits the reserved legacy IO range */ 235b8b572e1SStephen Rothwell unsigned long ea = (unsigned long)address; 236b8b572e1SStephen Rothwell return ea >= ISA_IO_BASE && ea < ISA_IO_END; 237b8b572e1SStephen Rothwell } 238b8b572e1SStephen Rothwell 239b8b572e1SStephen Rothwell extern int pcibios_unmap_io_space(struct pci_bus *bus); 240b8b572e1SStephen Rothwell extern int pcibios_map_io_space(struct pci_bus *bus); 241b8b572e1SStephen Rothwell 242b8b572e1SStephen Rothwell #ifdef CONFIG_NUMA 243b8b572e1SStephen Rothwell #define PHB_SET_NODE(PHB, NODE) ((PHB)->node = (NODE)) 244b8b572e1SStephen Rothwell #else 245b8b572e1SStephen Rothwell #define PHB_SET_NODE(PHB, NODE) ((PHB)->node = -1) 246b8b572e1SStephen Rothwell #endif 247b8b572e1SStephen Rothwell 248b8b572e1SStephen Rothwell #endif /* CONFIG_PPC64 */ 249b8b572e1SStephen Rothwell 250b8b572e1SStephen Rothwell /* Get the PCI host controller for an OF device */ 251b8b572e1SStephen Rothwell extern struct pci_controller *pci_find_hose_for_OF_device( 252b8b572e1SStephen Rothwell struct device_node* node); 253b8b572e1SStephen Rothwell 254b8b572e1SStephen Rothwell /* Fill up host controller resources from the OF node */ 255b8b572e1SStephen Rothwell extern void pci_process_bridge_OF_ranges(struct pci_controller *hose, 256b8b572e1SStephen Rothwell struct device_node *dev, int primary); 257b8b572e1SStephen Rothwell 258b8b572e1SStephen Rothwell /* Allocate & free a PCI host bridge structure */ 259b8b572e1SStephen Rothwell extern struct pci_controller *pcibios_alloc_controller(struct device_node *dev); 260b8b572e1SStephen Rothwell extern void pcibios_free_controller(struct pci_controller *phb); 261b8b572e1SStephen Rothwell 262b8b572e1SStephen Rothwell #ifdef CONFIG_PCI 263b8b572e1SStephen Rothwell extern int pcibios_vaddr_is_ioport(void __iomem *address); 264b8b572e1SStephen Rothwell #else 265b8b572e1SStephen Rothwell static inline int pcibios_vaddr_is_ioport(void __iomem *address) 266b8b572e1SStephen Rothwell { 267b8b572e1SStephen Rothwell return 0; 268b8b572e1SStephen Rothwell } 269b8b572e1SStephen Rothwell #endif /* CONFIG_PCI */ 270b8b572e1SStephen Rothwell 271b8b572e1SStephen Rothwell #endif /* __KERNEL__ */ 272b8b572e1SStephen Rothwell #endif /* _ASM_POWERPC_PCI_BRIDGE_H */ 273