io.h 5.6 KB

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