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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
/* $NetBSD: xel.c,v 1.18 2014/03/26 08:17:59 christos Exp $ */
/*
* Copyright (c) 1998 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Minoura Makoto.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* TSR Xellent30 driver.
* Detect Xellent30, and reserve its I/O area.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: xel.c,v 1.18 2014/03/26 08:17:59 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/device.h>
#include <machine/cpu.h>
#include <machine/bus.h>
#include <arch/x68k/dev/intiovar.h>
static paddr_t xel_addr(device_t, cfdata_t, struct intio_attach_args *);
static int xel_probe(paddr_t);
static int xel_match(device_t, cfdata_t, void *);
static void xel_attach(device_t, device_t, void *);
struct xel_softc {
bus_space_tag_t sc_bst;
bus_space_handle_t sc_bh;
};
CFATTACH_DECL_NEW(xel, sizeof(struct xel_softc),
xel_match, xel_attach, NULL, NULL);
static paddr_t xel_addrs[] = { 0xec0000, 0xec4000, 0xec8000, 0xecc000 };
#define XEL_MODE_RAM_LOWER 0x00
#define XEL_MODE_RAM_HIGHER 0x01
#define XEL_MODE_UNMAP_RAM 0x00
#define XEL_MODE_MAP_RAM 0x02
#define XEL_MODE_MPU_000 0x00
#define XEL_MODE_MPU_030 0x04
#define XEL_RAM_ADDR_LOWER 0xbc0000
#define XEL_RAM_ADDR_HIGHER 0xfc0000
static paddr_t
xel_addr(device_t parent, cfdata_t match, struct intio_attach_args *ia)
{
paddr_t addr = 0;
if (match->cf_addr == INTIOCF_ADDR_DEFAULT) {
int i;
for (i = 0; i < sizeof(xel_addrs)/sizeof(xel_addrs[0]); i++) {
if (xel_probe(xel_addrs[i])) {
addr = xel_addrs[i];
break;
}
}
} else {
if (xel_probe((paddr_t) match->cf_addr))
addr = (paddr_t) match->cf_addr;
}
if (addr) {
/* found! */
ia->ia_addr = (int) addr;
ia->ia_size = 0x4000;
if (intio_map_allocate_region(parent, ia, INTIO_MAP_TESTONLY)
< 0)
return 0;
else
return addr;
}
return 0;
}
extern int *nofault;
static int
xel_probe(paddr_t addr)
{
u_int32_t b1, b2;
volatile u_int16_t *start = (volatile u_int16_t *)IIOV(addr);
label_t faultbuf;
volatile u_int32_t *sram = (volatile u_int32_t *)IIOV(XEL_RAM_ADDR_HIGHER);
if (badaddr(start))
return 0;
nofault = (int *) &faultbuf;
if (setjmp(&faultbuf)) {
nofault = NULL;
return 0;
}
b1 = sram[0];
b2 = sram[1];
/* Try to map the Xellent local memory. */
start[0] = XEL_MODE_RAM_HIGHER | XEL_MODE_MAP_RAM | XEL_MODE_MPU_030;
#if 0
/* the contents should be deferent. */
if (b1 == sram[0] && b2 == sram[1]) {
nofault = (int *) 0;
return 0;
}
#else
/* Try to write to the local memory. */
sram[0] = 0x55555555;
sram[1] = 0xaaaaaaaa;
if (sram[0] != 0x55555555 || sram[1] != 0xaaaaaaaa) {
sram[0] = b1;
sram[1] = b2;
nofault = (int *) 0;
return 0;
}
sram[0] = 0xaaaaaaaa;
sram[1] = 0x55555555;
if (sram[0] != 0xaaaaaaaa || sram[1] != 0x55555555) {
sram[0] = b1;
sram[1] = b2;
nofault = (int *) 0;
return 0;
}
sram[0] = b1;
sram[1] = b2;
#endif
/* Unmap. */
start[0] = XEL_MODE_UNMAP_RAM | XEL_MODE_MPU_030;
nofault = NULL;
return 1;
}
static int
xel_match(device_t parent, cfdata_t match, void *aux)
{
struct intio_attach_args *ia = aux;
if (strcmp(ia->ia_name, "xel") != 0)
return 0;
if (xel_addr(parent, match, ia)) {
#ifdef DIAGNOSTIC
if (cputype != CPU_68030)
panic("Non-030 Xellent???");
#endif
return 1;
}
return 0;
}
static void
xel_attach(device_t parent, device_t self, void *aux)
{
struct xel_softc *sc = device_private(self);
struct intio_attach_args *ia = aux;
cfdata_t cf = device_cfdata(self);
paddr_t addr;
int r __diagused;
addr = xel_addr(parent, cf, aux);
sc->sc_bst = ia->ia_bst;
ia->ia_addr = (int) addr;
ia->ia_size = 0x4000;
r = intio_map_allocate_region(parent, ia, INTIO_MAP_ALLOCATE);
#ifdef DIAGNOSTIC
if (r)
panic("IO map for Xellent30 corruption??");
#endif
aprint_normal(": Xellent30 MPU Accelerator.\n");
return;
}
|