summaryrefslogtreecommitdiffstats
path: root/arch/mips/sni/io.c
blob: 8a97b80a81ead25eb06f2ff7f711703fed683317 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 *
 * Low level I/O functions for SNI.
 *
 * $Id: io.c,v 1.2 1998/03/27 08:53:50 ralf Exp $
 */
#include <linux/string.h>
#include <asm/mipsconfig.h>
#include <asm/addrspace.h>
#include <asm/system.h>
#include <asm/spinlock.h>
#include <asm/sni.h>

unsigned char sni_map_isa_cache;

#define unused __attribute__((unused))

/*
 * The PCIMT_CSMAPISA is shared by all processors; we need locking.
 *
 * XXX It's legal to use all the I/O memory access functions in interrupt
 * code, so we need to use the _irq locking stuff which may result in
 * significant IRQ latencies.
 */
static spinlock_t csmapisa_lock unused = SPIN_LOCK_UNLOCKED;

/*
 * Urgs...  We only can see a 16mb window of the 4gb EISA address space
 * at PCIMT_EISA_BASE.  Maladia segmentitis ...
 *
 * XXX Check out if accessing PCIMT_CSMAPISA really is slow.
 * For now assume so.
 */
static inline void update_isa_cache(unsigned long address)
{
	unsigned char upper;

	upper = address >> 24;
	if (sni_map_isa_cache != upper) {
		sni_map_isa_cache = upper;
		*(volatile unsigned char *)PCIMT_CSMAPISA = ~upper;
	}
}

static unsigned char sni_readb(unsigned long addr)
{
	unsigned char res;

	spin_lock_irq(&csmapisa_lock);
	update_isa_cache(addr);
	addr &= 0xffffff;
	res = *(volatile unsigned char *) (PCIMT_EISA_BASE + addr);
	spin_unlock_irq(&csmapisa_lock);

	return res;
}

static unsigned short sni_readw(unsigned long addr)
{
	unsigned short res;

	spin_lock_irq(&csmapisa_lock);
	update_isa_cache(addr);
	addr &= 0xffffff;
	res = *(volatile unsigned char *) (PCIMT_EISA_BASE + addr);
	spin_unlock_irq(&csmapisa_lock);

	return res;
}

static unsigned int sni_readl(unsigned long addr)
{
	unsigned int res;

	spin_lock_irq(&csmapisa_lock);
	update_isa_cache(addr);
	addr &= 0xffffff;
	res = *(volatile unsigned char *) (PCIMT_EISA_BASE + addr);
	spin_unlock_irq(&csmapisa_lock);

	return res;
}

static void sni_writeb(unsigned char val, unsigned long addr)
{
	spin_lock_irq(&csmapisa_lock);
	update_isa_cache(addr);
	addr &= 0xffffff;
	*(volatile unsigned char *) (PCIMT_EISA_BASE + addr) = val;
	spin_unlock_irq(&csmapisa_lock);
}

static void sni_writew(unsigned short val, unsigned long addr)
{
	spin_lock_irq(&csmapisa_lock);
	update_isa_cache(addr);
	addr &= 0xffffff;
	*(volatile unsigned char *) (PCIMT_EISA_BASE + addr) = val;
	spin_unlock_irq(&csmapisa_lock);
}

static void sni_writel(unsigned int val, unsigned long addr)
{
	spin_lock_irq(&csmapisa_lock);
	update_isa_cache(addr);
	addr &= 0xffffff;
	*(volatile unsigned char *) (PCIMT_EISA_BASE + addr) = val;
	spin_unlock_irq(&csmapisa_lock);
}

static void sni_memset_io(unsigned long addr, int val, unsigned long len)
{
	unsigned long waddr;

	waddr = PCIMT_EISA_BASE | (addr & 0xffffff);
	spin_lock_irq(&csmapisa_lock);
	while(len) {
		unsigned long fraglen;

		fraglen = (~addr + 1) & 0xffffff;
		fraglen = (fraglen < len) ? fraglen : len;
		update_isa_cache(addr);
		memset((char *)waddr, val, fraglen);
		addr += fraglen;
		waddr = waddr + fraglen - 0x1000000;
		len -= fraglen;
	}
	spin_unlock_irq(&csmapisa_lock);
}

static void sni_memcpy_fromio(unsigned long to, unsigned long from, unsigned long len)
{
	unsigned long waddr;

	waddr = PCIMT_EISA_BASE | (from & 0xffffff);
	spin_lock_irq(&csmapisa_lock);
	while(len) {
		unsigned long fraglen;

		fraglen = (~from + 1) & 0xffffff;
		fraglen = (fraglen < len) ? fraglen : len;
		update_isa_cache(from);
		memcpy((void *)to, (void *)waddr, fraglen);
		to += fraglen;
		from += fraglen;
		waddr = waddr + fraglen - 0x1000000;
		len -= fraglen;
	}
	spin_unlock_irq(&csmapisa_lock);
}

static void sni_memcpy_toio(unsigned long to, unsigned long from, unsigned long len)
{
	unsigned long waddr;

	waddr = PCIMT_EISA_BASE | (to & 0xffffff);
	spin_lock_irq(&csmapisa_lock);
	while(len) {
		unsigned long fraglen;

		fraglen = (~to + 1) & 0xffffff;
		fraglen = (fraglen < len) ? fraglen : len;
		update_isa_cache(to);
		memcpy((char *)to + PCIMT_EISA_BASE, (void *)from, fraglen);
		to += fraglen;
		from += fraglen;
		waddr = waddr + fraglen - 0x1000000;
		len -= fraglen;
	}
	spin_unlock_irq(&csmapisa_lock);
}