pci.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. #ifndef __ASM_PARISC_PCI_H
  2. #define __ASM_PARISC_PCI_H
  3. #include <linux/config.h>
  4. #include <asm/scatterlist.h>
  5. /*
  6. ** HP PCI platforms generally support multiple bus adapters.
  7. ** (workstations 1-~4, servers 2-~32)
  8. **
  9. ** Newer platforms number the busses across PCI bus adapters *sparsely*.
  10. ** E.g. 0, 8, 16, ...
  11. **
  12. ** Under a PCI bus, most HP platforms support PPBs up to two or three
  13. ** levels deep. See "Bit3" product line.
  14. */
  15. #define PCI_MAX_BUSSES 256
  16. /* To be used as: mdelay(pci_post_reset_delay);
  17. *
  18. * post_reset is the time the kernel should stall to prevent anyone from
  19. * accessing the PCI bus once #RESET is de-asserted.
  20. * PCI spec somewhere says 1 second but with multi-PCI bus systems,
  21. * this makes the boot time much longer than necessary.
  22. * 20ms seems to work for all the HP PCI implementations to date.
  23. */
  24. #define pci_post_reset_delay 50
  25. /*
  26. ** pci_hba_data (aka H2P_OBJECT in HP/UX)
  27. **
  28. ** This is the "common" or "base" data structure which HBA drivers
  29. ** (eg Dino or LBA) are required to place at the top of their own
  30. ** platform_data structure. I've heard this called "C inheritance" too.
  31. **
  32. ** Data needed by pcibios layer belongs here.
  33. */
  34. struct pci_hba_data {
  35. void __iomem *base_addr; /* aka Host Physical Address */
  36. const struct parisc_device *dev; /* device from PA bus walk */
  37. struct pci_bus *hba_bus; /* primary PCI bus below HBA */
  38. int hba_num; /* I/O port space access "key" */
  39. struct resource bus_num; /* PCI bus numbers */
  40. struct resource io_space; /* PIOP */
  41. struct resource lmmio_space; /* bus addresses < 4Gb */
  42. struct resource elmmio_space; /* additional bus addresses < 4Gb */
  43. struct resource gmmio_space; /* bus addresses > 4Gb */
  44. /* NOTE: Dino code assumes it can use *all* of the lmmio_space,
  45. * elmmio_space and gmmio_space as a contiguous array of
  46. * resources. This #define represents the array size */
  47. #define DINO_MAX_LMMIO_RESOURCES 3
  48. unsigned long lmmio_space_offset; /* CPU view - PCI view */
  49. void * iommu; /* IOMMU this device is under */
  50. /* REVISIT - spinlock to protect resources? */
  51. #define HBA_NAME_SIZE 16
  52. char io_name[HBA_NAME_SIZE];
  53. char lmmio_name[HBA_NAME_SIZE];
  54. char elmmio_name[HBA_NAME_SIZE];
  55. char gmmio_name[HBA_NAME_SIZE];
  56. };
  57. #define HBA_DATA(d) ((struct pci_hba_data *) (d))
  58. /*
  59. ** We support 2^16 I/O ports per HBA. These are set up in the form
  60. ** 0xbbxxxx, where bb is the bus number and xxxx is the I/O port
  61. ** space address.
  62. */
  63. #define HBA_PORT_SPACE_BITS 16
  64. #define HBA_PORT_BASE(h) ((h) << HBA_PORT_SPACE_BITS)
  65. #define HBA_PORT_SPACE_SIZE (1UL << HBA_PORT_SPACE_BITS)
  66. #define PCI_PORT_HBA(a) ((a) >> HBA_PORT_SPACE_BITS)
  67. #define PCI_PORT_ADDR(a) ((a) & (HBA_PORT_SPACE_SIZE - 1))
  68. #ifdef CONFIG_64BIT
  69. #define PCI_F_EXTEND 0xffffffff00000000UL
  70. #define PCI_IS_LMMIO(hba,a) pci_is_lmmio(hba,a)
  71. /* We need to know if an address is LMMMIO or GMMIO.
  72. * LMMIO requires mangling and GMMIO we must use as-is.
  73. */
  74. static __inline__ int pci_is_lmmio(struct pci_hba_data *hba, unsigned long a)
  75. {
  76. return(((a) & PCI_F_EXTEND) == PCI_F_EXTEND);
  77. }
  78. /*
  79. ** Convert between PCI (IO_VIEW) addresses and processor (PA_VIEW) addresses.
  80. ** See pci.c for more conversions used by Generic PCI code.
  81. **
  82. ** Platform characteristics/firmware guarantee that
  83. ** (1) PA_VIEW - IO_VIEW = lmmio_offset for both LMMIO and ELMMIO
  84. ** (2) PA_VIEW == IO_VIEW for GMMIO
  85. */
  86. #define PCI_BUS_ADDR(hba,a) (PCI_IS_LMMIO(hba,a) \
  87. ? ((a) - hba->lmmio_space_offset) /* mangle LMMIO */ \
  88. : (a)) /* GMMIO */
  89. #define PCI_HOST_ADDR(hba,a) (((a) & PCI_F_EXTEND) == 0 \
  90. ? (a) + hba->lmmio_space_offset \
  91. : (a))
  92. #else /* !CONFIG_64BIT */
  93. #define PCI_BUS_ADDR(hba,a) (a)
  94. #define PCI_HOST_ADDR(hba,a) (a)
  95. #define PCI_F_EXTEND 0UL
  96. #define PCI_IS_LMMIO(hba,a) (1) /* 32-bit doesn't support GMMIO */
  97. #endif /* !CONFIG_64BIT */
  98. /*
  99. ** KLUGE: linux/pci.h include asm/pci.h BEFORE declaring struct pci_bus
  100. ** (This eliminates some of the warnings).
  101. */
  102. struct pci_bus;
  103. struct pci_dev;
  104. /*
  105. * If the PCI device's view of memory is the same as the CPU's view of memory,
  106. * PCI_DMA_BUS_IS_PHYS is true. The networking and block device layers use
  107. * this boolean for bounce buffer decisions.
  108. */
  109. #ifdef CONFIG_PA20
  110. /* All PA-2.0 machines have an IOMMU. */
  111. #define PCI_DMA_BUS_IS_PHYS 0
  112. #define parisc_has_iommu() do { } while (0)
  113. #else
  114. #if defined(CONFIG_IOMMU_CCIO) || defined(CONFIG_IOMMU_SBA)
  115. extern int parisc_bus_is_phys; /* in arch/parisc/kernel/setup.c */
  116. #define PCI_DMA_BUS_IS_PHYS parisc_bus_is_phys
  117. #define parisc_has_iommu() do { parisc_bus_is_phys = 0; } while (0)
  118. #else
  119. #define PCI_DMA_BUS_IS_PHYS 1
  120. #define parisc_has_iommu() do { } while (0)
  121. #endif
  122. #endif /* !CONFIG_PA20 */
  123. /*
  124. ** Most PCI devices (eg Tulip, NCR720) also export the same registers
  125. ** to both MMIO and I/O port space. Due to poor performance of I/O Port
  126. ** access under HP PCI bus adapters, strongly reccomend use of MMIO
  127. ** address space.
  128. **
  129. ** While I'm at it more PA programming notes:
  130. **
  131. ** 1) MMIO stores (writes) are posted operations. This means the processor
  132. ** gets an "ACK" before the write actually gets to the device. A read
  133. ** to the same device (or typically the bus adapter above it) will
  134. ** force in-flight write transaction(s) out to the targeted device
  135. ** before the read can complete.
  136. **
  137. ** 2) The Programmed I/O (PIO) data may not always be strongly ordered with
  138. ** respect to DMA on all platforms. Ie PIO data can reach the processor
  139. ** before in-flight DMA reaches memory. Since most SMP PA platforms
  140. ** are I/O coherent, it generally doesn't matter...but sometimes
  141. ** it does.
  142. **
  143. ** I've helped device driver writers debug both types of problems.
  144. */
  145. struct pci_port_ops {
  146. u8 (*inb) (struct pci_hba_data *hba, u16 port);
  147. u16 (*inw) (struct pci_hba_data *hba, u16 port);
  148. u32 (*inl) (struct pci_hba_data *hba, u16 port);
  149. void (*outb) (struct pci_hba_data *hba, u16 port, u8 data);
  150. void (*outw) (struct pci_hba_data *hba, u16 port, u16 data);
  151. void (*outl) (struct pci_hba_data *hba, u16 port, u32 data);
  152. };
  153. struct pci_bios_ops {
  154. void (*init)(void);
  155. void (*fixup_bus)(struct pci_bus *bus);
  156. };
  157. /* pci_unmap_{single,page} is not a nop, thus... */
  158. #define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) \
  159. dma_addr_t ADDR_NAME;
  160. #define DECLARE_PCI_UNMAP_LEN(LEN_NAME) \
  161. __u32 LEN_NAME;
  162. #define pci_unmap_addr(PTR, ADDR_NAME) \
  163. ((PTR)->ADDR_NAME)
  164. #define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) \
  165. (((PTR)->ADDR_NAME) = (VAL))
  166. #define pci_unmap_len(PTR, LEN_NAME) \
  167. ((PTR)->LEN_NAME)
  168. #define pci_unmap_len_set(PTR, LEN_NAME, VAL) \
  169. (((PTR)->LEN_NAME) = (VAL))
  170. /*
  171. ** Stuff declared in arch/parisc/kernel/pci.c
  172. */
  173. extern struct pci_port_ops *pci_port;
  174. extern struct pci_bios_ops *pci_bios;
  175. #ifdef CONFIG_PCI
  176. extern void pcibios_register_hba(struct pci_hba_data *);
  177. extern void pcibios_set_master(struct pci_dev *);
  178. #else
  179. extern inline void pcibios_register_hba(struct pci_hba_data *x)
  180. {
  181. }
  182. #endif
  183. /*
  184. * pcibios_assign_all_busses() is used in drivers/pci/pci.c:pci_do_scan_bus()
  185. * 0 == check if bridge is numbered before re-numbering.
  186. * 1 == pci_do_scan_bus() should automatically number all PCI-PCI bridges.
  187. *
  188. * We *should* set this to zero for "legacy" platforms and one
  189. * for PAT platforms.
  190. *
  191. * But legacy platforms also need to renumber the busses below a Host
  192. * Bus controller. Adding a 4-port Tulip card on the first PCI root
  193. * bus of a C200 resulted in the secondary bus being numbered as 1.
  194. * The second PCI host bus controller's root bus had already been
  195. * assigned bus number 1 by firmware and sysfs complained.
  196. *
  197. * Firmware isn't doing anything wrong here since each controller
  198. * is its own PCI domain. It's simpler and easier for us to renumber
  199. * the busses rather than treat each Dino as a separate PCI domain.
  200. * Eventually, we may want to introduce PCI domains for Superdome or
  201. * rp7420/8420 boxes and then revisit this issue.
  202. */
  203. #define pcibios_assign_all_busses() (1)
  204. #define pcibios_scan_all_fns(a, b) (0)
  205. #define PCIBIOS_MIN_IO 0x10
  206. #define PCIBIOS_MIN_MEM 0x1000 /* NBPG - but pci/setup-res.c dies */
  207. /* Don't support DAC yet. */
  208. #define pci_dac_dma_supported(pci_dev, mask) (0)
  209. /* export the pci_ DMA API in terms of the dma_ one */
  210. #include <asm-generic/pci-dma-compat.h>
  211. #ifdef CONFIG_PCI
  212. static inline void pci_dma_burst_advice(struct pci_dev *pdev,
  213. enum pci_dma_burst_strategy *strat,
  214. unsigned long *strategy_parameter)
  215. {
  216. unsigned long cacheline_size;
  217. u8 byte;
  218. pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &byte);
  219. if (byte == 0)
  220. cacheline_size = 1024;
  221. else
  222. cacheline_size = (int) byte * 4;
  223. *strat = PCI_DMA_BURST_MULTIPLE;
  224. *strategy_parameter = cacheline_size;
  225. }
  226. #endif
  227. extern void
  228. pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
  229. struct resource *res);
  230. extern void
  231. pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,
  232. struct pci_bus_region *region);
  233. static inline struct resource *
  234. pcibios_select_root(struct pci_dev *pdev, struct resource *res)
  235. {
  236. struct resource *root = NULL;
  237. if (res->flags & IORESOURCE_IO)
  238. root = &ioport_resource;
  239. if (res->flags & IORESOURCE_MEM)
  240. root = &iomem_resource;
  241. return root;
  242. }
  243. static inline void pcibios_add_platform_entries(struct pci_dev *dev)
  244. {
  245. }
  246. static inline void pcibios_penalize_isa_irq(int irq, int active)
  247. {
  248. /* We don't need to penalize isa irq's */
  249. }
  250. #endif /* __ASM_PARISC_PCI_H */