Root/target/linux/ubicom32/files/arch/ubicom32/include/asm/io.h

1/*
2 * arch/ubicom32/include/asm/io.h
3 * I/O memory accessor functions for Ubicom32 architecture.
4 *
5 * (C) Copyright 2009, Ubicom, Inc.
6 *
7 * This file is part of the Ubicom32 Linux Kernel Port.
8 *
9 * The Ubicom32 Linux Kernel Port is free software: you can redistribute
10 * it and/or modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation, either version 2 of the
12 * License, or (at your option) any later version.
13 *
14 * The Ubicom32 Linux Kernel Port is distributed in the hope that it
15 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
16 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with the Ubicom32 Linux Kernel Port. If not,
21 * see <http://www.gnu.org/licenses/>.
22 *
23 * Ubicom32 implementation derived from (with many thanks):
24 * arch/m68knommu
25 * arch/blackfin
26 * arch/parisc
27 */
28#ifndef _ASM_UBICOM32_IO_H
29#define _ASM_UBICOM32_IO_H
30
31#ifdef __KERNEL__
32#include <linux/string.h>
33#include <linux/compiler.h>
34
35static inline unsigned short _swapw(volatile unsigned short v)
36{
37    return ((v << 8) | (v >> 8));
38}
39
40static inline unsigned int _swapl(volatile unsigned long v)
41{
42    return ((v << 24) | ((v & 0xff00) << 8) | ((v & 0xff0000) >> 8) | (v >> 24));
43}
44
45#ifndef CONFIG_PCI
46#define readb(addr) \
47    ({ unsigned char __v = (*(volatile unsigned char *) (addr)); __v; })
48#define readw(addr) \
49    ({ unsigned short __v = (*(volatile unsigned short *) (addr)); __v; })
50#define readl(addr) \
51    ({ unsigned int __v = (*(volatile unsigned int *) (addr)); __v; })
52
53#define writeb(b,addr) (void)((*(volatile unsigned char *) (addr)) = (b))
54#define writew(b,addr) (void)((*(volatile unsigned short *) (addr)) = (b))
55#define writel(b,addr) (void)((*(volatile unsigned int *) (addr)) = (b))
56#else /*CONFIG_PCI */
57
58#define PCI_CPU_REG_BASE (0x00000000UL) /* taking lower 2GB space */
59#define PCI_DEV_REG_BASE (0x80000000UL)
60
61#if PCI_CPU_REG_BASE > PCI_DEV_REG_BASE
62#define IS_PCI_ADDRESS(x) (((unsigned int)(x)&(PCI_CPU_REG_BASE)) == 0)
63#else
64#define IS_PCI_ADDRESS(x) ((unsigned int)(x)&(PCI_DEV_REG_BASE))
65#endif
66
67extern unsigned int ubi32_pci_read_u32(const volatile void __iomem *addr);
68extern unsigned short ubi32_pci_read_u16(const volatile void __iomem *addr);
69extern unsigned char ubi32_pci_read_u8(const volatile void __iomem *addr);
70extern void ubi32_pci_write_u32(unsigned int val, const volatile void __iomem *addr);
71extern void ubi32_pci_write_u16(unsigned short val, const volatile void __iomem *addr);
72extern void ubi32_pci_write_u8(unsigned char val, const volatile void __iomem *addr);
73
74static inline unsigned char readb(const volatile void __iomem *addr)
75{
76    if (IS_PCI_ADDRESS(addr))
77        return ubi32_pci_read_u8(addr);
78    else
79        return (unsigned char)(*(volatile unsigned char *)addr);
80}
81static inline unsigned short readw(const volatile void __iomem *addr)
82{
83    if (IS_PCI_ADDRESS(addr))
84        return ubi32_pci_read_u16(addr);
85    else
86        return (unsigned short)(*(volatile unsigned short *)addr);
87}
88
89static inline unsigned int readl(const volatile void __iomem *addr)
90{
91    if (IS_PCI_ADDRESS(addr))
92        return ubi32_pci_read_u32(addr);
93    else
94        return (unsigned int)(*(volatile unsigned int *)addr);
95}
96
97static inline void writel(unsigned int val, volatile void __iomem *addr)
98{
99    if (IS_PCI_ADDRESS(addr))
100                ubi32_pci_write_u32(val, addr);
101        else
102        *(volatile unsigned int *)addr = val;
103}
104
105static inline void writew(unsigned short val, volatile void __iomem *addr)
106{
107    if (IS_PCI_ADDRESS(addr))
108                ubi32_pci_write_u16(val, addr);
109        else
110        *(volatile unsigned short *)addr = val;
111}
112
113static inline void writeb(unsigned char val, volatile void __iomem *addr)
114{
115    if (IS_PCI_ADDRESS(addr))
116                ubi32_pci_write_u8(val, addr);
117        else
118        *(volatile unsigned char *)addr = val;
119}
120#endif
121
122#define readb_relaxed(addr) readb(addr)
123#define readw_relaxed(addr) readw(addr)
124#define readl_relaxed(addr) readl(addr)
125
126
127#define __raw_readb readb
128#define __raw_readw readw
129#define __raw_readl readl
130#define __raw_writeb writeb
131#define __raw_writew writew
132#define __raw_writel writel
133
134static inline void io_outsb(unsigned int addr, const void *buf, int len)
135{
136    volatile unsigned char *ap = (volatile unsigned char *) addr;
137    unsigned char *bp = (unsigned char *) buf;
138    while (len--)
139        *ap = *bp++;
140}
141
142static inline void io_outsw(unsigned int addr, const void *buf, int len)
143{
144    volatile unsigned short *ap = (volatile unsigned short *) addr;
145    unsigned short *bp = (unsigned short *) buf;
146    while (len--)
147        *ap = _swapw(*bp++);
148}
149
150static inline void io_outsl(unsigned int addr, const void *buf, int len)
151{
152    volatile unsigned int *ap = (volatile unsigned int *) addr;
153    unsigned int *bp = (unsigned int *) buf;
154    while (len--)
155        *ap = _swapl(*bp++);
156}
157
158static inline void io_insb(unsigned int addr, void *buf, int len)
159{
160    volatile unsigned char *ap = (volatile unsigned char *) addr;
161    unsigned char *bp = (unsigned char *) buf;
162    while (len--)
163        *bp++ = *ap;
164}
165
166static inline void io_insw(unsigned int addr, void *buf, int len)
167{
168    volatile unsigned short *ap = (volatile unsigned short *) addr;
169    unsigned short *bp = (unsigned short *) buf;
170    while (len--)
171        *bp++ = _swapw(*ap);
172}
173
174static inline void io_insl(unsigned int addr, void *buf, int len)
175{
176    volatile unsigned int *ap = (volatile unsigned int *) addr;
177    unsigned int *bp = (unsigned int *) buf;
178    while (len--)
179        *bp++ = _swapl(*ap);
180}
181
182#define mmiowb()
183
184/*
185 * make the short names macros so specific devices
186 * can override them as required
187 */
188#ifndef CONFIG_PCI
189#define memset_io(a,b,c) memset((void *)(a),(b),(c))
190#define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c))
191#define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c))
192#else
193extern void memcpy_fromio(void *to, const volatile void __iomem *from, unsigned len);
194extern void memcpy_toio(volatile void __iomem *to, const void *from, unsigned len);
195extern void memset_io(volatile void __iomem *addr, int val, size_t count);
196#endif
197
198#define inb(addr) readb(addr)
199#define inw(addr) readw(addr)
200#define inl(addr) readl(addr)
201#define outb(x,addr) ((void) writeb(x,addr))
202#define outw(x,addr) ((void) writew(x,addr))
203#define outl(x,addr) ((void) writel(x,addr))
204
205#define inb_p(addr) inb(addr)
206#define inw_p(addr) inw(addr)
207#define inl_p(addr) inl(addr)
208#define outb_p(x,addr) outb(x,addr)
209#define outw_p(x,addr) outw(x,addr)
210#define outl_p(x,addr) outl(x,addr)
211
212#define outsb(a,b,l) io_outsb(a,b,l)
213#define outsw(a,b,l) io_outsw(a,b,l)
214#define outsl(a,b,l) io_outsl(a,b,l)
215
216#define insb(a,b,l) io_insb(a,b,l)
217#define insw(a,b,l) io_insw(a,b,l)
218#define insl(a,b,l) io_insl(a,b,l)
219
220#ifndef CONFIG_PCI
221#define ioread8_rep(a,d,c) insb(a,d,c)
222#define ioread16_rep(a,d,c) insw(a,d,c)
223#define ioread32_rep(a,d,c) insl(a,d,c)
224#define iowrite8_rep(a,s,c) outsb(a,s,c)
225#define iowrite16_rep(a,s,c) outsw(a,s,c)
226#define iowrite32_rep(a,s,c) outsl(a,s,c)
227#else
228extern void ioread8_rep(void __iomem *port, void *buf, unsigned long count);
229extern void ioread16_rep(void __iomem *port, void *buf, unsigned long count);
230extern void ioread32_rep(void __iomem *port, void *buf, unsigned long count);
231extern void iowrite8_rep(void __iomem *port, const void *buf, unsigned long count);
232extern void iowrite16_rep(void __iomem *port, const void *buf, unsigned long count);
233extern void iowrite32_rep(void __iomem *port, const void *buf, unsigned long count);
234#endif
235
236
237#ifndef CONFIG_PCI
238#define ioread8(X) readb(X)
239#define ioread16(X) readw(X)
240#define ioread32(X) readl(X)
241#define iowrite8(val,X) writeb(val,X)
242#define iowrite16(val,X) writew(val,X)
243#define iowrite32(val,X) writel(val,X)
244#else /*CONFIG_PCI */
245extern unsigned char ioread8(void __iomem *addr);
246extern unsigned short ioread16(void __iomem *addr);
247extern unsigned int ioread32(void __iomem *addr);
248extern void iowrite8(unsigned char val, void __iomem *addr);
249extern void iowrite16(unsigned short val, void __iomem *addr);
250extern void iowrite32(unsigned int val, void __iomem *addr);
251#endif /* CONFIG_PCI */
252
253#define IO_SPACE_LIMIT 0xffff
254
255/* Values for nocacheflag and cmode */
256#define IOMAP_FULL_CACHING 0
257#define IOMAP_NOCACHE_SER 1
258#define IOMAP_NOCACHE_NONSER 2
259#define IOMAP_WRITETHROUGH 3
260
261extern void *__ioremap(unsigned long physaddr, unsigned long size, int cacheflag);
262extern void __iounmap(void *addr, unsigned long size);
263
264static inline void *ioremap(unsigned long physaddr, unsigned long size)
265{
266    return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
267}
268static inline void *ioremap_nocache(unsigned long physaddr, unsigned long size)
269{
270    return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
271}
272static inline void *ioremap_writethrough(unsigned long physaddr, unsigned long size)
273{
274    return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
275}
276static inline void *ioremap_fullcache(unsigned long physaddr, unsigned long size)
277{
278    return __ioremap(physaddr, size, IOMAP_FULL_CACHING);
279}
280
281extern void iounmap(void *addr);
282
283#define ioport_map(port, nr) ((void __iomem*)(port))
284#define ioport_unmap(addr)
285
286
287/* Pages to physical address... */
288#define page_to_phys(page) ((page - mem_map) << PAGE_SHIFT)
289#define page_to_bus(page) ((page - mem_map) << PAGE_SHIFT)
290
291/*
292 * Macros used for converting between virtual and physical mappings.
293 */
294#define phys_to_virt(vaddr) ((void *) (vaddr))
295#define virt_to_phys(vaddr) ((unsigned long) (vaddr))
296
297#define virt_to_bus virt_to_phys
298#define bus_to_virt phys_to_virt
299
300/*
301 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
302 * access
303 */
304#define xlate_dev_mem_ptr(p) __va(p)
305
306/*
307 * Convert a virtual cached pointer to an uncached pointer
308 */
309#define xlate_dev_kmem_ptr(p) p
310
311#endif /* __KERNEL__ */
312
313#endif /* _ASM_UBICOM32_IO_H */
314

Archive Download this file



interactive