io.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. #ifndef _ASM_CRIS_IO_H
  2. #define _ASM_CRIS_IO_H
  3. #include <asm/page.h> /* for __va, __pa */
  4. #include <arch/io.h>
  5. #include <asm-generic/iomap.h>
  6. #include <linux/kernel.h>
  7. struct cris_io_operations
  8. {
  9. u32 (*read_mem)(void *addr, int size);
  10. void (*write_mem)(u32 val, int size, void *addr);
  11. u32 (*read_io)(u32 port, void *addr, int size, int count);
  12. void (*write_io)(u32 port, void *addr, int size, int count);
  13. };
  14. #ifdef CONFIG_PCI
  15. extern struct cris_io_operations *cris_iops;
  16. #else
  17. #define cris_iops ((struct cris_io_operations*)NULL)
  18. #endif
  19. /*
  20. * Change virtual addresses to physical addresses and vv.
  21. */
  22. static inline unsigned long virt_to_phys(volatile void * address)
  23. {
  24. return __pa(address);
  25. }
  26. static inline void * phys_to_virt(unsigned long address)
  27. {
  28. return __va(address);
  29. }
  30. extern void __iomem * __ioremap(unsigned long offset, unsigned long size, unsigned long flags);
  31. extern void __iomem * __ioremap_prot(unsigned long phys_addr, unsigned long size, pgprot_t prot);
  32. static inline void __iomem * ioremap (unsigned long offset, unsigned long size)
  33. {
  34. return __ioremap(offset, size, 0);
  35. }
  36. extern void iounmap(volatile void * __iomem addr);
  37. extern void __iomem * ioremap_nocache(unsigned long offset, unsigned long size);
  38. /*
  39. * IO bus memory addresses are also 1:1 with the physical address
  40. */
  41. #define virt_to_bus virt_to_phys
  42. #define bus_to_virt phys_to_virt
  43. /*
  44. * readX/writeX() are used to access memory mapped devices. On some
  45. * architectures the memory mapped IO stuff needs to be accessed
  46. * differently. On the CRIS architecture, we just read/write the
  47. * memory location directly.
  48. */
  49. #ifdef CONFIG_PCI
  50. #define PCI_SPACE(x) ((((unsigned)(x)) & 0x10000000) == 0x10000000)
  51. #else
  52. #define PCI_SPACE(x) 0
  53. #endif
  54. static inline unsigned char readb(const volatile void __iomem *addr)
  55. {
  56. if (PCI_SPACE(addr) && cris_iops)
  57. return cris_iops->read_mem((void*)addr, 1);
  58. else
  59. return *(volatile unsigned char __force *) addr;
  60. }
  61. static inline unsigned short readw(const volatile void __iomem *addr)
  62. {
  63. if (PCI_SPACE(addr) && cris_iops)
  64. return cris_iops->read_mem((void*)addr, 2);
  65. else
  66. return *(volatile unsigned short __force *) addr;
  67. }
  68. static inline unsigned int readl(const volatile void __iomem *addr)
  69. {
  70. if (PCI_SPACE(addr) && cris_iops)
  71. return cris_iops->read_mem((void*)addr, 4);
  72. else
  73. return *(volatile unsigned int __force *) addr;
  74. }
  75. #define readb_relaxed(addr) readb(addr)
  76. #define readw_relaxed(addr) readw(addr)
  77. #define readl_relaxed(addr) readl(addr)
  78. #define __raw_readb readb
  79. #define __raw_readw readw
  80. #define __raw_readl readl
  81. static inline void writeb(unsigned char b, volatile void __iomem *addr)
  82. {
  83. if (PCI_SPACE(addr) && cris_iops)
  84. cris_iops->write_mem(b, 1, (void*)addr);
  85. else
  86. *(volatile unsigned char __force *) addr = b;
  87. }
  88. static inline void writew(unsigned short b, volatile void __iomem *addr)
  89. {
  90. if (PCI_SPACE(addr) && cris_iops)
  91. cris_iops->write_mem(b, 2, (void*)addr);
  92. else
  93. *(volatile unsigned short __force *) addr = b;
  94. }
  95. static inline void writel(unsigned int b, volatile void __iomem *addr)
  96. {
  97. if (PCI_SPACE(addr) && cris_iops)
  98. cris_iops->write_mem(b, 4, (void*)addr);
  99. else
  100. *(volatile unsigned int __force *) addr = b;
  101. }
  102. #define writeb_relaxed(b, addr) writeb(b, addr)
  103. #define writew_relaxed(b, addr) writew(b, addr)
  104. #define writel_relaxed(b, addr) writel(b, addr)
  105. #define __raw_writeb writeb
  106. #define __raw_writew writew
  107. #define __raw_writel writel
  108. #define mmiowb()
  109. #define memset_io(a,b,c) memset((void *)(a),(b),(c))
  110. #define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c))
  111. #define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c))
  112. /* I/O port access. Normally there is no I/O space on CRIS but when
  113. * Cardbus/PCI is enabled the request is passed through the bridge.
  114. */
  115. #define IO_SPACE_LIMIT 0xffff
  116. #define inb(port) (cris_iops ? cris_iops->read_io(port,NULL,1,1) : 0)
  117. #define inw(port) (cris_iops ? cris_iops->read_io(port,NULL,2,1) : 0)
  118. #define inl(port) (cris_iops ? cris_iops->read_io(port,NULL,4,1) : 0)
  119. #define insb(port,addr,count) (cris_iops ? cris_iops->read_io(port,addr,1,count) : 0)
  120. #define insw(port,addr,count) (cris_iops ? cris_iops->read_io(port,addr,2,count) : 0)
  121. #define insl(port,addr,count) (cris_iops ? cris_iops->read_io(port,addr,4,count) : 0)
  122. static inline void outb(unsigned char data, unsigned int port)
  123. {
  124. if (cris_iops)
  125. cris_iops->write_io(port, (void *) &data, 1, 1);
  126. }
  127. static inline void outw(unsigned short data, unsigned int port)
  128. {
  129. if (cris_iops)
  130. cris_iops->write_io(port, (void *) &data, 2, 1);
  131. }
  132. static inline void outl(unsigned int data, unsigned int port)
  133. {
  134. if (cris_iops)
  135. cris_iops->write_io(port, (void *) &data, 4, 1);
  136. }
  137. static inline void outsb(unsigned int port, const void *addr,
  138. unsigned long count)
  139. {
  140. if (cris_iops)
  141. cris_iops->write_io(port, (void *)addr, 1, count);
  142. }
  143. static inline void outsw(unsigned int port, const void *addr,
  144. unsigned long count)
  145. {
  146. if (cris_iops)
  147. cris_iops->write_io(port, (void *)addr, 2, count);
  148. }
  149. static inline void outsl(unsigned int port, const void *addr,
  150. unsigned long count)
  151. {
  152. if (cris_iops)
  153. cris_iops->write_io(port, (void *)addr, 4, count);
  154. }
  155. #define inb_p(port) inb(port)
  156. #define inw_p(port) inw(port)
  157. #define inl_p(port) inl(port)
  158. #define outb_p(val, port) outb((val), (port))
  159. #define outw_p(val, port) outw((val), (port))
  160. #define outl_p(val, port) outl((val), (port))
  161. /*
  162. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  163. * access
  164. */
  165. #define xlate_dev_mem_ptr(p) __va(p)
  166. /*
  167. * Convert a virtual cached pointer to an uncached pointer
  168. */
  169. #define xlate_dev_kmem_ptr(p) p
  170. #endif