io.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_IA64_IO_H
  3. #define _ASM_IA64_IO_H
  4. /*
  5. * This file contains the definitions for the emulated IO instructions
  6. * inb/inw/inl/outb/outw/outl and the "string versions" of the same
  7. * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
  8. * versions of the single-IO instructions (inb_p/inw_p/..).
  9. *
  10. * This file is not meant to be obfuscating: it's just complicated to
  11. * (a) handle it all in a way that makes gcc able to optimize it as
  12. * well as possible and (b) trying to avoid writing the same thing
  13. * over and over again with slight variations and possibly making a
  14. * mistake somewhere.
  15. *
  16. * Copyright (C) 1998-2003 Hewlett-Packard Co
  17. * David Mosberger-Tang <[email protected]>
  18. * Copyright (C) 1999 Asit Mallick <[email protected]>
  19. * Copyright (C) 1999 Don Dugger <[email protected]>
  20. */
  21. #include <asm/unaligned.h>
  22. #include <asm/early_ioremap.h>
  23. /* We don't use IO slowdowns on the ia64, but.. */
  24. #define __SLOW_DOWN_IO do { } while (0)
  25. #define SLOW_DOWN_IO do { } while (0)
  26. #define __IA64_UNCACHED_OFFSET RGN_BASE(RGN_UNCACHED)
  27. /*
  28. * The legacy I/O space defined by the ia64 architecture supports only 65536 ports, but
  29. * large machines may have multiple other I/O spaces so we can't place any a priori limit
  30. * on IO_SPACE_LIMIT. These additional spaces are described in ACPI.
  31. */
  32. #define IO_SPACE_LIMIT 0xffffffffffffffffUL
  33. #define MAX_IO_SPACES_BITS 8
  34. #define MAX_IO_SPACES (1UL << MAX_IO_SPACES_BITS)
  35. #define IO_SPACE_BITS 24
  36. #define IO_SPACE_SIZE (1UL << IO_SPACE_BITS)
  37. #define IO_SPACE_NR(port) ((port) >> IO_SPACE_BITS)
  38. #define IO_SPACE_BASE(space) ((space) << IO_SPACE_BITS)
  39. #define IO_SPACE_PORT(port) ((port) & (IO_SPACE_SIZE - 1))
  40. #define IO_SPACE_SPARSE_ENCODING(p) ((((p) >> 2) << 12) | ((p) & 0xfff))
  41. struct io_space {
  42. unsigned long mmio_base; /* base in MMIO space */
  43. int sparse;
  44. };
  45. extern struct io_space io_space[];
  46. extern unsigned int num_io_spaces;
  47. # ifdef __KERNEL__
  48. /*
  49. * All MMIO iomem cookies are in region 6; anything less is a PIO cookie:
  50. * 0xCxxxxxxxxxxxxxxx MMIO cookie (return from ioremap)
  51. * 0x000000001SPPPPPP PIO cookie (S=space number, P..P=port)
  52. *
  53. * ioread/writeX() uses the leading 1 in PIO cookies (PIO_OFFSET) to catch
  54. * code that uses bare port numbers without the prerequisite pci_iomap().
  55. */
  56. #define PIO_OFFSET (1UL << (MAX_IO_SPACES_BITS + IO_SPACE_BITS))
  57. #define PIO_MASK (PIO_OFFSET - 1)
  58. #define PIO_RESERVED __IA64_UNCACHED_OFFSET
  59. #define HAVE_ARCH_PIO_SIZE
  60. #include <asm/intrinsics.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. #define virt_to_phys virt_to_phys
  72. static inline void*
  73. phys_to_virt (unsigned long address)
  74. {
  75. return (void *) (address + PAGE_OFFSET);
  76. }
  77. #define phys_to_virt phys_to_virt
  78. #define ARCH_HAS_VALID_PHYS_ADDR_RANGE
  79. extern u64 kern_mem_attribute (unsigned long phys_addr, unsigned long size);
  80. extern int valid_phys_addr_range (phys_addr_t addr, size_t count); /* efi.c */
  81. extern int valid_mmap_phys_addr_range (unsigned long pfn, size_t count);
  82. # endif /* KERNEL */
  83. /*
  84. * Memory fence w/accept. This should never be used in code that is
  85. * not IA-64 specific.
  86. */
  87. #define __ia64_mf_a() ia64_mfa()
  88. static inline void*
  89. __ia64_mk_io_addr (unsigned long port)
  90. {
  91. struct io_space *space;
  92. unsigned long offset;
  93. space = &io_space[IO_SPACE_NR(port)];
  94. port = IO_SPACE_PORT(port);
  95. if (space->sparse)
  96. offset = IO_SPACE_SPARSE_ENCODING(port);
  97. else
  98. offset = port;
  99. return (void *) (space->mmio_base | offset);
  100. }
  101. /*
  102. * For the in/out routines, we need to do "mf.a" _after_ doing the I/O access to ensure
  103. * that the access has completed before executing other I/O accesses. Since we're doing
  104. * the accesses through an uncachable (UC) translation, the CPU will execute them in
  105. * program order. However, we still need to tell the compiler not to shuffle them around
  106. * during optimization, which is why we use "volatile" pointers.
  107. */
  108. #define inb inb
  109. static inline unsigned int inb(unsigned long port)
  110. {
  111. volatile unsigned char *addr = __ia64_mk_io_addr(port);
  112. unsigned char ret;
  113. ret = *addr;
  114. __ia64_mf_a();
  115. return ret;
  116. }
  117. #define inw inw
  118. static inline unsigned int inw(unsigned long port)
  119. {
  120. volatile unsigned short *addr = __ia64_mk_io_addr(port);
  121. unsigned short ret;
  122. ret = *addr;
  123. __ia64_mf_a();
  124. return ret;
  125. }
  126. #define inl inl
  127. static inline unsigned int inl(unsigned long port)
  128. {
  129. volatile unsigned int *addr = __ia64_mk_io_addr(port);
  130. unsigned int ret;
  131. ret = *addr;
  132. __ia64_mf_a();
  133. return ret;
  134. }
  135. #define outb outb
  136. static inline void outb(unsigned char val, unsigned long port)
  137. {
  138. volatile unsigned char *addr = __ia64_mk_io_addr(port);
  139. *addr = val;
  140. __ia64_mf_a();
  141. }
  142. #define outw outw
  143. static inline void outw(unsigned short val, unsigned long port)
  144. {
  145. volatile unsigned short *addr = __ia64_mk_io_addr(port);
  146. *addr = val;
  147. __ia64_mf_a();
  148. }
  149. #define outl outl
  150. static inline void outl(unsigned int val, unsigned long port)
  151. {
  152. volatile unsigned int *addr = __ia64_mk_io_addr(port);
  153. *addr = val;
  154. __ia64_mf_a();
  155. }
  156. #define insb insb
  157. static inline void insb(unsigned long port, void *dst, unsigned long count)
  158. {
  159. unsigned char *dp = dst;
  160. while (count--)
  161. *dp++ = inb(port);
  162. }
  163. #define insw insw
  164. static inline void insw(unsigned long port, void *dst, unsigned long count)
  165. {
  166. unsigned short *dp = dst;
  167. while (count--)
  168. put_unaligned(inw(port), dp++);
  169. }
  170. #define insl insl
  171. static inline void insl(unsigned long port, void *dst, unsigned long count)
  172. {
  173. unsigned int *dp = dst;
  174. while (count--)
  175. put_unaligned(inl(port), dp++);
  176. }
  177. #define outsb outsb
  178. static inline void outsb(unsigned long port, const void *src,
  179. unsigned long count)
  180. {
  181. const unsigned char *sp = src;
  182. while (count--)
  183. outb(*sp++, port);
  184. }
  185. #define outsw outsw
  186. static inline void outsw(unsigned long port, const void *src,
  187. unsigned long count)
  188. {
  189. const unsigned short *sp = src;
  190. while (count--)
  191. outw(get_unaligned(sp++), port);
  192. }
  193. #define outsl outsl
  194. static inline void outsl(unsigned long port, const void *src,
  195. unsigned long count)
  196. {
  197. const unsigned int *sp = src;
  198. while (count--)
  199. outl(get_unaligned(sp++), port);
  200. }
  201. # ifdef __KERNEL__
  202. extern void __iomem * ioremap(unsigned long offset, unsigned long size);
  203. extern void __iomem * ioremap_uc(unsigned long offset, unsigned long size);
  204. extern void iounmap (volatile void __iomem *addr);
  205. static inline void __iomem * ioremap_cache (unsigned long phys_addr, unsigned long size)
  206. {
  207. return ioremap(phys_addr, size);
  208. }
  209. #define ioremap ioremap
  210. #define ioremap_cache ioremap_cache
  211. #define ioremap_uc ioremap_uc
  212. #define iounmap iounmap
  213. /*
  214. * String version of IO memory access ops:
  215. */
  216. extern void memcpy_fromio(void *dst, const volatile void __iomem *src, long n);
  217. extern void memcpy_toio(volatile void __iomem *dst, const void *src, long n);
  218. extern void memset_io(volatile void __iomem *s, int c, long n);
  219. #define memcpy_fromio memcpy_fromio
  220. #define memcpy_toio memcpy_toio
  221. #define memset_io memset_io
  222. #define xlate_dev_mem_ptr xlate_dev_mem_ptr
  223. #include <asm-generic/io.h>
  224. #undef PCI_IOBASE
  225. # endif /* __KERNEL__ */
  226. #endif /* _ASM_IA64_IO_H */