io.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. #ifndef _ASM_IA64_IO_H
  2. #define _ASM_IA64_IO_H
  3. /*
  4. * This file contains the definitions for the emulated IO instructions
  5. * inb/inw/inl/outb/outw/outl and the "string versions" of the same
  6. * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
  7. * versions of the single-IO instructions (inb_p/inw_p/..).
  8. *
  9. * This file is not meant to be obfuscating: it's just complicated to
  10. * (a) handle it all in a way that makes gcc able to optimize it as
  11. * well as possible and (b) trying to avoid writing the same thing
  12. * over and over again with slight variations and possibly making a
  13. * mistake somewhere.
  14. *
  15. * Copyright (C) 1998-2003 Hewlett-Packard Co
  16. * David Mosberger-Tang <davidm@hpl.hp.com>
  17. * Copyright (C) 1999 Asit Mallick <asit.k.mallick@intel.com>
  18. * Copyright (C) 1999 Don Dugger <don.dugger@intel.com>
  19. */
  20. /* We don't use IO slowdowns on the ia64, but.. */
  21. #define __SLOW_DOWN_IO do { } while (0)
  22. #define SLOW_DOWN_IO do { } while (0)
  23. #define __IA64_UNCACHED_OFFSET RGN_BASE(RGN_UNCACHED)
  24. /*
  25. * The legacy I/O space defined by the ia64 architecture supports only 65536 ports, but
  26. * large machines may have multiple other I/O spaces so we can't place any a priori limit
  27. * on IO_SPACE_LIMIT. These additional spaces are described in ACPI.
  28. */
  29. #define IO_SPACE_LIMIT 0xffffffffffffffffUL
  30. #define MAX_IO_SPACES_BITS 4
  31. #define MAX_IO_SPACES (1UL << MAX_IO_SPACES_BITS)
  32. #define IO_SPACE_BITS 24
  33. #define IO_SPACE_SIZE (1UL << IO_SPACE_BITS)
  34. #define IO_SPACE_NR(port) ((port) >> IO_SPACE_BITS)
  35. #define IO_SPACE_BASE(space) ((space) << IO_SPACE_BITS)
  36. #define IO_SPACE_PORT(port) ((port) & (IO_SPACE_SIZE - 1))
  37. #define IO_SPACE_SPARSE_ENCODING(p) ((((p) >> 2) << 12) | ((p) & 0xfff))
  38. struct io_space {
  39. unsigned long mmio_base; /* base in MMIO space */
  40. int sparse;
  41. };
  42. extern struct io_space io_space[];
  43. extern unsigned int num_io_spaces;
  44. # ifdef __KERNEL__
  45. /*
  46. * All MMIO iomem cookies are in region 6; anything less is a PIO cookie:
  47. * 0xCxxxxxxxxxxxxxxx MMIO cookie (return from ioremap)
  48. * 0x000000001SPPPPPP PIO cookie (S=space number, P..P=port)
  49. *
  50. * ioread/writeX() uses the leading 1 in PIO cookies (PIO_OFFSET) to catch
  51. * code that uses bare port numbers without the prerequisite pci_iomap().
  52. */
  53. #define PIO_OFFSET (1UL << (MAX_IO_SPACES_BITS + IO_SPACE_BITS))
  54. #define PIO_MASK (PIO_OFFSET - 1)
  55. #define PIO_RESERVED __IA64_UNCACHED_OFFSET
  56. #define HAVE_ARCH_PIO_SIZE
  57. #include <asm/intrinsics.h>
  58. #include <asm/machvec.h>
  59. #include <asm/page.h>
  60. #include <asm/system.h>
  61. #include <asm-generic/iomap.h>
  62. /*
  63. * Change virtual addresses to physical addresses and vv.
  64. */
  65. static inline unsigned long
  66. virt_to_phys (volatile void *address)
  67. {
  68. return (unsigned long) address - PAGE_OFFSET;
  69. }
  70. static inline void*
  71. phys_to_virt (unsigned long address)
  72. {
  73. return (void *) (address + PAGE_OFFSET);
  74. }
  75. #define ARCH_HAS_VALID_PHYS_ADDR_RANGE
  76. extern int valid_phys_addr_range (unsigned long addr, size_t *count); /* efi.c */
  77. extern int valid_mmap_phys_addr_range (unsigned long addr, size_t *count);
  78. /*
  79. * The following two macros are deprecated and scheduled for removal.
  80. * Please use the PCI-DMA interface defined in <asm/pci.h> instead.
  81. */
  82. #define bus_to_virt phys_to_virt
  83. #define virt_to_bus virt_to_phys
  84. #define page_to_bus page_to_phys
  85. # endif /* KERNEL */
  86. /*
  87. * Memory fence w/accept. This should never be used in code that is
  88. * not IA-64 specific.
  89. */
  90. #define __ia64_mf_a() ia64_mfa()
  91. /**
  92. * ___ia64_mmiowb - I/O write barrier
  93. *
  94. * Ensure ordering of I/O space writes. This will make sure that writes
  95. * following the barrier will arrive after all previous writes. For most
  96. * ia64 platforms, this is a simple 'mf.a' instruction.
  97. *
  98. * See Documentation/DocBook/deviceiobook.tmpl for more information.
  99. */
  100. static inline void ___ia64_mmiowb(void)
  101. {
  102. ia64_mfa();
  103. }
  104. static inline void*
  105. __ia64_mk_io_addr (unsigned long port)
  106. {
  107. struct io_space *space;
  108. unsigned long offset;
  109. space = &io_space[IO_SPACE_NR(port)];
  110. port = IO_SPACE_PORT(port);
  111. if (space->sparse)
  112. offset = IO_SPACE_SPARSE_ENCODING(port);
  113. else
  114. offset = port;
  115. return (void *) (space->mmio_base | offset);
  116. }
  117. #define __ia64_inb ___ia64_inb
  118. #define __ia64_inw ___ia64_inw
  119. #define __ia64_inl ___ia64_inl
  120. #define __ia64_outb ___ia64_outb
  121. #define __ia64_outw ___ia64_outw
  122. #define __ia64_outl ___ia64_outl
  123. #define __ia64_readb ___ia64_readb
  124. #define __ia64_readw ___ia64_readw
  125. #define __ia64_readl ___ia64_readl
  126. #define __ia64_readq ___ia64_readq
  127. #define __ia64_readb_relaxed ___ia64_readb
  128. #define __ia64_readw_relaxed ___ia64_readw
  129. #define __ia64_readl_relaxed ___ia64_readl
  130. #define __ia64_readq_relaxed ___ia64_readq
  131. #define __ia64_writeb ___ia64_writeb
  132. #define __ia64_writew ___ia64_writew
  133. #define __ia64_writel ___ia64_writel
  134. #define __ia64_writeq ___ia64_writeq
  135. #define __ia64_mmiowb ___ia64_mmiowb
  136. /*
  137. * For the in/out routines, we need to do "mf.a" _after_ doing the I/O access to ensure
  138. * that the access has completed before executing other I/O accesses. Since we're doing
  139. * the accesses through an uncachable (UC) translation, the CPU will execute them in
  140. * program order. However, we still need to tell the compiler not to shuffle them around
  141. * during optimization, which is why we use "volatile" pointers.
  142. */
  143. static inline unsigned int
  144. ___ia64_inb (unsigned long port)
  145. {
  146. volatile unsigned char *addr = __ia64_mk_io_addr(port);
  147. unsigned char ret;
  148. ret = *addr;
  149. __ia64_mf_a();
  150. return ret;
  151. }
  152. static inline unsigned int
  153. ___ia64_inw (unsigned long port)
  154. {
  155. volatile unsigned short *addr = __ia64_mk_io_addr(port);
  156. unsigned short ret;
  157. ret = *addr;
  158. __ia64_mf_a();
  159. return ret;
  160. }
  161. static inline unsigned int
  162. ___ia64_inl (unsigned long port)
  163. {
  164. volatile unsigned int *addr = __ia64_mk_io_addr(port);
  165. unsigned int ret;
  166. ret = *addr;
  167. __ia64_mf_a();
  168. return ret;
  169. }
  170. static inline void
  171. ___ia64_outb (unsigned char val, unsigned long port)
  172. {
  173. volatile unsigned char *addr = __ia64_mk_io_addr(port);
  174. *addr = val;
  175. __ia64_mf_a();
  176. }
  177. static inline void
  178. ___ia64_outw (unsigned short val, unsigned long port)
  179. {
  180. volatile unsigned short *addr = __ia64_mk_io_addr(port);
  181. *addr = val;
  182. __ia64_mf_a();
  183. }
  184. static inline void
  185. ___ia64_outl (unsigned int val, unsigned long port)
  186. {
  187. volatile unsigned int *addr = __ia64_mk_io_addr(port);
  188. *addr = val;
  189. __ia64_mf_a();
  190. }
  191. static inline void
  192. __insb (unsigned long port, void *dst, unsigned long count)
  193. {
  194. unsigned char *dp = dst;
  195. while (count--)
  196. *dp++ = platform_inb(port);
  197. }
  198. static inline void
  199. __insw (unsigned long port, void *dst, unsigned long count)
  200. {
  201. unsigned short *dp = dst;
  202. while (count--)
  203. *dp++ = platform_inw(port);
  204. }
  205. static inline void
  206. __insl (unsigned long port, void *dst, unsigned long count)
  207. {
  208. unsigned int *dp = dst;
  209. while (count--)
  210. *dp++ = platform_inl(port);
  211. }
  212. static inline void
  213. __outsb (unsigned long port, const void *src, unsigned long count)
  214. {
  215. const unsigned char *sp = src;
  216. while (count--)
  217. platform_outb(*sp++, port);
  218. }
  219. static inline void
  220. __outsw (unsigned long port, const void *src, unsigned long count)
  221. {
  222. const unsigned short *sp = src;
  223. while (count--)
  224. platform_outw(*sp++, port);
  225. }
  226. static inline void
  227. __outsl (unsigned long port, const void *src, unsigned long count)
  228. {
  229. const unsigned int *sp = src;
  230. while (count--)
  231. platform_outl(*sp++, port);
  232. }
  233. /*
  234. * Unfortunately, some platforms are broken and do not follow the IA-64 architecture
  235. * specification regarding legacy I/O support. Thus, we have to make these operations
  236. * platform dependent...
  237. */
  238. #define __inb platform_inb
  239. #define __inw platform_inw
  240. #define __inl platform_inl
  241. #define __outb platform_outb
  242. #define __outw platform_outw
  243. #define __outl platform_outl
  244. #define __mmiowb platform_mmiowb
  245. #define inb(p) __inb(p)
  246. #define inw(p) __inw(p)
  247. #define inl(p) __inl(p)
  248. #define insb(p,d,c) __insb(p,d,c)
  249. #define insw(p,d,c) __insw(p,d,c)
  250. #define insl(p,d,c) __insl(p,d,c)
  251. #define outb(v,p) __outb(v,p)
  252. #define outw(v,p) __outw(v,p)
  253. #define outl(v,p) __outl(v,p)
  254. #define outsb(p,s,c) __outsb(p,s,c)
  255. #define outsw(p,s,c) __outsw(p,s,c)
  256. #define outsl(p,s,c) __outsl(p,s,c)
  257. #define mmiowb() __mmiowb()
  258. /*
  259. * The address passed to these functions are ioremap()ped already.
  260. *
  261. * We need these to be machine vectors since some platforms don't provide
  262. * DMA coherence via PIO reads (PCI drivers and the spec imply that this is
  263. * a good idea). Writes are ok though for all existing ia64 platforms (and
  264. * hopefully it'll stay that way).
  265. */
  266. static inline unsigned char
  267. ___ia64_readb (const volatile void __iomem *addr)
  268. {
  269. return *(volatile unsigned char __force *)addr;
  270. }
  271. static inline unsigned short
  272. ___ia64_readw (const volatile void __iomem *addr)
  273. {
  274. return *(volatile unsigned short __force *)addr;
  275. }
  276. static inline unsigned int
  277. ___ia64_readl (const volatile void __iomem *addr)
  278. {
  279. return *(volatile unsigned int __force *) addr;
  280. }
  281. static inline unsigned long
  282. ___ia64_readq (const volatile void __iomem *addr)
  283. {
  284. return *(volatile unsigned long __force *) addr;
  285. }
  286. static inline void
  287. __writeb (unsigned char val, volatile void __iomem *addr)
  288. {
  289. *(volatile unsigned char __force *) addr = val;
  290. }
  291. static inline void
  292. __writew (unsigned short val, volatile void __iomem *addr)
  293. {
  294. *(volatile unsigned short __force *) addr = val;
  295. }
  296. static inline void
  297. __writel (unsigned int val, volatile void __iomem *addr)
  298. {
  299. *(volatile unsigned int __force *) addr = val;
  300. }
  301. static inline void
  302. __writeq (unsigned long val, volatile void __iomem *addr)
  303. {
  304. *(volatile unsigned long __force *) addr = val;
  305. }
  306. #define __readb platform_readb
  307. #define __readw platform_readw
  308. #define __readl platform_readl
  309. #define __readq platform_readq
  310. #define __readb_relaxed platform_readb_relaxed
  311. #define __readw_relaxed platform_readw_relaxed
  312. #define __readl_relaxed platform_readl_relaxed
  313. #define __readq_relaxed platform_readq_relaxed
  314. #define readb(a) __readb((a))
  315. #define readw(a) __readw((a))
  316. #define readl(a) __readl((a))
  317. #define readq(a) __readq((a))
  318. #define readb_relaxed(a) __readb_relaxed((a))
  319. #define readw_relaxed(a) __readw_relaxed((a))
  320. #define readl_relaxed(a) __readl_relaxed((a))
  321. #define readq_relaxed(a) __readq_relaxed((a))
  322. #define __raw_readb readb
  323. #define __raw_readw readw
  324. #define __raw_readl readl
  325. #define __raw_readq readq
  326. #define __raw_readb_relaxed readb_relaxed
  327. #define __raw_readw_relaxed readw_relaxed
  328. #define __raw_readl_relaxed readl_relaxed
  329. #define __raw_readq_relaxed readq_relaxed
  330. #define writeb(v,a) __writeb((v), (a))
  331. #define writew(v,a) __writew((v), (a))
  332. #define writel(v,a) __writel((v), (a))
  333. #define writeq(v,a) __writeq((v), (a))
  334. #define __raw_writeb writeb
  335. #define __raw_writew writew
  336. #define __raw_writel writel
  337. #define __raw_writeq writeq
  338. #ifndef inb_p
  339. # define inb_p inb
  340. #endif
  341. #ifndef inw_p
  342. # define inw_p inw
  343. #endif
  344. #ifndef inl_p
  345. # define inl_p inl
  346. #endif
  347. #ifndef outb_p
  348. # define outb_p outb
  349. #endif
  350. #ifndef outw_p
  351. # define outw_p outw
  352. #endif
  353. #ifndef outl_p
  354. # define outl_p outl
  355. #endif
  356. /*
  357. * An "address" in IO memory space is not clearly either an integer or a pointer. We will
  358. * accept both, thus the casts.
  359. *
  360. * On ia-64, we access the physical I/O memory space through the uncached kernel region.
  361. */
  362. static inline void __iomem *
  363. ioremap (unsigned long offset, unsigned long size)
  364. {
  365. return (void __iomem *) (__IA64_UNCACHED_OFFSET | (offset));
  366. }
  367. static inline void
  368. iounmap (volatile void __iomem *addr)
  369. {
  370. }
  371. #define ioremap_nocache(o,s) ioremap(o,s)
  372. # ifdef __KERNEL__
  373. /*
  374. * String version of IO memory access ops:
  375. */
  376. extern void memcpy_fromio(void *dst, const volatile void __iomem *src, long n);
  377. extern void memcpy_toio(volatile void __iomem *dst, const void *src, long n);
  378. extern void memset_io(volatile void __iomem *s, int c, long n);
  379. #define dma_cache_inv(_start,_size) do { } while (0)
  380. #define dma_cache_wback(_start,_size) do { } while (0)
  381. #define dma_cache_wback_inv(_start,_size) do { } while (0)
  382. # endif /* __KERNEL__ */
  383. /*
  384. * Enabling BIO_VMERGE_BOUNDARY forces us to turn off I/O MMU bypassing. It is said that
  385. * BIO-level virtual merging can give up to 4% performance boost (not verified for ia64).
  386. * On the other hand, we know that I/O MMU bypassing gives ~8% performance improvement on
  387. * SPECweb-like workloads on zx1-based machines. Thus, for now we favor I/O MMU bypassing
  388. * over BIO-level virtual merging.
  389. */
  390. extern unsigned long ia64_max_iommu_merge_mask;
  391. #if 1
  392. #define BIO_VMERGE_BOUNDARY 0
  393. #else
  394. /*
  395. * It makes no sense at all to have this BIO_VMERGE_BOUNDARY macro here. Should be
  396. * replaced by dma_merge_mask() or something of that sort. Note: the only way
  397. * BIO_VMERGE_BOUNDARY is used is to mask off bits. Effectively, our definition gets
  398. * expanded into:
  399. *
  400. * addr & ((ia64_max_iommu_merge_mask + 1) - 1) == (addr & ia64_max_iommu_vmerge_mask)
  401. *
  402. * which is precisely what we want.
  403. */
  404. #define BIO_VMERGE_BOUNDARY (ia64_max_iommu_merge_mask + 1)
  405. #endif
  406. #endif /* _ASM_IA64_IO_H */