pci-bridge.h 4.5 KB

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