io.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*
  2. * U-Boot - io.h IO routines
  3. *
  4. * Copyright 2004-2009 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #ifndef _BLACKFIN_IO_H
  9. #define _BLACKFIN_IO_H
  10. #ifdef __KERNEL__
  11. #include <linux/compiler.h>
  12. #include <asm/blackfin.h>
  13. static inline void sync(void)
  14. {
  15. SSYNC();
  16. }
  17. /*
  18. * Given a physical address and a length, return a virtual address
  19. * that can be used to access the memory range with the caching
  20. * properties specified by "flags".
  21. */
  22. #define MAP_NOCACHE (0)
  23. #define MAP_WRCOMBINE (0)
  24. #define MAP_WRBACK (0)
  25. #define MAP_WRTHROUGH (0)
  26. static inline void *
  27. map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
  28. {
  29. return (void *)paddr;
  30. }
  31. /*
  32. * Take down a mapping set up by map_physmem().
  33. */
  34. static inline void unmap_physmem(void *vaddr, unsigned long flags)
  35. {
  36. }
  37. static inline phys_addr_t virt_to_phys(void * vaddr)
  38. {
  39. return (phys_addr_t)(vaddr);
  40. }
  41. /*
  42. * These are for ISA/PCI shared memory _only_ and should never be used
  43. * on any other type of memory, including Zorro memory. They are meant to
  44. * access the bus in the bus byte order which is little-endian!.
  45. *
  46. * readX/writeX() are used to access memory mapped devices. On some
  47. * architectures the memory mapped IO stuff needs to be accessed
  48. * differently. On the bfin architecture, we just read/write the
  49. * memory location directly.
  50. */
  51. #ifndef __ASSEMBLY__
  52. static inline unsigned char readb(const volatile void __iomem *addr)
  53. {
  54. unsigned int val;
  55. int tmp;
  56. __asm__ __volatile__ (
  57. "cli %1;"
  58. "NOP; NOP; SSYNC;"
  59. "%0 = b [%2] (z);"
  60. "sti %1;"
  61. : "=d"(val), "=d"(tmp)
  62. : "a"(addr)
  63. );
  64. return (unsigned char) val;
  65. }
  66. static inline unsigned short readw(const volatile void __iomem *addr)
  67. {
  68. unsigned int val;
  69. int tmp;
  70. __asm__ __volatile__ (
  71. "cli %1;"
  72. "NOP; NOP; SSYNC;"
  73. "%0 = w [%2] (z);"
  74. "sti %1;"
  75. : "=d"(val), "=d"(tmp)
  76. : "a"(addr)
  77. );
  78. return (unsigned short) val;
  79. }
  80. static inline unsigned int readl(const volatile void __iomem *addr)
  81. {
  82. unsigned int val;
  83. int tmp;
  84. __asm__ __volatile__ (
  85. "cli %1;"
  86. "NOP; NOP; SSYNC;"
  87. "%0 = [%2];"
  88. "sti %1;"
  89. : "=d"(val), "=d"(tmp)
  90. : "a"(addr)
  91. );
  92. return val;
  93. }
  94. #endif /* __ASSEMBLY__ */
  95. #define writeb(b, addr) (void)((*(volatile unsigned char *) (addr)) = (b))
  96. #define writew(b, addr) (void)((*(volatile unsigned short *) (addr)) = (b))
  97. #define writel(b, addr) (void)((*(volatile unsigned int *) (addr)) = (b))
  98. #define __raw_readb readb
  99. #define __raw_readw readw
  100. #define __raw_readl readl
  101. #define __raw_writeb writeb
  102. #define __raw_writew writew
  103. #define __raw_writel writel
  104. #define memset_io(a, b, c) memset((void *)(a), (b), (c))
  105. #define memcpy_fromio(a, b, c) memcpy((a), (void *)(b), (c))
  106. #define memcpy_toio(a, b, c) memcpy((void *)(a), (b), (c))
  107. /* Convert "I/O port addresses" to actual addresses. i.e. ugly casts. */
  108. #define __io(port) ((void *)(unsigned long)(port))
  109. #define inb(port) readb(__io(port))
  110. #define inw(port) readw(__io(port))
  111. #define inl(port) readl(__io(port))
  112. #define in_le32(port) inl(port)
  113. #define outb(x, port) writeb(x, __io(port))
  114. #define outw(x, port) writew(x, __io(port))
  115. #define outl(x, port) writel(x, __io(port))
  116. #define out_le32(x, port) outl(x, port)
  117. #define inb_p(port) inb(__io(port))
  118. #define inw_p(port) inw(__io(port))
  119. #define inl_p(port) inl(__io(port))
  120. #define outb_p(x, port) outb(x, __io(port))
  121. #define outw_p(x, port) outw(x, __io(port))
  122. #define outl_p(x, port) outl(x, __io(port))
  123. #define ioread8_rep(a, d, c) readsb(a, d, c)
  124. #define ioread16_rep(a, d, c) readsw(a, d, c)
  125. #define ioread32_rep(a, d, c) readsl(a, d, c)
  126. #define iowrite8_rep(a, s, c) writesb(a, s, c)
  127. #define iowrite16_rep(a, s, c) writesw(a, s, c)
  128. #define iowrite32_rep(a, s, c) writesl(a, s, c)
  129. #define ioread8(x) readb(x)
  130. #define ioread16(x) readw(x)
  131. #define ioread32(x) readl(x)
  132. #define iowrite8(val, x) writeb(val, x)
  133. #define iowrite16(val, x) writew(val, x)
  134. #define iowrite32(val, x) writel(val, x)
  135. #define mmiowb() wmb()
  136. #ifndef __ASSEMBLY__
  137. extern void outsb(unsigned long port, const void *addr, unsigned long count);
  138. extern void outsw(unsigned long port, const void *addr, unsigned long count);
  139. extern void outsw_8(unsigned long port, const void *addr, unsigned long count);
  140. extern void outsl(unsigned long port, const void *addr, unsigned long count);
  141. extern void insb(unsigned long port, void *addr, unsigned long count);
  142. extern void insw(unsigned long port, void *addr, unsigned long count);
  143. extern void insw_8(unsigned long port, void *addr, unsigned long count);
  144. extern void insl(unsigned long port, void *addr, unsigned long count);
  145. extern void insl_16(unsigned long port, void *addr, unsigned long count);
  146. static inline void readsl(const void __iomem *addr, void *buf, int len)
  147. {
  148. insl((unsigned long)addr, buf, len);
  149. }
  150. static inline void readsw(const void __iomem *addr, void *buf, int len)
  151. {
  152. insw((unsigned long)addr, buf, len);
  153. }
  154. static inline void readsb(const void __iomem *addr, void *buf, int len)
  155. {
  156. insb((unsigned long)addr, buf, len);
  157. }
  158. static inline void writesl(const void __iomem *addr, const void *buf, int len)
  159. {
  160. outsl((unsigned long)addr, buf, len);
  161. }
  162. static inline void writesw(const void __iomem *addr, const void *buf, int len)
  163. {
  164. outsw((unsigned long)addr, buf, len);
  165. }
  166. static inline void writesb(const void __iomem *addr, const void *buf, int len)
  167. {
  168. outsb((unsigned long)addr, buf, len);
  169. }
  170. #if defined(CONFIG_STAMP_CF) || defined(CONFIG_BFIN_IDE)
  171. /* This hack for CF/IDE needs to be addressed at some point */
  172. extern void cf_outsw(unsigned short *addr, unsigned short *sect_buf, int words);
  173. extern void cf_insw(unsigned short *sect_buf, unsigned short *addr, int words);
  174. extern unsigned char cf_inb(volatile unsigned char *addr);
  175. extern void cf_outb(unsigned char val, volatile unsigned char *addr);
  176. #undef inb
  177. #undef outb
  178. #undef insw
  179. #undef outsw
  180. #define inb(addr) cf_inb((void *)(addr))
  181. #define outb(x, addr) cf_outb((unsigned char)(x), (void *)(addr))
  182. #define insw(port, addr, cnt) cf_insw((void *)(addr), (void *)(port), cnt)
  183. #define outsw(port, addr, cnt) cf_outsw((void *)(port), (void *)(addr), cnt)
  184. #endif
  185. #endif
  186. #endif /* __KERNEL__ */
  187. #endif