pci-bridge.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #ifndef _ASM_POWERPC_PCI_BRIDGE_H
  2. #define _ASM_POWERPC_PCI_BRIDGE_H
  3. #ifdef __KERNEL__
  4. #ifndef CONFIG_PPC64
  5. #include <asm-ppc/pci-bridge.h>
  6. #else
  7. #include <linux/pci.h>
  8. #include <linux/list.h>
  9. /*
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version
  13. * 2 of the License, or (at your option) any later version.
  14. */
  15. /*
  16. * Structure of a PCI controller (host bridge)
  17. */
  18. struct pci_controller {
  19. struct pci_bus *bus;
  20. char is_dynamic;
  21. int node;
  22. void *arch_data;
  23. struct list_head list_node;
  24. int first_busno;
  25. int last_busno;
  26. void __iomem *io_base_virt;
  27. unsigned long io_base_phys;
  28. /* Some machines have a non 1:1 mapping of
  29. * the PCI memory space in the CPU bus space
  30. */
  31. unsigned long pci_mem_offset;
  32. unsigned long pci_io_size;
  33. struct pci_ops *ops;
  34. volatile unsigned int __iomem *cfg_addr;
  35. volatile void __iomem *cfg_data;
  36. /* Currently, we limit ourselves to 1 IO range and 3 mem
  37. * ranges since the common pci_bus structure can't handle more
  38. */
  39. struct resource io_resource;
  40. struct resource mem_resources[3];
  41. int global_number;
  42. int local_number;
  43. unsigned long buid;
  44. unsigned long dma_window_base_cur;
  45. unsigned long dma_window_size;
  46. };
  47. /*
  48. * PCI stuff, for nodes representing PCI devices, pointed to
  49. * by device_node->data.
  50. */
  51. struct pci_controller;
  52. struct iommu_table;
  53. struct pci_dn {
  54. int busno; /* pci bus number */
  55. int bussubno; /* pci subordinate bus number */
  56. int devfn; /* pci device and function number */
  57. int class_code; /* pci device class */
  58. #ifdef CONFIG_PPC_PSERIES
  59. int eeh_mode; /* See eeh.h for possible EEH_MODEs */
  60. int eeh_config_addr;
  61. int eeh_pe_config_addr; /* new-style partition endpoint address */
  62. int eeh_check_count; /* # times driver ignored error */
  63. int eeh_freeze_count; /* # times this device froze up. */
  64. #endif
  65. int pci_ext_config_space; /* for pci devices */
  66. struct pci_controller *phb; /* for pci devices */
  67. struct iommu_table *iommu_table; /* for phb's or bridges */
  68. struct pci_dev *pcidev; /* back-pointer to the pci device */
  69. struct device_node *node; /* back-pointer to the device_node */
  70. u32 config_space[16]; /* saved PCI config space */
  71. };
  72. /* Get the pointer to a device_node's pci_dn */
  73. #define PCI_DN(dn) ((struct pci_dn *) (dn)->data)
  74. struct device_node *fetch_dev_dn(struct pci_dev *dev);
  75. /* Get a device_node from a pci_dev. This code must be fast except
  76. * in the case where the sysdata is incorrect and needs to be fixed
  77. * up (this will only happen once).
  78. * In this case the sysdata will have been inherited from a PCI host
  79. * bridge or a PCI-PCI bridge further up the tree, so it will point
  80. * to a valid struct pci_dn, just not the one we want.
  81. */
  82. static inline struct device_node *pci_device_to_OF_node(struct pci_dev *dev)
  83. {
  84. struct device_node *dn = dev->sysdata;
  85. struct pci_dn *pdn = dn->data;
  86. if (pdn && pdn->devfn == dev->devfn && pdn->busno == dev->bus->number)
  87. return dn; /* fast path. sysdata is good */
  88. return fetch_dev_dn(dev);
  89. }
  90. static inline int pci_device_from_OF_node(struct device_node *np,
  91. u8 *bus, u8 *devfn)
  92. {
  93. if (!PCI_DN(np))
  94. return -ENODEV;
  95. *bus = PCI_DN(np)->busno;
  96. *devfn = PCI_DN(np)->devfn;
  97. return 0;
  98. }
  99. static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus)
  100. {
  101. if (bus->self)
  102. return pci_device_to_OF_node(bus->self);
  103. else
  104. return bus->sysdata; /* Must be root bus (PHB) */
  105. }
  106. /** Find the bus corresponding to the indicated device node */
  107. struct pci_bus * pcibios_find_pci_bus(struct device_node *dn);
  108. extern void pci_process_bridge_OF_ranges(struct pci_controller *hose,
  109. struct device_node *dev, int primary);
  110. /** Remove all of the PCI devices under this bus */
  111. void pcibios_remove_pci_devices(struct pci_bus *bus);
  112. /** Discover new pci devices under this bus, and add them */
  113. void pcibios_add_pci_devices(struct pci_bus * bus);
  114. void pcibios_fixup_new_pci_devices(struct pci_bus *bus, int fix_bus);
  115. extern int pcibios_remove_root_bus(struct pci_controller *phb);
  116. static inline struct pci_controller *pci_bus_to_host(struct pci_bus *bus)
  117. {
  118. struct device_node *busdn = bus->sysdata;
  119. BUG_ON(busdn == NULL);
  120. return PCI_DN(busdn)->phb;
  121. }
  122. extern struct pci_controller*
  123. pci_find_hose_for_OF_device(struct device_node* node);
  124. extern struct pci_controller *
  125. pcibios_alloc_controller(struct device_node *dev);
  126. extern void pcibios_free_controller(struct pci_controller *phb);
  127. #ifdef CONFIG_PCI
  128. extern unsigned long pci_address_to_pio(phys_addr_t address);
  129. #else
  130. static inline unsigned long pci_address_to_pio(phys_addr_t address)
  131. {
  132. return (unsigned long)-1;
  133. }
  134. #endif
  135. /* Return values for ppc_md.pci_probe_mode function */
  136. #define PCI_PROBE_NONE -1 /* Don't look at this bus at all */
  137. #define PCI_PROBE_NORMAL 0 /* Do normal PCI probing */
  138. #define PCI_PROBE_DEVTREE 1 /* Instantiate from device tree */
  139. #ifdef CONFIG_NUMA
  140. #define PHB_SET_NODE(PHB, NODE) ((PHB)->node = (NODE))
  141. #else
  142. #define PHB_SET_NODE(PHB, NODE) ((PHB)->node = -1)
  143. #endif
  144. #endif /* CONFIG_PPC64 */
  145. #endif /* __KERNEL__ */
  146. #endif