io.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 __raw_writeb writeb
  103. #define __raw_writew writew
  104. #define __raw_writel writel
  105. #define mmiowb()
  106. #define memset_io(a,b,c) memset((void *)(a),(b),(c))
  107. #define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c))
  108. #define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c))
  109. /* I/O port access. Normally there is no I/O space on CRIS but when
  110. * Cardbus/PCI is enabled the request is passed through the bridge.
  111. */
  112. #define IO_SPACE_LIMIT 0xffff
  113. #define inb(port) (cris_iops ? cris_iops->read_io(port,NULL,1,1) : 0)
  114. #define inw(port) (cris_iops ? cris_iops->read_io(port,NULL,2,1) : 0)
  115. #define inl(port) (cris_iops ? cris_iops->read_io(port,NULL,4,1) : 0)
  116. #define insb(port,addr,count) (cris_iops ? cris_iops->read_io(port,addr,1,count) : 0)
  117. #define insw(port,addr,count) (cris_iops ? cris_iops->read_io(port,addr,2,count) : 0)
  118. #define insl(port,addr,count) (cris_iops ? cris_iops->read_io(port,addr,4,count) : 0)
  119. static inline void outb(unsigned char data, unsigned int port)
  120. {
  121. if (cris_iops)
  122. cris_iops->write_io(port, (void *) &data, 1, 1);
  123. }
  124. static inline void outw(unsigned short data, unsigned int port)
  125. {
  126. if (cris_iops)
  127. cris_iops->write_io(port, (void *) &data, 2, 1);
  128. }
  129. static inline void outl(unsigned int data, unsigned int port)
  130. {
  131. if (cris_iops)
  132. cris_iops->write_io(port, (void *) &data, 4, 1);
  133. }
  134. static inline void outsb(unsigned int port, const void *addr,
  135. unsigned long count)
  136. {
  137. if (cris_iops)
  138. cris_iops->write_io(port, (void *)addr, 1, count);
  139. }
  140. static inline void outsw(unsigned int port, const void *addr,
  141. unsigned long count)
  142. {
  143. if (cris_iops)
  144. cris_iops->write_io(port, (void *)addr, 2, count);
  145. }
  146. static inline void outsl(unsigned int port, const void *addr,
  147. unsigned long count)
  148. {
  149. if (cris_iops)
  150. cris_iops->write_io(port, (void *)addr, 4, count);
  151. }
  152. /*
  153. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  154. * 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