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