pci-bridge.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. #ifndef _ASM_POWERPC_PCI_BRIDGE_H
  2. #define _ASM_POWERPC_PCI_BRIDGE_H
  3. #ifdef __KERNEL__
  4. /*
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version
  8. * 2 of the License, or (at your option) any later version.
  9. */
  10. #include <linux/pci.h>
  11. #include <linux/list.h>
  12. #include <linux/ioport.h>
  13. #include <asm-generic/pci-bridge.h>
  14. /* Return values for pci_controller_ops.probe_mode function */
  15. #define PCI_PROBE_NONE -1 /* Don't look at this bus at all */
  16. #define PCI_PROBE_NORMAL 0 /* Do normal PCI probing */
  17. #define PCI_PROBE_DEVTREE 1 /* Instantiate from device tree */
  18. struct device_node;
  19. /*
  20. * PCI controller operations
  21. */
  22. struct pci_controller_ops {
  23. void (*dma_dev_setup)(struct pci_dev *dev);
  24. void (*dma_bus_setup)(struct pci_bus *bus);
  25. int (*probe_mode)(struct pci_bus *);
  26. /* Called when pci_enable_device() is called. Returns true to
  27. * allow assignment/enabling of the device. */
  28. bool (*enable_device_hook)(struct pci_dev *);
  29. /* Called during PCI resource reassignment */
  30. resource_size_t (*window_alignment)(struct pci_bus *, unsigned long type);
  31. };
  32. /*
  33. * Structure of a PCI controller (host bridge)
  34. */
  35. struct pci_controller {
  36. struct pci_bus *bus;
  37. char is_dynamic;
  38. #ifdef CONFIG_PPC64
  39. int node;
  40. #endif
  41. struct device_node *dn;
  42. struct list_head list_node;
  43. struct device *parent;
  44. int first_busno;
  45. int last_busno;
  46. int self_busno;
  47. struct resource busn;
  48. void __iomem *io_base_virt;
  49. #ifdef CONFIG_PPC64
  50. void *io_base_alloc;
  51. #endif
  52. resource_size_t io_base_phys;
  53. resource_size_t pci_io_size;
  54. /* Some machines have a special region to forward the ISA
  55. * "memory" cycles such as VGA memory regions. Left to 0
  56. * if unsupported
  57. */
  58. resource_size_t isa_mem_phys;
  59. resource_size_t isa_mem_size;
  60. struct pci_controller_ops controller_ops;
  61. struct pci_ops *ops;
  62. unsigned int __iomem *cfg_addr;
  63. void __iomem *cfg_data;
  64. /*
  65. * Used for variants of PCI indirect handling and possible quirks:
  66. * SET_CFG_TYPE - used on 4xx or any PHB that does explicit type0/1
  67. * EXT_REG - provides access to PCI-e extended registers
  68. * SURPRESS_PRIMARY_BUS - we suppress the setting of PCI_PRIMARY_BUS
  69. * on Freescale PCI-e controllers since they used the PCI_PRIMARY_BUS
  70. * to determine which bus number to match on when generating type0
  71. * config cycles
  72. * NO_PCIE_LINK - the Freescale PCI-e controllers have issues with
  73. * hanging if we don't have link and try to do config cycles to
  74. * anything but the PHB. Only allow talking to the PHB if this is
  75. * set.
  76. * BIG_ENDIAN - cfg_addr is a big endian register
  77. * BROKEN_MRM - the 440EPx/GRx chips have an errata that causes hangs on
  78. * the PLB4. Effectively disable MRM commands by setting this.
  79. * FSL_CFG_REG_LINK - Freescale controller version in which the PCIe
  80. * link status is in a RC PCIe cfg register (vs being a SoC register)
  81. */
  82. #define PPC_INDIRECT_TYPE_SET_CFG_TYPE 0x00000001
  83. #define PPC_INDIRECT_TYPE_EXT_REG 0x00000002
  84. #define PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS 0x00000004
  85. #define PPC_INDIRECT_TYPE_NO_PCIE_LINK 0x00000008
  86. #define PPC_INDIRECT_TYPE_BIG_ENDIAN 0x00000010
  87. #define PPC_INDIRECT_TYPE_BROKEN_MRM 0x00000020
  88. #define PPC_INDIRECT_TYPE_FSL_CFG_REG_LINK 0x00000040
  89. u32 indirect_type;
  90. /* Currently, we limit ourselves to 1 IO range and 3 mem
  91. * ranges since the common pci_bus structure can't handle more
  92. */
  93. struct resource io_resource;
  94. struct resource mem_resources[3];
  95. resource_size_t mem_offset[3];
  96. int global_number; /* PCI domain number */
  97. resource_size_t dma_window_base_cur;
  98. resource_size_t dma_window_size;
  99. #ifdef CONFIG_PPC64
  100. unsigned long buid;
  101. struct pci_dn *pci_data;
  102. #endif /* CONFIG_PPC64 */
  103. void *private_data;
  104. };
  105. /* These are used for config access before all the PCI probing
  106. has been done. */
  107. extern int early_read_config_byte(struct pci_controller *hose, int bus,
  108. int dev_fn, int where, u8 *val);
  109. extern int early_read_config_word(struct pci_controller *hose, int bus,
  110. int dev_fn, int where, u16 *val);
  111. extern int early_read_config_dword(struct pci_controller *hose, int bus,
  112. int dev_fn, int where, u32 *val);
  113. extern int early_write_config_byte(struct pci_controller *hose, int bus,
  114. int dev_fn, int where, u8 val);
  115. extern int early_write_config_word(struct pci_controller *hose, int bus,
  116. int dev_fn, int where, u16 val);
  117. extern int early_write_config_dword(struct pci_controller *hose, int bus,
  118. int dev_fn, int where, u32 val);
  119. extern int early_find_capability(struct pci_controller *hose, int bus,
  120. int dev_fn, int cap);
  121. extern void setup_indirect_pci(struct pci_controller* hose,
  122. resource_size_t cfg_addr,
  123. resource_size_t cfg_data, u32 flags);
  124. extern int indirect_read_config(struct pci_bus *bus, unsigned int devfn,
  125. int offset, int len, u32 *val);
  126. extern int __indirect_read_config(struct pci_controller *hose,
  127. unsigned char bus_number, unsigned int devfn,
  128. int offset, int len, u32 *val);
  129. extern int indirect_write_config(struct pci_bus *bus, unsigned int devfn,
  130. int offset, int len, u32 val);
  131. static inline struct pci_controller *pci_bus_to_host(const struct pci_bus *bus)
  132. {
  133. return bus->sysdata;
  134. }
  135. #ifndef CONFIG_PPC64
  136. extern int pci_device_from_OF_node(struct device_node *node,
  137. u8 *bus, u8 *devfn);
  138. extern void pci_create_OF_bus_map(void);
  139. static inline int isa_vaddr_is_ioport(void __iomem *address)
  140. {
  141. /* No specific ISA handling on ppc32 at this stage, it
  142. * all goes through PCI
  143. */
  144. return 0;
  145. }
  146. #else /* CONFIG_PPC64 */
  147. /*
  148. * PCI stuff, for nodes representing PCI devices, pointed to
  149. * by device_node->data.
  150. */
  151. struct iommu_table;
  152. struct pci_dn {
  153. int flags;
  154. int busno; /* pci bus number */
  155. int devfn; /* pci device and function number */
  156. int vendor_id; /* Vendor ID */
  157. int device_id; /* Device ID */
  158. int class_code; /* Device class code */
  159. struct pci_dn *parent;
  160. struct pci_controller *phb; /* for pci devices */
  161. struct iommu_table *iommu_table; /* for phb's or bridges */
  162. struct device_node *node; /* back-pointer to the device_node */
  163. int pci_ext_config_space; /* for pci devices */
  164. struct pci_dev *pcidev; /* back-pointer to the pci device */
  165. #ifdef CONFIG_EEH
  166. struct eeh_dev *edev; /* eeh device */
  167. #endif
  168. #define IODA_INVALID_PE (-1)
  169. #ifdef CONFIG_PPC_POWERNV
  170. int pe_number;
  171. #endif
  172. struct list_head child_list;
  173. struct list_head list;
  174. };
  175. /* Get the pointer to a device_node's pci_dn */
  176. #define PCI_DN(dn) ((struct pci_dn *) (dn)->data)
  177. extern struct pci_dn *pci_get_pdn_by_devfn(struct pci_bus *bus,
  178. int devfn);
  179. extern struct pci_dn *pci_get_pdn(struct pci_dev *pdev);
  180. extern void *update_dn_pci_info(struct device_node *dn, void *data);
  181. static inline int pci_device_from_OF_node(struct device_node *np,
  182. u8 *bus, u8 *devfn)
  183. {
  184. if (!PCI_DN(np))
  185. return -ENODEV;
  186. *bus = PCI_DN(np)->busno;
  187. *devfn = PCI_DN(np)->devfn;
  188. return 0;
  189. }
  190. #if defined(CONFIG_EEH)
  191. static inline struct eeh_dev *pdn_to_eeh_dev(struct pci_dn *pdn)
  192. {
  193. return pdn ? pdn->edev : NULL;
  194. }
  195. #else
  196. #define pdn_to_eeh_dev(x) (NULL)
  197. #endif
  198. /** Find the bus corresponding to the indicated device node */
  199. extern struct pci_bus *pcibios_find_pci_bus(struct device_node *dn);
  200. /** Remove all of the PCI devices under this bus */
  201. extern void pcibios_remove_pci_devices(struct pci_bus *bus);
  202. /** Discover new pci devices under this bus, and add them */
  203. extern void pcibios_add_pci_devices(struct pci_bus *bus);
  204. extern void isa_bridge_find_early(struct pci_controller *hose);
  205. static inline int isa_vaddr_is_ioport(void __iomem *address)
  206. {
  207. /* Check if address hits the reserved legacy IO range */
  208. unsigned long ea = (unsigned long)address;
  209. return ea >= ISA_IO_BASE && ea < ISA_IO_END;
  210. }
  211. extern int pcibios_unmap_io_space(struct pci_bus *bus);
  212. extern int pcibios_map_io_space(struct pci_bus *bus);
  213. #ifdef CONFIG_NUMA
  214. #define PHB_SET_NODE(PHB, NODE) ((PHB)->node = (NODE))
  215. #else
  216. #define PHB_SET_NODE(PHB, NODE) ((PHB)->node = -1)
  217. #endif
  218. #endif /* CONFIG_PPC64 */
  219. /* Get the PCI host controller for an OF device */
  220. extern struct pci_controller *pci_find_hose_for_OF_device(
  221. struct device_node* node);
  222. /* Fill up host controller resources from the OF node */
  223. extern void pci_process_bridge_OF_ranges(struct pci_controller *hose,
  224. struct device_node *dev, int primary);
  225. /* Allocate & free a PCI host bridge structure */
  226. extern struct pci_controller *pcibios_alloc_controller(struct device_node *dev);
  227. extern void pcibios_free_controller(struct pci_controller *phb);
  228. #ifdef CONFIG_PCI
  229. extern int pcibios_vaddr_is_ioport(void __iomem *address);
  230. #else
  231. static inline int pcibios_vaddr_is_ioport(void __iomem *address)
  232. {
  233. return 0;
  234. }
  235. #endif /* CONFIG_PCI */
  236. /*
  237. * Shims to prefer pci_controller version over ppc_md where available.
  238. */
  239. static inline void pci_dma_dev_setup(struct pci_dev *dev)
  240. {
  241. struct pci_controller *phb = pci_bus_to_host(dev->bus);
  242. if (phb->controller_ops.dma_dev_setup)
  243. phb->controller_ops.dma_dev_setup(dev);
  244. else if (ppc_md.pci_dma_dev_setup)
  245. ppc_md.pci_dma_dev_setup(dev);
  246. }
  247. static inline void pci_dma_bus_setup(struct pci_bus *bus)
  248. {
  249. struct pci_controller *phb = pci_bus_to_host(bus);
  250. if (phb->controller_ops.dma_bus_setup)
  251. phb->controller_ops.dma_bus_setup(bus);
  252. else if (ppc_md.pci_dma_bus_setup)
  253. ppc_md.pci_dma_bus_setup(bus);
  254. }
  255. static inline int pci_probe_mode(struct pci_bus *bus)
  256. {
  257. struct pci_controller *phb = pci_bus_to_host(bus);
  258. if (phb->controller_ops.probe_mode)
  259. return phb->controller_ops.probe_mode(bus);
  260. if (ppc_md.pci_probe_mode)
  261. return ppc_md.pci_probe_mode(bus);
  262. return PCI_PROBE_NORMAL;
  263. }
  264. static inline bool pcibios_enable_device_hook(struct pci_dev *dev)
  265. {
  266. struct pci_controller *phb = pci_bus_to_host(dev->bus);
  267. if (phb->controller_ops.enable_device_hook)
  268. return phb->controller_ops.enable_device_hook(dev);
  269. if (ppc_md.pcibios_enable_device_hook)
  270. return ppc_md.pcibios_enable_device_hook(dev);
  271. return true;
  272. }
  273. static inline resource_size_t pci_window_alignment(struct pci_bus *bus,
  274. unsigned long type)
  275. {
  276. struct pci_controller *phb = pci_bus_to_host(bus);
  277. if (phb->controller_ops.window_alignment)
  278. return phb->controller_ops.window_alignment(bus, type);
  279. if (ppc_md.pcibios_window_alignment)
  280. return ppc_md.pcibios_window_alignment(bus, type);
  281. /*
  282. * PCI core will figure out the default
  283. * alignment: 4KiB for I/O and 1MiB for
  284. * memory window.
  285. */
  286. return 1;
  287. }
  288. #endif /* __KERNEL__ */
  289. #endif /* _ASM_POWERPC_PCI_BRIDGE_H */