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