2 * Device driver for Specialix range (SI/XIO) of serial line multiplexors.
4 * Copyright (C) 2000, Peter Wemm <peter@netplex.com.au>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notices, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notices, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED
16 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
18 * NO EVENT SHALL THE AUTHORS BE LIABLE.
20 * $FreeBSD: src/sys/dev/si/si_isa.c,v 1.1 2000/01/24 07:24:01 peter Exp $
23 #include "opt_debug_si.h"
25 #include <sys/param.h>
26 #include <sys/systm.h>
27 #include <sys/kernel.h>
34 #include <bus/isa/isavar.h>
36 /* Look for a valid board at the given mem addr */
38 si_isa_probe(device_t dev)
43 volatile unsigned char was, *ux;
44 volatile unsigned char *maddr;
48 sc = device_get_softc(dev);
49 unit = device_get_unit(dev);
52 sc->sc_mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
54 0, ~0, SIPROBEALLOC, RF_ACTIVE);
57 paddr = (caddr_t)rman_get_start(sc->sc_mem_res);/* physical */
58 maddr = rman_get_virtual(sc->sc_mem_res); /* in kvm */
60 DPRINT((0, DBG_AUTOBOOT, "si%d: probe at virtual=%p physical=%p\n",
64 * this is a lie, but it's easier than trying to handle caching
65 * and ram conflicts in the >1M and <16M region.
67 if ((caddr_t)paddr < (caddr_t)0xA0000 ||
68 (caddr_t)paddr >= (caddr_t)0x100000) {
69 kprintf("si%d: iomem (%p) out of range\n",
74 if (((uintptr_t)paddr & 0x7fff) != 0) {
75 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL,
76 "si%d: iomem (%p) not on 32k boundary\n", unit, paddr));
80 /* Is there anything out there? (0x17 is just an arbitrary number) */
83 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL,
84 "si%d: 0x17 check fail at phys %p\n", unit, paddr));
88 * Let's look first for a JET ISA card, since that's pretty easy
90 * All jet hosts are supposed to have this string in the IDROM,
91 * but it's not worth checking on self-IDing busses like PCI.
94 unsigned char *jet_chk_str = "JET HOST BY KEV#";
96 for (i = 0; i < strlen(jet_chk_str); i++)
97 if (jet_chk_str[i] != *(maddr + SIJETIDSTR + 2 * i))
100 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL, "si%d: JET first check - 0x%x\n",
101 unit, (*(maddr+SIJETIDBASE))));
102 if (*(maddr+SIJETIDBASE) != (SISPLXID&0xff))
104 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL, "si%d: JET second check - 0x%x\n",
105 unit, (*(maddr+SIJETIDBASE+2))));
106 if (*(maddr+SIJETIDBASE+2) != ((SISPLXID&0xff00)>>8))
108 /* It must be a Jet ISA or RIO card */
109 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL, "si%d: JET id check - 0x%x\n",
110 unit, (*(maddr+SIUNIQID))));
111 if ((*(maddr+SIUNIQID) & 0xf0) != 0x20)
113 /* It must be a Jet ISA SI/XIO card */
114 *(maddr + SIJETCONFIG) = 0;
116 ramsize = SIJET_RAMSIZE;
121 * OK, now to see if whatever responded is really an SI card.
122 * Try for a MK II next (SIHOST2)
124 for (i = SIPLSIG; i < SIPLSIG + 8; i++)
125 if ((*(maddr+i) & 7) != (~(unsigned char)i & 7))
128 /* It must be an SIHOST2 */
129 *(maddr + SIPLRESET) = 0;
130 *(maddr + SIPLIRQCLR) = 0;
131 *(maddr + SIPLIRQSET) = 0x10;
133 ramsize = SIHOST2_RAMSIZE;
138 * Its not a MK II, so try for a MK I (SIHOST)
140 *(maddr+SIRESET) = 0x0; /* reset the card */
141 *(maddr+SIINTCL) = 0x0; /* clear int */
142 *(maddr+SIRAM) = 0x17;
143 if (*(maddr+SIRAM) != (unsigned char)0x17)
145 *(maddr+0x7ff8) = 0x17;
146 if (*(maddr+0x7ff8) != (unsigned char)0x17) {
147 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL,
148 "si%d: 0x17 check fail at phys %p = 0x%x\n",
149 unit, paddr+0x77f8, *(maddr+0x77f8)));
153 /* It must be an SIHOST (maybe?) - there must be a better way XXX */
155 ramsize = SIHOST_RAMSIZE;
158 DPRINT((0, DBG_AUTOBOOT, "si%d: found type %d card, try memory test\n",
160 /* Try the acid test */
162 for (i = 0; i < ramsize; i++, ux++)
163 *ux = (unsigned char)(i&0xff);
165 for (i = 0; i < ramsize; i++, ux++) {
166 if ((was = *ux) != (unsigned char)(i&0xff)) {
167 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL,
168 "si%d: match fail at phys %p, was %x should be %x\n",
169 unit, paddr + i, was, i&0xff));
174 /* clear out the RAM */
176 for (i = 0; i < ramsize; i++)
179 for (i = 0; i < ramsize; i++) {
180 if ((was = *ux++) != 0) {
181 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL,
182 "si%d: clear fail at phys %p, was %x\n",
183 unit, paddr + i, was));
189 * Success, we've found a valid board, now fill in
190 * the adapter structure.
194 switch (isa_get_irq(dev)) {
201 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL,
202 "si%d: bad IRQ value - %d\n",
203 unit, isa_get_irq(dev)));
206 sc->sc_memsize = SIHOST2_MEMSIZE;
209 switch (isa_get_irq(dev)) {
217 sc->sc_memsize = SIHOST_MEMSIZE;
220 switch (isa_get_irq(dev)) {
230 sc->sc_memsize = SIJETISA_MEMSIZE;
232 case SIMCA: /* MCA */
234 kprintf("si%d: card type %d not supported\n", unit, type);
238 bus_release_resource(dev, SYS_RES_MEMORY,
239 sc->sc_mem_rid, sc->sc_mem_res);
241 return (0); /* success! */
244 if (sc->sc_mem_res) {
245 bus_release_resource(dev, SYS_RES_MEMORY,
246 sc->sc_mem_rid, sc->sc_mem_res);
253 si_isa_attach(device_t dev)
261 sc = device_get_softc(dev);
264 sc->sc_mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
266 0, ~0, 1, RF_ACTIVE);
267 if (!sc->sc_mem_res) {
268 device_printf(dev, "couldn't map memory\n");
271 sc->sc_paddr = (caddr_t)rman_get_start(sc->sc_mem_res);
272 sc->sc_maddr = rman_get_virtual(sc->sc_mem_res);
275 sc->sc_irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->sc_irq_rid,
276 0, ~0, 1, RF_ACTIVE | RF_SHAREABLE);
277 if (!sc->sc_irq_res) {
278 device_printf(dev, "couldn't allocate interrupt\n");
281 sc->sc_irq = rman_get_start(sc->sc_irq_res);
282 error = bus_setup_intr(dev, sc->sc_irq_res, INTR_MPSAFE, si_intr, sc, &ih, NULL);
284 device_printf(dev, "couldn't activate interrupt\n");
288 error = siattach(dev);
291 return (0); /* success */
296 if (sc->sc_irq_res) {
298 bus_teardown_intr(dev, sc->sc_irq_res, ih);
299 bus_release_resource(dev, SYS_RES_IRQ,
300 sc->sc_irq_rid, sc->sc_irq_res);
303 if (sc->sc_mem_res) {
304 bus_release_resource(dev, SYS_RES_MEMORY,
305 sc->sc_mem_rid, sc->sc_mem_res);
311 static device_method_t si_isa_methods[] = {
312 /* Device interface */
313 DEVMETHOD(device_probe, si_isa_probe),
314 DEVMETHOD(device_attach, si_isa_attach),
319 static driver_t si_isa_driver = {
322 sizeof(struct si_softc),
325 DRIVER_MODULE(si, isa, si_isa_driver, si_devclass, NULL, NULL);