io.h 7.8 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 mm_ptov(addr) ((void *)__phys_to_virt(addr))
  128. #define mm_vtop(addr) ((unsigned long)__virt_to_phys(addr))
  129. #define phys_to_virt(addr) ((void *)__phys_to_virt(addr))
  130. #define virt_to_phys(addr) ((unsigned long)__virt_to_phys(addr))
  131. #define virt_to_bus(addr) ((unsigned long)__virt_to_phys(addr))
  132. #define page_to_bus(page) (page_to_phys(page))
  133. #define bus_to_virt(addr) (phys_to_virt(addr))
  134. extern void iounmap(void *addr);
  135. /*extern void *__ioremap(phys_addr_t address, unsigned long size,
  136. unsigned long flags);*/
  137. extern void __iomem *ioremap(phys_addr_t address, unsigned long size);
  138. #define ioremap_writethrough(addr, size) ioremap((addr), (size))
  139. #define ioremap_nocache(addr, size) ioremap((addr), (size))
  140. #define ioremap_fullcache(addr, size) ioremap((addr), (size))
  141. #else /* CONFIG_MMU */
  142. /**
  143. * virt_to_phys - map virtual addresses to physical
  144. * @address: address to remap
  145. *
  146. * The returned physical address is the physical (CPU) mapping for
  147. * the memory address given. It is only valid to use this function on
  148. * addresses directly mapped or allocated via kmalloc.
  149. *
  150. * This function does not give bus mappings for DMA transfers. In
  151. * almost all conceivable cases a device driver should not be using
  152. * this function
  153. */
  154. static inline unsigned long __iomem virt_to_phys(volatile void *address)
  155. {
  156. return __pa((unsigned long)address);
  157. }
  158. #define virt_to_bus virt_to_phys
  159. /**
  160. * phys_to_virt - map physical address to virtual
  161. * @address: address to remap
  162. *
  163. * The returned virtual address is a current CPU mapping for
  164. * the memory address given. It is only valid to use this function on
  165. * addresses that have a kernel mapping
  166. *
  167. * This function does not handle bus mappings for DMA transfers. In
  168. * almost all conceivable cases a device driver should not be using
  169. * this function
  170. */
  171. static inline void *phys_to_virt(unsigned long address)
  172. {
  173. return (void *)__va(address);
  174. }
  175. #define bus_to_virt(a) phys_to_virt(a)
  176. static inline void __iomem *__ioremap(phys_addr_t address, unsigned long size,
  177. unsigned long flags)
  178. {
  179. return (void *)address;
  180. }
  181. #define ioremap(physaddr, size) ((void __iomem *)(unsigned long)(physaddr))
  182. #define iounmap(addr) ((void)0)
  183. #define ioremap_nocache(physaddr, size) ioremap(physaddr, size)
  184. #endif /* CONFIG_MMU */
  185. /*
  186. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  187. * access
  188. */
  189. #define xlate_dev_mem_ptr(p) __va(p)
  190. /*
  191. * Convert a virtual cached pointer to an uncached pointer
  192. */
  193. #define xlate_dev_kmem_ptr(p) p
  194. /*
  195. * Big Endian
  196. */
  197. #define out_be32(a, v) __raw_writel((v), (void __iomem __force *)(a))
  198. #define out_be16(a, v) __raw_writew((v), (a))
  199. #define in_be32(a) __raw_readl((const void __iomem __force *)(a))
  200. #define in_be16(a) __raw_readw(a)
  201. #define writel_be(v, a) out_be32((__force unsigned *)a, v)
  202. #define readl_be(a) in_be32((__force unsigned *)a)
  203. /*
  204. * Little endian
  205. */
  206. #define out_le32(a, v) __raw_writel(__cpu_to_le32(v), (a))
  207. #define out_le16(a, v) __raw_writew(__cpu_to_le16(v), (a))
  208. #define in_le32(a) __le32_to_cpu(__raw_readl(a))
  209. #define in_le16(a) __le16_to_cpu(__raw_readw(a))
  210. /* Byte ops */
  211. #define out_8(a, v) __raw_writeb((v), (a))
  212. #define in_8(a) __raw_readb(a)
  213. #define ioport_map(port, nr) ((void __iomem *)(port))
  214. #define ioport_unmap(addr)
  215. #endif /* _ASM_MICROBLAZE_IO_H */