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 /* 18e02def5bSDaniel Axtens * PCI controller operations 19e02def5bSDaniel Axtens */ 20e02def5bSDaniel Axtens struct pci_controller_ops { 21e02def5bSDaniel Axtens void (*dma_dev_setup)(struct pci_dev *dev); 22*b122c954SDaniel Axtens void (*dma_bus_setup)(struct pci_bus *bus); 23e02def5bSDaniel Axtens }; 24e02def5bSDaniel Axtens 25e02def5bSDaniel Axtens /* 26b8b572e1SStephen Rothwell * Structure of a PCI controller (host bridge) 27b8b572e1SStephen Rothwell */ 28b8b572e1SStephen Rothwell struct pci_controller { 29b8b572e1SStephen Rothwell struct pci_bus *bus; 30b8b572e1SStephen Rothwell char is_dynamic; 31b8b572e1SStephen Rothwell #ifdef CONFIG_PPC64 32b8b572e1SStephen Rothwell int node; 33b8b572e1SStephen Rothwell #endif 34b8b572e1SStephen Rothwell struct device_node *dn; 35b8b572e1SStephen Rothwell struct list_head list_node; 36b8b572e1SStephen Rothwell struct device *parent; 37b8b572e1SStephen Rothwell 38b8b572e1SStephen Rothwell int first_busno; 39b8b572e1SStephen Rothwell int last_busno; 40b8b572e1SStephen Rothwell int self_busno; 41be8e60d8SYinghai Lu struct resource busn; 42b8b572e1SStephen Rothwell 43b8b572e1SStephen Rothwell void __iomem *io_base_virt; 44b8b572e1SStephen Rothwell #ifdef CONFIG_PPC64 45b8b572e1SStephen Rothwell void *io_base_alloc; 46b8b572e1SStephen Rothwell #endif 47b8b572e1SStephen Rothwell resource_size_t io_base_phys; 48b8b572e1SStephen Rothwell resource_size_t pci_io_size; 49b8b572e1SStephen Rothwell 50e9f82cb7SBenjamin Herrenschmidt /* Some machines have a special region to forward the ISA 51e9f82cb7SBenjamin Herrenschmidt * "memory" cycles such as VGA memory regions. Left to 0 52e9f82cb7SBenjamin Herrenschmidt * if unsupported 53e9f82cb7SBenjamin Herrenschmidt */ 54e9f82cb7SBenjamin Herrenschmidt resource_size_t isa_mem_phys; 55e9f82cb7SBenjamin Herrenschmidt resource_size_t isa_mem_size; 56e9f82cb7SBenjamin Herrenschmidt 57e02def5bSDaniel Axtens struct pci_controller_ops controller_ops; 58b8b572e1SStephen Rothwell struct pci_ops *ops; 59b8b572e1SStephen Rothwell unsigned int __iomem *cfg_addr; 60b8b572e1SStephen Rothwell void __iomem *cfg_data; 61b8b572e1SStephen Rothwell 62b8b572e1SStephen Rothwell /* 63b8b572e1SStephen Rothwell * Used for variants of PCI indirect handling and possible quirks: 64b8b572e1SStephen Rothwell * SET_CFG_TYPE - used on 4xx or any PHB that does explicit type0/1 65b8b572e1SStephen Rothwell * EXT_REG - provides access to PCI-e extended registers 6625985edcSLucas De Marchi * SURPRESS_PRIMARY_BUS - we suppress the setting of PCI_PRIMARY_BUS 67b8b572e1SStephen Rothwell * on Freescale PCI-e controllers since they used the PCI_PRIMARY_BUS 68b8b572e1SStephen Rothwell * to determine which bus number to match on when generating type0 69b8b572e1SStephen Rothwell * config cycles 70b8b572e1SStephen Rothwell * NO_PCIE_LINK - the Freescale PCI-e controllers have issues with 71b8b572e1SStephen Rothwell * hanging if we don't have link and try to do config cycles to 72b8b572e1SStephen Rothwell * anything but the PHB. Only allow talking to the PHB if this is 73b8b572e1SStephen Rothwell * set. 74b8b572e1SStephen Rothwell * BIG_ENDIAN - cfg_addr is a big endian register 75b8b572e1SStephen Rothwell * BROKEN_MRM - the 440EPx/GRx chips have an errata that causes hangs on 76b8b572e1SStephen Rothwell * the PLB4. Effectively disable MRM commands by setting this. 7734642bbbSKumar Gala * FSL_CFG_REG_LINK - Freescale controller version in which the PCIe 7834642bbbSKumar Gala * link status is in a RC PCIe cfg register (vs being a SoC register) 79b8b572e1SStephen Rothwell */ 80b8b572e1SStephen Rothwell #define PPC_INDIRECT_TYPE_SET_CFG_TYPE 0x00000001 81b8b572e1SStephen Rothwell #define PPC_INDIRECT_TYPE_EXT_REG 0x00000002 82b8b572e1SStephen Rothwell #define PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS 0x00000004 83b8b572e1SStephen Rothwell #define PPC_INDIRECT_TYPE_NO_PCIE_LINK 0x00000008 84b8b572e1SStephen Rothwell #define PPC_INDIRECT_TYPE_BIG_ENDIAN 0x00000010 85b8b572e1SStephen Rothwell #define PPC_INDIRECT_TYPE_BROKEN_MRM 0x00000020 8634642bbbSKumar Gala #define PPC_INDIRECT_TYPE_FSL_CFG_REG_LINK 0x00000040 87b8b572e1SStephen Rothwell u32 indirect_type; 88b8b572e1SStephen Rothwell /* Currently, we limit ourselves to 1 IO range and 3 mem 89b8b572e1SStephen Rothwell * ranges since the common pci_bus structure can't handle more 90b8b572e1SStephen Rothwell */ 91b8b572e1SStephen Rothwell struct resource io_resource; 92b8b572e1SStephen Rothwell struct resource mem_resources[3]; 933fd47f06SBenjamin Herrenschmidt resource_size_t mem_offset[3]; 94b8b572e1SStephen Rothwell int global_number; /* PCI domain number */ 9589d93347SBecky Bruce 9689d93347SBecky Bruce resource_size_t dma_window_base_cur; 9789d93347SBecky Bruce resource_size_t dma_window_size; 9889d93347SBecky Bruce 99b8b572e1SStephen Rothwell #ifdef CONFIG_PPC64 100b8b572e1SStephen Rothwell unsigned long buid; 101cca87d30SGavin Shan struct pci_dn *pci_data; 10234642bbbSKumar Gala #endif /* CONFIG_PPC64 */ 103b8b572e1SStephen Rothwell 104b8b572e1SStephen Rothwell void *private_data; 105b8b572e1SStephen Rothwell }; 106b8b572e1SStephen Rothwell 107b8b572e1SStephen Rothwell /* These are used for config access before all the PCI probing 108b8b572e1SStephen Rothwell has been done. */ 109b8b572e1SStephen Rothwell extern int early_read_config_byte(struct pci_controller *hose, int bus, 110b8b572e1SStephen Rothwell int dev_fn, int where, u8 *val); 111b8b572e1SStephen Rothwell extern int early_read_config_word(struct pci_controller *hose, int bus, 112b8b572e1SStephen Rothwell int dev_fn, int where, u16 *val); 113b8b572e1SStephen Rothwell extern int early_read_config_dword(struct pci_controller *hose, int bus, 114b8b572e1SStephen Rothwell int dev_fn, int where, u32 *val); 115b8b572e1SStephen Rothwell extern int early_write_config_byte(struct pci_controller *hose, int bus, 116b8b572e1SStephen Rothwell int dev_fn, int where, u8 val); 117b8b572e1SStephen Rothwell extern int early_write_config_word(struct pci_controller *hose, int bus, 118b8b572e1SStephen Rothwell int dev_fn, int where, u16 val); 119b8b572e1SStephen Rothwell extern int early_write_config_dword(struct pci_controller *hose, int bus, 120b8b572e1SStephen Rothwell int dev_fn, int where, u32 val); 121b8b572e1SStephen Rothwell 122b8b572e1SStephen Rothwell extern int early_find_capability(struct pci_controller *hose, int bus, 123b8b572e1SStephen Rothwell int dev_fn, int cap); 124b8b572e1SStephen Rothwell 125b8b572e1SStephen Rothwell extern void setup_indirect_pci(struct pci_controller* hose, 126b8b572e1SStephen Rothwell resource_size_t cfg_addr, 127b8b572e1SStephen Rothwell resource_size_t cfg_data, u32 flags); 12889c2dd62SKumar Gala 12950d8f87dSRojhalat Ibrahim extern int indirect_read_config(struct pci_bus *bus, unsigned int devfn, 13050d8f87dSRojhalat Ibrahim int offset, int len, u32 *val); 13150d8f87dSRojhalat Ibrahim 1326d5f6a0eSKim Phillips extern int __indirect_read_config(struct pci_controller *hose, 1336d5f6a0eSKim Phillips unsigned char bus_number, unsigned int devfn, 1346d5f6a0eSKim Phillips int offset, int len, u32 *val); 1356d5f6a0eSKim Phillips 13650d8f87dSRojhalat Ibrahim extern int indirect_write_config(struct pci_bus *bus, unsigned int devfn, 13750d8f87dSRojhalat Ibrahim int offset, int len, u32 val); 13850d8f87dSRojhalat Ibrahim 13989c2dd62SKumar Gala static inline struct pci_controller *pci_bus_to_host(const struct pci_bus *bus) 14089c2dd62SKumar Gala { 14189c2dd62SKumar Gala return bus->sysdata; 14289c2dd62SKumar Gala } 14389c2dd62SKumar Gala 14498d9f30cSBenjamin Herrenschmidt #ifndef CONFIG_PPC64 14598d9f30cSBenjamin Herrenschmidt 14698d9f30cSBenjamin Herrenschmidt extern int pci_device_from_OF_node(struct device_node *node, 14798d9f30cSBenjamin Herrenschmidt u8 *bus, u8 *devfn); 14898d9f30cSBenjamin Herrenschmidt extern void pci_create_OF_bus_map(void); 14998d9f30cSBenjamin Herrenschmidt 15089c2dd62SKumar Gala static inline int isa_vaddr_is_ioport(void __iomem *address) 15189c2dd62SKumar Gala { 15289c2dd62SKumar Gala /* No specific ISA handling on ppc32 at this stage, it 15389c2dd62SKumar Gala * all goes through PCI 15489c2dd62SKumar Gala */ 15589c2dd62SKumar Gala return 0; 15689c2dd62SKumar Gala } 15789c2dd62SKumar Gala 158b8b572e1SStephen Rothwell #else /* CONFIG_PPC64 */ 159b8b572e1SStephen Rothwell 160b8b572e1SStephen Rothwell /* 161b8b572e1SStephen Rothwell * PCI stuff, for nodes representing PCI devices, pointed to 162b8b572e1SStephen Rothwell * by device_node->data. 163b8b572e1SStephen Rothwell */ 164b8b572e1SStephen Rothwell struct iommu_table; 165b8b572e1SStephen Rothwell 166b8b572e1SStephen Rothwell struct pci_dn { 167cca87d30SGavin Shan int flags; 168cca87d30SGavin Shan 169b8b572e1SStephen Rothwell int busno; /* pci bus number */ 170b8b572e1SStephen Rothwell int devfn; /* pci device and function number */ 171c035ff1dSGavin Shan int vendor_id; /* Vendor ID */ 172c035ff1dSGavin Shan int device_id; /* Device ID */ 173c035ff1dSGavin Shan int class_code; /* Device class code */ 174b8b572e1SStephen Rothwell 175cca87d30SGavin Shan struct pci_dn *parent; 176b8b572e1SStephen Rothwell struct pci_controller *phb; /* for pci devices */ 177b8b572e1SStephen Rothwell struct iommu_table *iommu_table; /* for phb's or bridges */ 178b8b572e1SStephen Rothwell struct device_node *node; /* back-pointer to the device_node */ 179b8b572e1SStephen Rothwell 180b8b572e1SStephen Rothwell int pci_ext_config_space; /* for pci devices */ 181b8b572e1SStephen Rothwell 182b8b572e1SStephen Rothwell struct pci_dev *pcidev; /* back-pointer to the pci device */ 183184cd4a3SBenjamin Herrenschmidt #ifdef CONFIG_EEH 1842a0352faSGavin Shan struct eeh_dev *edev; /* eeh device */ 185b8b572e1SStephen Rothwell #endif 186184cd4a3SBenjamin Herrenschmidt #define IODA_INVALID_PE (-1) 187184cd4a3SBenjamin Herrenschmidt #ifdef CONFIG_PPC_POWERNV 188184cd4a3SBenjamin Herrenschmidt int pe_number; 189184cd4a3SBenjamin Herrenschmidt #endif 190cca87d30SGavin Shan struct list_head child_list; 191cca87d30SGavin Shan struct list_head list; 192b8b572e1SStephen Rothwell }; 193b8b572e1SStephen Rothwell 194b8b572e1SStephen Rothwell /* Get the pointer to a device_node's pci_dn */ 195b8b572e1SStephen Rothwell #define PCI_DN(dn) ((struct pci_dn *) (dn)->data) 196b8b572e1SStephen Rothwell 197cca87d30SGavin Shan extern struct pci_dn *pci_get_pdn_by_devfn(struct pci_bus *bus, 198cca87d30SGavin Shan int devfn); 199b72c1f65SBenjamin Herrenschmidt extern struct pci_dn *pci_get_pdn(struct pci_dev *pdev); 2002eb4afb6SKumar Gala extern void *update_dn_pci_info(struct device_node *dn, void *data); 201b8b572e1SStephen Rothwell 202b8b572e1SStephen Rothwell static inline int pci_device_from_OF_node(struct device_node *np, 203b8b572e1SStephen Rothwell u8 *bus, u8 *devfn) 204b8b572e1SStephen Rothwell { 205b8b572e1SStephen Rothwell if (!PCI_DN(np)) 206b8b572e1SStephen Rothwell return -ENODEV; 207b8b572e1SStephen Rothwell *bus = PCI_DN(np)->busno; 208b8b572e1SStephen Rothwell *devfn = PCI_DN(np)->devfn; 209b8b572e1SStephen Rothwell return 0; 210b8b572e1SStephen Rothwell } 211b8b572e1SStephen Rothwell 2122a0352faSGavin Shan #if defined(CONFIG_EEH) 213e8e9b34cSGavin Shan static inline struct eeh_dev *pdn_to_eeh_dev(struct pci_dn *pdn) 214e8e9b34cSGavin Shan { 215e8e9b34cSGavin Shan return pdn ? pdn->edev : NULL; 216e8e9b34cSGavin Shan } 217f8f7d63fSGavin Shan #else 218e8e9b34cSGavin Shan #define pdn_to_eeh_dev(x) (NULL) 2192a0352faSGavin Shan #endif 2202a0352faSGavin Shan 221b8b572e1SStephen Rothwell /** Find the bus corresponding to the indicated device node */ 222b8b572e1SStephen Rothwell extern struct pci_bus *pcibios_find_pci_bus(struct device_node *dn); 223b8b572e1SStephen Rothwell 224b8b572e1SStephen Rothwell /** Remove all of the PCI devices under this bus */ 225b8b572e1SStephen Rothwell extern void pcibios_remove_pci_devices(struct pci_bus *bus); 226b8b572e1SStephen Rothwell 227b8b572e1SStephen Rothwell /** Discover new pci devices under this bus, and add them */ 228b8b572e1SStephen Rothwell extern void pcibios_add_pci_devices(struct pci_bus *bus); 229b8b572e1SStephen Rothwell 230b8b572e1SStephen Rothwell 231b8b572e1SStephen Rothwell extern void isa_bridge_find_early(struct pci_controller *hose); 232b8b572e1SStephen Rothwell 233b8b572e1SStephen Rothwell static inline int isa_vaddr_is_ioport(void __iomem *address) 234b8b572e1SStephen Rothwell { 235b8b572e1SStephen Rothwell /* Check if address hits the reserved legacy IO range */ 236b8b572e1SStephen Rothwell unsigned long ea = (unsigned long)address; 237b8b572e1SStephen Rothwell return ea >= ISA_IO_BASE && ea < ISA_IO_END; 238b8b572e1SStephen Rothwell } 239b8b572e1SStephen Rothwell 240b8b572e1SStephen Rothwell extern int pcibios_unmap_io_space(struct pci_bus *bus); 241b8b572e1SStephen Rothwell extern int pcibios_map_io_space(struct pci_bus *bus); 242b8b572e1SStephen Rothwell 243b8b572e1SStephen Rothwell #ifdef CONFIG_NUMA 244b8b572e1SStephen Rothwell #define PHB_SET_NODE(PHB, NODE) ((PHB)->node = (NODE)) 245b8b572e1SStephen Rothwell #else 246b8b572e1SStephen Rothwell #define PHB_SET_NODE(PHB, NODE) ((PHB)->node = -1) 247b8b572e1SStephen Rothwell #endif 248b8b572e1SStephen Rothwell 249b8b572e1SStephen Rothwell #endif /* CONFIG_PPC64 */ 250b8b572e1SStephen Rothwell 251b8b572e1SStephen Rothwell /* Get the PCI host controller for an OF device */ 252b8b572e1SStephen Rothwell extern struct pci_controller *pci_find_hose_for_OF_device( 253b8b572e1SStephen Rothwell struct device_node* node); 254b8b572e1SStephen Rothwell 255b8b572e1SStephen Rothwell /* Fill up host controller resources from the OF node */ 256b8b572e1SStephen Rothwell extern void pci_process_bridge_OF_ranges(struct pci_controller *hose, 257b8b572e1SStephen Rothwell struct device_node *dev, int primary); 258b8b572e1SStephen Rothwell 259b8b572e1SStephen Rothwell /* Allocate & free a PCI host bridge structure */ 260b8b572e1SStephen Rothwell extern struct pci_controller *pcibios_alloc_controller(struct device_node *dev); 261b8b572e1SStephen Rothwell extern void pcibios_free_controller(struct pci_controller *phb); 262b8b572e1SStephen Rothwell 263b8b572e1SStephen Rothwell #ifdef CONFIG_PCI 264b8b572e1SStephen Rothwell extern int pcibios_vaddr_is_ioport(void __iomem *address); 265b8b572e1SStephen Rothwell #else 266b8b572e1SStephen Rothwell static inline int pcibios_vaddr_is_ioport(void __iomem *address) 267b8b572e1SStephen Rothwell { 268b8b572e1SStephen Rothwell return 0; 269b8b572e1SStephen Rothwell } 270b8b572e1SStephen Rothwell #endif /* CONFIG_PCI */ 271b8b572e1SStephen Rothwell 272e02def5bSDaniel Axtens /* 273e02def5bSDaniel Axtens * Shims to prefer pci_controller version over ppc_md where available. 274e02def5bSDaniel Axtens */ 275e02def5bSDaniel Axtens static inline void pci_dma_dev_setup(struct pci_dev *dev) 276e02def5bSDaniel Axtens { 277e02def5bSDaniel Axtens struct pci_controller *phb = pci_bus_to_host(dev->bus); 278e02def5bSDaniel Axtens 279e02def5bSDaniel Axtens if (phb->controller_ops.dma_dev_setup) 280e02def5bSDaniel Axtens phb->controller_ops.dma_dev_setup(dev); 281e02def5bSDaniel Axtens else if (ppc_md.pci_dma_dev_setup) 282e02def5bSDaniel Axtens ppc_md.pci_dma_dev_setup(dev); 283e02def5bSDaniel Axtens } 284e02def5bSDaniel Axtens 285*b122c954SDaniel Axtens static inline void pci_dma_bus_setup(struct pci_bus *bus) 286*b122c954SDaniel Axtens { 287*b122c954SDaniel Axtens struct pci_controller *phb = pci_bus_to_host(bus); 288*b122c954SDaniel Axtens 289*b122c954SDaniel Axtens if (phb->controller_ops.dma_bus_setup) 290*b122c954SDaniel Axtens phb->controller_ops.dma_bus_setup(bus); 291*b122c954SDaniel Axtens else if (ppc_md.pci_dma_bus_setup) 292*b122c954SDaniel Axtens ppc_md.pci_dma_bus_setup(bus); 293*b122c954SDaniel Axtens } 294*b122c954SDaniel Axtens 295b8b572e1SStephen Rothwell #endif /* __KERNEL__ */ 296b8b572e1SStephen Rothwell #endif /* _ASM_POWERPC_PCI_BRIDGE_H */ 297