pci-bridge.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. resource_size_t cfg_addr,
  87. resource_size_t cfg_data, u32 flags);
  88. extern void setup_grackle(struct pci_controller *hose);
  89. extern void __init update_bridge_resource(struct pci_dev *dev,
  90. struct resource *res);
  91. #else
  92. /*
  93. * This program is free software; you can redistribute it and/or
  94. * modify it under the terms of the GNU General Public License
  95. * as published by the Free Software Foundation; either version
  96. * 2 of the License, or (at your option) any later version.
  97. */
  98. /*
  99. * Structure of a PCI controller (host bridge)
  100. */
  101. struct pci_controller {
  102. struct pci_bus *bus;
  103. char is_dynamic;
  104. int node;
  105. void *arch_data;
  106. struct list_head list_node;
  107. struct device *parent;
  108. int first_busno;
  109. int last_busno;
  110. void __iomem *io_base_virt;
  111. void *io_base_alloc;
  112. resource_size_t io_base_phys;
  113. /* Some machines have a non 1:1 mapping of
  114. * the PCI memory space in the CPU bus space
  115. */
  116. resource_size_t pci_mem_offset;
  117. unsigned long pci_io_size;
  118. struct pci_ops *ops;
  119. volatile unsigned int __iomem *cfg_addr;
  120. volatile void __iomem *cfg_data;
  121. /* Currently, we limit ourselves to 1 IO range and 3 mem
  122. * ranges since the common pci_bus structure can't handle more
  123. */
  124. struct resource io_resource;
  125. struct resource mem_resources[3];
  126. int global_number;
  127. unsigned long buid;
  128. unsigned long dma_window_base_cur;
  129. unsigned long dma_window_size;
  130. void *private_data;
  131. };
  132. /*
  133. * PCI stuff, for nodes representing PCI devices, pointed to
  134. * by device_node->data.
  135. */
  136. struct pci_controller;
  137. struct iommu_table;
  138. struct pci_dn {
  139. int busno; /* pci bus number */
  140. int bussubno; /* pci subordinate bus number */
  141. int devfn; /* pci device and function number */
  142. int class_code; /* pci device class */
  143. struct pci_controller *phb; /* for pci devices */
  144. struct iommu_table *iommu_table; /* for phb's or bridges */
  145. struct pci_dev *pcidev; /* back-pointer to the pci device */
  146. struct device_node *node; /* back-pointer to the device_node */
  147. int pci_ext_config_space; /* for pci devices */
  148. #ifdef CONFIG_EEH
  149. int eeh_mode; /* See eeh.h for possible EEH_MODEs */
  150. int eeh_config_addr;
  151. int eeh_pe_config_addr; /* new-style partition endpoint address */
  152. int eeh_check_count; /* # times driver ignored error */
  153. int eeh_freeze_count; /* # times this device froze up. */
  154. int eeh_false_positives; /* # times this device reported #ff's */
  155. u32 config_space[16]; /* saved PCI config space */
  156. #endif
  157. };
  158. /* Get the pointer to a device_node's pci_dn */
  159. #define PCI_DN(dn) ((struct pci_dn *) (dn)->data)
  160. struct device_node *fetch_dev_dn(struct pci_dev *dev);
  161. /* Get a device_node from a pci_dev. This code must be fast except
  162. * in the case where the sysdata is incorrect and needs to be fixed
  163. * up (this will only happen once).
  164. * In this case the sysdata will have been inherited from a PCI host
  165. * bridge or a PCI-PCI bridge further up the tree, so it will point
  166. * to a valid struct pci_dn, just not the one we want.
  167. */
  168. static inline struct device_node *pci_device_to_OF_node(struct pci_dev *dev)
  169. {
  170. struct device_node *dn = dev->sysdata;
  171. struct pci_dn *pdn = dn->data;
  172. if (pdn && pdn->devfn == dev->devfn && pdn->busno == dev->bus->number)
  173. return dn; /* fast path. sysdata is good */
  174. return fetch_dev_dn(dev);
  175. }
  176. static inline int pci_device_from_OF_node(struct device_node *np,
  177. u8 *bus, u8 *devfn)
  178. {
  179. if (!PCI_DN(np))
  180. return -ENODEV;
  181. *bus = PCI_DN(np)->busno;
  182. *devfn = PCI_DN(np)->devfn;
  183. return 0;
  184. }
  185. static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus)
  186. {
  187. if (bus->self)
  188. return pci_device_to_OF_node(bus->self);
  189. else
  190. return bus->sysdata; /* Must be root bus (PHB) */
  191. }
  192. /** Find the bus corresponding to the indicated device node */
  193. struct pci_bus * pcibios_find_pci_bus(struct device_node *dn);
  194. /** Remove all of the PCI devices under this bus */
  195. void pcibios_remove_pci_devices(struct pci_bus *bus);
  196. /** Discover new pci devices under this bus, and add them */
  197. void pcibios_add_pci_devices(struct pci_bus * bus);
  198. void pcibios_fixup_new_pci_devices(struct pci_bus *bus, int fix_bus);
  199. extern int pcibios_remove_root_bus(struct pci_controller *phb);
  200. static inline struct pci_controller *pci_bus_to_host(struct pci_bus *bus)
  201. {
  202. struct device_node *busdn = bus->sysdata;
  203. BUG_ON(busdn == NULL);
  204. return PCI_DN(busdn)->phb;
  205. }
  206. extern void pcibios_free_controller(struct pci_controller *phb);
  207. extern void isa_bridge_find_early(struct pci_controller *hose);
  208. static inline int isa_vaddr_is_ioport(void __iomem *address)
  209. {
  210. /* Check if address hits the reserved legacy IO range */
  211. unsigned long ea = (unsigned long)address;
  212. return ea >= ISA_IO_BASE && ea < ISA_IO_END;
  213. }
  214. extern int pcibios_unmap_io_space(struct pci_bus *bus);
  215. extern int pcibios_map_io_space(struct pci_bus *bus);
  216. /* Return values for ppc_md.pci_probe_mode function */
  217. #define PCI_PROBE_NONE -1 /* Don't look at this bus at all */
  218. #define PCI_PROBE_NORMAL 0 /* Do normal PCI probing */
  219. #define PCI_PROBE_DEVTREE 1 /* Instantiate from device tree */
  220. #ifdef CONFIG_NUMA
  221. #define PHB_SET_NODE(PHB, NODE) ((PHB)->node = (NODE))
  222. #else
  223. #define PHB_SET_NODE(PHB, NODE) ((PHB)->node = -1)
  224. #endif
  225. #endif /* CONFIG_PPC64 */
  226. /* Get the PCI host controller for an OF device */
  227. extern struct pci_controller*
  228. pci_find_hose_for_OF_device(struct device_node* node);
  229. /* Fill up host controller resources from the OF node */
  230. extern void
  231. pci_process_bridge_OF_ranges(struct pci_controller *hose,
  232. struct device_node *dev, int primary);
  233. /* Allocate a new PCI host bridge structure */
  234. extern struct pci_controller *
  235. pcibios_alloc_controller(struct device_node *dev);
  236. #ifdef CONFIG_PCI
  237. extern unsigned long pci_address_to_pio(phys_addr_t address);
  238. extern int pcibios_vaddr_is_ioport(void __iomem *address);
  239. #else
  240. static inline unsigned long pci_address_to_pio(phys_addr_t address)
  241. {
  242. return (unsigned long)-1;
  243. }
  244. static inline int pcibios_vaddr_is_ioport(void __iomem *address)
  245. {
  246. return 0;
  247. }
  248. #endif
  249. #endif /* __KERNEL__ */
  250. #endif