2 * (C) Copyright 2003, Psyent Corporation <www.psyent.com>
3 * Scott McNutt <smcnutt@psyent.com>
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
23 #ifndef __ASM_NIOS_IO_H_
24 #define __ASM_NIOS_IO_H_
26 #define __raw_writeb(v,a) (*(volatile unsigned char *)(a) = (v))
27 #define __raw_writew(v,a) (*(volatile unsigned short *)(a) = (v))
28 #define __raw_writel(v,a) (*(volatile unsigned int *)(a) = (v))
30 #define __raw_readb(a) (*(volatile unsigned char *)(a))
31 #define __raw_readw(a) (*(volatile unsigned short *)(a))
32 #define __raw_readl(a) (*(volatile unsigned int *)(a))
36 asm volatile( " pfxio 0 \n"\
39 :"=r"(val) : "r" (addr)); val;})
42 ({unsigned short val;\
43 asm volatile( " pfxio 0 \n"\
46 :"=r"(val) : "r" (addr)); val;})
50 asm volatile( " pfxio 0 \n"\
52 :"=r"(val) : "r" (addr)); val;})
54 #define writeb(addr,val)\
55 asm volatile ( " fill8 %%r0, %1 \n"\
56 " st8d [%0], %%r0 \n"\
57 : : "r" (addr), "r" (val) : "r0")
59 #define writew(addr,val)\
60 asm volatile ( " fill16 %%r0, %1 \n"\
61 " st16d [%0], %%r0 \n"\
62 : : "r" (addr), "r" (val) : "r0")
64 #define writel(addr,val)\
65 asm volatile ( " st [%0], %1 \n"\
66 : : "r" (addr), "r" (val))
68 #define inb(addr) readb(addr)
69 #define inw(addr) readw(addr)
70 #define inl(addr) readl(addr)
71 #define outb(val,addr) writeb(addr,val)
72 #define outw(val,addr) writew(addr,val)
73 #define outl(val,addr) writel(addr,val)
75 static inline void insb (unsigned long port, void *dst, unsigned long count)
77 unsigned char *p = dst;
78 while (count--) *p++ = inb (port);
80 static inline void insw (unsigned long port, void *dst, unsigned long count)
82 unsigned short *p = dst;
83 while (count--) *p++ = inw (port);
85 static inline void insl (unsigned long port, void *dst, unsigned long count)
87 unsigned long *p = dst;
88 while (count--) *p++ = inl (port);
91 static inline void outsb (unsigned long port, const void *src, unsigned long count)
93 const unsigned char *p = src;
94 while (count--) outb (*p++, port);
97 static inline void outsw (unsigned long port, const void *src, unsigned long count)
99 const unsigned short *p = src;
100 while (count--) outw (*p++, port);
102 static inline void outsl (unsigned long port, const void *src, unsigned long count)
104 const unsigned long *p = src;
105 while (count--) outl (*p++, port);
108 static inline void sync(void)
113 * Given a physical address and a length, return a virtual address
114 * that can be used to access the memory range with the caching
115 * properties specified by "flags".
117 typedef unsigned long phys_addr_t;
119 #define MAP_NOCACHE (0)
120 #define MAP_WRCOMBINE (0)
121 #define MAP_WRBACK (0)
122 #define MAP_WRTHROUGH (0)
125 map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
127 return (void *)paddr;
131 * Take down a mapping set up by map_physmem().
133 static inline void unmap_physmem(void *vaddr, unsigned long flags)
138 #endif /* __ASM_NIOS_IO_H_ */