pci.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. #ifndef _ASM_TILE_PCI_H
  15. #define _ASM_TILE_PCI_H
  16. #include <linux/dma-mapping.h>
  17. #include <linux/pci.h>
  18. #include <asm-generic/pci_iomap.h>
  19. #ifndef __tilegx__
  20. /*
  21. * Structure of a PCI controller (host bridge)
  22. */
  23. struct pci_controller {
  24. int index; /* PCI domain number */
  25. struct pci_bus *root_bus;
  26. int last_busno;
  27. int hv_cfg_fd[2]; /* config{0,1} fds for this PCIe controller */
  28. int hv_mem_fd; /* fd to Hypervisor for MMIO operations */
  29. struct pci_ops *ops;
  30. int irq_base; /* Base IRQ from the Hypervisor */
  31. int plx_gen1; /* flag for PLX Gen 1 configuration */
  32. /* Address ranges that are routed to this controller/bridge. */
  33. struct resource mem_resources[3];
  34. };
  35. /*
  36. * This flag tells if the platform is TILEmpower that needs
  37. * special configuration for the PLX switch chip.
  38. */
  39. extern int tile_plx_gen1;
  40. static inline void pci_iounmap(struct pci_dev *dev, void __iomem *addr) {}
  41. #define TILE_NUM_PCIE 2
  42. /*
  43. * The hypervisor maps the entirety of CPA-space as bus addresses, so
  44. * bus addresses are physical addresses. The networking and block
  45. * device layers use this boolean for bounce buffer decisions.
  46. */
  47. #define PCI_DMA_BUS_IS_PHYS 1
  48. /* generic pci stuff */
  49. #include <asm-generic/pci.h>
  50. #else
  51. #include <asm/page.h>
  52. #include <gxio/trio.h>
  53. /**
  54. * We reserve the hugepage-size address range at the top of the 64-bit address
  55. * space to serve as the PCI window, emulating the BAR0 space of an endpoint
  56. * device. This window is used by the chip-to-chip applications running on
  57. * the RC node. The reason for carving out this window is that Mem-Maps that
  58. * back up this window will not overlap with those that map the real physical
  59. * memory.
  60. */
  61. #define PCIE_HOST_BAR0_SIZE HPAGE_SIZE
  62. #define PCIE_HOST_BAR0_START HPAGE_MASK
  63. /**
  64. * The first PAGE_SIZE of the above "BAR" window is mapped to the
  65. * gxpci_host_regs structure.
  66. */
  67. #define PCIE_HOST_REGS_SIZE PAGE_SIZE
  68. /*
  69. * This is the PCI address where the Mem-Map interrupt regions start.
  70. * We use the 2nd to the last huge page of the 64-bit address space.
  71. * The last huge page is used for the rootcomplex "bar", for C2C purpose.
  72. */
  73. #define MEM_MAP_INTR_REGIONS_BASE (HPAGE_MASK - HPAGE_SIZE)
  74. /*
  75. * Each Mem-Map interrupt region occupies 4KB.
  76. */
  77. #define MEM_MAP_INTR_REGION_SIZE (1 << TRIO_MAP_MEM_LIM__ADDR_SHIFT)
  78. /*
  79. * Allocate the PCI BAR window right below 4GB.
  80. */
  81. #define TILE_PCI_BAR_WINDOW_TOP (1ULL << 32)
  82. /*
  83. * Allocate 1GB for the PCI BAR window.
  84. */
  85. #define TILE_PCI_BAR_WINDOW_SIZE (1 << 30)
  86. /*
  87. * This is the highest bus address targeting the host memory that
  88. * can be generated by legacy PCI devices with 32-bit or less
  89. * DMA capability, dictated by the BAR window size and location.
  90. */
  91. #define TILE_PCI_MAX_DIRECT_DMA_ADDRESS \
  92. (TILE_PCI_BAR_WINDOW_TOP - TILE_PCI_BAR_WINDOW_SIZE - 1)
  93. /*
  94. * We shift the PCI bus range for all the physical memory up by the whole PA
  95. * range. The corresponding CPA of an incoming PCI request will be the PCI
  96. * address minus TILE_PCI_MEM_MAP_BASE_OFFSET. This also implies
  97. * that the 64-bit capable devices will be given DMA addresses as
  98. * the CPA plus TILE_PCI_MEM_MAP_BASE_OFFSET. To support 32-bit
  99. * devices, we create a separate map region that handles the low
  100. * 4GB.
  101. *
  102. * This design lets us avoid the "PCI hole" problem where the host bridge
  103. * won't pass DMA traffic with target addresses that happen to fall within the
  104. * BAR space. This enables us to use all the physical memory for DMA, instead
  105. * of wasting the same amount of physical memory as the BAR window size.
  106. */
  107. #define TILE_PCI_MEM_MAP_BASE_OFFSET (1ULL << CHIP_PA_WIDTH())
  108. /*
  109. * Start of the PCI memory resource, which starts at the end of the
  110. * maximum system physical RAM address.
  111. */
  112. #define TILE_PCI_MEM_START (1ULL << CHIP_PA_WIDTH())
  113. /*
  114. * Structure of a PCI controller (host bridge) on Gx.
  115. */
  116. struct pci_controller {
  117. /* Pointer back to the TRIO that this PCIe port is connected to. */
  118. gxio_trio_context_t *trio;
  119. int mac; /* PCIe mac index on the TRIO shim */
  120. int trio_index; /* Index of TRIO shim that contains the MAC. */
  121. int pio_mem_index; /* PIO region index for memory access */
  122. #ifdef CONFIG_TILE_PCI_IO
  123. int pio_io_index; /* PIO region index for I/O space access */
  124. #endif
  125. /*
  126. * Mem-Map regions for all the memory controllers so that Linux can
  127. * map all of its physical memory space to the PCI bus.
  128. */
  129. int mem_maps[MAX_NUMNODES];
  130. int index; /* PCI domain number */
  131. struct pci_bus *root_bus;
  132. /* PCI I/O space resource for this controller. */
  133. struct resource io_space;
  134. char io_space_name[32];
  135. /* PCI memory space resource for this controller. */
  136. struct resource mem_space;
  137. char mem_space_name[32];
  138. uint64_t mem_offset; /* cpu->bus memory mapping offset. */
  139. int first_busno;
  140. struct pci_ops *ops;
  141. /* Table that maps the INTx numbers to Linux irq numbers. */
  142. int irq_intx_table[4];
  143. };
  144. extern struct pci_controller pci_controllers[TILEGX_NUM_TRIO * TILEGX_TRIO_PCIES];
  145. extern gxio_trio_context_t trio_contexts[TILEGX_NUM_TRIO];
  146. extern int num_trio_shims;
  147. extern void pci_iounmap(struct pci_dev *dev, void __iomem *);
  148. /*
  149. * The PCI address space does not equal the physical memory address
  150. * space (we have an IOMMU). The IDE and SCSI device layers use this
  151. * boolean for bounce buffer decisions.
  152. */
  153. #define PCI_DMA_BUS_IS_PHYS 0
  154. #endif /* __tilegx__ */
  155. int __init tile_pci_init(void);
  156. int __init pcibios_init(void);
  157. void pcibios_fixup_bus(struct pci_bus *bus);
  158. #define pci_domain_nr(bus) (((struct pci_controller *)(bus)->sysdata)->index)
  159. /*
  160. * This decides whether to display the domain number in /proc.
  161. */
  162. static inline int pci_proc_domain(struct pci_bus *bus)
  163. {
  164. return 1;
  165. }
  166. /*
  167. * pcibios_assign_all_busses() tells whether or not the bus numbers
  168. * should be reassigned, in case the BIOS didn't do it correctly, or
  169. * in case we don't have a BIOS and we want to let Linux do it.
  170. */
  171. static inline int pcibios_assign_all_busses(void)
  172. {
  173. return 1;
  174. }
  175. #define PCIBIOS_MIN_MEM 0
  176. /* Minimum PCI I/O address, starting at the page boundary. */
  177. #define PCIBIOS_MIN_IO PAGE_SIZE
  178. /* Use any cpu for PCI. */
  179. #define cpumask_of_pcibus(bus) cpu_online_mask
  180. /* implement the pci_ DMA API in terms of the generic device dma_ one */
  181. #include <asm-generic/pci-dma-compat.h>
  182. #endif /* _ASM_TILE_PCI_H */