Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 1 | /* |
Chris Zankel | 173d6681 | 2006-12-10 02:18:48 -0800 | [diff] [blame] | 2 | * include/asm-xtensa/io.h |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 3 | * |
| 4 | * This file is subject to the terms and conditions of the GNU General Public |
| 5 | * License. See the file "COPYING" in the main directory of this archive |
| 6 | * for more details. |
| 7 | * |
| 8 | * Copyright (C) 2001 - 2005 Tensilica Inc. |
| 9 | */ |
| 10 | |
| 11 | #ifndef _XTENSA_IO_H |
| 12 | #define _XTENSA_IO_H |
| 13 | |
| 14 | #ifdef __KERNEL__ |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 15 | #include <asm/byteorder.h> |
Adrian Bunk | c51aea8 | 2007-07-23 18:43:54 -0700 | [diff] [blame] | 16 | #include <asm/page.h> |
Chris Zankel | 6656920 | 2007-08-22 10:14:51 -0700 | [diff] [blame] | 17 | #include <linux/kernel.h> |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 18 | |
| 19 | #include <linux/types.h> |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 20 | |
Chris Zankel | 00c81d2 | 2008-10-21 09:08:31 -0700 | [diff] [blame] | 21 | #define XCHAL_KIO_CACHED_VADDR 0xe0000000 |
| 22 | #define XCHAL_KIO_BYPASS_VADDR 0xf0000000 |
Chris Zankel | 173d6681 | 2006-12-10 02:18:48 -0800 | [diff] [blame] | 23 | #define XCHAL_KIO_PADDR 0xf0000000 |
Chris Zankel | 00c81d2 | 2008-10-21 09:08:31 -0700 | [diff] [blame] | 24 | #define XCHAL_KIO_SIZE 0x10000000 |
| 25 | |
| 26 | #define IOADDR(x) (XCHAL_KIO_BYPASS_VADDR + (x)) |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 27 | |
| 28 | /* |
| 29 | * swap functions to change byte order from little-endian to big-endian and |
| 30 | * vice versa. |
| 31 | */ |
| 32 | |
| 33 | static inline unsigned short _swapw (unsigned short v) |
| 34 | { |
| 35 | return (v << 8) | (v >> 8); |
| 36 | } |
| 37 | |
| 38 | static inline unsigned int _swapl (unsigned int v) |
| 39 | { |
| 40 | return (v << 24) | ((v & 0xff00) << 8) | ((v >> 8) & 0xff00) | (v >> 24); |
| 41 | } |
| 42 | |
| 43 | /* |
| 44 | * Change virtual addresses to physical addresses and vv. |
| 45 | * These are trivial on the 1:1 Linux/Xtensa mapping |
| 46 | */ |
| 47 | |
Adrian Bunk | d99cf71 | 2005-09-03 15:57:53 -0700 | [diff] [blame] | 48 | static inline unsigned long virt_to_phys(volatile void * address) |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 49 | { |
Chris Zankel | 173d6681 | 2006-12-10 02:18:48 -0800 | [diff] [blame] | 50 | return __pa(address); |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Adrian Bunk | d99cf71 | 2005-09-03 15:57:53 -0700 | [diff] [blame] | 53 | static inline void * phys_to_virt(unsigned long address) |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 54 | { |
Chris Zankel | 173d6681 | 2006-12-10 02:18:48 -0800 | [diff] [blame] | 55 | return __va(address); |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | /* |
Chris Zankel | 173d6681 | 2006-12-10 02:18:48 -0800 | [diff] [blame] | 59 | * virt_to_bus and bus_to_virt are deprecated. |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 60 | */ |
| 61 | |
Chris Zankel | 173d6681 | 2006-12-10 02:18:48 -0800 | [diff] [blame] | 62 | #define virt_to_bus(x) virt_to_phys(x) |
| 63 | #define bus_to_virt(x) phys_to_virt(x) |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 64 | |
| 65 | /* |
Chris Zankel | 173d6681 | 2006-12-10 02:18:48 -0800 | [diff] [blame] | 66 | * Return the virtual (cached) address for the specified bus memory. |
| 67 | * Note that we currently don't support any address outside the KIO segment. |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 68 | */ |
| 69 | |
Adrian Bunk | d99cf71 | 2005-09-03 15:57:53 -0700 | [diff] [blame] | 70 | static inline void *ioremap(unsigned long offset, unsigned long size) |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 71 | { |
Johannes Weiner | e5083a6 | 2009-03-04 16:21:31 +0100 | [diff] [blame] | 72 | #ifdef CONFIG_MMU |
Chris Zankel | 173d6681 | 2006-12-10 02:18:48 -0800 | [diff] [blame] | 73 | if (offset >= XCHAL_KIO_PADDR |
| 74 | && offset < XCHAL_KIO_PADDR + XCHAL_KIO_SIZE) |
| 75 | return (void*)(offset-XCHAL_KIO_PADDR+XCHAL_KIO_BYPASS_VADDR); |
Chris Zankel | 173d6681 | 2006-12-10 02:18:48 -0800 | [diff] [blame] | 76 | else |
| 77 | BUG(); |
Johannes Weiner | e5083a6 | 2009-03-04 16:21:31 +0100 | [diff] [blame] | 78 | #else |
| 79 | return (void *)offset; |
| 80 | #endif |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Adrian Bunk | d99cf71 | 2005-09-03 15:57:53 -0700 | [diff] [blame] | 83 | static inline void *ioremap_nocache(unsigned long offset, unsigned long size) |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 84 | { |
Johannes Weiner | e5083a6 | 2009-03-04 16:21:31 +0100 | [diff] [blame] | 85 | #ifdef CONFIG_MMU |
Chris Zankel | 173d6681 | 2006-12-10 02:18:48 -0800 | [diff] [blame] | 86 | if (offset >= XCHAL_KIO_PADDR |
| 87 | && offset < XCHAL_KIO_PADDR + XCHAL_KIO_SIZE) |
| 88 | return (void*)(offset-XCHAL_KIO_PADDR+XCHAL_KIO_CACHED_VADDR); |
| 89 | else |
| 90 | BUG(); |
Johannes Weiner | e5083a6 | 2009-03-04 16:21:31 +0100 | [diff] [blame] | 91 | #else |
| 92 | return (void *)offset; |
| 93 | #endif |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Adrian Bunk | d99cf71 | 2005-09-03 15:57:53 -0700 | [diff] [blame] | 96 | static inline void iounmap(void *addr) |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 97 | { |
| 98 | } |
| 99 | |
| 100 | /* |
| 101 | * Generic I/O |
| 102 | */ |
| 103 | |
| 104 | #define readb(addr) \ |
| 105 | ({ unsigned char __v = (*(volatile unsigned char *)(addr)); __v; }) |
| 106 | #define readw(addr) \ |
| 107 | ({ unsigned short __v = (*(volatile unsigned short *)(addr)); __v; }) |
| 108 | #define readl(addr) \ |
| 109 | ({ unsigned int __v = (*(volatile unsigned int *)(addr)); __v; }) |
| 110 | #define writeb(b, addr) (void)((*(volatile unsigned char *)(addr)) = (b)) |
| 111 | #define writew(b, addr) (void)((*(volatile unsigned short *)(addr)) = (b)) |
| 112 | #define writel(b, addr) (void)((*(volatile unsigned int *)(addr)) = (b)) |
| 113 | |
| 114 | static inline __u8 __raw_readb(const volatile void __iomem *addr) |
| 115 | { |
| 116 | return *(__force volatile __u8 *)(addr); |
| 117 | } |
| 118 | static inline __u16 __raw_readw(const volatile void __iomem *addr) |
| 119 | { |
| 120 | return *(__force volatile __u16 *)(addr); |
| 121 | } |
| 122 | static inline __u32 __raw_readl(const volatile void __iomem *addr) |
| 123 | { |
| 124 | return *(__force volatile __u32 *)(addr); |
| 125 | } |
| 126 | static inline void __raw_writeb(__u8 b, volatile void __iomem *addr) |
| 127 | { |
| 128 | *(__force volatile __u8 *)(addr) = b; |
| 129 | } |
| 130 | static inline void __raw_writew(__u16 b, volatile void __iomem *addr) |
| 131 | { |
| 132 | *(__force volatile __u16 *)(addr) = b; |
| 133 | } |
| 134 | static inline void __raw_writel(__u32 b, volatile void __iomem *addr) |
| 135 | { |
| 136 | *(__force volatile __u32 *)(addr) = b; |
| 137 | } |
| 138 | |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 139 | /* These are the definitions for the x86 IO instructions |
| 140 | * inb/inw/inl/outb/outw/outl, the "string" versions |
| 141 | * insb/insw/insl/outsb/outsw/outsl, and the "pausing" versions |
| 142 | * inb_p/inw_p/... |
| 143 | * The macros don't do byte-swapping. |
| 144 | */ |
| 145 | |
Chris Zankel | 173d6681 | 2006-12-10 02:18:48 -0800 | [diff] [blame] | 146 | #define inb(port) readb((u8 *)((port))) |
| 147 | #define outb(val, port) writeb((val),(u8 *)((unsigned long)(port))) |
| 148 | #define inw(port) readw((u16 *)((port))) |
| 149 | #define outw(val, port) writew((val),(u16 *)((unsigned long)(port))) |
| 150 | #define inl(port) readl((u32 *)((port))) |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 151 | #define outl(val, port) writel((val),(u32 *)((unsigned long)(port))) |
| 152 | |
| 153 | #define inb_p(port) inb((port)) |
| 154 | #define outb_p(val, port) outb((val), (port)) |
| 155 | #define inw_p(port) inw((port)) |
| 156 | #define outw_p(val, port) outw((val), (port)) |
| 157 | #define inl_p(port) inl((port)) |
| 158 | #define outl_p(val, port) outl((val), (port)) |
| 159 | |
| 160 | extern void insb (unsigned long port, void *dst, unsigned long count); |
| 161 | extern void insw (unsigned long port, void *dst, unsigned long count); |
| 162 | extern void insl (unsigned long port, void *dst, unsigned long count); |
| 163 | extern void outsb (unsigned long port, const void *src, unsigned long count); |
| 164 | extern void outsw (unsigned long port, const void *src, unsigned long count); |
| 165 | extern void outsl (unsigned long port, const void *src, unsigned long count); |
| 166 | |
| 167 | #define IO_SPACE_LIMIT ~0 |
| 168 | |
| 169 | #define memset_io(a,b,c) memset((void *)(a),(b),(c)) |
| 170 | #define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c)) |
| 171 | #define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c)) |
| 172 | |
| 173 | /* At this point the Xtensa doesn't provide byte swap instructions */ |
| 174 | |
| 175 | #ifdef __XTENSA_EB__ |
| 176 | # define in_8(addr) (*(u8*)(addr)) |
| 177 | # define in_le16(addr) _swapw(*(u16*)(addr)) |
| 178 | # define in_le32(addr) _swapl(*(u32*)(addr)) |
| 179 | # define out_8(b, addr) *(u8*)(addr) = (b) |
| 180 | # define out_le16(b, addr) *(u16*)(addr) = _swapw(b) |
| 181 | # define out_le32(b, addr) *(u32*)(addr) = _swapl(b) |
| 182 | #elif defined(__XTENSA_EL__) |
| 183 | # define in_8(addr) (*(u8*)(addr)) |
| 184 | # define in_le16(addr) (*(u16*)(addr)) |
| 185 | # define in_le32(addr) (*(u32*)(addr)) |
| 186 | # define out_8(b, addr) *(u8*)(addr) = (b) |
| 187 | # define out_le16(b, addr) *(u16*)(addr) = (b) |
| 188 | # define out_le32(b, addr) *(u32*)(addr) = (b) |
| 189 | #else |
| 190 | # error processor byte order undefined! |
| 191 | #endif |
| 192 | |
| 193 | |
| 194 | /* |
Chris Zankel | 173d6681 | 2006-12-10 02:18:48 -0800 | [diff] [blame] | 195 | * Convert a physical pointer to a virtual kernel pointer for /dev/mem access |
| 196 | */ |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 197 | #define xlate_dev_mem_ptr(p) __va(p) |
| 198 | |
| 199 | /* |
Chris Zankel | 173d6681 | 2006-12-10 02:18:48 -0800 | [diff] [blame] | 200 | * Convert a virtual cached pointer to an uncached pointer |
| 201 | */ |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 202 | #define xlate_dev_kmem_ptr(p) p |
| 203 | |
| 204 | |
| 205 | #endif /* __KERNEL__ */ |
| 206 | |
| 207 | #endif /* _XTENSA_IO_H */ |