io.h 4.7 KB

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