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