2 * (C) Copyright 2011, Julius Baxter <julius@opencores.org>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 #ifndef __ASM_OPENRISC_IO_H
21 #define __ASM_OPENRISC_IO_H
24 * Given a physical address and a length, return a virtual address
25 * that can be used to access the memory range with the caching
26 * properties specified by "flags".
28 #define MAP_NOCACHE (0)
29 #define MAP_WRCOMBINE (0)
30 #define MAP_WRBACK (0)
31 #define MAP_WRTHROUGH (0)
34 map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
40 * Take down a mapping set up by map_physmem().
42 static inline void unmap_physmem(void *vaddr, unsigned long flags)
48 * Change virtual addresses to physical addresses
50 static inline phys_addr_t virt_to_phys(void *vaddr)
52 return (phys_addr_t)(vaddr);
57 * readX/writeX() are used to access memory mapped devices. On some
58 * architectures the memory mapped IO stuff needs to be accessed
59 * differently. On the openrisc architecture, we just read/write the
60 * memory location directly.
62 #define readb(addr) (*(volatile unsigned char *) (addr))
63 #define readw(addr) (*(volatile unsigned short *) (addr))
64 #define readl(addr) (*(volatile unsigned int *) (addr))
65 #define __raw_readb readb
66 #define __raw_readw readw
67 #define __raw_readl readl
69 #define writeb(b, addr) ((*(volatile unsigned char *) (addr)) = (b))
70 #define writew(b, addr) ((*(volatile unsigned short *) (addr)) = (b))
71 #define writel(b, addr) ((*(volatile unsigned int *) (addr)) = (b))
72 #define __raw_writeb writeb
73 #define __raw_writew writew
74 #define __raw_writel writel
76 #define memset_io(a, b, c) memset((void *)(a), (b), (c))
77 #define memcpy_fromio(a, b, c) memcpy((a), (void *)(b), (c))
78 #define memcpy_toio(a, b, c) memcpy((void *)(a), (b), (c))
81 * Again, OpenRISC does not require mem IO specific function.
86 #define IO_SPACE_LIMIT 0xffffffff
88 #define inb(port) readb((port + IO_BASE))
89 #define outb(value, port) writeb((value), (port + IO_BASE))
90 #define inb_p(port) inb((port))
91 #define outb_p(value, port) outb((value), (port))
94 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
97 #define xlate_dev_mem_ptr(p) __va(p)
100 * Convert a virtual cached pointer to an uncached pointer
102 #define xlate_dev_kmem_ptr(p) p
104 #define ioread8(addr) readb(addr)
105 #define ioread16(addr) readw(addr)
106 #define ioread32(addr) readl(addr)
108 #define iowrite8(v, addr) writeb((v), (addr))
109 #define iowrite16(v, addr) writew((v), (addr))
110 #define iowrite32(v, addr) writel((v), (addr))