pci-bridge.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. * use only on ARCH=ppc
  56. */
  57. int set_cfg_type;
  58. /*
  59. * Used for variants of PCI indirect handling and possible quirks:
  60. * SET_CFG_TYPE - used on 4xx or any PHB that does explicit type0/1
  61. * EXT_REG - provides access to PCI-e extended registers
  62. */
  63. #define PPC_INDIRECT_TYPE_SET_CFG_TYPE (0x00000001)
  64. #define PPC_INDIRECT_TYPE_EXT_REG (0x00000002)
  65. u32 indirect_type;
  66. /* Currently, we limit ourselves to 1 IO range and 3 mem
  67. * ranges since the common pci_bus structure can't handle more
  68. */
  69. struct resource io_resource;
  70. struct resource mem_resources[3];
  71. int mem_resource_count;
  72. /* Host bridge I/O and Memory space
  73. * Used for BAR placement algorithms
  74. */
  75. struct resource io_space;
  76. struct resource mem_space;
  77. };
  78. static inline struct pci_controller *pci_bus_to_host(struct pci_bus *bus)
  79. {
  80. return bus->sysdata;
  81. }
  82. /* These are used for config access before all the PCI probing
  83. has been done. */
  84. int early_read_config_byte(struct pci_controller *hose, int bus, int dev_fn,
  85. int where, u8 *val);
  86. int early_read_config_word(struct pci_controller *hose, int bus, int dev_fn,
  87. int where, u16 *val);
  88. int early_read_config_dword(struct pci_controller *hose, int bus, int dev_fn,
  89. int where, u32 *val);
  90. int early_write_config_byte(struct pci_controller *hose, int bus, int dev_fn,
  91. int where, u8 val);
  92. int early_write_config_word(struct pci_controller *hose, int bus, int dev_fn,
  93. int where, u16 val);
  94. int early_write_config_dword(struct pci_controller *hose, int bus, int dev_fn,
  95. int where, u32 val);
  96. extern void setup_indirect_pci_nomap(struct pci_controller* hose,
  97. void __iomem *cfg_addr, void __iomem *cfg_data);
  98. extern void setup_indirect_pci(struct pci_controller* hose,
  99. u32 cfg_addr, u32 cfg_data);
  100. extern void setup_grackle(struct pci_controller *hose);
  101. extern unsigned char common_swizzle(struct pci_dev *, unsigned char *);
  102. /*
  103. * The following code swizzles for exactly one bridge. The routine
  104. * common_swizzle below handles multiple bridges. But there are a
  105. * some boards that don't follow the PCI spec's suggestion so we
  106. * break this piece out separately.
  107. */
  108. static inline unsigned char bridge_swizzle(unsigned char pin,
  109. unsigned char idsel)
  110. {
  111. return (((pin-1) + idsel) % 4) + 1;
  112. }
  113. /*
  114. * The following macro is used to lookup irqs in a standard table
  115. * format for those PPC systems that do not already have PCI
  116. * interrupts properly routed.
  117. */
  118. /* FIXME - double check this */
  119. #define PCI_IRQ_TABLE_LOOKUP \
  120. ({ long _ctl_ = -1; \
  121. if (idsel >= min_idsel && idsel <= max_idsel && pin <= irqs_per_slot) \
  122. _ctl_ = pci_irq_table[idsel - min_idsel][pin-1]; \
  123. _ctl_; })
  124. /*
  125. * Scan the buses below a given PCI host bridge and assign suitable
  126. * resources to all devices found.
  127. */
  128. extern int pciauto_bus_scan(struct pci_controller *, int);
  129. #ifdef CONFIG_PCI
  130. extern unsigned long pci_address_to_pio(phys_addr_t address);
  131. #else
  132. static inline unsigned long pci_address_to_pio(phys_addr_t address)
  133. {
  134. return (unsigned long)-1;
  135. }
  136. #endif
  137. #endif
  138. #endif /* __KERNEL__ */