Home | History | Annotate | Line # | Download | only in dev
scsirom.c revision 1.9.6.1
      1 /*	$NetBSD: scsirom.c,v 1.9.6.1 2004/08/03 10:42:47 skrll 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 the NetBSD
     21  *        Foundation, Inc. and its contributors.
     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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     26  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  * POSSIBILITY OF SUCH DAMAGE.
     36  */
     37 
     38 /*
     39  * SCSI BIOS ROM.
     40  * Used to probe the board.
     41  */
     42 
     43 #include <sys/cdefs.h>
     44 __KERNEL_RCSID(0, "$NetBSD: scsirom.c,v 1.9.6.1 2004/08/03 10:42:47 skrll Exp $");
     45 
     46 #include <sys/param.h>
     47 #include <sys/systm.h>
     48 #include <sys/device.h>
     49 
     50 #include <machine/bus.h>
     51 #include <machine/cpu.h>
     52 
     53 #include <arch/x68k/dev/intiovar.h>
     54 #include <arch/x68k/dev/scsiromvar.h>
     55 
     56 struct {
     57 	paddr_t addr, devaddr;
     58 	int intr;
     59 	const char id[7];
     60 } scsirom_descr[] = {{
     61 	0x00fc0000, 0x00e96020, 108, "SCSIIN"
     62 }, {
     63 	0x00ea0020, 0x00ea0000, 246, "SCSIEX"
     64 }};
     65 
     66 #define SCSIROM_ID	0x24
     67 
     68 /*
     69  * autoconf stuff
     70  */
     71 static int scsirom_find __P((struct device *, struct intio_attach_args *));
     72 static int scsirom_match __P((struct device *, struct cfdata *, void *));
     73 static void scsirom_attach __P((struct device *, struct device *, void *));
     74 
     75 CFATTACH_DECL(scsirom, sizeof(struct scsirom_softc),
     76     scsirom_match, scsirom_attach, NULL, NULL);
     77 
     78 static int
     79 scsirom_find (parent, ia)
     80 	struct device *parent;
     81 	struct intio_attach_args *ia;
     82 {
     83 	bus_space_handle_t ioh;
     84 	char buf[10];
     85 	int which;
     86 	int r = -1;
     87 
     88 	if (ia->ia_addr == scsirom_descr[INTERNAL].addr)
     89 		which = INTERNAL;
     90 	else if (ia->ia_addr == scsirom_descr[EXTERNAL].addr)
     91 		which = EXTERNAL;
     92 	else
     93 		return -1;
     94 
     95 	ia->ia_size = 0x1fe0;
     96 	if (intio_map_allocate_region (parent, ia, INTIO_MAP_TESTONLY))
     97 		return -1;
     98 
     99 	if (bus_space_map (ia->ia_bst, ia->ia_addr, ia->ia_size, 0, &ioh) < 0)
    100 		return -1;
    101 	if (badaddr ((caddr_t)INTIO_ADDR(ia->ia_addr+SCSIROM_ID))) {
    102 		bus_space_unmap (ia->ia_bst, ioh, ia->ia_size);
    103 		return -1;
    104 	}
    105 	bus_space_read_region_1 (ia->ia_bst, ioh, SCSIROM_ID, buf, 6);
    106 	if (memcmp(buf, scsirom_descr[which].id, 6) == 0)
    107 		r = which;
    108 	bus_space_unmap (ia->ia_bst, ioh, ia->ia_size);
    109 
    110 	return r;
    111 }
    112 
    113 static int
    114 scsirom_match(parent, cf, aux)
    115 	struct device *parent;
    116 	struct cfdata *cf;
    117 	void *aux;
    118 {
    119 	struct intio_attach_args *ia = aux;
    120 	int r;
    121 
    122 	if (strcmp (ia->ia_name, "scsirom") != 0)
    123 		return 0;
    124 
    125 	if (ia->ia_addr == INTIOCF_ADDR_DEFAULT) {
    126 		ia->ia_addr = scsirom_descr[0].addr;
    127 		r = scsirom_find (parent, ia);
    128 		if (r == INTERNAL)
    129 			return 1;
    130 		ia->ia_addr = scsirom_descr[1].addr;
    131 		r = scsirom_find (parent, ia);
    132 		if (r == EXTERNAL)
    133 			return 1;
    134 		return 0;
    135 	} else if (scsirom_find(parent, ia) >= 0)
    136 		return 1;
    137 	else
    138 		return 0;
    139 }
    140 
    141 static void
    142 scsirom_attach(parent, self, aux)
    143 	struct device *parent, *self;
    144 	void *aux;
    145 {
    146 	struct scsirom_softc *sc = (struct scsirom_softc *)self;
    147 	struct intio_attach_args *ia = aux;
    148 	int r;
    149 	struct cfdata *cf;
    150 
    151 	sc->sc_addr = ia->ia_addr;
    152 	sc->sc_which = scsirom_find (parent, ia);
    153 #ifdef DIAGNOSTIC
    154 	if (sc->sc_which < 0)
    155 		panic ("SCSIROM curruption??");
    156 #endif
    157 	r = intio_map_allocate_region (parent, ia, INTIO_MAP_ALLOCATE);
    158 #ifdef DIAGNOSTIC
    159 	if (r)
    160 		panic ("IO map for SCSIROM corruption??");
    161 #endif
    162 
    163 	ia->ia_addr = scsirom_descr[sc->sc_which].devaddr;
    164 	if (ia->ia_intr == INTIOCF_INTR_DEFAULT)
    165 		ia->ia_intr = scsirom_descr[sc->sc_which].intr;
    166 
    167 	if (sc->sc_which == INTERNAL)
    168 		printf (": On-board at %p\n", (void*)ia->ia_addr);
    169 	else
    170 		printf (": External at %p\n", (void*)ia->ia_addr);
    171 
    172 	cf = config_search (NULL, self, ia);
    173 	if (cf) {
    174 		config_attach(self, cf, ia, NULL);
    175 	} else {
    176 		printf ("%s: no matching device; ignored.\n",
    177 			self->dv_xname);
    178 	}
    179 
    180 	return;
    181 }
    182