io.h 5.5 KB

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