io.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu>
  3. * Copyright (C) 2007-2009 PetaLogix
  4. * Copyright (C) 2006 Atmark Techno, Inc.
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #ifndef _ASM_MICROBLAZE_IO_H
  11. #define _ASM_MICROBLAZE_IO_H
  12. #include <asm/byteorder.h>
  13. #include <asm/page.h>
  14. #include <linux/types.h>
  15. #include <linux/mm.h> /* Get struct page {...} */
  16. #include <asm-generic/iomap.h>
  17. #ifndef CONFIG_PCI
  18. #define _IO_BASE 0
  19. #define _ISA_MEM_BASE 0
  20. #define PCI_DRAM_OFFSET 0
  21. #else
  22. #define _IO_BASE isa_io_base
  23. #define _ISA_MEM_BASE isa_mem_base
  24. #define PCI_DRAM_OFFSET pci_dram_offset
  25. #endif
  26. extern unsigned long isa_io_base;
  27. extern unsigned long pci_io_base;
  28. extern unsigned long pci_dram_offset;
  29. extern resource_size_t isa_mem_base;
  30. #define IO_SPACE_LIMIT (0xFFFFFFFF)
  31. static inline unsigned char __raw_readb(const volatile void __iomem *addr)
  32. {
  33. return *(volatile unsigned char __force *)addr;
  34. }
  35. static inline unsigned short __raw_readw(const volatile void __iomem *addr)
  36. {
  37. return *(volatile unsigned short __force *)addr;
  38. }
  39. static inline unsigned int __raw_readl(const volatile void __iomem *addr)
  40. {
  41. return *(volatile unsigned int __force *)addr;
  42. }
  43. static inline unsigned long __raw_readq(const volatile void __iomem *addr)
  44. {
  45. return *(volatile unsigned long __force *)addr;
  46. }
  47. static inline void __raw_writeb(unsigned char v, volatile void __iomem *addr)
  48. {
  49. *(volatile unsigned char __force *)addr = v;
  50. }
  51. static inline void __raw_writew(unsigned short v, volatile void __iomem *addr)
  52. {
  53. *(volatile unsigned short __force *)addr = v;
  54. }
  55. static inline void __raw_writel(unsigned int v, volatile void __iomem *addr)
  56. {
  57. *(volatile unsigned int __force *)addr = v;
  58. }
  59. static inline void __raw_writeq(unsigned long v, volatile void __iomem *addr)
  60. {
  61. *(volatile unsigned long __force *)addr = v;
  62. }
  63. /*
  64. * read (readb, readw, readl, readq) and write (writeb, writew,
  65. * writel, writeq) accessors are for PCI and thus littel endian.
  66. * Linux 2.4 for Microblaze had this wrong.
  67. */
  68. static inline unsigned char readb(const volatile void __iomem *addr)
  69. {
  70. return *(volatile unsigned char __force *)addr;
  71. }
  72. static inline unsigned short readw(const volatile void __iomem *addr)
  73. {
  74. return le16_to_cpu(*(volatile unsigned short __force *)addr);
  75. }
  76. static inline unsigned int readl(const volatile void __iomem *addr)
  77. {
  78. return le32_to_cpu(*(volatile unsigned int __force *)addr);
  79. }
  80. static inline void writeb(unsigned char v, volatile void __iomem *addr)
  81. {
  82. *(volatile unsigned char __force *)addr = v;
  83. }
  84. static inline void writew(unsigned short v, volatile void __iomem *addr)
  85. {
  86. *(volatile unsigned short __force *)addr = cpu_to_le16(v);
  87. }
  88. static inline void writel(unsigned int v, volatile void __iomem *addr)
  89. {
  90. *(volatile unsigned int __force *)addr = cpu_to_le32(v);
  91. }
  92. /* ioread and iowrite variants. thease are for now same as __raw_
  93. * variants of accessors. we might check for endianess in the feature
  94. */
  95. #define ioread8(addr) __raw_readb((u8 *)(addr))
  96. #define ioread16(addr) __raw_readw((u16 *)(addr))
  97. #define ioread32(addr) __raw_readl((u32 *)(addr))
  98. #define iowrite8(v, addr) __raw_writeb((u8)(v), (u8 *)(addr))
  99. #define iowrite16(v, addr) __raw_writew((u16)(v), (u16 *)(addr))
  100. #define iowrite32(v, addr) __raw_writel((u32)(v), (u32 *)(addr))
  101. #define ioread16be(addr) __raw_readw((u16 *)(addr))
  102. #define ioread32be(addr) __raw_readl((u32 *)(addr))
  103. #define iowrite16be(v, addr) __raw_writew((u16)(v), (u16 *)(addr))
  104. #define iowrite32be(v, addr) __raw_writel((u32)(v), (u32 *)(addr))
  105. /* These are the definitions for the x86 IO instructions
  106. * inb/inw/inl/outb/outw/outl, the "string" versions
  107. * insb/insw/insl/outsb/outsw/outsl, and the "pausing" versions
  108. * inb_p/inw_p/...
  109. * The macros don't do byte-swapping.
  110. */
  111. #define inb(port) readb((u8 *)((port)))
  112. #define outb(val, port) writeb((val), (u8 *)((unsigned long)(port)))
  113. #define inw(port) readw((u16 *)((port)))
  114. #define outw(val, port) writew((val), (u16 *)((unsigned long)(port)))
  115. #define inl(port) readl((u32 *)((port)))
  116. #define outl(val, port) writel((val), (u32 *)((unsigned long)(port)))
  117. #define inb_p(port) inb((port))
  118. #define outb_p(val, port) outb((val), (port))
  119. #define inw_p(port) inw((port))
  120. #define outw_p(val, port) outw((val), (port))
  121. #define inl_p(port) inl((port))
  122. #define outl_p(val, port) outl((val), (port))
  123. #define memset_io(a, b, c) memset((void *)(a), (b), (c))
  124. #define memcpy_fromio(a, b, c) memcpy((a), (void *)(b), (c))
  125. #define memcpy_toio(a, b, c) memcpy((void *)(a), (b), (c))
  126. #ifdef CONFIG_MMU
  127. #define phys_to_virt(addr) ((void *)__phys_to_virt(addr))
  128. #define virt_to_phys(addr) ((unsigned long)__virt_to_phys(addr))
  129. #define virt_to_bus(addr) ((unsigned long)__virt_to_phys(addr))
  130. #define page_to_bus(page) (page_to_phys(page))
  131. #define bus_to_virt(addr) (phys_to_virt(addr))
  132. extern void iounmap(void *addr);
  133. /*extern void *__ioremap(phys_addr_t address, unsigned long size,
  134. unsigned long flags);*/
  135. extern void __iomem *ioremap(phys_addr_t address, unsigned long size);
  136. #define ioremap_writethrough(addr, size) ioremap((addr), (size))
  137. #define ioremap_nocache(addr, size) ioremap((addr), (size))
  138. #define ioremap_fullcache(addr, size) ioremap((addr), (size))
  139. #else /* CONFIG_MMU */
  140. /**
  141. * virt_to_phys - map virtual addresses to physical
  142. * @address: address to remap
  143. *
  144. * The returned physical address is the physical (CPU) mapping for
  145. * the memory address given. It is only valid to use this function on
  146. * addresses directly mapped or allocated via kmalloc.
  147. *
  148. * This function does not give bus mappings for DMA transfers. In
  149. * almost all conceivable cases a device driver should not be using
  150. * this function
  151. */
  152. static inline unsigned long __iomem virt_to_phys(volatile void *address)
  153. {
  154. return __pa((unsigned long)address);
  155. }
  156. #define virt_to_bus virt_to_phys
  157. /**
  158. * phys_to_virt - map physical address to virtual
  159. * @address: address to remap
  160. *
  161. * The returned virtual address is a current CPU mapping for
  162. * the memory address given. It is only valid to use this function on
  163. * addresses that have a kernel mapping
  164. *
  165. * This function does not handle bus mappings for DMA transfers. In
  166. * almost all conceivable cases a device driver should not be using
  167. * this function
  168. */
  169. static inline void *phys_to_virt(unsigned long address)
  170. {
  171. return (void *)__va(address);
  172. }
  173. #define bus_to_virt(a) phys_to_virt(a)
  174. static inline void __iomem *__ioremap(phys_addr_t address, unsigned long size,
  175. unsigned long flags)
  176. {
  177. return (void *)address;
  178. }
  179. #define ioremap(physaddr, size) ((void __iomem *)(unsigned long)(physaddr))
  180. #define iounmap(addr) ((void)0)
  181. #define ioremap_nocache(physaddr, size) ioremap(physaddr, size)
  182. #endif /* CONFIG_MMU */
  183. /*
  184. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  185. * access
  186. */
  187. #define xlate_dev_mem_ptr(p) __va(p)
  188. /*
  189. * Convert a virtual cached pointer to an uncached pointer
  190. */
  191. #define xlate_dev_kmem_ptr(p) p
  192. /*
  193. * Big Endian
  194. */
  195. #define out_be32(a, v) __raw_writel((v), (void __iomem __force *)(a))
  196. #define out_be16(a, v) __raw_writew((v), (a))
  197. #define in_be32(a) __raw_readl((const void __iomem __force *)(a))
  198. #define in_be16(a) __raw_readw(a)
  199. #define writel_be(v, a) out_be32((__force unsigned *)a, v)
  200. #define readl_be(a) in_be32((__force unsigned *)a)
  201. /*
  202. * Little endian
  203. */
  204. #define out_le32(a, v) __raw_writel(__cpu_to_le32(v), (a))
  205. #define out_le16(a, v) __raw_writew(__cpu_to_le16(v), (a))
  206. #define in_le32(a) __le32_to_cpu(__raw_readl(a))
  207. #define in_le16(a) __le16_to_cpu(__raw_readw(a))
  208. /* Byte ops */
  209. #define out_8(a, v) __raw_writeb((v), (a))
  210. #define in_8(a) __raw_readb(a)
  211. #define mmiowb()
  212. #define ioport_map(port, nr) ((void __iomem *)(port))
  213. #define ioport_unmap(addr)
  214. #endif /* _ASM_MICROBLAZE_IO_H */