blob: 07b7299dab20e3ccb8c6c5740d408cf577d8174f [file] [log] [blame]
Chris Zankel9a8fd552005-06-23 22:01:26 -07001/*
Chris Zankel173d6682006-12-10 02:18:48 -08002 * include/asm-xtensa/io.h
Chris Zankel9a8fd552005-06-23 22:01:26 -07003 *
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 Zankel9a8fd552005-06-23 22:01:26 -070015#include <asm/byteorder.h>
Adrian Bunkc51aea82007-07-23 18:43:54 -070016#include <asm/page.h>
Chris Zankel66569202007-08-22 10:14:51 -070017#include <linux/kernel.h>
Chris Zankel9a8fd552005-06-23 22:01:26 -070018
19#include <linux/types.h>
Chris Zankel9a8fd552005-06-23 22:01:26 -070020
Chris Zankel00c81d22008-10-21 09:08:31 -070021#define XCHAL_KIO_CACHED_VADDR 0xe0000000
22#define XCHAL_KIO_BYPASS_VADDR 0xf0000000
Chris Zankel173d6682006-12-10 02:18:48 -080023#define XCHAL_KIO_PADDR 0xf0000000
Chris Zankel00c81d22008-10-21 09:08:31 -070024#define XCHAL_KIO_SIZE 0x10000000
25
26#define IOADDR(x) (XCHAL_KIO_BYPASS_VADDR + (x))
Chris Zankel9a8fd552005-06-23 22:01:26 -070027
28/*
29 * swap functions to change byte order from little-endian to big-endian and
30 * vice versa.
31 */
32
33static inline unsigned short _swapw (unsigned short v)
34{
35 return (v << 8) | (v >> 8);
36}
37
38static 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 Bunkd99cf712005-09-03 15:57:53 -070048static inline unsigned long virt_to_phys(volatile void * address)
Chris Zankel9a8fd552005-06-23 22:01:26 -070049{
Chris Zankel173d6682006-12-10 02:18:48 -080050 return __pa(address);
Chris Zankel9a8fd552005-06-23 22:01:26 -070051}
52
Adrian Bunkd99cf712005-09-03 15:57:53 -070053static inline void * phys_to_virt(unsigned long address)
Chris Zankel9a8fd552005-06-23 22:01:26 -070054{
Chris Zankel173d6682006-12-10 02:18:48 -080055 return __va(address);
Chris Zankel9a8fd552005-06-23 22:01:26 -070056}
57
58/*
Chris Zankel173d6682006-12-10 02:18:48 -080059 * virt_to_bus and bus_to_virt are deprecated.
Chris Zankel9a8fd552005-06-23 22:01:26 -070060 */
61
Chris Zankel173d6682006-12-10 02:18:48 -080062#define virt_to_bus(x) virt_to_phys(x)
63#define bus_to_virt(x) phys_to_virt(x)
Chris Zankel9a8fd552005-06-23 22:01:26 -070064
65/*
Chris Zankel173d6682006-12-10 02:18:48 -080066 * 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 Zankel9a8fd552005-06-23 22:01:26 -070068 */
69
Adrian Bunkd99cf712005-09-03 15:57:53 -070070static inline void *ioremap(unsigned long offset, unsigned long size)
Chris Zankel9a8fd552005-06-23 22:01:26 -070071{
Chris Zankel173d6682006-12-10 02:18:48 -080072 if (offset >= XCHAL_KIO_PADDR
73 && offset < XCHAL_KIO_PADDR + XCHAL_KIO_SIZE)
74 return (void*)(offset-XCHAL_KIO_PADDR+XCHAL_KIO_BYPASS_VADDR);
75
76 else
77 BUG();
Chris Zankel9a8fd552005-06-23 22:01:26 -070078}
79
Adrian Bunkd99cf712005-09-03 15:57:53 -070080static inline void *ioremap_nocache(unsigned long offset, unsigned long size)
Chris Zankel9a8fd552005-06-23 22:01:26 -070081{
Chris Zankel173d6682006-12-10 02:18:48 -080082 if (offset >= XCHAL_KIO_PADDR
83 && offset < XCHAL_KIO_PADDR + XCHAL_KIO_SIZE)
84 return (void*)(offset-XCHAL_KIO_PADDR+XCHAL_KIO_CACHED_VADDR);
85 else
86 BUG();
Chris Zankel9a8fd552005-06-23 22:01:26 -070087}
88
Adrian Bunkd99cf712005-09-03 15:57:53 -070089static inline void iounmap(void *addr)
Chris Zankel9a8fd552005-06-23 22:01:26 -070090{
91}
92
93/*
94 * Generic I/O
95 */
96
97#define readb(addr) \
98 ({ unsigned char __v = (*(volatile unsigned char *)(addr)); __v; })
99#define readw(addr) \
100 ({ unsigned short __v = (*(volatile unsigned short *)(addr)); __v; })
101#define readl(addr) \
102 ({ unsigned int __v = (*(volatile unsigned int *)(addr)); __v; })
103#define writeb(b, addr) (void)((*(volatile unsigned char *)(addr)) = (b))
104#define writew(b, addr) (void)((*(volatile unsigned short *)(addr)) = (b))
105#define writel(b, addr) (void)((*(volatile unsigned int *)(addr)) = (b))
106
107static inline __u8 __raw_readb(const volatile void __iomem *addr)
108{
109 return *(__force volatile __u8 *)(addr);
110}
111static inline __u16 __raw_readw(const volatile void __iomem *addr)
112{
113 return *(__force volatile __u16 *)(addr);
114}
115static inline __u32 __raw_readl(const volatile void __iomem *addr)
116{
117 return *(__force volatile __u32 *)(addr);
118}
119static inline void __raw_writeb(__u8 b, volatile void __iomem *addr)
120{
121 *(__force volatile __u8 *)(addr) = b;
122}
123static inline void __raw_writew(__u16 b, volatile void __iomem *addr)
124{
125 *(__force volatile __u16 *)(addr) = b;
126}
127static inline void __raw_writel(__u32 b, volatile void __iomem *addr)
128{
129 *(__force volatile __u32 *)(addr) = b;
130}
131
Chris Zankel9a8fd552005-06-23 22:01:26 -0700132/* These are the definitions for the x86 IO instructions
133 * inb/inw/inl/outb/outw/outl, the "string" versions
134 * insb/insw/insl/outsb/outsw/outsl, and the "pausing" versions
135 * inb_p/inw_p/...
136 * The macros don't do byte-swapping.
137 */
138
Chris Zankel173d6682006-12-10 02:18:48 -0800139#define inb(port) readb((u8 *)((port)))
140#define outb(val, port) writeb((val),(u8 *)((unsigned long)(port)))
141#define inw(port) readw((u16 *)((port)))
142#define outw(val, port) writew((val),(u16 *)((unsigned long)(port)))
143#define inl(port) readl((u32 *)((port)))
Chris Zankel9a8fd552005-06-23 22:01:26 -0700144#define outl(val, port) writel((val),(u32 *)((unsigned long)(port)))
145
146#define inb_p(port) inb((port))
147#define outb_p(val, port) outb((val), (port))
148#define inw_p(port) inw((port))
149#define outw_p(val, port) outw((val), (port))
150#define inl_p(port) inl((port))
151#define outl_p(val, port) outl((val), (port))
152
153extern void insb (unsigned long port, void *dst, unsigned long count);
154extern void insw (unsigned long port, void *dst, unsigned long count);
155extern void insl (unsigned long port, void *dst, unsigned long count);
156extern void outsb (unsigned long port, const void *src, unsigned long count);
157extern void outsw (unsigned long port, const void *src, unsigned long count);
158extern void outsl (unsigned long port, const void *src, unsigned long count);
159
160#define IO_SPACE_LIMIT ~0
161
162#define memset_io(a,b,c) memset((void *)(a),(b),(c))
163#define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c))
164#define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c))
165
166/* At this point the Xtensa doesn't provide byte swap instructions */
167
168#ifdef __XTENSA_EB__
169# define in_8(addr) (*(u8*)(addr))
170# define in_le16(addr) _swapw(*(u16*)(addr))
171# define in_le32(addr) _swapl(*(u32*)(addr))
172# define out_8(b, addr) *(u8*)(addr) = (b)
173# define out_le16(b, addr) *(u16*)(addr) = _swapw(b)
174# define out_le32(b, addr) *(u32*)(addr) = _swapl(b)
175#elif defined(__XTENSA_EL__)
176# define in_8(addr) (*(u8*)(addr))
177# define in_le16(addr) (*(u16*)(addr))
178# define in_le32(addr) (*(u32*)(addr))
179# define out_8(b, addr) *(u8*)(addr) = (b)
180# define out_le16(b, addr) *(u16*)(addr) = (b)
181# define out_le32(b, addr) *(u32*)(addr) = (b)
182#else
183# error processor byte order undefined!
184#endif
185
186
187/*
Chris Zankel173d6682006-12-10 02:18:48 -0800188 * Convert a physical pointer to a virtual kernel pointer for /dev/mem access
189 */
Chris Zankel9a8fd552005-06-23 22:01:26 -0700190#define xlate_dev_mem_ptr(p) __va(p)
191
192/*
Chris Zankel173d6682006-12-10 02:18:48 -0800193 * Convert a virtual cached pointer to an uncached pointer
194 */
Chris Zankel9a8fd552005-06-23 22:01:26 -0700195#define xlate_dev_kmem_ptr(p) p
196
197
198#endif /* __KERNEL__ */
199
200#endif /* _XTENSA_IO_H */