xref: /netbsd-src/sys/arch/x68k/dev/spc.c (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1 /*	$NetBSD: spc.c,v 1.26 2003/07/15 01:44:52 lukem Exp $	*/
2 
3 /*-
4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jarle Greipsland, Charles M. Hannum and Masaru Oki.
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. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: spc.c,v 1.26 2003/07/15 01:44:52 lukem Exp $");
41 
42 #include "opt_ddb.h"
43 
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/kernel.h>
47 #include <sys/device.h>
48 
49 #include <machine/bus.h>
50 #include <machine/cpu.h>
51 
52 #include <dev/scsipi/scsi_all.h>
53 #include <dev/scsipi/scsipi_all.h>
54 #include <dev/scsipi/scsiconf.h>
55 
56 #include <arch/x68k/dev/intiovar.h>
57 #include <arch/x68k/dev/scsiromvar.h>
58 #include <arch/x68k/x68k/iodevice.h>
59 
60 #include <dev/ic/mb89352var.h>
61 #include <dev/ic/mb89352reg.h>
62 
63 static int spc_intio_match __P((struct device *, struct cfdata *, void *));
64 static void spc_intio_attach __P((struct device *, struct device *, void *));
65 
66 CFATTACH_DECL(spc_intio, sizeof (struct spc_softc),
67     spc_intio_match, spc_intio_attach, NULL, NULL);
68 
69 static int
70 spc_intio_match(parent, cf, aux)
71 	struct device *parent;
72 	struct cfdata *cf;
73 	void *aux;
74 {
75 	struct intio_attach_args *ia = aux;
76 	bus_space_tag_t iot = ia->ia_bst;
77 	bus_space_handle_t ioh;
78 
79 	ia->ia_size=0x20;
80 
81 	if (intio_map_allocate_region(parent->dv_parent, ia,
82 				      INTIO_MAP_TESTONLY) < 0)
83 		return 0;
84 
85 	if (bus_space_map(iot, ia->ia_addr, 0x20, BUS_SPACE_MAP_SHIFTED,
86 			  &ioh) < 0)
87 		return 0;
88 	if (badaddr ((caddr_t)INTIO_ADDR(ia->ia_addr + BDID)))
89 		return 0;
90 	bus_space_unmap(iot, ioh, 0x20);
91 
92 	return 1;
93 }
94 
95 static void
96 spc_intio_attach(parent, self, aux)
97 	struct device *parent, *self;
98 	void *aux;
99 {
100 	struct spc_softc *sc = (struct spc_softc *)self;
101 	struct intio_attach_args *ia = aux;
102 	bus_space_tag_t iot = ia->ia_bst;
103 	bus_space_handle_t ioh;
104 
105 	printf ("\n");
106 
107 	intio_map_allocate_region(parent->dv_parent, ia,
108 				  INTIO_MAP_ALLOCATE);
109 	if (bus_space_map(iot, ia->ia_addr, 0x20, BUS_SPACE_MAP_SHIFTED,
110 			  &ioh)) {
111 		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
112 		return;
113 	}
114 
115 	sc->sc_iot = iot;
116 	sc->sc_ioh = ioh;
117 	sc->sc_initiator = IODEVbase->io_sram[0x70] & 0x7; /* XXX */
118 
119 	if (intio_intr_establish(ia->ia_intr, "spc", spc_intr, sc))
120 		panic ("spcattach: interrupt vector busy");
121 
122 	spc_attach(sc);
123 }
124