io.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (C) 2005-2017 Andes Technology Corporation
  3. #ifndef __ASM_NDS32_IO_H
  4. #define __ASM_NDS32_IO_H
  5. #include <linux/types.h>
  6. extern void iounmap(volatile void __iomem *addr);
  7. #define __raw_writeb __raw_writeb
  8. static inline void __raw_writeb(u8 val, volatile void __iomem *addr)
  9. {
  10. asm volatile("sbi %0, [%1]" : : "r" (val), "r" (addr));
  11. }
  12. #define __raw_writew __raw_writew
  13. static inline void __raw_writew(u16 val, volatile void __iomem *addr)
  14. {
  15. asm volatile("shi %0, [%1]" : : "r" (val), "r" (addr));
  16. }
  17. #define __raw_writel __raw_writel
  18. static inline void __raw_writel(u32 val, volatile void __iomem *addr)
  19. {
  20. asm volatile("swi %0, [%1]" : : "r" (val), "r" (addr));
  21. }
  22. #define __raw_readb __raw_readb
  23. static inline u8 __raw_readb(const volatile void __iomem *addr)
  24. {
  25. u8 val;
  26. asm volatile("lbi %0, [%1]" : "=r" (val) : "r" (addr));
  27. return val;
  28. }
  29. #define __raw_readw __raw_readw
  30. static inline u16 __raw_readw(const volatile void __iomem *addr)
  31. {
  32. u16 val;
  33. asm volatile("lhi %0, [%1]" : "=r" (val) : "r" (addr));
  34. return val;
  35. }
  36. #define __raw_readl __raw_readl
  37. static inline u32 __raw_readl(const volatile void __iomem *addr)
  38. {
  39. u32 val;
  40. asm volatile("lwi %0, [%1]" : "=r" (val) : "r" (addr));
  41. return val;
  42. }
  43. #define __iormb() rmb()
  44. #define __iowmb() wmb()
  45. #define mmiowb() __asm__ __volatile__ ("msync all" : : : "memory");
  46. /*
  47. * {read,write}{b,w,l,q}_relaxed() are like the regular version, but
  48. * are not guaranteed to provide ordering against spinlocks or memory
  49. * accesses.
  50. */
  51. #define readb_relaxed(c) ({ u8 __v = __raw_readb(c); __v; })
  52. #define readw_relaxed(c) ({ u16 __v = le16_to_cpu((__force __le16)__raw_readw(c)); __v; })
  53. #define readl_relaxed(c) ({ u32 __v = le32_to_cpu((__force __le32)__raw_readl(c)); __v; })
  54. #define writeb_relaxed(v,c) ((void)__raw_writeb((v),(c)))
  55. #define writew_relaxed(v,c) ((void)__raw_writew((__force u16)cpu_to_le16(v),(c)))
  56. #define writel_relaxed(v,c) ((void)__raw_writel((__force u32)cpu_to_le32(v),(c)))
  57. /*
  58. * {read,write}{b,w,l,q}() access little endian memory and return result in
  59. * native endianness.
  60. */
  61. #define readb(c) ({ u8 __v = readb_relaxed(c); __iormb(); __v; })
  62. #define readw(c) ({ u16 __v = readw_relaxed(c); __iormb(); __v; })
  63. #define readl(c) ({ u32 __v = readl_relaxed(c); __iormb(); __v; })
  64. #define writeb(v,c) ({ __iowmb(); writeb_relaxed((v),(c)); })
  65. #define writew(v,c) ({ __iowmb(); writew_relaxed((v),(c)); })
  66. #define writel(v,c) ({ __iowmb(); writel_relaxed((v),(c)); })
  67. #include <asm-generic/io.h>
  68. #endif /* __ASM_NDS32_IO_H */