pci-bridge.h 8.6 KB

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