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