Home | History | Annotate | Line # | Download | only in dev
scsirom.c revision 1.10.8.1
      1  1.10.8.1     kent /*	$NetBSD: scsirom.c,v 1.10.8.1 2005/04/29 11:28:28 kent 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.10    lukem 
     43      1.10    lukem #include <sys/cdefs.h>
     44  1.10.8.1     kent __KERNEL_RCSID(0, "$NetBSD: scsirom.c,v 1.10.8.1 2005/04/29 11:28:28 kent Exp $");
     45       1.2  minoura 
     46       1.2  minoura #include <sys/param.h>
     47       1.2  minoura #include <sys/systm.h>
     48       1.2  minoura #include <sys/device.h>
     49       1.2  minoura 
     50       1.2  minoura #include <machine/bus.h>
     51       1.2  minoura #include <machine/cpu.h>
     52       1.2  minoura 
     53       1.2  minoura #include <arch/x68k/dev/intiovar.h>
     54       1.2  minoura #include <arch/x68k/dev/scsiromvar.h>
     55       1.2  minoura 
     56       1.2  minoura struct {
     57       1.2  minoura 	paddr_t addr, devaddr;
     58       1.2  minoura 	int intr;
     59       1.2  minoura 	const char id[7];
     60       1.2  minoura } scsirom_descr[] = {{
     61       1.2  minoura 	0x00fc0000, 0x00e96020, 108, "SCSIIN"
     62       1.2  minoura }, {
     63       1.2  minoura 	0x00ea0020, 0x00ea0000, 246, "SCSIEX"
     64       1.2  minoura }};
     65       1.2  minoura 
     66       1.2  minoura #define SCSIROM_ID	0x24
     67       1.2  minoura 
     68       1.2  minoura /*
     69       1.2  minoura  * autoconf stuff
     70       1.2  minoura  */
     71  1.10.8.1     kent static int scsirom_find(struct device *, struct intio_attach_args *);
     72  1.10.8.1     kent static int scsirom_match(struct device *, struct cfdata *, void *);
     73  1.10.8.1     kent static void scsirom_attach(struct device *, struct device *, void *);
     74       1.2  minoura 
     75       1.8  thorpej CFATTACH_DECL(scsirom, sizeof(struct scsirom_softc),
     76       1.9  thorpej     scsirom_match, scsirom_attach, NULL, NULL);
     77       1.2  minoura 
     78  1.10.8.1     kent static int
     79  1.10.8.1     kent scsirom_find(struct device *parent, struct intio_attach_args *ia)
     80       1.2  minoura {
     81       1.2  minoura 	bus_space_handle_t ioh;
     82       1.2  minoura 	char buf[10];
     83       1.2  minoura 	int which;
     84       1.2  minoura 	int r = -1;
     85       1.2  minoura 
     86       1.2  minoura 	if (ia->ia_addr == scsirom_descr[INTERNAL].addr)
     87       1.2  minoura 		which = INTERNAL;
     88       1.2  minoura 	else if (ia->ia_addr == scsirom_descr[EXTERNAL].addr)
     89       1.2  minoura 		which = EXTERNAL;
     90       1.2  minoura 	else
     91       1.2  minoura 		return -1;
     92       1.2  minoura 
     93       1.2  minoura 	ia->ia_size = 0x1fe0;
     94       1.2  minoura 	if (intio_map_allocate_region (parent, ia, INTIO_MAP_TESTONLY))
     95       1.2  minoura 		return -1;
     96       1.2  minoura 
     97       1.2  minoura 	if (bus_space_map (ia->ia_bst, ia->ia_addr, ia->ia_size, 0, &ioh) < 0)
     98       1.2  minoura 		return -1;
     99       1.4  minoura 	if (badaddr ((caddr_t)INTIO_ADDR(ia->ia_addr+SCSIROM_ID))) {
    100       1.4  minoura 		bus_space_unmap (ia->ia_bst, ioh, ia->ia_size);
    101       1.4  minoura 		return -1;
    102       1.4  minoura 	}
    103       1.5  minoura 	bus_space_read_region_1 (ia->ia_bst, ioh, SCSIROM_ID, buf, 6);
    104       1.2  minoura 	if (memcmp(buf, scsirom_descr[which].id, 6) == 0)
    105       1.2  minoura 		r = which;
    106       1.2  minoura 	bus_space_unmap (ia->ia_bst, ioh, ia->ia_size);
    107       1.2  minoura 
    108       1.2  minoura 	return r;
    109       1.2  minoura }
    110       1.2  minoura 
    111  1.10.8.1     kent static int
    112  1.10.8.1     kent scsirom_match(struct device *parent, struct cfdata *cf, void *aux)
    113       1.2  minoura {
    114       1.2  minoura 	struct intio_attach_args *ia = aux;
    115       1.2  minoura 	int r;
    116       1.2  minoura 
    117       1.2  minoura 	if (strcmp (ia->ia_name, "scsirom") != 0)
    118       1.2  minoura 		return 0;
    119       1.2  minoura 
    120       1.2  minoura 	if (ia->ia_addr == INTIOCF_ADDR_DEFAULT) {
    121       1.2  minoura 		ia->ia_addr = scsirom_descr[0].addr;
    122       1.2  minoura 		r = scsirom_find (parent, ia);
    123       1.2  minoura 		if (r == INTERNAL)
    124       1.2  minoura 			return 1;
    125       1.2  minoura 		ia->ia_addr = scsirom_descr[1].addr;
    126       1.2  minoura 		r = scsirom_find (parent, ia);
    127       1.2  minoura 		if (r == EXTERNAL)
    128       1.2  minoura 			return 1;
    129       1.2  minoura 		return 0;
    130       1.2  minoura 	} else if (scsirom_find(parent, ia) >= 0)
    131       1.2  minoura 		return 1;
    132       1.2  minoura 	else
    133       1.2  minoura 		return 0;
    134       1.2  minoura }
    135       1.2  minoura 
    136  1.10.8.1     kent static void
    137  1.10.8.1     kent scsirom_attach(struct device *parent, struct device *self, void *aux)
    138       1.2  minoura {
    139       1.2  minoura 	struct scsirom_softc *sc = (struct scsirom_softc *)self;
    140       1.2  minoura 	struct intio_attach_args *ia = aux;
    141       1.2  minoura 	int r;
    142       1.2  minoura 	struct cfdata *cf;
    143       1.2  minoura 
    144       1.2  minoura 	sc->sc_addr = ia->ia_addr;
    145       1.2  minoura 	sc->sc_which = scsirom_find (parent, ia);
    146       1.2  minoura #ifdef DIAGNOSTIC
    147       1.2  minoura 	if (sc->sc_which < 0)
    148       1.2  minoura 		panic ("SCSIROM curruption??");
    149       1.2  minoura #endif
    150       1.2  minoura 	r = intio_map_allocate_region (parent, ia, INTIO_MAP_ALLOCATE);
    151       1.2  minoura #ifdef DIAGNOSTIC
    152       1.2  minoura 	if (r)
    153       1.2  minoura 		panic ("IO map for SCSIROM corruption??");
    154       1.2  minoura #endif
    155       1.2  minoura 
    156       1.2  minoura 	ia->ia_addr = scsirom_descr[sc->sc_which].devaddr;
    157       1.2  minoura 	if (ia->ia_intr == INTIOCF_INTR_DEFAULT)
    158       1.2  minoura 		ia->ia_intr = scsirom_descr[sc->sc_which].intr;
    159       1.2  minoura 
    160       1.2  minoura 	if (sc->sc_which == INTERNAL)
    161       1.3  minoura 		printf (": On-board at %p\n", (void*)ia->ia_addr);
    162       1.2  minoura 	else
    163       1.3  minoura 		printf (": External at %p\n", (void*)ia->ia_addr);
    164       1.2  minoura 
    165       1.2  minoura 	cf = config_search (NULL, self, ia);
    166       1.2  minoura 	if (cf) {
    167       1.2  minoura 		config_attach(self, cf, ia, NULL);
    168       1.2  minoura 	} else {
    169       1.2  minoura 		printf ("%s: no matching device; ignored.\n",
    170       1.2  minoura 			self->dv_xname);
    171       1.2  minoura 	}
    172       1.2  minoura 
    173       1.2  minoura 	return;
    174       1.2  minoura }
    175