io.h 12 KB

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