scsirom.c revision 1.4       1 /*	$NetBSD: scsirom.c,v 1.4 1999/04/22 12:55:53 minoura Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1999 NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Minoura Makoto.
      9  *
     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.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *      This product includes software developed by Charles D. Cranor and
     21  *      Washington University.
     22  * 4. The name of the author may not be used to endorse or promote products
     23  *    derived from this software without specific prior written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     26  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     27  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     28  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     30  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     31  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     32  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     33  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     34  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     35  */
     36 
     37 /*
     38  * SCSI BIOS ROM.
     39  * Used to probe the board.
     40  */
     41 
     42 #include <sys/param.h>
     43 #include <sys/systm.h>
     44 #include <sys/device.h>
     45 
     46 #include <machine/bus.h>
     47 #include <machine/cpu.h>
     48 
     49 #include <arch/x68k/dev/intiovar.h>
     50 #include <arch/x68k/dev/scsiromvar.h>
     51 
     52 struct {
     53 	paddr_t addr, devaddr;
     54 	int intr;
     55 	const char id[7];
     56 } scsirom_descr[] = {{
     57 	0x00fc0000, 0x00e96020, 108, "SCSIIN"
     58 }, {
     59 	0x00ea0020, 0x00ea0000, 246, "SCSIEX"
     60 }};
     61 
     62 #define SCSIROM_ID	0x24
     63 
     64 /*
     65  * autoconf stuff
     66  */
     67 static int scsirom_find __P((struct device *, struct intio_attach_args *));
     68 static int scsirom_match __P((struct device *, struct cfdata *, void *));
     69 static void scsirom_attach __P((struct device *, struct device *, void *));
     70 
     71 struct cfattach scsirom_ca = {
     72 	sizeof(struct scsirom_softc), scsirom_match, scsirom_attach
     73 };
     74 
     75 static int
     76 scsirom_find (parent, ia)
     77 	struct device *parent;
     78 	struct intio_attach_args *ia;
     79 {
     80 	bus_space_handle_t ioh;
     81 	char buf[10];
     82 	int which;
     83 	int r = -1;
     84 
     85 	if (ia->ia_addr == scsirom_descr[INTERNAL].addr)
     86 		which = INTERNAL;
     87 	else if (ia->ia_addr == scsirom_descr[EXTERNAL].addr)
     88 		which = EXTERNAL;
     89 	else
     90 		return -1;
     91 
     92 	ia->ia_size = 0x1fe0;
     93 	if (intio_map_allocate_region (parent, ia, INTIO_MAP_TESTONLY))
     94 		return -1;
     95 
     96 	if (bus_space_map (ia->ia_bst, ia->ia_addr, ia->ia_size, 0, &ioh) < 0)
     97 		return -1;
     98 	if (badaddr ((caddr_t)INTIO_ADDR(ia->ia_addr+SCSIROM_ID))) {
     99 		bus_space_unmap (ia->ia_bst, ioh, ia->ia_size);
    100 		return -1;
    101 	}
    102 	if (memcmp(buf, scsirom_descr[which].id, 6) == 0)
    103 		r = which;
    104 	bus_space_unmap (ia->ia_bst, ioh, ia->ia_size);
    105 
    106 	return r;
    107 }
    108 
    109 static int
    110 scsirom_match(parent, cf, aux)
    111 	struct device *parent;
    112 	struct cfdata *cf;
    113 	void *aux;
    114 {
    115 	struct intio_attach_args *ia = aux;
    116 	int r;
    117 
    118 	if (strcmp (ia->ia_name, "scsirom") != 0)
    119 		return 0;
    120 
    121 	if (ia->ia_addr == INTIOCF_ADDR_DEFAULT) {
    122 		ia->ia_addr = scsirom_descr[0].addr;
    123 		r = scsirom_find (parent, ia);
    124 		if (r == INTERNAL)
    125 			return 1;
    126 		ia->ia_addr = scsirom_descr[1].addr;
    127 		r = scsirom_find (parent, ia);
    128 		if (r == EXTERNAL)
    129 			return 1;
    130 		return 0;
    131 	} else if (scsirom_find(parent, ia) >= 0)
    132 		return 1;
    133 	else
    134 		return 0;
    135 }
    136 
    137 static void
    138 scsirom_attach(parent, self, aux)
    139 	struct device *parent, *self;
    140 	void *aux;
    141 {
    142 	struct scsirom_softc *sc = (struct scsirom_softc *)self;
    143 	struct intio_attach_args *ia = aux;
    144 	int r;
    145 	struct cfdata *cf;
    146 
    147 	sc->sc_addr = ia->ia_addr;
    148 	sc->sc_which = scsirom_find (parent, ia);
    149 #ifdef DIAGNOSTIC
    150 	if (sc->sc_which < 0)
    151 		panic ("SCSIROM curruption??");
    152 #endif
    153 	r = intio_map_allocate_region (parent, ia, INTIO_MAP_ALLOCATE);
    154 #ifdef DIAGNOSTIC
    155 	if (r)
    156 		panic ("IO map for SCSIROM corruption??");
    157 #endif
    158 
    159 	ia->ia_addr = scsirom_descr[sc->sc_which].devaddr;
    160 	if (ia->ia_intr == INTIOCF_INTR_DEFAULT)
    161 		ia->ia_intr = scsirom_descr[sc->sc_which].intr;
    162 
    163 	if (sc->sc_which == INTERNAL)
    164 		printf (": On-board at %p\n", (void*)ia->ia_addr);
    165 	else
    166 		printf (": External at %p\n", (void*)ia->ia_addr);
    167 
    168 	cf = config_search (NULL, self, ia);
    169 	if (cf) {
    170 		config_attach(self, cf, ia, NULL);
    171 	} else {
    172 		printf ("%s: no matching device; ignored.\n",
    173 			self->dv_xname);
    174 	}
    175 
    176 	return;
    177 }
    178