pci-bridge.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. #ifndef _ASM_POWERPC_PCI_BRIDGE_H
  2. #define _ASM_POWERPC_PCI_BRIDGE_H
  3. #ifdef __KERNEL__
  4. #include <linux/pci.h>
  5. #include <linux/list.h>
  6. #include <linux/ioport.h>
  7. #ifndef CONFIG_PPC64
  8. struct device_node;
  9. struct pci_controller;
  10. /*
  11. * Structure of a PCI controller (host bridge)
  12. */
  13. struct pci_controller {
  14. struct pci_bus *bus;
  15. char is_dynamic;
  16. void *arch_data;
  17. struct list_head list_node;
  18. struct device *parent;
  19. int first_busno;
  20. int last_busno;
  21. int self_busno;
  22. void __iomem *io_base_virt;
  23. resource_size_t io_base_phys;
  24. /* Some machines (PReP) have a non 1:1 mapping of
  25. * the PCI memory space in the CPU bus space
  26. */
  27. resource_size_t pci_mem_offset;
  28. struct pci_ops *ops;
  29. volatile unsigned int __iomem *cfg_addr;
  30. volatile void __iomem *cfg_data;
  31. /*
  32. * Used for variants of PCI indirect handling and possible quirks:
  33. * SET_CFG_TYPE - used on 4xx or any PHB that does explicit type0/1
  34. * EXT_REG - provides access to PCI-e extended registers
  35. * SURPRESS_PRIMARY_BUS - we surpress the setting of PCI_PRIMARY_BUS
  36. * on Freescale PCI-e controllers since they used the PCI_PRIMARY_BUS
  37. * to determine which bus number to match on when generating type0
  38. * config cycles
  39. * NO_PCIE_LINK - the Freescale PCI-e controllers have issues with
  40. * hanging if we don't have link and try to do config cycles to
  41. * anything but the PHB. Only allow talking to the PHB if this is
  42. * set.
  43. * BIG_ENDIAN - cfg_addr is a big endian register
  44. */
  45. #define PPC_INDIRECT_TYPE_SET_CFG_TYPE (0x00000001)
  46. #define PPC_INDIRECT_TYPE_EXT_REG (0x00000002)
  47. #define PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS (0x00000004)
  48. #define PPC_INDIRECT_TYPE_NO_PCIE_LINK (0x00000008)
  49. #define PPC_INDIRECT_TYPE_BIG_ENDIAN (0x00000010)
  50. u32 indirect_type;
  51. /* Currently, we limit ourselves to 1 IO range and 3 mem
  52. * ranges since the common pci_bus structure can't handle more
  53. */
  54. struct resource io_resource;
  55. struct resource mem_resources[3];
  56. int global_number; /* PCI domain number */
  57. };
  58. static inline struct pci_controller *pci_bus_to_host(struct pci_bus *bus)
  59. {
  60. return bus->sysdata;
  61. }
  62. static inline int isa_vaddr_is_ioport(void __iomem *address)
  63. {
  64. /* No specific ISA handling on ppc32 at this stage, it
  65. * all goes through PCI
  66. */
  67. return 0;
  68. }
  69. /* These are used for config access before all the PCI probing
  70. has been done. */
  71. int early_read_config_byte(struct pci_controller *hose, int bus, int dev_fn,
  72. int where, u8 *val);
  73. int early_read_config_word(struct pci_controller *hose, int bus, int dev_fn,
  74. int where, u16 *val);
  75. int early_read_config_dword(struct pci_controller *hose, int bus, int dev_fn,
  76. int where, u32 *val);
  77. int early_write_config_byte(struct pci_controller *hose, int bus, int dev_fn,
  78. int where, u8 val);
  79. int early_write_config_word(struct pci_controller *hose, int bus, int dev_fn,
  80. int where, u16 val);
  81. int early_write_config_dword(struct pci_controller *hose, int bus, int dev_fn,
  82. int where, u32 val);
  83. extern int early_find_capability(struct pci_controller *hose, int bus,
  84. int dev_fn, int cap);
  85. extern void setup_indirect_pci(struct pci_controller* hose,
  86. u32 cfg_addr, u32 cfg_data, u32 flags);
  87. extern void setup_grackle(struct pci_controller *hose);
  88. extern void __init update_bridge_resource(struct pci_dev *dev,
  89. struct resource *res);
  90. #else
  91. /*
  92. * This program is free software; you can redistribute it and/or
  93. * modify it under the terms of the GNU General Public License
  94. * as published by the Free Software Foundation; either version
  95. * 2 of the License, or (at your option) any later version.
  96. */
  97. /*
  98. * Structure of a PCI controller (host bridge)
  99. */
  100. struct pci_controller {
  101. struct pci_bus *bus;
  102. char is_dynamic;
  103. int node;
  104. void *arch_data;
  105. struct list_head list_node;
  106. struct device *parent;
  107. int first_busno;
  108. int last_busno;
  109. void __iomem *io_base_virt;
  110. void *io_base_alloc;
  111. resource_size_t io_base_phys;
  112. /* Some machines have a non 1:1 mapping of
  113. * the PCI memory space in the CPU bus space
  114. */
  115. resource_size_t pci_mem_offset;
  116. unsigned long pci_io_size;
  117. struct pci_ops *ops;
  118. volatile unsigned int __iomem *cfg_addr;
  119. volatile void __iomem *cfg_data;
  120. /* Currently, we limit ourselves to 1 IO range and 3 mem
  121. * ranges since the common pci_bus structure can't handle more
  122. */
  123. struct resource io_resource;
  124. struct resource mem_resources[3];
  125. int global_number;
  126. unsigned long buid;
  127. unsigned long dma_window_base_cur;
  128. unsigned long dma_window_size;
  129. void *private_data;
  130. };
  131. /*
  132. * PCI stuff, for nodes representing PCI devices, pointed to
  133. * by device_node->data.
  134. */
  135. struct pci_controller;
  136. struct iommu_table;
  137. struct pci_dn {
  138. int busno; /* pci bus number */
  139. int bussubno; /* pci subordinate bus number */
  140. int devfn; /* pci device and function number */
  141. int class_code; /* pci device class */
  142. struct pci_controller *phb; /* for pci devices */
  143. struct iommu_table *iommu_table; /* for phb's or bridges */
  144. struct pci_dev *pcidev; /* back-pointer to the pci device */
  145. struct device_node *node; /* back-pointer to the device_node */
  146. int pci_ext_config_space; /* for pci devices */
  147. #ifdef CONFIG_EEH
  148. int eeh_mode; /* See eeh.h for possible EEH_MODEs */
  149. int eeh_config_addr;
  150. int eeh_pe_config_addr; /* new-style partition endpoint address */
  151. int eeh_check_count; /* # times driver ignored error */
  152. int eeh_freeze_count; /* # times this device froze up. */
  153. int eeh_false_positives; /* # times this device reported #ff's */
  154. u32 config_space[16]; /* saved PCI config space */
  155. #endif
  156. };
  157. /* Get the pointer to a device_node's pci_dn */
  158. #define PCI_DN(dn) ((struct pci_dn *) (dn)->data)
  159. struct device_node *fetch_dev_dn(struct pci_dev *dev);
  160. /* Get a device_node from a pci_dev. This code must be fast except
  161. * in the case where the sysdata is incorrect and needs to be fixed
  162. * up (this will only happen once).
  163. * In this case the sysdata will have been inherited from a PCI host
  164. * bridge or a PCI-PCI bridge further up the tree, so it will point
  165. * to a valid struct pci_dn, just not the one we want.
  166. */
  167. static inline struct device_node *pci_device_to_OF_node(struct pci_dev *dev)
  168. {
  169. struct device_node *dn = dev->sysdata;
  170. struct pci_dn *pdn = dn->data;
  171. if (pdn && pdn->devfn == dev->devfn && pdn->busno == dev->bus->number)
  172. return dn; /* fast path. sysdata is good */
  173. return fetch_dev_dn(dev);
  174. }
  175. static inline int pci_device_from_OF_node(struct device_node *np,
  176. u8 *bus, u8 *devfn)
  177. {
  178. if (!PCI_DN(np))
  179. return -ENODEV;
  180. *bus = PCI_DN(np)->busno;
  181. *devfn = PCI_DN(np)->devfn;
  182. return 0;
  183. }
  184. static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus)
  185. {
  186. if (bus->self)
  187. return pci_device_to_OF_node(bus->self);
  188. else
  189. return bus->sysdata; /* Must be root bus (PHB) */
  190. }
  191. /** Find the bus corresponding to the indicated device node */
  192. struct pci_bus * pcibios_find_pci_bus(struct device_node *dn);
  193. /** Remove all of the PCI devices under this bus */
  194. void pcibios_remove_pci_devices(struct pci_bus *bus);
  195. /** Discover new pci devices under this bus, and add them */
  196. void pcibios_add_pci_devices(struct pci_bus * bus);
  197. void pcibios_fixup_new_pci_devices(struct pci_bus *bus, int fix_bus);
  198. extern int pcibios_remove_root_bus(struct pci_controller *phb);
  199. static inline struct pci_controller *pci_bus_to_host(struct pci_bus *bus)
  200. {
  201. struct device_node *busdn = bus->sysdata;
  202. BUG_ON(busdn == NULL);
  203. return PCI_DN(busdn)->phb;
  204. }
  205. extern void pcibios_free_controller(struct pci_controller *phb);
  206. extern void isa_bridge_find_early(struct pci_controller *hose);
  207. static inline int isa_vaddr_is_ioport(void __iomem *address)
  208. {
  209. /* Check if address hits the reserved legacy IO range */
  210. unsigned long ea = (unsigned long)address;
  211. return ea >= ISA_IO_BASE && ea < ISA_IO_END;
  212. }
  213. extern int pcibios_unmap_io_space(struct pci_bus *bus);
  214. extern int pcibios_map_io_space(struct pci_bus *bus);
  215. /* Return values for ppc_md.pci_probe_mode function */
  216. #define PCI_PROBE_NONE -1 /* Don't look at this bus at all */
  217. #define PCI_PROBE_NORMAL 0 /* Do normal PCI probing */
  218. #define PCI_PROBE_DEVTREE 1 /* Instantiate from device tree */
  219. #ifdef CONFIG_NUMA
  220. #define PHB_SET_NODE(PHB, NODE) ((PHB)->node = (NODE))
  221. #else
  222. #define PHB_SET_NODE(PHB, NODE) ((PHB)->node = -1)
  223. #endif
  224. #endif /* CONFIG_PPC64 */
  225. /* Get the PCI host controller for an OF device */
  226. extern struct pci_controller*
  227. pci_find_hose_for_OF_device(struct device_node* node);
  228. /* Fill up host controller resources from the OF node */
  229. extern void
  230. pci_process_bridge_OF_ranges(struct pci_controller *hose,
  231. struct device_node *dev, int primary);
  232. /* Allocate a new PCI host bridge structure */
  233. extern struct pci_controller *
  234. pcibios_alloc_controller(struct device_node *dev);
  235. #ifdef CONFIG_PCI
  236. extern unsigned long pci_address_to_pio(phys_addr_t address);
  237. extern int pcibios_vaddr_is_ioport(void __iomem *address);
  238. #else
  239. static inline unsigned long pci_address_to_pio(phys_addr_t address)
  240. {
  241. return (unsigned long)-1;
  242. }
  243. static inline int pcibios_vaddr_is_ioport(void __iomem *address)
  244. {
  245. return 0;
  246. }
  247. #endif
  248. #endif /* __KERNEL__ */
  249. #endif