io.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * IO header file
  4. *
  5. * Copyright (C) 2001-2007 Tensilica Inc.
  6. * Based on the Linux/Xtensa version of this header.
  7. */
  8. #ifndef _XTENSA_IO_H
  9. #define _XTENSA_IO_H
  10. #include <linux/types.h>
  11. #include <asm/byteorder.h>
  12. /*
  13. * swap functions to change byte order from little-endian to big-endian and
  14. * vice versa.
  15. */
  16. static inline unsigned short _swapw(unsigned short v)
  17. {
  18. return (v << 8) | (v >> 8);
  19. }
  20. static inline unsigned int _swapl(unsigned int v)
  21. {
  22. return (v << 24) | ((v & 0xff00) << 8) |
  23. ((v >> 8) & 0xff00) | (v >> 24);
  24. }
  25. /*
  26. * Generic I/O
  27. */
  28. #define readb(addr) \
  29. ({ unsigned char __v = (*(volatile unsigned char *)(addr)); __v; })
  30. #define readw(addr) \
  31. ({ unsigned short __v = (*(volatile unsigned short *)(addr)); __v; })
  32. #define readl(addr) \
  33. ({ unsigned int __v = (*(volatile unsigned int *)(addr)); __v; })
  34. #define writeb(b, addr) (void)((*(volatile unsigned char *)(addr)) = (b))
  35. #define writew(b, addr) (void)((*(volatile unsigned short *)(addr)) = (b))
  36. #define writel(b, addr) (void)((*(volatile unsigned int *)(addr)) = (b))
  37. #define __raw_readb readb
  38. #define __raw_readw readw
  39. #define __raw_readl readl
  40. #define __raw_writeb writeb
  41. #define __raw_writew writew
  42. #define __raw_writel writel
  43. /* These are the definitions for the x86 IO instructions
  44. * inb/inw/inl/outb/outw/outl, the "string" versions
  45. * insb/insw/insl/outsb/outsw/outsl, and the "pausing" versions
  46. * inb_p/inw_p/...
  47. * The macros don't do byte-swapping.
  48. */
  49. #define inb(port) readb((u8 *)((port)))
  50. #define outb(val, port) writeb((val), (u8 *)((unsigned long)(port)))
  51. #define inw(port) readw((u16 *)((port)))
  52. #define outw(val, port) writew((val), (u16 *)((unsigned long)(port)))
  53. #define inl(port) readl((u32 *)((port)))
  54. #define outl(val, port) writel((val), (u32 *)((unsigned long)(port)))
  55. #define inb_p(port) inb((port))
  56. #define outb_p(val, port) outb((val), (port))
  57. #define inw_p(port) inw((port))
  58. #define outw_p(val, port) outw((val), (port))
  59. #define inl_p(port) inl((port))
  60. #define outl_p(val, port) outl((val), (port))
  61. void insb(unsigned long port, void *dst, unsigned long count);
  62. void insw(unsigned long port, void *dst, unsigned long count);
  63. void insl(unsigned long port, void *dst, unsigned long count);
  64. void outsb(unsigned long port, const void *src, unsigned long count);
  65. void outsw(unsigned long port, const void *src, unsigned long count);
  66. void outsl(unsigned long port, const void *src, unsigned long count);
  67. #define IO_SPACE_LIMIT ~0
  68. #define memset_io(a, b, c) memset((void *)(a), (b), (c))
  69. #define memcpy_fromio(a, b, c) memcpy((a), (void *)(b), (c))
  70. #define memcpy_toio(a, b, c) memcpy((void *)(a), (b), (c))
  71. /* At this point the Xtensa doesn't provide byte swap instructions */
  72. #ifdef __XTENSA_EB__
  73. # define in_8(addr) (*(u8 *)(addr))
  74. # define in_le16(addr) _swapw(*(u16 *)(addr))
  75. # define in_le32(addr) _swapl(*(u32 *)(addr))
  76. # define out_8(b, addr) *(u8 *)(addr) = (b)
  77. # define out_le16(b, addr) *(u16 *)(addr) = _swapw(b)
  78. # define out_le32(b, addr) *(u32 *)(addr) = _swapl(b)
  79. #elif defined(__XTENSA_EL__)
  80. # define in_8(addr) (*(u8 *)(addr))
  81. # define in_le16(addr) (*(u16 *)(addr))
  82. # define in_le32(addr) (*(u32 *)(addr))
  83. # define out_8(b, addr) *(u8 *)(addr) = (b)
  84. # define out_le16(b, addr) *(u16 *)(addr) = (b)
  85. # define out_le32(b, addr) *(u32 *)(addr) = (b)
  86. #else
  87. # error processor byte order undefined!
  88. #endif
  89. /*
  90. * Convert a physical pointer to a virtual kernel pointer for /dev/mem access
  91. */
  92. #define xlate_dev_mem_ptr(p) __va(p)
  93. /*
  94. * Convert a virtual cached pointer to an uncached pointer
  95. */
  96. #define xlate_dev_kmem_ptr(p) p
  97. /*
  98. * Dummy function to keep U-Boot's cfi_flash.c driver happy.
  99. */
  100. static inline void sync(void)
  101. {
  102. }
  103. #include <asm-generic/io.h>
  104. #endif /* _XTENSA_IO_H */