blob: 5c173424d0744bdd6cfdda945e57985adff9060c [file] [log] [blame]
Michal Simek2c572c22009-03-27 14:25:33 +01001/*
Michal Simekdc95be12009-05-26 16:30:16 +02002 * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu>
3 * Copyright (C) 2007-2009 PetaLogix
Michal Simek2c572c22009-03-27 14:25:33 +01004 * 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
11#ifndef _ASM_MICROBLAZE_IO_H
12#define _ASM_MICROBLAZE_IO_H
13
14#include <asm/byteorder.h>
15#include <asm/page.h>
16#include <linux/types.h>
Michal Simekdc95be12009-05-26 16:30:16 +020017#include <asm/byteorder.h>
18#include <linux/mm.h> /* Get struct page {...} */
19
Michal Simek2c572c22009-03-27 14:25:33 +010020
21#define IO_SPACE_LIMIT (0xFFFFFFFF)
22
23static inline unsigned char __raw_readb(const volatile void __iomem *addr)
24{
25 return *(volatile unsigned char __force *)addr;
26}
27static inline unsigned short __raw_readw(const volatile void __iomem *addr)
28{
29 return *(volatile unsigned short __force *)addr;
30}
31static inline unsigned int __raw_readl(const volatile void __iomem *addr)
32{
33 return *(volatile unsigned int __force *)addr;
34}
35static inline unsigned long __raw_readq(const volatile void __iomem *addr)
36{
37 return *(volatile unsigned long __force *)addr;
38}
39static inline void __raw_writeb(unsigned char v, volatile void __iomem *addr)
40{
41 *(volatile unsigned char __force *)addr = v;
42}
43static inline void __raw_writew(unsigned short v, volatile void __iomem *addr)
44{
45 *(volatile unsigned short __force *)addr = v;
46}
47static inline void __raw_writel(unsigned int v, volatile void __iomem *addr)
48{
49 *(volatile unsigned int __force *)addr = v;
50}
51static inline void __raw_writeq(unsigned long v, volatile void __iomem *addr)
52{
53 *(volatile unsigned long __force *)addr = v;
54}
55
56/*
57 * read (readb, readw, readl, readq) and write (writeb, writew,
58 * writel, writeq) accessors are for PCI and thus littel endian.
59 * Linux 2.4 for Microblaze had this wrong.
60 */
61static inline unsigned char readb(const volatile void __iomem *addr)
62{
63 return *(volatile unsigned char __force *)addr;
64}
65static inline unsigned short readw(const volatile void __iomem *addr)
66{
67 return le16_to_cpu(*(volatile unsigned short __force *)addr);
68}
69static inline unsigned int readl(const volatile void __iomem *addr)
70{
71 return le32_to_cpu(*(volatile unsigned int __force *)addr);
72}
73static inline void writeb(unsigned char v, volatile void __iomem *addr)
74{
75 *(volatile unsigned char __force *)addr = v;
76}
77static inline void writew(unsigned short v, volatile void __iomem *addr)
78{
79 *(volatile unsigned short __force *)addr = cpu_to_le16(v);
80}
81static inline void writel(unsigned int v, volatile void __iomem *addr)
82{
83 *(volatile unsigned int __force *)addr = cpu_to_le32(v);
84}
85
86/* ioread and iowrite variants. thease are for now same as __raw_
87 * variants of accessors. we might check for endianess in the feature
88 */
89#define ioread8(addr) __raw_readb((u8 *)(addr))
90#define ioread16(addr) __raw_readw((u16 *)(addr))
91#define ioread32(addr) __raw_readl((u32 *)(addr))
92#define iowrite8(v, addr) __raw_writeb((u8)(v), (u8 *)(addr))
93#define iowrite16(v, addr) __raw_writew((u16)(v), (u16 *)(addr))
94#define iowrite32(v, addr) __raw_writel((u32)(v), (u32 *)(addr))
95
96/* These are the definitions for the x86 IO instructions
97 * inb/inw/inl/outb/outw/outl, the "string" versions
98 * insb/insw/insl/outsb/outsw/outsl, and the "pausing" versions
99 * inb_p/inw_p/...
100 * The macros don't do byte-swapping.
101 */
102#define inb(port) readb((u8 *)((port)))
103#define outb(val, port) writeb((val), (u8 *)((unsigned long)(port)))
104#define inw(port) readw((u16 *)((port)))
105#define outw(val, port) writew((val), (u16 *)((unsigned long)(port)))
106#define inl(port) readl((u32 *)((port)))
107#define outl(val, port) writel((val), (u32 *)((unsigned long)(port)))
108
109#define inb_p(port) inb((port))
110#define outb_p(val, port) outb((val), (port))
111#define inw_p(port) inw((port))
112#define outw_p(val, port) outw((val), (port))
113#define inl_p(port) inl((port))
114#define outl_p(val, port) outl((val), (port))
115
116#define memset_io(a, b, c) memset((void *)(a), (b), (c))
117#define memcpy_fromio(a, b, c) memcpy((a), (void *)(b), (c))
118#define memcpy_toio(a, b, c) memcpy((void *)(a), (b), (c))
119
Michal Simekdc95be12009-05-26 16:30:16 +0200120#ifdef CONFIG_MMU
121
122#define mm_ptov(addr) ((void *)__phys_to_virt(addr))
123#define mm_vtop(addr) ((unsigned long)__virt_to_phys(addr))
124#define phys_to_virt(addr) ((void *)__phys_to_virt(addr))
125#define virt_to_phys(addr) ((unsigned long)__virt_to_phys(addr))
126#define virt_to_bus(addr) ((unsigned long)__virt_to_phys(addr))
127
128#define __page_address(page) \
129 (PAGE_OFFSET + (((page) - mem_map) << PAGE_SHIFT))
130#define page_to_phys(page) virt_to_phys((void *)__page_address(page))
131#define page_to_bus(page) (page_to_phys(page))
132#define bus_to_virt(addr) (phys_to_virt(addr))
133
134extern void iounmap(void *addr);
135/*extern void *__ioremap(phys_addr_t address, unsigned long size,
136 unsigned long flags);*/
137extern 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
142#else /* CONFIG_MMU */
143
Michal Simek2c572c22009-03-27 14:25:33 +0100144/**
145 * virt_to_phys - map virtual addresses to physical
146 * @address: address to remap
147 *
148 * The returned physical address is the physical (CPU) mapping for
149 * the memory address given. It is only valid to use this function on
150 * addresses directly mapped or allocated via kmalloc.
151 *
152 * This function does not give bus mappings for DMA transfers. In
153 * almost all conceivable cases a device driver should not be using
154 * this function
155 */
156static inline unsigned long __iomem virt_to_phys(volatile void *address)
157{
158 return __pa((unsigned long)address);
159}
160
161#define virt_to_bus virt_to_phys
162
163/**
164 * phys_to_virt - map physical address to virtual
165 * @address: address to remap
166 *
167 * The returned virtual address is a current CPU mapping for
168 * the memory address given. It is only valid to use this function on
169 * addresses that have a kernel mapping
170 *
171 * This function does not handle bus mappings for DMA transfers. In
172 * almost all conceivable cases a device driver should not be using
173 * this function
174 */
175static inline void *phys_to_virt(unsigned long address)
176{
177 return (void *)__va(address);
178}
179
180#define bus_to_virt(a) phys_to_virt(a)
181
182static inline void __iomem *__ioremap(phys_addr_t address, unsigned long size,
183 unsigned long flags)
184{
185 return (void *)address;
186}
187
188#define ioremap(physaddr, size) ((void __iomem *)(unsigned long)(physaddr))
189#define iounmap(addr) ((void)0)
190#define ioremap_nocache(physaddr, size) ioremap(physaddr, size)
191
Michal Simekdc95be12009-05-26 16:30:16 +0200192#endif /* CONFIG_MMU */
193
Michal Simek2c572c22009-03-27 14:25:33 +0100194/*
195 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
196 * access
197 */
198#define xlate_dev_mem_ptr(p) __va(p)
199
200/*
201 * Convert a virtual cached pointer to an uncached pointer
202 */
203#define xlate_dev_kmem_ptr(p) p
204
205/*
206 * Big Endian
207 */
208#define out_be32(a, v) __raw_writel((v), (void __iomem __force *)(a))
209#define out_be16(a, v) __raw_writew((v), (a))
210
211#define in_be32(a) __raw_readl((const void __iomem __force *)(a))
212#define in_be16(a) __raw_readw(a)
213
214/*
215 * Little endian
216 */
217
218#define out_le32(a, v) __raw_writel(__cpu_to_le32(v), (a));
219#define out_le16(a, v) __raw_writew(__cpu_to_le16(v), (a))
220
221#define in_le32(a) __le32_to_cpu(__raw_readl(a))
222#define in_le16(a) __le16_to_cpu(__raw_readw(a))
223
224/* Byte ops */
225#define out_8(a, v) __raw_writeb((v), (a))
226#define in_8(a) __raw_readb(a)
227
228/* FIXME */
229static inline void __iomem *ioport_map(unsigned long port, unsigned int len)
230{
231 return (void __iomem *) (port);
232}
233
234static inline void ioport_unmap(void __iomem *addr)
235{
236 /* Nothing to do */
237}
238
239#endif /* _ASM_MICROBLAZE_IO_H */