pci-bridge.h 8.3 KB

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