io.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #ifndef _ASM_ARC_IO_H
  9. #define _ASM_ARC_IO_H
  10. #include <linux/types.h>
  11. #include <asm/byteorder.h>
  12. #include <asm/page.h>
  13. #ifdef CONFIG_ISA_ARCV2
  14. #include <asm/barrier.h>
  15. #define __iormb() rmb()
  16. #define __iowmb() wmb()
  17. #else
  18. #define __iormb() do { } while (0)
  19. #define __iowmb() do { } while (0)
  20. #endif
  21. extern void __iomem *ioremap(phys_addr_t paddr, unsigned long size);
  22. extern void __iomem *ioremap_prot(phys_addr_t paddr, unsigned long size,
  23. unsigned long flags);
  24. static inline void __iomem *ioport_map(unsigned long port, unsigned int nr)
  25. {
  26. return (void __iomem *)port;
  27. }
  28. static inline void ioport_unmap(void __iomem *addr)
  29. {
  30. }
  31. extern void iounmap(const void __iomem *addr);
  32. #define ioremap_nocache(phy, sz) ioremap(phy, sz)
  33. #define ioremap_wc(phy, sz) ioremap(phy, sz)
  34. #define ioremap_wt(phy, sz) ioremap(phy, sz)
  35. /*
  36. * io{read,write}{16,32}be() macros
  37. */
  38. #define ioread16be(p) ({ u16 __v = be16_to_cpu((__force __be16)__raw_readw(p)); __iormb(); __v; })
  39. #define ioread32be(p) ({ u32 __v = be32_to_cpu((__force __be32)__raw_readl(p)); __iormb(); __v; })
  40. #define iowrite16be(v,p) ({ __iowmb(); __raw_writew((__force u16)cpu_to_be16(v), p); })
  41. #define iowrite32be(v,p) ({ __iowmb(); __raw_writel((__force u32)cpu_to_be32(v), p); })
  42. /* Change struct page to physical address */
  43. #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
  44. #define __raw_readb __raw_readb
  45. static inline u8 __raw_readb(const volatile void __iomem *addr)
  46. {
  47. u8 b;
  48. __asm__ __volatile__(
  49. " ldb%U1 %0, %1 \n"
  50. : "=r" (b)
  51. : "m" (*(volatile u8 __force *)addr)
  52. : "memory");
  53. return b;
  54. }
  55. #define __raw_readw __raw_readw
  56. static inline u16 __raw_readw(const volatile void __iomem *addr)
  57. {
  58. u16 s;
  59. __asm__ __volatile__(
  60. " ldw%U1 %0, %1 \n"
  61. : "=r" (s)
  62. : "m" (*(volatile u16 __force *)addr)
  63. : "memory");
  64. return s;
  65. }
  66. #define __raw_readl __raw_readl
  67. static inline u32 __raw_readl(const volatile void __iomem *addr)
  68. {
  69. u32 w;
  70. __asm__ __volatile__(
  71. " ld%U1 %0, %1 \n"
  72. : "=r" (w)
  73. : "m" (*(volatile u32 __force *)addr)
  74. : "memory");
  75. return w;
  76. }
  77. #define __raw_writeb __raw_writeb
  78. static inline void __raw_writeb(u8 b, volatile void __iomem *addr)
  79. {
  80. __asm__ __volatile__(
  81. " stb%U1 %0, %1 \n"
  82. :
  83. : "r" (b), "m" (*(volatile u8 __force *)addr)
  84. : "memory");
  85. }
  86. #define __raw_writew __raw_writew
  87. static inline void __raw_writew(u16 s, volatile void __iomem *addr)
  88. {
  89. __asm__ __volatile__(
  90. " stw%U1 %0, %1 \n"
  91. :
  92. : "r" (s), "m" (*(volatile u16 __force *)addr)
  93. : "memory");
  94. }
  95. #define __raw_writel __raw_writel
  96. static inline void __raw_writel(u32 w, volatile void __iomem *addr)
  97. {
  98. __asm__ __volatile__(
  99. " st%U1 %0, %1 \n"
  100. :
  101. : "r" (w), "m" (*(volatile u32 __force *)addr)
  102. : "memory");
  103. }
  104. /*
  105. * MMIO can also get buffered/optimized in micro-arch, so barriers needed
  106. * Based on ARM model for the typical use case
  107. *
  108. * <ST [DMA buffer]>
  109. * <writel MMIO "go" reg>
  110. * or:
  111. * <readl MMIO "status" reg>
  112. * <LD [DMA buffer]>
  113. *
  114. * http://lkml.kernel.org/r/20150622133656.GG1583@arm.com
  115. */
  116. #define readb(c) ({ u8 __v = readb_relaxed(c); __iormb(); __v; })
  117. #define readw(c) ({ u16 __v = readw_relaxed(c); __iormb(); __v; })
  118. #define readl(c) ({ u32 __v = readl_relaxed(c); __iormb(); __v; })
  119. #define writeb(v,c) ({ __iowmb(); writeb_relaxed(v,c); })
  120. #define writew(v,c) ({ __iowmb(); writew_relaxed(v,c); })
  121. #define writel(v,c) ({ __iowmb(); writel_relaxed(v,c); })
  122. /*
  123. * Relaxed API for drivers which can handle barrier ordering themselves
  124. *
  125. * Also these are defined to perform little endian accesses.
  126. * To provide the typical device register semantics of fixed endian,
  127. * swap the byte order for Big Endian
  128. *
  129. * http://lkml.kernel.org/r/201603100845.30602.arnd@arndb.de
  130. */
  131. #define readb_relaxed(c) __raw_readb(c)
  132. #define readw_relaxed(c) ({ u16 __r = le16_to_cpu((__force __le16) \
  133. __raw_readw(c)); __r; })
  134. #define readl_relaxed(c) ({ u32 __r = le32_to_cpu((__force __le32) \
  135. __raw_readl(c)); __r; })
  136. #define writeb_relaxed(v,c) __raw_writeb(v,c)
  137. #define writew_relaxed(v,c) __raw_writew((__force u16) cpu_to_le16(v),c)
  138. #define writel_relaxed(v,c) __raw_writel((__force u32) cpu_to_le32(v),c)
  139. #include <asm-generic/io.h>
  140. #endif /* _ASM_ARC_IO_H */