Wolfgang Denk | 9f191a1 | 2005-08-06 01:56:59 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003, 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 | #ifndef __ASM_NIOS_IO_H_ |
| 24 | #define __ASM_NIOS_IO_H_ |
| 25 | |
Haavard Skinnemoen | 47f6085 | 2007-12-13 12:56:31 +0100 | [diff] [blame] | 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)) |
| 29 | |
| 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)) |
| 33 | |
Wolfgang Denk | 9f191a1 | 2005-08-06 01:56:59 +0200 | [diff] [blame] | 34 | #define readb(addr)\ |
| 35 | ({unsigned char val;\ |
| 36 | asm volatile( " pfxio 0 \n"\ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 37 | " ld %0, [%1] \n"\ |
Wolfgang Denk | 9f191a1 | 2005-08-06 01:56:59 +0200 | [diff] [blame] | 38 | " ext8d %0, %1 \n"\ |
| 39 | :"=r"(val) : "r" (addr)); val;}) |
| 40 | |
| 41 | #define readw(addr)\ |
| 42 | ({unsigned short val;\ |
| 43 | asm volatile( " pfxio 0 \n"\ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 44 | " ld %0, [%1] \n"\ |
Wolfgang Denk | 9f191a1 | 2005-08-06 01:56:59 +0200 | [diff] [blame] | 45 | " ext16d %0, %1 \n"\ |
| 46 | :"=r"(val) : "r" (addr)); val;}) |
| 47 | |
| 48 | #define readl(addr)\ |
| 49 | ({unsigned long val;\ |
| 50 | asm volatile( " pfxio 0 \n"\ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 51 | " ld %0, [%1] \n"\ |
Wolfgang Denk | 9f191a1 | 2005-08-06 01:56:59 +0200 | [diff] [blame] | 52 | :"=r"(val) : "r" (addr)); val;}) |
| 53 | |
| 54 | #define writeb(addr,val)\ |
| 55 | asm volatile ( " fill8 %%r0, %1 \n"\ |
| 56 | " st8d [%0], %%r0 \n"\ |
| 57 | : : "r" (addr), "r" (val) : "r0") |
| 58 | |
| 59 | #define writew(addr,val)\ |
| 60 | asm volatile ( " fill16 %%r0, %1 \n"\ |
| 61 | " st16d [%0], %%r0 \n"\ |
| 62 | : : "r" (addr), "r" (val) : "r0") |
| 63 | |
| 64 | #define writel(addr,val)\ |
| 65 | asm volatile ( " st [%0], %1 \n"\ |
| 66 | : : "r" (addr), "r" (val)) |
| 67 | |
| 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) |
| 74 | |
| 75 | static inline void insb (unsigned long port, void *dst, unsigned long count) |
| 76 | { |
| 77 | unsigned char *p = dst; |
| 78 | while (count--) *p++ = inb (port); |
| 79 | } |
| 80 | static inline void insw (unsigned long port, void *dst, unsigned long count) |
| 81 | { |
| 82 | unsigned short *p = dst; |
| 83 | while (count--) *p++ = inw (port); |
| 84 | } |
| 85 | static inline void insl (unsigned long port, void *dst, unsigned long count) |
| 86 | { |
| 87 | unsigned long *p = dst; |
| 88 | while (count--) *p++ = inl (port); |
| 89 | } |
| 90 | |
| 91 | static inline void outsb (unsigned long port, const void *src, unsigned long count) |
| 92 | { |
| 93 | const unsigned char *p = src; |
| 94 | while (count--) outb (*p++, port); |
| 95 | } |
| 96 | |
| 97 | static inline void outsw (unsigned long port, const void *src, unsigned long count) |
| 98 | { |
| 99 | const unsigned short *p = src; |
| 100 | while (count--) outw (*p++, port); |
| 101 | } |
| 102 | static inline void outsl (unsigned long port, const void *src, unsigned long count) |
| 103 | { |
| 104 | const unsigned long *p = src; |
| 105 | while (count--) outl (*p++, port); |
| 106 | } |
| 107 | |
Haiying Wang | c123a38 | 2007-02-21 16:52:31 +0100 | [diff] [blame] | 108 | static inline void sync(void) |
| 109 | { |
| 110 | } |
| 111 | |
Haavard Skinnemoen | f985551 | 2007-12-13 12:56:33 +0100 | [diff] [blame] | 112 | /* |
| 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". |
| 116 | */ |
Haavard Skinnemoen | f985551 | 2007-12-13 12:56:33 +0100 | [diff] [blame] | 117 | #define MAP_NOCACHE (0) |
| 118 | #define MAP_WRCOMBINE (0) |
| 119 | #define MAP_WRBACK (0) |
| 120 | #define MAP_WRTHROUGH (0) |
| 121 | |
| 122 | static inline void * |
| 123 | map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags) |
| 124 | { |
| 125 | return (void *)paddr; |
| 126 | } |
| 127 | |
| 128 | /* |
| 129 | * Take down a mapping set up by map_physmem(). |
| 130 | */ |
| 131 | static inline void unmap_physmem(void *vaddr, unsigned long flags) |
| 132 | { |
| 133 | |
| 134 | } |
| 135 | |
Kumar Gala | 9364a67 | 2008-12-13 17:20:27 -0600 | [diff] [blame] | 136 | static inline phys_addr_t virt_to_phys(void * vaddr) |
| 137 | { |
| 138 | return (phys_addr_t)(vaddr); |
| 139 | } |
| 140 | |
Wolfgang Denk | 9f191a1 | 2005-08-06 01:56:59 +0200 | [diff] [blame] | 141 | #endif /* __ASM_NIOS_IO_H_ */ |