xref: /netbsd-src/sys/arch/sun3/dev/sebuf.c (revision 03daa790ebb1227f96803546c28ec9033628154d)
1 /*	$NetBSD: sebuf.c,v 1.21 2024/12/20 23:52:00 tsutsui Exp $	*/
2 
3 /*-
4  * Copyright (c) 1997 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Gordon W. Ross.
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  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * Sun3/E SCSI/Ethernet board.  This is a VME board with some memory,
34  * an Intel Ether, and an NCR5380 SCSI with a cheap DMA engine.
35  * Note that the SCSI DMA engine can ONLY access the memory on
36  * the SE board, NOT the main memory, because it can not master
37  * VME transfers.
38  *
39  * This driver ("sebuf") is the parent of two child drivers:
40  *   se: yet another variant of NCR 5380 SCSI H/W
41  *   ie: yet anotehr variant of Intel 82586 Ethernet
42  *
43  * The job of this parent is to map the memory and partition it for
44  * the two children.  This driver has no device nodes.
45  */
46 
47 #include <sys/cdefs.h>
48 __KERNEL_RCSID(0, "$NetBSD: sebuf.c,v 1.21 2024/12/20 23:52:00 tsutsui Exp $");
49 
50 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/conf.h>
53 #include <sys/device.h>
54 #include <sys/ioctl.h>
55 #include <sys/mman.h>
56 #include <sys/proc.h>
57 #include <sys/tty.h>
58 
59 #include <uvm/uvm_extern.h>
60 
61 #include <machine/autoconf.h>
62 #include <machine/cpu.h>
63 
64 #include "sereg.h"
65 #include "sevar.h"
66 
67 struct sebuf_softc {
68 	device_t sc_dev;		/* base device (required) */
69 	struct sebuf_regs *sc_regs;
70 };
71 
72 /*
73  * Autoconfig attachment
74  */
75 
76 static int  sebuf_match(device_t, cfdata_t, void *);
77 static void sebuf_attach(device_t, device_t, void *);
78 static int  sebuf_print(void *, const char *);
79 
80 CFATTACH_DECL_NEW(sebuf, sizeof(struct sebuf_softc),
81     sebuf_match, sebuf_attach, NULL, NULL);
82 
83 static int
84 sebuf_match(device_t parent, cfdata_t cf, void *args)
85 {
86 	struct confargs *ca = args;
87 	struct se_regs *sreg;
88 	struct ie_regs *ereg;
89 	int pa, x;
90 
91 	if (ca->ca_paddr == -1)
92 		return 0;
93 
94 	/* Is it there at all? */
95 	pa = ca->ca_paddr;
96 	x = bus_peek(ca->ca_bustype, pa, 2);
97 	if (x == -1)
98 		return 0;
99 
100 	/* Look at the CSR for the SCSI part. */
101 	pa = ca->ca_paddr + offsetof(struct sebuf_regs, se_scsi_regs);
102 	sreg = bus_tmapin(ca->ca_bustype, pa);
103 	/* Write some bits that are wired to zero. */
104 	sreg->se_csr = 0xFFF3;
105 	x = peek_word((void *)(&sreg->se_csr));
106 	bus_tmapout(sreg);
107 	if ((x == -1) || (x & 0xFCF0)) {
108 #ifdef	DEBUG
109 		aprint_debug("%s: SCSI csr=0x%x\n", __func__, x);
110 #endif
111 		return 0;
112 	}
113 
114 	/* Look at the CSR for the Ethernet part. */
115 	pa = ca->ca_paddr + offsetof(struct sebuf_regs, se_eth_regs);
116 	ereg = bus_tmapin(ca->ca_bustype, pa);
117 	/* Write some bits that are wired to zero. */
118 	ereg->ie_csr = 0x0FFF;
119 	x = peek_word((void *)(&ereg->ie_csr));
120 	bus_tmapout(ereg);
121 	if ((x == -1) || (x & 0xFFF)) {
122 #ifdef	DEBUG
123 		printf("%s: Ether csr=0x%x\n", __func__, x);
124 #endif
125 		return 0;
126 	}
127 
128 	/* Default interrupt priority always splbio==2 */
129 	if (ca->ca_intpri == -1)
130 		ca->ca_intpri = 2;
131 
132 	return 1;
133 }
134 
135 static void
136 sebuf_attach(device_t parent, device_t self, void *args)
137 {
138 	struct sebuf_softc *sc = device_private(self);
139 	struct confargs *ca = args;
140 	struct sebuf_attach_args aa;
141 	struct sebuf_regs *regs;
142 
143 	sc->sc_dev = self;
144 	aprint_normal("\n");
145 
146 	if (ca->ca_intpri != 2)
147 		panic("sebuf: bad level");
148 
149 	/* Map in the whole board. */
150 	regs = (struct sebuf_regs *)bus_mapin(ca->ca_bustype, ca->ca_paddr,
151 	    sizeof(struct sebuf_regs));
152 	if (regs == NULL)
153 		panic("%s", __func__);
154 	sc->sc_regs = regs;
155 
156 	/* Attach the SCSI child. */
157 	aa.ca = *ca;	/* structure copy */
158 	aa.ca.ca_paddr = 0; /* prevent misuse */
159 	aa.name = "se";
160 	aa.buf  = &regs->se_scsi_buf[0];
161 	aa.blen = SE_NCRBUFSIZE;
162 	aa.regs = &regs->se_scsi_regs;
163 	(void)config_found(self, (void *)&aa, sebuf_print, CFARGS_NONE);
164 
165 	/* Attach the Ethernet child. */
166 	aa.ca.ca_intpri++;
167 	aa.ca.ca_intvec++;
168 	aa.name = "ie";
169 	aa.buf  = &regs->se_eth_buf[0];
170 	aa.blen = SE_IEBUFSIZE;
171 	aa.regs = &regs->se_eth_regs;
172 	(void)config_found(self, (void *)&aa, sebuf_print, CFARGS_NONE);
173 }
174 
175 static int
176 sebuf_print(void *aux, const char *name)
177 {
178 
179 	if (name != NULL)
180 		aprint_normal("%s: ", name);
181 
182 	return UNCONF;
183 }
184