blob: 121405cd605528247a4c7bc9b6d9f2315e6046f4 [file] [log] [blame]
wdenkef3386f2004-10-10 21:27:30 +00001/*
2 * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
3 * Scott McNutt <smcnutt@psyent.com>
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#ifndef __ASM_NIOS2_IO_H_
25#define __ASM_NIOS2_IO_H_
26
Haiying Wangc123a382007-02-21 16:52:31 +010027static inline void sync(void)
28{
29 __asm__ __volatile__ ("sync" : : : "memory");
30}
wdenkef3386f2004-10-10 21:27:30 +000031
Haavard Skinnemoenf9855512007-12-13 12:56:33 +010032/*
33 * Given a physical address and a length, return a virtual address
34 * that can be used to access the memory range with the caching
35 * properties specified by "flags".
36 */
Haavard Skinnemoenf9855512007-12-13 12:56:33 +010037#define MAP_NOCACHE (0)
38#define MAP_WRCOMBINE (0)
39#define MAP_WRBACK (0)
40#define MAP_WRTHROUGH (0)
41
42static inline void *
43map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
44{
45 return (void *)paddr;
46}
47
48/*
49 * Take down a mapping set up by map_physmem().
50 */
51static inline void unmap_physmem(void *vaddr, unsigned long flags)
52{
53
54}
55
Kumar Gala9364a672008-12-13 17:20:27 -060056static inline phys_addr_t virt_to_phys(void * vaddr)
57{
58 return (phys_addr_t)(vaddr);
59}
60
wdenkef3386f2004-10-10 21:27:30 +000061extern unsigned char inb (unsigned char *port);
62extern unsigned short inw (unsigned short *port);
63extern unsigned inl (unsigned port);
wdenk194b8392005-03-30 23:28:18 +000064
Haavard Skinnemoen47f60852007-12-13 12:56:31 +010065#define __raw_writeb(v,a) (*(volatile unsigned char *)(a) = (v))
66#define __raw_writew(v,a) (*(volatile unsigned short *)(a) = (v))
67#define __raw_writel(v,a) (*(volatile unsigned int *)(a) = (v))
68
69#define __raw_readb(a) (*(volatile unsigned char *)(a))
70#define __raw_readw(a) (*(volatile unsigned short *)(a))
71#define __raw_readl(a) (*(volatile unsigned int *)(a))
72
wdenk194b8392005-03-30 23:28:18 +000073#define readb(addr)\
74 ({unsigned char val;\
75 asm volatile( "ldbio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;})
76#define readw(addr)\
77 ({unsigned short val;\
78 asm volatile( "ldhio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;})
79#define readl(addr)\
80 ({unsigned long val;\
81 asm volatile( "ldwio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;})
Scott McNutta5721a32006-06-08 11:59:57 -040082
Scott McNutt0fd72d32010-03-21 21:24:43 -040083#define writeb(val,addr)\
84 asm volatile ("stbio %0, 0(%1)" : : "r" (val), "r" (addr))
85#define writew(val,addr)\
86 asm volatile ("sthio %0, 0(%1)" : : "r" (val), "r" (addr))
87#define writel(val,addr)\
88 asm volatile ("stwio %0, 0(%1)" : : "r" (val), "r" (addr))
wdenk194b8392005-03-30 23:28:18 +000089
90#define inb(addr) readb(addr)
91#define inw(addr) readw(addr)
92#define inl(addr) readl(addr)
Scott McNutt0fd72d32010-03-21 21:24:43 -040093#define outb(val, addr) writeb(val,addr)
94#define outw(val, addr) writew(val,addr)
95#define outl(val, addr) writel(val,addr)
wdenk194b8392005-03-30 23:28:18 +000096
97static inline void insb (unsigned long port, void *dst, unsigned long count)
98{
99 unsigned char *p = dst;
100 while (count--) *p++ = inb (port);
101}
102static inline void insw (unsigned long port, void *dst, unsigned long count)
103{
104 unsigned short *p = dst;
105 while (count--) *p++ = inw (port);
106}
107static inline void insl (unsigned long port, void *dst, unsigned long count)
108{
109 unsigned long *p = dst;
110 while (count--) *p++ = inl (port);
111}
112
113static inline void outsb (unsigned long port, const void *src, unsigned long count)
114{
115 const unsigned char *p = src;
116 while (count--) outb (*p++, port);
117}
118
119static inline void outsw (unsigned long port, const void *src, unsigned long count)
120{
121 const unsigned short *p = src;
122 while (count--) outw (*p++, port);
123}
124static inline void outsl (unsigned long port, const void *src, unsigned long count)
125{
126 const unsigned long *p = src;
127 while (count--) outl (*p++, port);
128}
wdenkef3386f2004-10-10 21:27:30 +0000129
130#endif /* __ASM_NIOS2_IO_H_ */