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.
22 #include <sys/cdefs.h>
23 __FBSDID("$FreeBSD$");
25 #include "opt_debug_si.h"
27 #include <sys/param.h>
28 #include <sys/systm.h>
29 #include <sys/kernel.h>
30 #include <sys/module.h>
32 #include <machine/bus.h>
34 #include <machine/resource.h>
36 #include <dev/si/sireg.h>
37 #include <dev/si/sivar.h>
39 #include <isa/isavar.h>
41 /* Look for a valid board at the given mem addr */
43 si_isa_probe(device_t dev)
48 volatile unsigned char was, *ux;
49 volatile unsigned char *maddr;
54 if (isa_get_vendorid(dev))
57 sc = device_get_softc(dev);
58 unit = device_get_unit(dev);
61 sc->sc_mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
63 0, ~0, SIPROBEALLOC, RF_ACTIVE);
64 if (!sc->sc_mem_res) {
65 device_printf(dev, "cannot allocate memory resource\n");
68 paddr = (caddr_t)rman_get_start(sc->sc_mem_res);/* physical */
69 maddr = rman_get_virtual(sc->sc_mem_res); /* in kvm */
71 DPRINT((0, DBG_AUTOBOOT, "si%d: probe at virtual=0x%x physical=0x%x\n",
75 * this is a lie, but it's easier than trying to handle caching
76 * and ram conflicts in the >1M and <16M region.
78 if ((caddr_t)paddr < (caddr_t)0xA0000 ||
79 (caddr_t)paddr >= (caddr_t)0x100000) {
80 device_printf(dev, "maddr (%p) out of range\n", paddr);
84 if (((uintptr_t)paddr & 0x7fff) != 0) {
85 device_printf(dev, "maddr (%p) not on 32k boundary\n", paddr);
89 /* Is there anything out there? (0x17 is just an arbitrary number) */
92 device_printf(dev, "0x17 check fail at phys %p\n", paddr);
96 * Let's look first for a JET ISA card, since that's pretty easy
98 * All jet hosts are supposed to have this string in the IDROM,
99 * but it's not worth checking on self-IDing busses like PCI.
102 unsigned char *jet_chk_str = "JET HOST BY KEV#";
104 for (i = 0; i < strlen(jet_chk_str); i++)
105 if (jet_chk_str[i] != *(maddr + SIJETIDSTR + 2 * i))
108 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL, "si%d: JET first check - 0x%x\n",
109 unit, (*(maddr+SIJETIDBASE))));
110 if (*(maddr+SIJETIDBASE) != (SISPLXID&0xff))
112 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL, "si%d: JET second check - 0x%x\n",
113 unit, (*(maddr+SIJETIDBASE+2))));
114 if (*(maddr+SIJETIDBASE+2) != ((SISPLXID&0xff00)>>8))
116 /* It must be a Jet ISA or RIO card */
117 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL, "si%d: JET id check - 0x%x\n",
118 unit, (*(maddr+SIUNIQID))));
119 if ((*(maddr+SIUNIQID) & 0xf0) != 0x20)
121 /* It must be a Jet ISA SI/XIO card */
122 *(maddr + SIJETCONFIG) = 0;
124 ramsize = SIJET_RAMSIZE;
129 * OK, now to see if whatever responded is really an SI card.
130 * Try for a MK II next (SIHOST2)
132 for (i = SIPLSIG; i < SIPLSIG + 8; i++)
133 if ((*(maddr+i) & 7) != (~(unsigned char)i & 7))
136 /* It must be an SIHOST2 */
137 *(maddr + SIPLRESET) = 0;
138 *(maddr + SIPLIRQCLR) = 0;
139 *(maddr + SIPLIRQSET) = 0x10;
141 ramsize = SIHOST2_RAMSIZE;
146 * Its not a MK II, so try for a MK I (SIHOST)
148 *(maddr+SIRESET) = 0x0; /* reset the card */
149 *(maddr+SIINTCL) = 0x0; /* clear int */
150 *(maddr+SIRAM) = 0x17;
151 if (*(maddr+SIRAM) != (unsigned char)0x17)
153 *(maddr+0x7ff8) = 0x17;
154 if (*(maddr+0x7ff8) != (unsigned char)0x17) {
155 device_printf(dev, "0x17 check fail at phys %p = 0x%x\n",
156 paddr+0x77f8, *(maddr+0x77f8));
160 /* It must be an SIHOST (maybe?) - there must be a better way XXX */
162 ramsize = SIHOST_RAMSIZE;
165 DPRINT((0, DBG_AUTOBOOT, "si%d: found type %d card, try memory test\n",
167 /* Try the acid test */
169 for (i = 0; i < ramsize; i++, ux++)
170 *ux = (unsigned char)(i&0xff);
172 for (i = 0; i < ramsize; i++, ux++) {
173 if ((was = *ux) != (unsigned char)(i&0xff)) {
175 "memtest fail at phys %p, was %x should be %x\n",
176 paddr + i, was, i & 0xff);
181 /* clear out the RAM */
183 for (i = 0; i < ramsize; i++)
186 for (i = 0; i < ramsize; i++) {
187 if ((was = *ux++) != 0) {
188 device_printf(dev, "clear fail at phys %p, was %x\n",
195 * Success, we've found a valid board, now fill in
196 * the adapter structure.
200 switch (isa_get_irq(dev)) {
207 "bad IRQ value - %d (11, 12, 15 allowed)\n",
211 sc->sc_memsize = SIHOST2_MEMSIZE;
214 switch (isa_get_irq(dev)) {
221 "bad IRQ value - %d (11, 12, 15 allowed)\n",
225 sc->sc_memsize = SIHOST_MEMSIZE;
228 switch (isa_get_irq(dev)) {
237 "bad IRQ value - %d (9, 10, 11, 12, 15 allowed)\n",
241 sc->sc_memsize = SIJETISA_MEMSIZE;
243 case SIMCA: /* MCA */
245 device_printf(dev, "card type %d not supported\n", type);
249 bus_release_resource(dev, SYS_RES_MEMORY,
250 sc->sc_mem_rid, sc->sc_mem_res);
252 return (0); /* success! */
255 if (sc->sc_mem_res) {
256 bus_release_resource(dev, SYS_RES_MEMORY,
257 sc->sc_mem_rid, sc->sc_mem_res);
264 si_isa_attach(device_t dev)
272 sc = device_get_softc(dev);
275 sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
278 if (!sc->sc_mem_res) {
279 device_printf(dev, "couldn't map memory\n");
282 sc->sc_paddr = (caddr_t)rman_get_start(sc->sc_mem_res);
283 sc->sc_maddr = rman_get_virtual(sc->sc_mem_res);
286 sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ,
288 RF_ACTIVE | RF_SHAREABLE);
289 if (!sc->sc_irq_res) {
290 device_printf(dev, "couldn't allocate interrupt\n");
293 sc->sc_irq = rman_get_start(sc->sc_irq_res);
294 error = bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_TTY,
295 NULL, si_intr, sc, &ih);
297 device_printf(dev, "couldn't activate interrupt\n");
301 error = siattach(dev);
304 return (0); /* success */
309 if (sc->sc_irq_res) {
311 bus_teardown_intr(dev, sc->sc_irq_res, ih);
312 bus_release_resource(dev, SYS_RES_IRQ,
313 sc->sc_irq_rid, sc->sc_irq_res);
316 if (sc->sc_mem_res) {
317 bus_release_resource(dev, SYS_RES_MEMORY,
318 sc->sc_mem_rid, sc->sc_mem_res);
324 static device_method_t si_isa_methods[] = {
325 /* Device interface */
326 DEVMETHOD(device_probe, si_isa_probe),
327 DEVMETHOD(device_attach, si_isa_attach),
332 static driver_t si_isa_driver = {
335 sizeof(struct si_softc),
338 DRIVER_MODULE(si, isa, si_isa_driver, si_devclass, 0, 0);