pci-bridge.h 7.9 KB

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