pci-bridge.h 8.0 KB

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