io.h 5.6 KB

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