wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 1 | /* |
| 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 Wang | c123a38 | 2007-02-21 16:52:31 +0100 | [diff] [blame] | 27 | static inline void sync(void) |
| 28 | { |
| 29 | __asm__ __volatile__ ("sync" : : : "memory"); |
| 30 | } |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 31 | |
Haavard Skinnemoen | f985551 | 2007-12-13 12:56:33 +0100 | [diff] [blame] | 32 | /* |
| 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 Skinnemoen | f985551 | 2007-12-13 12:56:33 +0100 | [diff] [blame] | 37 | #define MAP_NOCACHE (0) |
| 38 | #define MAP_WRCOMBINE (0) |
| 39 | #define MAP_WRBACK (0) |
| 40 | #define MAP_WRTHROUGH (0) |
| 41 | |
| 42 | static inline void * |
| 43 | map_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 | */ |
| 51 | static inline void unmap_physmem(void *vaddr, unsigned long flags) |
| 52 | { |
| 53 | |
| 54 | } |
| 55 | |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 56 | extern unsigned char inb (unsigned char *port); |
| 57 | extern unsigned short inw (unsigned short *port); |
| 58 | extern unsigned inl (unsigned port); |
wdenk | 194b839 | 2005-03-30 23:28:18 +0000 | [diff] [blame] | 59 | |
Haavard Skinnemoen | 47f6085 | 2007-12-13 12:56:31 +0100 | [diff] [blame] | 60 | #define __raw_writeb(v,a) (*(volatile unsigned char *)(a) = (v)) |
| 61 | #define __raw_writew(v,a) (*(volatile unsigned short *)(a) = (v)) |
| 62 | #define __raw_writel(v,a) (*(volatile unsigned int *)(a) = (v)) |
| 63 | |
| 64 | #define __raw_readb(a) (*(volatile unsigned char *)(a)) |
| 65 | #define __raw_readw(a) (*(volatile unsigned short *)(a)) |
| 66 | #define __raw_readl(a) (*(volatile unsigned int *)(a)) |
| 67 | |
wdenk | 194b839 | 2005-03-30 23:28:18 +0000 | [diff] [blame] | 68 | #define readb(addr)\ |
| 69 | ({unsigned char val;\ |
| 70 | asm volatile( "ldbio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;}) |
| 71 | #define readw(addr)\ |
| 72 | ({unsigned short val;\ |
| 73 | asm volatile( "ldhio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;}) |
| 74 | #define readl(addr)\ |
| 75 | ({unsigned long val;\ |
| 76 | asm volatile( "ldwio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;}) |
Scott McNutt | a5721a3 | 2006-06-08 11:59:57 -0400 | [diff] [blame] | 77 | |
wdenk | 194b839 | 2005-03-30 23:28:18 +0000 | [diff] [blame] | 78 | #define writeb(addr,val)\ |
Scott McNutt | a5721a3 | 2006-06-08 11:59:57 -0400 | [diff] [blame] | 79 | asm volatile ("stbio %1, 0(%0)" : : "r" (addr), "r" (val)) |
wdenk | 194b839 | 2005-03-30 23:28:18 +0000 | [diff] [blame] | 80 | #define writew(addr,val)\ |
Scott McNutt | a5721a3 | 2006-06-08 11:59:57 -0400 | [diff] [blame] | 81 | asm volatile ("sthio %1, 0(%0)" : : "r" (addr), "r" (val)) |
wdenk | 194b839 | 2005-03-30 23:28:18 +0000 | [diff] [blame] | 82 | #define writel(addr,val)\ |
Scott McNutt | a5721a3 | 2006-06-08 11:59:57 -0400 | [diff] [blame] | 83 | asm volatile ("stwio %1, 0(%0)" : : "r" (addr), "r" (val)) |
wdenk | 194b839 | 2005-03-30 23:28:18 +0000 | [diff] [blame] | 84 | |
| 85 | #define inb(addr) readb(addr) |
| 86 | #define inw(addr) readw(addr) |
| 87 | #define inl(addr) readl(addr) |
| 88 | #define outb(addr,val) writeb(addr,val) |
| 89 | #define outw(addr,val) writew(addr,val) |
| 90 | #define outl(addr,val) writel(addr,val) |
| 91 | |
| 92 | static inline void insb (unsigned long port, void *dst, unsigned long count) |
| 93 | { |
| 94 | unsigned char *p = dst; |
| 95 | while (count--) *p++ = inb (port); |
| 96 | } |
| 97 | static inline void insw (unsigned long port, void *dst, unsigned long count) |
| 98 | { |
| 99 | unsigned short *p = dst; |
| 100 | while (count--) *p++ = inw (port); |
| 101 | } |
| 102 | static inline void insl (unsigned long port, void *dst, unsigned long count) |
| 103 | { |
| 104 | unsigned long *p = dst; |
| 105 | while (count--) *p++ = inl (port); |
| 106 | } |
| 107 | |
| 108 | static inline void outsb (unsigned long port, const void *src, unsigned long count) |
| 109 | { |
| 110 | const unsigned char *p = src; |
| 111 | while (count--) outb (*p++, port); |
| 112 | } |
| 113 | |
| 114 | static inline void outsw (unsigned long port, const void *src, unsigned long count) |
| 115 | { |
| 116 | const unsigned short *p = src; |
| 117 | while (count--) outw (*p++, port); |
| 118 | } |
| 119 | static inline void outsl (unsigned long port, const void *src, unsigned long count) |
| 120 | { |
| 121 | const unsigned long *p = src; |
| 122 | while (count--) outl (*p++, port); |
| 123 | } |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 124 | |
| 125 | #endif /* __ASM_NIOS2_IO_H_ */ |