1 1.35 isaki /* $NetBSD: spc.c,v 1.35 2008/12/18 05:56:42 isaki Exp $ */ 2 1.1 oki 3 1.20 minoura /*- 4 1.20 minoura * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 1.20 minoura * All rights reserved. 6 1.20 minoura * 7 1.20 minoura * This code is derived from software contributed to The NetBSD Foundation 8 1.20 minoura * by Jarle Greipsland, Charles M. Hannum and Masaru Oki. 9 1.1 oki * 10 1.1 oki * Redistribution and use in source and binary forms, with or without 11 1.1 oki * modification, are permitted provided that the following conditions 12 1.1 oki * are met: 13 1.1 oki * 1. Redistributions of source code must retain the above copyright 14 1.1 oki * notice, this list of conditions and the following disclaimer. 15 1.1 oki * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 oki * notice, this list of conditions and the following disclaimer in the 17 1.1 oki * documentation and/or other materials provided with the distribution. 18 1.1 oki * 19 1.20 minoura * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.20 minoura * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.20 minoura * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.20 minoura * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.20 minoura * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.20 minoura * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.20 minoura * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.20 minoura * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.20 minoura * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.20 minoura * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 oki * POSSIBILITY OF SUCH DAMAGE. 30 1.1 oki */ 31 1.26 lukem 32 1.26 lukem #include <sys/cdefs.h> 33 1.35 isaki __KERNEL_RCSID(0, "$NetBSD: spc.c,v 1.35 2008/12/18 05:56:42 isaki Exp $"); 34 1.1 oki 35 1.15 jonathan #include "opt_ddb.h" 36 1.1 oki 37 1.1 oki #include <sys/param.h> 38 1.1 oki #include <sys/systm.h> 39 1.1 oki #include <sys/kernel.h> 40 1.1 oki #include <sys/device.h> 41 1.20 minoura 42 1.20 minoura #include <machine/bus.h> 43 1.20 minoura #include <machine/cpu.h> 44 1.1 oki 45 1.10 bouyer #include <dev/scsipi/scsi_all.h> 46 1.10 bouyer #include <dev/scsipi/scsipi_all.h> 47 1.10 bouyer #include <dev/scsipi/scsiconf.h> 48 1.1 oki 49 1.20 minoura #include <arch/x68k/dev/intiovar.h> 50 1.20 minoura #include <arch/x68k/dev/scsiromvar.h> 51 1.20 minoura #include <arch/x68k/x68k/iodevice.h> 52 1.1 oki 53 1.20 minoura #include <dev/ic/mb89352var.h> 54 1.20 minoura #include <dev/ic/mb89352reg.h> 55 1.1 oki 56 1.33 tsutsui static int spc_intio_match(device_t, cfdata_t, void *); 57 1.33 tsutsui static void spc_intio_attach(device_t, device_t, void *); 58 1.1 oki 59 1.33 tsutsui CFATTACH_DECL_NEW(spc_intio, sizeof(struct spc_softc), 60 1.24 thorpej spc_intio_match, spc_intio_attach, NULL, NULL); 61 1.1 oki 62 1.31 isaki static int 63 1.33 tsutsui spc_intio_match(device_t parent, cfdata_t cf, void *aux) 64 1.1 oki { 65 1.20 minoura struct intio_attach_args *ia = aux; 66 1.20 minoura bus_space_tag_t iot = ia->ia_bst; 67 1.20 minoura bus_space_handle_t ioh; 68 1.1 oki 69 1.33 tsutsui ia->ia_size = 0x20; 70 1.1 oki 71 1.30 thorpej if (intio_map_allocate_region(device_parent(parent), ia, 72 1.20 minoura INTIO_MAP_TESTONLY) < 0) 73 1.1 oki return 0; 74 1.1 oki 75 1.20 minoura if (bus_space_map(iot, ia->ia_addr, 0x20, BUS_SPACE_MAP_SHIFTED, 76 1.20 minoura &ioh) < 0) 77 1.20 minoura return 0; 78 1.35 isaki if (badaddr((void *)IIOV(ia->ia_addr + BDID))) 79 1.1 oki return 0; 80 1.20 minoura bus_space_unmap(iot, ioh, 0x20); 81 1.1 oki 82 1.20 minoura return 1; 83 1.1 oki } 84 1.1 oki 85 1.31 isaki static void 86 1.33 tsutsui spc_intio_attach(device_t parent, device_t self, void *aux) 87 1.1 oki { 88 1.33 tsutsui struct spc_softc *sc = device_private(self); 89 1.20 minoura struct intio_attach_args *ia = aux; 90 1.20 minoura bus_space_tag_t iot = ia->ia_bst; 91 1.20 minoura bus_space_handle_t ioh; 92 1.20 minoura 93 1.33 tsutsui sc->sc_dev = self; 94 1.20 minoura 95 1.30 thorpej intio_map_allocate_region(device_parent(parent), ia, 96 1.20 minoura INTIO_MAP_ALLOCATE); 97 1.20 minoura if (bus_space_map(iot, ia->ia_addr, 0x20, BUS_SPACE_MAP_SHIFTED, 98 1.20 minoura &ioh)) { 99 1.33 tsutsui aprint_error(": can't map i/o space\n"); 100 1.12 oki return; 101 1.1 oki } 102 1.33 tsutsui aprint_normal("\n"); 103 1.1 oki 104 1.20 minoura sc->sc_iot = iot; 105 1.20 minoura sc->sc_ioh = ioh; 106 1.20 minoura sc->sc_initiator = IODEVbase->io_sram[0x70] & 0x7; /* XXX */ 107 1.1 oki 108 1.25 tsutsui if (intio_intr_establish(ia->ia_intr, "spc", spc_intr, sc)) 109 1.32 isaki panic("spcattach: interrupt vector busy"); 110 1.1 oki 111 1.25 tsutsui spc_attach(sc); 112 1.1 oki } 113