xref: /netbsd-src/sys/arch/sun3/dev/sebuf.c (revision d48f14661dda8638fee055ba15d35bdfb29b9fa8)
1 /*	$NetBSD: sebuf.c,v 1.14 2005/12/11 12:19:20 christos 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  * 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 /*
40  * Sun3/E SCSI/Ethernet board.  This is a VME board with some memory,
41  * an Intel Ether, and an NCR5380 SCSI with a cheap DMA engine.
42  * Note that the SCSI DMA engine can ONLY access the memory on
43  * the SE board, NOT the main memory, because it can not master
44  * VME transfers.
45  *
46  * This driver ("sebuf") is the parent of two child drivers:
47  *   se: yet another variant of NCR 5380 SCSI H/W
48  *   ie: yet anotehr variant of Intel 82586 Ethernet
49  *
50  * The job of this parent is to map the memory and partition it for
51  * the two children.  This driver has no device nodes.
52  */
53 
54 #include <sys/cdefs.h>
55 __KERNEL_RCSID(0, "$NetBSD: sebuf.c,v 1.14 2005/12/11 12:19:20 christos Exp $");
56 
57 #include <sys/param.h>
58 #include <sys/systm.h>
59 #include <sys/conf.h>
60 #include <sys/device.h>
61 #include <sys/ioctl.h>
62 #include <sys/malloc.h>
63 #include <sys/mman.h>
64 #include <sys/proc.h>
65 #include <sys/tty.h>
66 
67 #include <uvm/uvm_extern.h>
68 
69 #include <machine/autoconf.h>
70 #include <machine/cpu.h>
71 
72 #include "sereg.h"
73 #include "sevar.h"
74 
75 struct sebuf_softc {
76 	struct	device sc_dev;		/* base device (required) */
77 	struct sebuf_regs *sc_regs;
78 };
79 
80 /*
81  * Autoconfig attachment
82  */
83 
84 static int  sebuf_match(struct device *, struct cfdata *, void *);
85 static void sebuf_attach(struct device *, struct device *, void *);
86 static int  sebuf_print(void *, const char *);
87 
88 CFATTACH_DECL(sebuf, sizeof(struct sebuf_softc),
89     sebuf_match, sebuf_attach, NULL, NULL);
90 
91 static int
92 sebuf_match(struct device *parent, struct cfdata *cf, void *args)
93 {
94 	struct confargs *ca = args;
95 	struct se_regs *sreg;
96 	struct ie_regs *ereg;
97 	int pa, x;
98 
99 	if (ca->ca_paddr == -1)
100 		return (0);
101 
102 	/* Is it there at all? */
103 	pa = ca->ca_paddr;
104 	x = bus_peek(ca->ca_bustype, pa, 2);
105 	if (x == -1)
106 		return (0);
107 
108 	/* Look at the CSR for the SCSI part. */
109 	pa = ca->ca_paddr + offsetof(struct sebuf_regs, se_scsi_regs);
110 	sreg = bus_tmapin(ca->ca_bustype, pa);
111 	/* Write some bits that are wired to zero. */
112 	sreg->se_csr = 0xFFF3;
113 	x = peek_word((caddr_t)(&sreg->se_csr));
114 	bus_tmapout(sreg);
115 	if ((x == -1) || (x & 0xFCF0)) {
116 #ifdef	DEBUG
117 		printf("sebuf_match: SCSI csr=0x%x\n", x);
118 #endif
119 		return (0);
120 	}
121 
122 	/* Look at the CSR for the Ethernet part. */
123 	pa = ca->ca_paddr + offsetof(struct sebuf_regs, se_eth_regs);
124 	ereg = bus_tmapin(ca->ca_bustype, pa);
125 	/* Write some bits that are wired to zero. */
126 	ereg->ie_csr = 0x0FFF;
127 	x = peek_word((caddr_t)(&ereg->ie_csr));
128 	bus_tmapout(ereg);
129 	if ((x == -1) || (x & 0xFFF)) {
130 #ifdef	DEBUG
131 		printf("sebuf_match: Ether csr=0x%x\n", x);
132 #endif
133 		return (0);
134 	}
135 
136 	/* Default interrupt priority always splbio==2 */
137 	if (ca->ca_intpri == -1)
138 		ca->ca_intpri = 2;
139 
140 	return (1);
141 }
142 
143 static void
144 sebuf_attach(struct device *parent, struct device *self, void *args)
145 {
146 	struct sebuf_softc *sc = (struct sebuf_softc *)self;
147 	struct confargs *ca = args;
148 	struct sebuf_attach_args aa;
149 	struct sebuf_regs *regs;
150 
151 	printf("\n");
152 
153 	if (ca->ca_intpri != 2)
154 		panic("sebuf: bad level");
155 
156 	/* Map in the whole board. */
157 	regs = (struct sebuf_regs *)
158 		bus_mapin(ca->ca_bustype, ca->ca_paddr,
159 			  sizeof(struct sebuf_regs));
160 	if (regs == NULL)
161 		panic("sebuf_attach");
162 	sc->sc_regs = regs;
163 
164 	/* Attach the SCSI child. */
165 	aa.ca = *ca;	/* structure copy */
166 	aa.ca.ca_paddr = 0; /* prevent misuse */
167 	aa.name = "se";
168 	aa.buf  = &regs->se_scsi_buf[0];
169 	aa.blen = SE_NCRBUFSIZE;
170 	aa.regs = &regs->se_scsi_regs;
171 	(void) config_found(self, (void *) &aa, sebuf_print);
172 
173 	/* Attach the Ethernet child. */
174 	aa.ca.ca_intpri++;
175 	aa.ca.ca_intvec++;
176 	aa.name = "ie";
177 	aa.buf  = &regs->se_eth_buf[0];
178 	aa.blen = SE_IEBUFSIZE;
179 	aa.regs = &regs->se_eth_regs;
180 	(void) config_found(self, (void *) &aa, sebuf_print);
181 }
182 
183 static int
184 sebuf_print(void *aux, const char *name)
185 {
186 
187 	if (name != NULL)
188 		aprint_normal("%s: ", name);
189 
190 	return UNCONF;
191 }
192