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 109*25985edcSLucas De Marchi * SURPRESS_PRIMARY_BUS - we suppress 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); 16689c2dd62SKumar Gala 16789c2dd62SKumar Gala static inline struct pci_controller *pci_bus_to_host(const struct pci_bus *bus) 16889c2dd62SKumar Gala { 16989c2dd62SKumar Gala return bus->sysdata; 17089c2dd62SKumar Gala } 17189c2dd62SKumar Gala 172b5d937deSGrant Likely #ifndef CONFIG_PPC64 173b5d937deSGrant Likely 17404bea68bSSebastian Andrzej Siewior static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus) 17504bea68bSSebastian Andrzej Siewior { 17604bea68bSSebastian Andrzej Siewior struct pci_controller *host; 17704bea68bSSebastian Andrzej Siewior 17804bea68bSSebastian Andrzej Siewior if (bus->self) 17904bea68bSSebastian Andrzej Siewior return pci_device_to_OF_node(bus->self); 18004bea68bSSebastian Andrzej Siewior host = pci_bus_to_host(bus); 18104bea68bSSebastian Andrzej Siewior return host ? host->dn : NULL; 18204bea68bSSebastian Andrzej Siewior } 18304bea68bSSebastian Andrzej Siewior 18489c2dd62SKumar Gala static inline int isa_vaddr_is_ioport(void __iomem *address) 18589c2dd62SKumar Gala { 18689c2dd62SKumar Gala /* No specific ISA handling on ppc32 at this stage, it 18789c2dd62SKumar Gala * all goes through PCI 18889c2dd62SKumar Gala */ 18989c2dd62SKumar Gala return 0; 19089c2dd62SKumar Gala } 19189c2dd62SKumar Gala 192b8b572e1SStephen Rothwell #else /* CONFIG_PPC64 */ 193b8b572e1SStephen Rothwell 194b8b572e1SStephen Rothwell /* 195b8b572e1SStephen Rothwell * PCI stuff, for nodes representing PCI devices, pointed to 196b8b572e1SStephen Rothwell * by device_node->data. 197b8b572e1SStephen Rothwell */ 198b8b572e1SStephen Rothwell struct iommu_table; 199b8b572e1SStephen Rothwell 200b8b572e1SStephen Rothwell struct pci_dn { 201b8b572e1SStephen Rothwell int busno; /* pci bus number */ 202b8b572e1SStephen Rothwell int devfn; /* pci device and function number */ 203b8b572e1SStephen Rothwell 204b8b572e1SStephen Rothwell struct pci_controller *phb; /* for pci devices */ 205b8b572e1SStephen Rothwell struct iommu_table *iommu_table; /* for phb's or bridges */ 206b8b572e1SStephen Rothwell struct device_node *node; /* back-pointer to the device_node */ 207b8b572e1SStephen Rothwell 208b8b572e1SStephen Rothwell int pci_ext_config_space; /* for pci devices */ 209b8b572e1SStephen Rothwell 210b8b572e1SStephen Rothwell #ifdef CONFIG_EEH 211b8b572e1SStephen Rothwell struct pci_dev *pcidev; /* back-pointer to the pci device */ 212b8b572e1SStephen Rothwell int class_code; /* pci device class */ 213b8b572e1SStephen Rothwell int eeh_mode; /* See eeh.h for possible EEH_MODEs */ 214b8b572e1SStephen Rothwell int eeh_config_addr; 215b8b572e1SStephen Rothwell int eeh_pe_config_addr; /* new-style partition endpoint address */ 216b8b572e1SStephen Rothwell int eeh_check_count; /* # times driver ignored error */ 217b8b572e1SStephen Rothwell int eeh_freeze_count; /* # times this device froze up. */ 218b8b572e1SStephen Rothwell int eeh_false_positives; /* # times this device reported #ff's */ 219b8b572e1SStephen Rothwell u32 config_space[16]; /* saved PCI config space */ 220b8b572e1SStephen Rothwell #endif 221b8b572e1SStephen Rothwell }; 222b8b572e1SStephen Rothwell 223b8b572e1SStephen Rothwell /* Get the pointer to a device_node's pci_dn */ 224b8b572e1SStephen Rothwell #define PCI_DN(dn) ((struct pci_dn *) (dn)->data) 225b8b572e1SStephen Rothwell 226b8b572e1SStephen Rothwell extern struct device_node *fetch_dev_dn(struct pci_dev *dev); 2272eb4afb6SKumar Gala extern void * update_dn_pci_info(struct device_node *dn, void *data); 228b8b572e1SStephen Rothwell 229b8b572e1SStephen Rothwell /* Get a device_node from a pci_dev. This code must be fast except 230b8b572e1SStephen Rothwell * in the case where the sysdata is incorrect and needs to be fixed 231b5d937deSGrant Likely * up (this will only happen once). */ 232b8b572e1SStephen Rothwell static inline struct device_node *pci_device_to_OF_node(struct pci_dev *dev) 233b8b572e1SStephen Rothwell { 234b5d937deSGrant Likely return dev->dev.of_node ? dev->dev.of_node : fetch_dev_dn(dev); 235b8b572e1SStephen Rothwell } 236b8b572e1SStephen Rothwell 237b8b572e1SStephen Rothwell static inline int pci_device_from_OF_node(struct device_node *np, 238b8b572e1SStephen Rothwell u8 *bus, u8 *devfn) 239b8b572e1SStephen Rothwell { 240b8b572e1SStephen Rothwell if (!PCI_DN(np)) 241b8b572e1SStephen Rothwell return -ENODEV; 242b8b572e1SStephen Rothwell *bus = PCI_DN(np)->busno; 243b8b572e1SStephen Rothwell *devfn = PCI_DN(np)->devfn; 244b8b572e1SStephen Rothwell return 0; 245b8b572e1SStephen Rothwell } 246b8b572e1SStephen Rothwell 247b8b572e1SStephen Rothwell static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus) 248b8b572e1SStephen Rothwell { 249b8b572e1SStephen Rothwell if (bus->self) 250b8b572e1SStephen Rothwell return pci_device_to_OF_node(bus->self); 251b8b572e1SStephen Rothwell else 252b5d937deSGrant Likely return bus->dev.of_node; /* Must be root bus (PHB) */ 253b8b572e1SStephen Rothwell } 254b8b572e1SStephen Rothwell 255b8b572e1SStephen Rothwell /** Find the bus corresponding to the indicated device node */ 256b8b572e1SStephen Rothwell extern struct pci_bus *pcibios_find_pci_bus(struct device_node *dn); 257b8b572e1SStephen Rothwell 258b8b572e1SStephen Rothwell /** Remove all of the PCI devices under this bus */ 259b8b572e1SStephen Rothwell extern void pcibios_remove_pci_devices(struct pci_bus *bus); 260b8b572e1SStephen Rothwell 261b8b572e1SStephen Rothwell /** Discover new pci devices under this bus, and add them */ 262b8b572e1SStephen Rothwell extern void pcibios_add_pci_devices(struct pci_bus *bus); 263b8b572e1SStephen Rothwell 264b8b572e1SStephen Rothwell 265b8b572e1SStephen Rothwell extern void isa_bridge_find_early(struct pci_controller *hose); 266b8b572e1SStephen Rothwell 267b8b572e1SStephen Rothwell static inline int isa_vaddr_is_ioport(void __iomem *address) 268b8b572e1SStephen Rothwell { 269b8b572e1SStephen Rothwell /* Check if address hits the reserved legacy IO range */ 270b8b572e1SStephen Rothwell unsigned long ea = (unsigned long)address; 271b8b572e1SStephen Rothwell return ea >= ISA_IO_BASE && ea < ISA_IO_END; 272b8b572e1SStephen Rothwell } 273b8b572e1SStephen Rothwell 274b8b572e1SStephen Rothwell extern int pcibios_unmap_io_space(struct pci_bus *bus); 275b8b572e1SStephen Rothwell extern int pcibios_map_io_space(struct pci_bus *bus); 276b8b572e1SStephen Rothwell 277b8b572e1SStephen Rothwell #ifdef CONFIG_NUMA 278b8b572e1SStephen Rothwell #define PHB_SET_NODE(PHB, NODE) ((PHB)->node = (NODE)) 279b8b572e1SStephen Rothwell #else 280b8b572e1SStephen Rothwell #define PHB_SET_NODE(PHB, NODE) ((PHB)->node = -1) 281b8b572e1SStephen Rothwell #endif 282b8b572e1SStephen Rothwell 283b8b572e1SStephen Rothwell #endif /* CONFIG_PPC64 */ 284b8b572e1SStephen Rothwell 285b8b572e1SStephen Rothwell /* Get the PCI host controller for an OF device */ 286b8b572e1SStephen Rothwell extern struct pci_controller *pci_find_hose_for_OF_device( 287b8b572e1SStephen Rothwell struct device_node* node); 288b8b572e1SStephen Rothwell 289b8b572e1SStephen Rothwell /* Fill up host controller resources from the OF node */ 290b8b572e1SStephen Rothwell extern void pci_process_bridge_OF_ranges(struct pci_controller *hose, 291b8b572e1SStephen Rothwell struct device_node *dev, int primary); 292b8b572e1SStephen Rothwell 293b8b572e1SStephen Rothwell /* Allocate & free a PCI host bridge structure */ 294b8b572e1SStephen Rothwell extern struct pci_controller *pcibios_alloc_controller(struct device_node *dev); 295b8b572e1SStephen Rothwell extern void pcibios_free_controller(struct pci_controller *phb); 29653280323SBenjamin Herrenschmidt extern void pcibios_setup_phb_resources(struct pci_controller *hose); 297b8b572e1SStephen Rothwell 298b8b572e1SStephen Rothwell #ifdef CONFIG_PCI 299b8b572e1SStephen Rothwell extern int pcibios_vaddr_is_ioport(void __iomem *address); 300b8b572e1SStephen Rothwell #else 301b8b572e1SStephen Rothwell static inline int pcibios_vaddr_is_ioport(void __iomem *address) 302b8b572e1SStephen Rothwell { 303b8b572e1SStephen Rothwell return 0; 304b8b572e1SStephen Rothwell } 305b8b572e1SStephen Rothwell #endif /* CONFIG_PCI */ 306b8b572e1SStephen Rothwell 307b8b572e1SStephen Rothwell #endif /* __KERNEL__ */ 308b8b572e1SStephen Rothwell #endif /* _ASM_POWERPC_PCI_BRIDGE_H */ 309