io.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * linux/include/asm-xtensa/io.h
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * Copyright (C) 2001 - 2005 Tensilica Inc.
  9. */
  10. #ifndef _XTENSA_IO_H
  11. #define _XTENSA_IO_H
  12. #ifdef __KERNEL__
  13. #include <linux/config.h>
  14. #include <asm/byteorder.h>
  15. #include <linux/types.h>
  16. #include <asm/fixmap.h>
  17. #define _IO_BASE 0
  18. /*
  19. * swap functions to change byte order from little-endian to big-endian and
  20. * vice versa.
  21. */
  22. static inline unsigned short _swapw (unsigned short v)
  23. {
  24. return (v << 8) | (v >> 8);
  25. }
  26. static inline unsigned int _swapl (unsigned int v)
  27. {
  28. return (v << 24) | ((v & 0xff00) << 8) | ((v >> 8) & 0xff00) | (v >> 24);
  29. }
  30. /*
  31. * Change virtual addresses to physical addresses and vv.
  32. * These are trivial on the 1:1 Linux/Xtensa mapping
  33. */
  34. static inline unsigned long virt_to_phys(volatile void * address)
  35. {
  36. return PHYSADDR((unsigned long)address);
  37. }
  38. static inline void * phys_to_virt(unsigned long address)
  39. {
  40. return (void*) CACHED_ADDR(address);
  41. }
  42. /*
  43. * IO bus memory addresses are also 1:1 with the physical address
  44. */
  45. static inline unsigned long virt_to_bus(volatile void * address)
  46. {
  47. return PHYSADDR((unsigned long)address);
  48. }
  49. static inline void * bus_to_virt (unsigned long address)
  50. {
  51. return (void *) CACHED_ADDR(address);
  52. }
  53. /*
  54. * Change "struct page" to physical address.
  55. */
  56. static inline void *ioremap(unsigned long offset, unsigned long size)
  57. {
  58. return (void *) CACHED_ADDR_IO(offset);
  59. }
  60. static inline void *ioremap_nocache(unsigned long offset, unsigned long size)
  61. {
  62. return (void *) BYPASS_ADDR_IO(offset);
  63. }
  64. static inline void iounmap(void *addr)
  65. {
  66. }
  67. /*
  68. * Generic I/O
  69. */
  70. #define readb(addr) \
  71. ({ unsigned char __v = (*(volatile unsigned char *)(addr)); __v; })
  72. #define readw(addr) \
  73. ({ unsigned short __v = (*(volatile unsigned short *)(addr)); __v; })
  74. #define readl(addr) \
  75. ({ unsigned int __v = (*(volatile unsigned int *)(addr)); __v; })
  76. #define writeb(b, addr) (void)((*(volatile unsigned char *)(addr)) = (b))
  77. #define writew(b, addr) (void)((*(volatile unsigned short *)(addr)) = (b))
  78. #define writel(b, addr) (void)((*(volatile unsigned int *)(addr)) = (b))
  79. static inline __u8 __raw_readb(const volatile void __iomem *addr)
  80. {
  81. return *(__force volatile __u8 *)(addr);
  82. }
  83. static inline __u16 __raw_readw(const volatile void __iomem *addr)
  84. {
  85. return *(__force volatile __u16 *)(addr);
  86. }
  87. static inline __u32 __raw_readl(const volatile void __iomem *addr)
  88. {
  89. return *(__force volatile __u32 *)(addr);
  90. }
  91. static inline void __raw_writeb(__u8 b, volatile void __iomem *addr)
  92. {
  93. *(__force volatile __u8 *)(addr) = b;
  94. }
  95. static inline void __raw_writew(__u16 b, volatile void __iomem *addr)
  96. {
  97. *(__force volatile __u16 *)(addr) = b;
  98. }
  99. static inline void __raw_writel(__u32 b, volatile void __iomem *addr)
  100. {
  101. *(__force volatile __u32 *)(addr) = b;
  102. }
  103. /* These are the definitions for the x86 IO instructions
  104. * inb/inw/inl/outb/outw/outl, the "string" versions
  105. * insb/insw/insl/outsb/outsw/outsl, and the "pausing" versions
  106. * inb_p/inw_p/...
  107. * The macros don't do byte-swapping.
  108. */
  109. #define inb(port) readb((u8 *)((port)+_IO_BASE))
  110. #define outb(val, port) writeb((val),(u8 *)((unsigned long)(port)+_IO_BASE))
  111. #define inw(port) readw((u16 *)((port)+_IO_BASE))
  112. #define outw(val, port) writew((val),(u16 *)((unsigned long)(port)+_IO_BASE))
  113. #define inl(port) readl((u32 *)((port)+_IO_BASE))
  114. #define outl(val, port) writel((val),(u32 *)((unsigned long)(port)))
  115. #define inb_p(port) inb((port))
  116. #define outb_p(val, port) outb((val), (port))
  117. #define inw_p(port) inw((port))
  118. #define outw_p(val, port) outw((val), (port))
  119. #define inl_p(port) inl((port))
  120. #define outl_p(val, port) outl((val), (port))
  121. extern void insb (unsigned long port, void *dst, unsigned long count);
  122. extern void insw (unsigned long port, void *dst, unsigned long count);
  123. extern void insl (unsigned long port, void *dst, unsigned long count);
  124. extern void outsb (unsigned long port, const void *src, unsigned long count);
  125. extern void outsw (unsigned long port, const void *src, unsigned long count);
  126. extern void outsl (unsigned long port, const void *src, unsigned long count);
  127. #define IO_SPACE_LIMIT ~0
  128. #define memset_io(a,b,c) memset((void *)(a),(b),(c))
  129. #define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c))
  130. #define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c))
  131. /* At this point the Xtensa doesn't provide byte swap instructions */
  132. #ifdef __XTENSA_EB__
  133. # define in_8(addr) (*(u8*)(addr))
  134. # define in_le16(addr) _swapw(*(u16*)(addr))
  135. # define in_le32(addr) _swapl(*(u32*)(addr))
  136. # define out_8(b, addr) *(u8*)(addr) = (b)
  137. # define out_le16(b, addr) *(u16*)(addr) = _swapw(b)
  138. # define out_le32(b, addr) *(u32*)(addr) = _swapl(b)
  139. #elif defined(__XTENSA_EL__)
  140. # define in_8(addr) (*(u8*)(addr))
  141. # define in_le16(addr) (*(u16*)(addr))
  142. # define in_le32(addr) (*(u32*)(addr))
  143. # define out_8(b, addr) *(u8*)(addr) = (b)
  144. # define out_le16(b, addr) *(u16*)(addr) = (b)
  145. # define out_le32(b, addr) *(u32*)(addr) = (b)
  146. #else
  147. # error processor byte order undefined!
  148. #endif
  149. /*
  150. * * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  151. * * access
  152. * */
  153. #define xlate_dev_mem_ptr(p) __va(p)
  154. /*
  155. * * Convert a virtual cached pointer to an uncached pointer
  156. * */
  157. #define xlate_dev_kmem_ptr(p) p
  158. #endif /* __KERNEL__ */
  159. #endif /* _XTENSA_IO_H */