2 * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu>
3 * Copyright (C) 2007-2009 PetaLogix
4 * Copyright (C) 2006 Atmark Techno, Inc.
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
11 #ifndef _ASM_MICROBLAZE_IO_H
12 #define _ASM_MICROBLAZE_IO_H
14 #include <asm/byteorder.h>
16 #include <linux/types.h>
17 #include <linux/mm.h> /* Get struct page {...} */
18 #include <asm-generic/iomap.h>
22 #define _ISA_MEM_BASE 0
23 #define PCI_DRAM_OFFSET 0
25 #define _IO_BASE isa_io_base
26 #define _ISA_MEM_BASE isa_mem_base
27 #define PCI_DRAM_OFFSET pci_dram_offset
30 extern unsigned long isa_io_base
;
31 extern unsigned long pci_io_base
;
32 extern unsigned long pci_dram_offset
;
34 extern resource_size_t isa_mem_base
;
36 #define IO_SPACE_LIMIT (0xFFFFFFFF)
38 /* the following is needed to support PCI with some drivers */
42 static inline unsigned char __raw_readb(const volatile void __iomem
*addr
)
44 return *(volatile unsigned char __force
*)addr
;
46 static inline unsigned short __raw_readw(const volatile void __iomem
*addr
)
48 return *(volatile unsigned short __force
*)addr
;
50 static inline unsigned int __raw_readl(const volatile void __iomem
*addr
)
52 return *(volatile unsigned int __force
*)addr
;
54 static inline unsigned long __raw_readq(const volatile void __iomem
*addr
)
56 return *(volatile unsigned long __force
*)addr
;
58 static inline void __raw_writeb(unsigned char v
, volatile void __iomem
*addr
)
60 *(volatile unsigned char __force
*)addr
= v
;
62 static inline void __raw_writew(unsigned short v
, volatile void __iomem
*addr
)
64 *(volatile unsigned short __force
*)addr
= v
;
66 static inline void __raw_writel(unsigned int v
, volatile void __iomem
*addr
)
68 *(volatile unsigned int __force
*)addr
= v
;
70 static inline void __raw_writeq(unsigned long v
, volatile void __iomem
*addr
)
72 *(volatile unsigned long __force
*)addr
= v
;
76 * read (readb, readw, readl, readq) and write (writeb, writew,
77 * writel, writeq) accessors are for PCI and thus little endian.
78 * Linux 2.4 for Microblaze had this wrong.
80 static inline unsigned char readb(const volatile void __iomem
*addr
)
82 return *(volatile unsigned char __force
*)addr
;
84 static inline unsigned short readw(const volatile void __iomem
*addr
)
86 return le16_to_cpu(*(volatile unsigned short __force
*)addr
);
88 static inline unsigned int readl(const volatile void __iomem
*addr
)
90 return le32_to_cpu(*(volatile unsigned int __force
*)addr
);
92 static inline void writeb(unsigned char v
, volatile void __iomem
*addr
)
94 *(volatile unsigned char __force
*)addr
= v
;
96 static inline void writew(unsigned short v
, volatile void __iomem
*addr
)
98 *(volatile unsigned short __force
*)addr
= cpu_to_le16(v
);
100 static inline void writel(unsigned int v
, volatile void __iomem
*addr
)
102 *(volatile unsigned int __force
*)addr
= cpu_to_le32(v
);
105 /* ioread and iowrite variants. thease are for now same as __raw_
106 * variants of accessors. we might check for endianess in the feature
108 #define ioread8(addr) __raw_readb((u8 *)(addr))
109 #define ioread16(addr) __raw_readw((u16 *)(addr))
110 #define ioread32(addr) __raw_readl((u32 *)(addr))
111 #define iowrite8(v, addr) __raw_writeb((u8)(v), (u8 *)(addr))
112 #define iowrite16(v, addr) __raw_writew((u16)(v), (u16 *)(addr))
113 #define iowrite32(v, addr) __raw_writel((u32)(v), (u32 *)(addr))
115 #define ioread16be(addr) __raw_readw((u16 *)(addr))
116 #define ioread32be(addr) __raw_readl((u32 *)(addr))
117 #define iowrite16be(v, addr) __raw_writew((u16)(v), (u16 *)(addr))
118 #define iowrite32be(v, addr) __raw_writel((u32)(v), (u32 *)(addr))
120 /* These are the definitions for the x86 IO instructions
121 * inb/inw/inl/outb/outw/outl, the "string" versions
122 * insb/insw/insl/outsb/outsw/outsl, and the "pausing" versions
124 * The macros don't do byte-swapping.
126 #define inb(port) readb((u8 *)((unsigned long)(port)))
127 #define outb(val, port) writeb((val), (u8 *)((unsigned long)(port)))
128 #define inw(port) readw((u16 *)((unsigned long)(port)))
129 #define outw(val, port) writew((val), (u16 *)((unsigned long)(port)))
130 #define inl(port) readl((u32 *)((unsigned long)(port)))
131 #define outl(val, port) writel((val), (u32 *)((unsigned long)(port)))
133 #define inb_p(port) inb((port))
134 #define outb_p(val, port) outb((val), (port))
135 #define inw_p(port) inw((port))
136 #define outw_p(val, port) outw((val), (port))
137 #define inl_p(port) inl((port))
138 #define outl_p(val, port) outl((val), (port))
140 #define memset_io(a, b, c) memset((void *)(a), (b), (c))
141 #define memcpy_fromio(a, b, c) memcpy((a), (void *)(b), (c))
142 #define memcpy_toio(a, b, c) memcpy((void *)(a), (b), (c))
146 #define phys_to_virt(addr) ((void *)__phys_to_virt(addr))
147 #define virt_to_phys(addr) ((unsigned long)__virt_to_phys(addr))
148 #define virt_to_bus(addr) ((unsigned long)__virt_to_phys(addr))
150 #define page_to_bus(page) (page_to_phys(page))
151 #define bus_to_virt(addr) (phys_to_virt(addr))
153 extern void iounmap(void __iomem
*addr
);
154 /*extern void *__ioremap(phys_addr_t address, unsigned long size,
155 unsigned long flags);*/
156 extern void __iomem
*ioremap(phys_addr_t address
, unsigned long size
);
157 #define ioremap_writethrough(addr, size) ioremap((addr), (size))
158 #define ioremap_nocache(addr, size) ioremap((addr), (size))
159 #define ioremap_fullcache(addr, size) ioremap((addr), (size))
161 #else /* CONFIG_MMU */
164 * virt_to_phys - map virtual addresses to physical
165 * @address: address to remap
167 * The returned physical address is the physical (CPU) mapping for
168 * the memory address given. It is only valid to use this function on
169 * addresses directly mapped or allocated via kmalloc.
171 * This function does not give bus mappings for DMA transfers. In
172 * almost all conceivable cases a device driver should not be using
175 static inline unsigned long __iomem
virt_to_phys(volatile void *address
)
177 return __pa((unsigned long)address
);
180 #define virt_to_bus virt_to_phys
183 * phys_to_virt - map physical address to virtual
184 * @address: address to remap
186 * The returned virtual address is a current CPU mapping for
187 * the memory address given. It is only valid to use this function on
188 * addresses that have a kernel mapping
190 * This function does not handle bus mappings for DMA transfers. In
191 * almost all conceivable cases a device driver should not be using
194 static inline void *phys_to_virt(unsigned long address
)
196 return (void *)__va(address
);
199 #define bus_to_virt(a) phys_to_virt(a)
201 static inline void __iomem
*__ioremap(phys_addr_t address
, unsigned long size
,
204 return (void *)address
;
207 #define ioremap(physaddr, size) ((void __iomem *)(unsigned long)(physaddr))
208 #define iounmap(addr) ((void)0)
209 #define ioremap_nocache(physaddr, size) ioremap(physaddr, size)
211 #endif /* CONFIG_MMU */
214 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
217 #define xlate_dev_mem_ptr(p) __va(p)
220 * Convert a virtual cached pointer to an uncached pointer
222 #define xlate_dev_kmem_ptr(p) p
227 #define out_be32(a, v) __raw_writel((v), (void __iomem __force *)(a))
228 #define out_be16(a, v) __raw_writew((v), (a))
230 #define in_be32(a) __raw_readl((const void __iomem __force *)(a))
231 #define in_be16(a) __raw_readw(a)
233 #define writel_be(v, a) out_be32((__force unsigned *)a, v)
234 #define readl_be(a) in_be32((__force unsigned *)a)
240 #define out_le32(a, v) __raw_writel(__cpu_to_le32(v), (a))
241 #define out_le16(a, v) __raw_writew(__cpu_to_le16(v), (a))
243 #define in_le32(a) __le32_to_cpu(__raw_readl(a))
244 #define in_le16(a) __le16_to_cpu(__raw_readw(a))
247 #define out_8(a, v) __raw_writeb((v), (a))
248 #define in_8(a) __raw_readb(a)
252 #define ioport_map(port, nr) ((void __iomem *)(port))
253 #define ioport_unmap(addr)
255 /* from asm-generic/io.h */
257 static inline void insb(unsigned long addr
, void *buffer
, int count
)
270 static inline void insw(unsigned long addr
, void *buffer
, int count
)
283 static inline void insl(unsigned long addr
, void *buffer
, int count
)
296 static inline void outsb(unsigned long addr
, const void *buffer
, int count
)
299 const u8
*buf
= buffer
;
308 static inline void outsw(unsigned long addr
, const void *buffer
, int count
)
311 const u16
*buf
= buffer
;
320 static inline void outsl(unsigned long addr
, const void *buffer
, int count
)
323 const u32
*buf
= buffer
;
331 #define ioread8_rep(p, dst, count) \
332 insb((unsigned long) (p), (dst), (count))
333 #define ioread16_rep(p, dst, count) \
334 insw((unsigned long) (p), (dst), (count))
335 #define ioread32_rep(p, dst, count) \
336 insl((unsigned long) (p), (dst), (count))
338 #define iowrite8_rep(p, src, count) \
339 outsb((unsigned long) (p), (src), (count))
340 #define iowrite16_rep(p, src, count) \
341 outsw((unsigned long) (p), (src), (count))
342 #define iowrite32_rep(p, src, count) \
343 outsl((unsigned long) (p), (src), (count))
345 #endif /* _ASM_MICROBLAZE_IO_H */