io.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * 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 <asm/byteorder.h>
  14. #include <asm/page.h>
  15. #include <linux/bug.h>
  16. #include <linux/kernel.h>
  17. #include <linux/types.h>
  18. #define XCHAL_KIO_CACHED_VADDR 0xe0000000
  19. #define XCHAL_KIO_BYPASS_VADDR 0xf0000000
  20. #define XCHAL_KIO_PADDR 0xf0000000
  21. #define XCHAL_KIO_SIZE 0x10000000
  22. #define IOADDR(x) (XCHAL_KIO_BYPASS_VADDR + (x))
  23. /*
  24. * swap functions to change byte order from little-endian to big-endian and
  25. * vice versa.
  26. */
  27. static inline unsigned short _swapw (unsigned short v)
  28. {
  29. return (v << 8) | (v >> 8);
  30. }
  31. static inline unsigned int _swapl (unsigned int v)
  32. {
  33. return (v << 24) | ((v & 0xff00) << 8) | ((v >> 8) & 0xff00) | (v >> 24);
  34. }
  35. /*
  36. * Change virtual addresses to physical addresses and vv.
  37. * These are trivial on the 1:1 Linux/Xtensa mapping
  38. */
  39. static inline unsigned long virt_to_phys(volatile void * address)
  40. {
  41. return __pa(address);
  42. }
  43. static inline void * phys_to_virt(unsigned long address)
  44. {
  45. return __va(address);
  46. }
  47. /*
  48. * virt_to_bus and bus_to_virt are deprecated.
  49. */
  50. #define virt_to_bus(x) virt_to_phys(x)
  51. #define bus_to_virt(x) phys_to_virt(x)
  52. /*
  53. * Return the virtual (cached) address for the specified bus memory.
  54. * Note that we currently don't support any address outside the KIO segment.
  55. */
  56. static inline void *ioremap(unsigned long offset, unsigned long size)
  57. {
  58. #ifdef CONFIG_MMU
  59. if (offset >= XCHAL_KIO_PADDR
  60. && offset < XCHAL_KIO_PADDR + XCHAL_KIO_SIZE)
  61. return (void*)(offset-XCHAL_KIO_PADDR+XCHAL_KIO_BYPASS_VADDR);
  62. else
  63. BUG();
  64. #else
  65. return (void *)offset;
  66. #endif
  67. }
  68. static inline void *ioremap_nocache(unsigned long offset, unsigned long size)
  69. {
  70. #ifdef CONFIG_MMU
  71. if (offset >= XCHAL_KIO_PADDR
  72. && offset < XCHAL_KIO_PADDR + XCHAL_KIO_SIZE)
  73. return (void*)(offset-XCHAL_KIO_PADDR+XCHAL_KIO_CACHED_VADDR);
  74. else
  75. BUG();
  76. #else
  77. return (void *)offset;
  78. #endif
  79. }
  80. static inline void iounmap(void *addr)
  81. {
  82. }
  83. /*
  84. * Generic I/O
  85. */
  86. #define readb(addr) \
  87. ({ unsigned char __v = (*(volatile unsigned char *)(addr)); __v; })
  88. #define readw(addr) \
  89. ({ unsigned short __v = (*(volatile unsigned short *)(addr)); __v; })
  90. #define readl(addr) \
  91. ({ unsigned int __v = (*(volatile unsigned int *)(addr)); __v; })
  92. #define writeb(b, addr) (void)((*(volatile unsigned char *)(addr)) = (b))
  93. #define writew(b, addr) (void)((*(volatile unsigned short *)(addr)) = (b))
  94. #define writel(b, addr) (void)((*(volatile unsigned int *)(addr)) = (b))
  95. static inline __u8 __raw_readb(const volatile void __iomem *addr)
  96. {
  97. return *(__force volatile __u8 *)(addr);
  98. }
  99. static inline __u16 __raw_readw(const volatile void __iomem *addr)
  100. {
  101. return *(__force volatile __u16 *)(addr);
  102. }
  103. static inline __u32 __raw_readl(const volatile void __iomem *addr)
  104. {
  105. return *(__force volatile __u32 *)(addr);
  106. }
  107. static inline void __raw_writeb(__u8 b, volatile void __iomem *addr)
  108. {
  109. *(__force volatile __u8 *)(addr) = b;
  110. }
  111. static inline void __raw_writew(__u16 b, volatile void __iomem *addr)
  112. {
  113. *(__force volatile __u16 *)(addr) = b;
  114. }
  115. static inline void __raw_writel(__u32 b, volatile void __iomem *addr)
  116. {
  117. *(__force volatile __u32 *)(addr) = b;
  118. }
  119. /* These are the definitions for the x86 IO instructions
  120. * inb/inw/inl/outb/outw/outl, the "string" versions
  121. * insb/insw/insl/outsb/outsw/outsl, and the "pausing" versions
  122. * inb_p/inw_p/...
  123. * The macros don't do byte-swapping.
  124. */
  125. #define inb(port) readb((u8 *)((port)))
  126. #define outb(val, port) writeb((val),(u8 *)((unsigned long)(port)))
  127. #define inw(port) readw((u16 *)((port)))
  128. #define outw(val, port) writew((val),(u16 *)((unsigned long)(port)))
  129. #define inl(port) readl((u32 *)((port)))
  130. #define outl(val, port) writel((val),(u32 *)((unsigned long)(port)))
  131. #define inb_p(port) inb((port))
  132. #define outb_p(val, port) outb((val), (port))
  133. #define inw_p(port) inw((port))
  134. #define outw_p(val, port) outw((val), (port))
  135. #define inl_p(port) inl((port))
  136. #define outl_p(val, port) outl((val), (port))
  137. extern void insb (unsigned long port, void *dst, unsigned long count);
  138. extern void insw (unsigned long port, void *dst, unsigned long count);
  139. extern void insl (unsigned long port, void *dst, unsigned long count);
  140. extern void outsb (unsigned long port, const void *src, unsigned long count);
  141. extern void outsw (unsigned long port, const void *src, unsigned long count);
  142. extern void outsl (unsigned long port, const void *src, unsigned long count);
  143. #define IO_SPACE_LIMIT ~0
  144. #define memset_io(a,b,c) memset((void *)(a),(b),(c))
  145. #define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c))
  146. #define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c))
  147. /* At this point the Xtensa doesn't provide byte swap instructions */
  148. #ifdef __XTENSA_EB__
  149. # define in_8(addr) (*(u8*)(addr))
  150. # define in_le16(addr) _swapw(*(u16*)(addr))
  151. # define in_le32(addr) _swapl(*(u32*)(addr))
  152. # define out_8(b, addr) *(u8*)(addr) = (b)
  153. # define out_le16(b, addr) *(u16*)(addr) = _swapw(b)
  154. # define out_le32(b, addr) *(u32*)(addr) = _swapl(b)
  155. #elif defined(__XTENSA_EL__)
  156. # define in_8(addr) (*(u8*)(addr))
  157. # define in_le16(addr) (*(u16*)(addr))
  158. # define in_le32(addr) (*(u32*)(addr))
  159. # define out_8(b, addr) *(u8*)(addr) = (b)
  160. # define out_le16(b, addr) *(u16*)(addr) = (b)
  161. # define out_le32(b, addr) *(u32*)(addr) = (b)
  162. #else
  163. # error processor byte order undefined!
  164. #endif
  165. /*
  166. * Convert a physical pointer to a virtual kernel pointer for /dev/mem access
  167. */
  168. #define xlate_dev_mem_ptr(p) __va(p)
  169. /*
  170. * Convert a virtual cached pointer to an uncached pointer
  171. */
  172. #define xlate_dev_kmem_ptr(p) p
  173. #endif /* __KERNEL__ */
  174. #endif /* _XTENSA_IO_H */