pci-bridge.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #ifdef __KERNEL__
  2. #ifndef _ASM_PCI_BRIDGE_H
  3. #define _ASM_PCI_BRIDGE_H
  4. #include <linux/ioport.h>
  5. #include <linux/pci.h>
  6. struct device_node;
  7. struct pci_controller;
  8. /*
  9. * pci_io_base returns the memory address at which you can access
  10. * the I/O space for PCI bus number `bus' (or NULL on error).
  11. */
  12. extern void __iomem *pci_bus_io_base(unsigned int bus);
  13. extern unsigned long pci_bus_io_base_phys(unsigned int bus);
  14. extern unsigned long pci_bus_mem_base_phys(unsigned int bus);
  15. /* Allocate a new PCI host bridge structure */
  16. extern struct pci_controller* pcibios_alloc_controller(void);
  17. /* Helper function for setting up resources */
  18. extern void pci_init_resource(struct resource *res, resource_size_t start,
  19. resource_size_t end, int flags, char *name);
  20. /* Get the PCI host controller for a bus */
  21. extern struct pci_controller* pci_bus_to_hose(int bus);
  22. /* Get the PCI host controller for an OF device */
  23. extern struct pci_controller*
  24. pci_find_hose_for_OF_device(struct device_node* node);
  25. /* Fill up host controller resources from the OF node */
  26. extern void
  27. pci_process_bridge_OF_ranges(struct pci_controller *hose,
  28. struct device_node *dev, int primary);
  29. /*
  30. * Structure of a PCI controller (host bridge)
  31. */
  32. struct pci_controller {
  33. int index; /* PCI domain number */
  34. struct pci_controller *next;
  35. struct pci_bus *bus;
  36. void *arch_data;
  37. struct device *parent;
  38. int first_busno;
  39. int last_busno;
  40. int self_busno;
  41. /* bus_offset is only used by ARCH=ppc */
  42. int bus_offset;
  43. void __iomem *io_base_virt;
  44. resource_size_t io_base_phys;
  45. /* Some machines (PReP) have a non 1:1 mapping of
  46. * the PCI memory space in the CPU bus space
  47. */
  48. resource_size_t pci_mem_offset;
  49. struct pci_ops *ops;
  50. volatile unsigned int __iomem *cfg_addr;
  51. volatile void __iomem *cfg_data;
  52. /*
  53. * If set, indirect method will set the cfg_type bit as
  54. * needed to generate type 1 configuration transactions.
  55. */
  56. int set_cfg_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. int mem_resource_count;
  63. /* Host bridge I/O and Memory space
  64. * Used for BAR placement algorithms
  65. */
  66. struct resource io_space;
  67. struct resource mem_space;
  68. };
  69. static inline struct pci_controller *pci_bus_to_host(struct pci_bus *bus)
  70. {
  71. return bus->sysdata;
  72. }
  73. /* These are used for config access before all the PCI probing
  74. has been done. */
  75. int early_read_config_byte(struct pci_controller *hose, int bus, int dev_fn,
  76. int where, u8 *val);
  77. int early_read_config_word(struct pci_controller *hose, int bus, int dev_fn,
  78. int where, u16 *val);
  79. int early_read_config_dword(struct pci_controller *hose, int bus, int dev_fn,
  80. int where, u32 *val);
  81. int early_write_config_byte(struct pci_controller *hose, int bus, int dev_fn,
  82. int where, u8 val);
  83. int early_write_config_word(struct pci_controller *hose, int bus, int dev_fn,
  84. int where, u16 val);
  85. int early_write_config_dword(struct pci_controller *hose, int bus, int dev_fn,
  86. int where, u32 val);
  87. extern void setup_indirect_pci_nomap(struct pci_controller* hose,
  88. void __iomem *cfg_addr, void __iomem *cfg_data);
  89. extern void setup_indirect_pci(struct pci_controller* hose,
  90. u32 cfg_addr, u32 cfg_data);
  91. extern void setup_grackle(struct pci_controller *hose);
  92. extern unsigned char common_swizzle(struct pci_dev *, unsigned char *);
  93. /*
  94. * The following code swizzles for exactly one bridge. The routine
  95. * common_swizzle below handles multiple bridges. But there are a
  96. * some boards that don't follow the PCI spec's suggestion so we
  97. * break this piece out separately.
  98. */
  99. static inline unsigned char bridge_swizzle(unsigned char pin,
  100. unsigned char idsel)
  101. {
  102. return (((pin-1) + idsel) % 4) + 1;
  103. }
  104. /*
  105. * The following macro is used to lookup irqs in a standard table
  106. * format for those PPC systems that do not already have PCI
  107. * interrupts properly routed.
  108. */
  109. /* FIXME - double check this */
  110. #define PCI_IRQ_TABLE_LOOKUP \
  111. ({ long _ctl_ = -1; \
  112. if (idsel >= min_idsel && idsel <= max_idsel && pin <= irqs_per_slot) \
  113. _ctl_ = pci_irq_table[idsel - min_idsel][pin-1]; \
  114. _ctl_; })
  115. /*
  116. * Scan the buses below a given PCI host bridge and assign suitable
  117. * resources to all devices found.
  118. */
  119. extern int pciauto_bus_scan(struct pci_controller *, int);
  120. #ifdef CONFIG_PCI
  121. extern unsigned long pci_address_to_pio(phys_addr_t address);
  122. #else
  123. static inline unsigned long pci_address_to_pio(phys_addr_t address)
  124. {
  125. return (unsigned long)-1;
  126. }
  127. #endif
  128. #endif
  129. #endif /* __KERNEL__ */