pci-bridge.h 5.0 KB

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