pci-bridge.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 bus_offset;
  41. void __iomem *io_base_virt;
  42. resource_size_t io_base_phys;
  43. /* Some machines (PReP) have a non 1:1 mapping of
  44. * the PCI memory space in the CPU bus space
  45. */
  46. resource_size_t pci_mem_offset;
  47. struct pci_ops *ops;
  48. volatile unsigned int __iomem *cfg_addr;
  49. volatile void __iomem *cfg_data;
  50. /*
  51. * If set, indirect method will set the cfg_type bit as
  52. * needed to generate type 1 configuration transactions.
  53. */
  54. int set_cfg_type;
  55. /* Currently, we limit ourselves to 1 IO range and 3 mem
  56. * ranges since the common pci_bus structure can't handle more
  57. */
  58. struct resource io_resource;
  59. struct resource mem_resources[3];
  60. int mem_resource_count;
  61. /* Host bridge I/O and Memory space
  62. * Used for BAR placement algorithms
  63. */
  64. struct resource io_space;
  65. struct resource mem_space;
  66. };
  67. static inline struct pci_controller *pci_bus_to_host(struct pci_bus *bus)
  68. {
  69. return bus->sysdata;
  70. }
  71. /* These are used for config access before all the PCI probing
  72. has been done. */
  73. int early_read_config_byte(struct pci_controller *hose, int bus, int dev_fn,
  74. int where, u8 *val);
  75. int early_read_config_word(struct pci_controller *hose, int bus, int dev_fn,
  76. int where, u16 *val);
  77. int early_read_config_dword(struct pci_controller *hose, int bus, int dev_fn,
  78. int where, u32 *val);
  79. int early_write_config_byte(struct pci_controller *hose, int bus, int dev_fn,
  80. int where, u8 val);
  81. int early_write_config_word(struct pci_controller *hose, int bus, int dev_fn,
  82. int where, u16 val);
  83. int early_write_config_dword(struct pci_controller *hose, int bus, int dev_fn,
  84. int where, u32 val);
  85. extern void setup_indirect_pci_nomap(struct pci_controller* hose,
  86. void __iomem *cfg_addr, void __iomem *cfg_data);
  87. extern void setup_indirect_pci(struct pci_controller* hose,
  88. u32 cfg_addr, u32 cfg_data);
  89. extern void setup_grackle(struct pci_controller *hose);
  90. extern unsigned char common_swizzle(struct pci_dev *, unsigned char *);
  91. /*
  92. * The following code swizzles for exactly one bridge. The routine
  93. * common_swizzle below handles multiple bridges. But there are a
  94. * some boards that don't follow the PCI spec's suggestion so we
  95. * break this piece out separately.
  96. */
  97. static inline unsigned char bridge_swizzle(unsigned char pin,
  98. unsigned char idsel)
  99. {
  100. return (((pin-1) + idsel) % 4) + 1;
  101. }
  102. /*
  103. * The following macro is used to lookup irqs in a standard table
  104. * format for those PPC systems that do not already have PCI
  105. * interrupts properly routed.
  106. */
  107. /* FIXME - double check this */
  108. #define PCI_IRQ_TABLE_LOOKUP \
  109. ({ long _ctl_ = -1; \
  110. if (idsel >= min_idsel && idsel <= max_idsel && pin <= irqs_per_slot) \
  111. _ctl_ = pci_irq_table[idsel - min_idsel][pin-1]; \
  112. _ctl_; })
  113. /*
  114. * Scan the buses below a given PCI host bridge and assign suitable
  115. * resources to all devices found.
  116. */
  117. extern int pciauto_bus_scan(struct pci_controller *, int);
  118. #ifdef CONFIG_PCI
  119. extern unsigned long pci_address_to_pio(phys_addr_t address);
  120. #else
  121. static inline unsigned long pci_address_to_pio(phys_addr_t address)
  122. {
  123. return (unsigned long)-1;
  124. }
  125. #endif
  126. #endif
  127. #endif /* __KERNEL__ */