io.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. extern void __iomem *ioremap(unsigned long physaddr, unsigned long size);
  14. extern void __iomem *ioremap_prot(phys_addr_t offset, unsigned long size,
  15. unsigned long flags);
  16. extern void iounmap(const void __iomem *addr);
  17. #define ioremap_nocache(phy, sz) ioremap(phy, sz)
  18. #define ioremap_wc(phy, sz) ioremap(phy, sz)
  19. #define ioremap_wt(phy, sz) ioremap(phy, sz)
  20. /* Change struct page to physical address */
  21. #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
  22. #define __raw_readb __raw_readb
  23. static inline u8 __raw_readb(const volatile void __iomem *addr)
  24. {
  25. u8 b;
  26. __asm__ __volatile__(
  27. " ldb%U1 %0, %1 \n"
  28. : "=r" (b)
  29. : "m" (*(volatile u8 __force *)addr)
  30. : "memory");
  31. return b;
  32. }
  33. #define __raw_readw __raw_readw
  34. static inline u16 __raw_readw(const volatile void __iomem *addr)
  35. {
  36. u16 s;
  37. __asm__ __volatile__(
  38. " ldw%U1 %0, %1 \n"
  39. : "=r" (s)
  40. : "m" (*(volatile u16 __force *)addr)
  41. : "memory");
  42. return s;
  43. }
  44. #define __raw_readl __raw_readl
  45. static inline u32 __raw_readl(const volatile void __iomem *addr)
  46. {
  47. u32 w;
  48. __asm__ __volatile__(
  49. " ld%U1 %0, %1 \n"
  50. : "=r" (w)
  51. : "m" (*(volatile u32 __force *)addr)
  52. : "memory");
  53. return w;
  54. }
  55. #define __raw_writeb __raw_writeb
  56. static inline void __raw_writeb(u8 b, volatile void __iomem *addr)
  57. {
  58. __asm__ __volatile__(
  59. " stb%U1 %0, %1 \n"
  60. :
  61. : "r" (b), "m" (*(volatile u8 __force *)addr)
  62. : "memory");
  63. }
  64. #define __raw_writew __raw_writew
  65. static inline void __raw_writew(u16 s, volatile void __iomem *addr)
  66. {
  67. __asm__ __volatile__(
  68. " stw%U1 %0, %1 \n"
  69. :
  70. : "r" (s), "m" (*(volatile u16 __force *)addr)
  71. : "memory");
  72. }
  73. #define __raw_writel __raw_writel
  74. static inline void __raw_writel(u32 w, volatile void __iomem *addr)
  75. {
  76. __asm__ __volatile__(
  77. " st%U1 %0, %1 \n"
  78. :
  79. : "r" (w), "m" (*(volatile u32 __force *)addr)
  80. : "memory");
  81. }
  82. #ifdef CONFIG_ISA_ARCV2
  83. #include <asm/barrier.h>
  84. #define __iormb() rmb()
  85. #define __iowmb() wmb()
  86. #else
  87. #define __iormb() do { } while (0)
  88. #define __iowmb() do { } while (0)
  89. #endif
  90. /*
  91. * MMIO can also get buffered/optimized in micro-arch, so barriers needed
  92. * Based on ARM model for the typical use case
  93. *
  94. * <ST [DMA buffer]>
  95. * <writel MMIO "go" reg>
  96. * or:
  97. * <readl MMIO "status" reg>
  98. * <LD [DMA buffer]>
  99. *
  100. * http://lkml.kernel.org/r/20150622133656.GG1583@arm.com
  101. */
  102. #define readb(c) ({ u8 __v = readb_relaxed(c); __iormb(); __v; })
  103. #define readw(c) ({ u16 __v = readw_relaxed(c); __iormb(); __v; })
  104. #define readl(c) ({ u32 __v = readl_relaxed(c); __iormb(); __v; })
  105. #define writeb(v,c) ({ __iowmb(); writeb_relaxed(v,c); })
  106. #define writew(v,c) ({ __iowmb(); writew_relaxed(v,c); })
  107. #define writel(v,c) ({ __iowmb(); writel_relaxed(v,c); })
  108. /*
  109. * Relaxed API for drivers which can handle any ordering themselves
  110. */
  111. #define readb_relaxed(c) __raw_readb(c)
  112. #define readw_relaxed(c) __raw_readw(c)
  113. #define readl_relaxed(c) __raw_readl(c)
  114. #define writeb_relaxed(v,c) __raw_writeb(v,c)
  115. #define writew_relaxed(v,c) __raw_writew(v,c)
  116. #define writel_relaxed(v,c) __raw_writel(v,c)
  117. #include <asm-generic/io.h>
  118. #endif /* _ASM_ARC_IO_H */