Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / x68k / dev / xel.c
blob0387d75be4a8578f255c4aae47e06d46b33cb640
1 /* $NetBSD: xel.c,v 1.16 2008/12/18 05:56:42 isaki Exp $ */
3 /*
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Minoura Makoto.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * TSR Xellent30 driver.
34 * Detect Xellent30, and reserve its I/O area.
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: xel.c,v 1.16 2008/12/18 05:56:42 isaki Exp $");
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
43 #include <sys/device.h>
45 #include <machine/cpu.h>
46 #include <machine/bus.h>
48 #include <arch/x68k/dev/intiovar.h>
50 static paddr_t xel_addr(device_t, cfdata_t, struct intio_attach_args *);
51 static int xel_probe(paddr_t);
52 static int xel_match(device_t, cfdata_t, void *);
53 static void xel_attach(device_t, device_t, void *);
55 struct xel_softc {
56 bus_space_tag_t sc_bst;
57 bus_space_handle_t sc_bh;
60 CFATTACH_DECL_NEW(xel, sizeof(struct xel_softc),
61 xel_match, xel_attach, NULL, NULL);
63 static paddr_t xel_addrs[] = { 0xec0000, 0xec4000, 0xec8000, 0xecc000 };
65 #define XEL_MODE_RAM_LOWER 0x00
66 #define XEL_MODE_RAM_HIGHER 0x01
67 #define XEL_MODE_UNMAP_RAM 0x00
68 #define XEL_MODE_MAP_RAM 0x02
69 #define XEL_MODE_MPU_000 0x00
70 #define XEL_MODE_MPU_030 0x04
72 #define XEL_RAM_ADDR_LOWER 0xbc0000
73 #define XEL_RAM_ADDR_HIGHER 0xfc0000
76 static paddr_t
77 xel_addr(device_t parent, cfdata_t match, struct intio_attach_args *ia)
79 paddr_t addr = 0;
81 if (match->cf_addr == INTIOCF_ADDR_DEFAULT) {
82 int i;
84 for (i = 0; i < sizeof(xel_addrs)/sizeof(xel_addrs[0]); i++) {
85 if (xel_probe(xel_addrs[i])) {
86 addr = xel_addrs[i];
87 break;
90 } else {
91 if (xel_probe((paddr_t) match->cf_addr))
92 addr = (paddr_t) match->cf_addr;
95 if (addr) {
96 /* found! */
97 ia->ia_addr = (int) addr;
98 ia->ia_size = 0x4000;
99 if (intio_map_allocate_region(parent, ia, INTIO_MAP_TESTONLY)
100 < 0)
101 return 0;
102 else
103 return addr;
106 return 0;
109 extern int *nofault;
111 static int
112 xel_probe(paddr_t addr)
114 u_int32_t b1, b2;
115 volatile u_int16_t *start = (volatile u_int16_t *)IIOV(addr);
116 label_t faultbuf;
117 volatile u_int32_t *sram = (volatile u_int32_t *)IIOV(XEL_RAM_ADDR_HIGHER);
119 if (badaddr(start))
120 return 0;
122 nofault = (int *) &faultbuf;
123 if (setjmp(&faultbuf)) {
124 nofault = NULL;
125 return 0;
128 b1 = sram[0];
129 b2 = sram[1];
130 /* Try to map the Xellent local memory. */
131 start[0] = XEL_MODE_RAM_HIGHER | XEL_MODE_MAP_RAM | XEL_MODE_MPU_030;
133 #if 0
134 /* the contents should be deferent. */
135 if (b1 == sram[0] && b2 == sram[1]) {
136 nofault = (int *) 0;
137 return 0;
139 #else
140 /* Try to write to the local memory. */
141 sram[0] = 0x55555555;
142 sram[1] = 0xaaaaaaaa;
143 if (sram[0] != 0x55555555 || sram[1] != 0xaaaaaaaa) {
144 sram[0] = b1;
145 sram[1] = b2;
146 nofault = (int *) 0;
147 return 0;
149 sram[0] = 0xaaaaaaaa;
150 sram[1] = 0x55555555;
151 if (sram[0] != 0xaaaaaaaa || sram[1] != 0x55555555) {
152 sram[0] = b1;
153 sram[1] = b2;
154 nofault = (int *) 0;
155 return 0;
157 sram[0] = b1;
158 sram[1] = b2;
159 #endif
161 /* Unmap. */
162 start[0] = XEL_MODE_UNMAP_RAM | XEL_MODE_MPU_030;
164 nofault = NULL;
165 return 1;
168 static int
169 xel_match(device_t parent, cfdata_t match, void *aux)
171 struct intio_attach_args *ia = aux;
173 if (strcmp(ia->ia_name, "xel") != 0)
174 return 0;
176 if (xel_addr(parent, match, ia)) {
177 #ifdef DIAGNOSTIC
178 if (cputype != CPU_68030)
179 panic("Non-030 Xellent???");
180 #endif
181 return 1;
183 return 0;
186 static void
187 xel_attach(device_t parent, device_t self, void *aux)
189 struct xel_softc *sc = device_private(self);
190 struct intio_attach_args *ia = aux;
191 cfdata_t cf = device_cfdata(self);
192 paddr_t addr;
193 int r;
195 addr = xel_addr(parent, cf, aux);
196 sc->sc_bst = ia->ia_bst;
197 ia->ia_addr = (int) addr;
198 ia->ia_size = 0x4000;
199 r = intio_map_allocate_region(parent, ia, INTIO_MAP_ALLOCATE);
200 #ifdef DIAGNOSTIC
201 if (r)
202 panic("IO map for Xellent30 corruption??");
203 #endif
204 aprint_normal(": Xellent30 MPU Accelerator.\n");
206 return;