Merge branch 'core/urgent'
[linux-2.6/x86.git] / arch / microblaze / include / asm / io.h
blob8cdac14b55b071b4b6889bed5be83bc58d406266
1 /*
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
8 * for more details.
9 */
11 #ifndef _ASM_MICROBLAZE_IO_H
12 #define _ASM_MICROBLAZE_IO_H
14 #include <asm/byteorder.h>
15 #include <asm/page.h>
16 #include <linux/types.h>
17 #include <linux/mm.h> /* Get struct page {...} */
18 #include <asm-generic/iomap.h>
20 #ifndef CONFIG_PCI
21 #define _IO_BASE 0
22 #define _ISA_MEM_BASE 0
23 #define PCI_DRAM_OFFSET 0
24 #else
25 #define _IO_BASE isa_io_base
26 #define _ISA_MEM_BASE isa_mem_base
27 #define PCI_DRAM_OFFSET pci_dram_offset
28 #endif
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 static inline unsigned char __raw_readb(const volatile void __iomem *addr)
40 return *(volatile unsigned char __force *)addr;
42 static inline unsigned short __raw_readw(const volatile void __iomem *addr)
44 return *(volatile unsigned short __force *)addr;
46 static inline unsigned int __raw_readl(const volatile void __iomem *addr)
48 return *(volatile unsigned int __force *)addr;
50 static inline unsigned long __raw_readq(const volatile void __iomem *addr)
52 return *(volatile unsigned long __force *)addr;
54 static inline void __raw_writeb(unsigned char v, volatile void __iomem *addr)
56 *(volatile unsigned char __force *)addr = v;
58 static inline void __raw_writew(unsigned short v, volatile void __iomem *addr)
60 *(volatile unsigned short __force *)addr = v;
62 static inline void __raw_writel(unsigned int v, volatile void __iomem *addr)
64 *(volatile unsigned int __force *)addr = v;
66 static inline void __raw_writeq(unsigned long v, volatile void __iomem *addr)
68 *(volatile unsigned long __force *)addr = v;
72 * read (readb, readw, readl, readq) and write (writeb, writew,
73 * writel, writeq) accessors are for PCI and thus little endian.
74 * Linux 2.4 for Microblaze had this wrong.
76 static inline unsigned char readb(const volatile void __iomem *addr)
78 return *(volatile unsigned char __force *)addr;
80 static inline unsigned short readw(const volatile void __iomem *addr)
82 return le16_to_cpu(*(volatile unsigned short __force *)addr);
84 static inline unsigned int readl(const volatile void __iomem *addr)
86 return le32_to_cpu(*(volatile unsigned int __force *)addr);
88 static inline void writeb(unsigned char v, volatile void __iomem *addr)
90 *(volatile unsigned char __force *)addr = v;
92 static inline void writew(unsigned short v, volatile void __iomem *addr)
94 *(volatile unsigned short __force *)addr = cpu_to_le16(v);
96 static inline void writel(unsigned int v, volatile void __iomem *addr)
98 *(volatile unsigned int __force *)addr = cpu_to_le32(v);
101 /* ioread and iowrite variants. thease are for now same as __raw_
102 * variants of accessors. we might check for endianess in the feature
104 #define ioread8(addr) __raw_readb((u8 *)(addr))
105 #define ioread16(addr) __raw_readw((u16 *)(addr))
106 #define ioread32(addr) __raw_readl((u32 *)(addr))
107 #define iowrite8(v, addr) __raw_writeb((u8)(v), (u8 *)(addr))
108 #define iowrite16(v, addr) __raw_writew((u16)(v), (u16 *)(addr))
109 #define iowrite32(v, addr) __raw_writel((u32)(v), (u32 *)(addr))
111 #define ioread16be(addr) __raw_readw((u16 *)(addr))
112 #define ioread32be(addr) __raw_readl((u32 *)(addr))
113 #define iowrite16be(v, addr) __raw_writew((u16)(v), (u16 *)(addr))
114 #define iowrite32be(v, addr) __raw_writel((u32)(v), (u32 *)(addr))
116 /* These are the definitions for the x86 IO instructions
117 * inb/inw/inl/outb/outw/outl, the "string" versions
118 * insb/insw/insl/outsb/outsw/outsl, and the "pausing" versions
119 * inb_p/inw_p/...
120 * The macros don't do byte-swapping.
122 #define inb(port) readb((u8 *)((port)))
123 #define outb(val, port) writeb((val), (u8 *)((unsigned long)(port)))
124 #define inw(port) readw((u16 *)((port)))
125 #define outw(val, port) writew((val), (u16 *)((unsigned long)(port)))
126 #define inl(port) readl((u32 *)((port)))
127 #define outl(val, port) writel((val), (u32 *)((unsigned long)(port)))
129 #define inb_p(port) inb((port))
130 #define outb_p(val, port) outb((val), (port))
131 #define inw_p(port) inw((port))
132 #define outw_p(val, port) outw((val), (port))
133 #define inl_p(port) inl((port))
134 #define outl_p(val, port) outl((val), (port))
136 #define memset_io(a, b, c) memset((void *)(a), (b), (c))
137 #define memcpy_fromio(a, b, c) memcpy((a), (void *)(b), (c))
138 #define memcpy_toio(a, b, c) memcpy((void *)(a), (b), (c))
140 #ifdef CONFIG_MMU
142 #define phys_to_virt(addr) ((void *)__phys_to_virt(addr))
143 #define virt_to_phys(addr) ((unsigned long)__virt_to_phys(addr))
144 #define virt_to_bus(addr) ((unsigned long)__virt_to_phys(addr))
146 #define page_to_bus(page) (page_to_phys(page))
147 #define bus_to_virt(addr) (phys_to_virt(addr))
149 extern void iounmap(void *addr);
150 /*extern void *__ioremap(phys_addr_t address, unsigned long size,
151 unsigned long flags);*/
152 extern void __iomem *ioremap(phys_addr_t address, unsigned long size);
153 #define ioremap_writethrough(addr, size) ioremap((addr), (size))
154 #define ioremap_nocache(addr, size) ioremap((addr), (size))
155 #define ioremap_fullcache(addr, size) ioremap((addr), (size))
157 #else /* CONFIG_MMU */
160 * virt_to_phys - map virtual addresses to physical
161 * @address: address to remap
163 * The returned physical address is the physical (CPU) mapping for
164 * the memory address given. It is only valid to use this function on
165 * addresses directly mapped or allocated via kmalloc.
167 * This function does not give bus mappings for DMA transfers. In
168 * almost all conceivable cases a device driver should not be using
169 * this function
171 static inline unsigned long __iomem virt_to_phys(volatile void *address)
173 return __pa((unsigned long)address);
176 #define virt_to_bus virt_to_phys
179 * phys_to_virt - map physical address to virtual
180 * @address: address to remap
182 * The returned virtual address is a current CPU mapping for
183 * the memory address given. It is only valid to use this function on
184 * addresses that have a kernel mapping
186 * This function does not handle bus mappings for DMA transfers. In
187 * almost all conceivable cases a device driver should not be using
188 * this function
190 static inline void *phys_to_virt(unsigned long address)
192 return (void *)__va(address);
195 #define bus_to_virt(a) phys_to_virt(a)
197 static inline void __iomem *__ioremap(phys_addr_t address, unsigned long size,
198 unsigned long flags)
200 return (void *)address;
203 #define ioremap(physaddr, size) ((void __iomem *)(unsigned long)(physaddr))
204 #define iounmap(addr) ((void)0)
205 #define ioremap_nocache(physaddr, size) ioremap(physaddr, size)
207 #endif /* CONFIG_MMU */
210 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
211 * access
213 #define xlate_dev_mem_ptr(p) __va(p)
216 * Convert a virtual cached pointer to an uncached pointer
218 #define xlate_dev_kmem_ptr(p) p
221 * Big Endian
223 #define out_be32(a, v) __raw_writel((v), (void __iomem __force *)(a))
224 #define out_be16(a, v) __raw_writew((v), (a))
226 #define in_be32(a) __raw_readl((const void __iomem __force *)(a))
227 #define in_be16(a) __raw_readw(a)
229 #define writel_be(v, a) out_be32((__force unsigned *)a, v)
230 #define readl_be(a) in_be32((__force unsigned *)a)
233 * Little endian
236 #define out_le32(a, v) __raw_writel(__cpu_to_le32(v), (a))
237 #define out_le16(a, v) __raw_writew(__cpu_to_le16(v), (a))
239 #define in_le32(a) __le32_to_cpu(__raw_readl(a))
240 #define in_le16(a) __le16_to_cpu(__raw_readw(a))
242 /* Byte ops */
243 #define out_8(a, v) __raw_writeb((v), (a))
244 #define in_8(a) __raw_readb(a)
246 #define mmiowb()
248 #define ioport_map(port, nr) ((void __iomem *)(port))
249 #define ioport_unmap(addr)
251 #endif /* _ASM_MICROBLAZE_IO_H */