Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / sun3 / dev / sebuf.c
blob1574f407968ef9d9867ea6fb9fefbd5f8343e13c
1 /* $NetBSD: sebuf.c,v 1.16 2008/04/28 20:23:37 martin Exp $ */
3 /*-
4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Gordon W. Ross.
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.
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.
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.
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
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.
47 #include <sys/cdefs.h>
48 __KERNEL_RCSID(0, "$NetBSD: sebuf.c,v 1.16 2008/04/28 20:23:37 martin Exp $");
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/malloc.h>
56 #include <sys/mman.h>
57 #include <sys/proc.h>
58 #include <sys/tty.h>
60 #include <uvm/uvm_extern.h>
62 #include <machine/autoconf.h>
63 #include <machine/cpu.h>
65 #include "sereg.h"
66 #include "sevar.h"
68 struct sebuf_softc {
69 device_t sc_dev; /* base device (required) */
70 struct sebuf_regs *sc_regs;
74 * Autoconfig attachment
77 static int sebuf_match(device_t, cfdata_t, void *);
78 static void sebuf_attach(device_t, device_t, void *);
79 static int sebuf_print(void *, const char *);
81 CFATTACH_DECL_NEW(sebuf, sizeof(struct sebuf_softc),
82 sebuf_match, sebuf_attach, NULL, NULL);
84 static int
85 sebuf_match(device_t parent, cfdata_t cf, void *args)
87 struct confargs *ca = args;
88 struct se_regs *sreg;
89 struct ie_regs *ereg;
90 int pa, x;
92 if (ca->ca_paddr == -1)
93 return 0;
95 /* Is it there at all? */
96 pa = ca->ca_paddr;
97 x = bus_peek(ca->ca_bustype, pa, 2);
98 if (x == -1)
99 return 0;
101 /* Look at the CSR for the SCSI part. */
102 pa = ca->ca_paddr + offsetof(struct sebuf_regs, se_scsi_regs);
103 sreg = bus_tmapin(ca->ca_bustype, pa);
104 /* Write some bits that are wired to zero. */
105 sreg->se_csr = 0xFFF3;
106 x = peek_word((void *)(&sreg->se_csr));
107 bus_tmapout(sreg);
108 if ((x == -1) || (x & 0xFCF0)) {
109 #ifdef DEBUG
110 aprint_debug("%s: SCSI csr=0x%x\n", __func__, x);
111 #endif
112 return 0;
115 /* Look at the CSR for the Ethernet part. */
116 pa = ca->ca_paddr + offsetof(struct sebuf_regs, se_eth_regs);
117 ereg = bus_tmapin(ca->ca_bustype, pa);
118 /* Write some bits that are wired to zero. */
119 ereg->ie_csr = 0x0FFF;
120 x = peek_word((void *)(&ereg->ie_csr));
121 bus_tmapout(ereg);
122 if ((x == -1) || (x & 0xFFF)) {
123 #ifdef DEBUG
124 printf("%s: Ether csr=0x%x\n", __func__, x);
125 #endif
126 return 0;
129 /* Default interrupt priority always splbio==2 */
130 if (ca->ca_intpri == -1)
131 ca->ca_intpri = 2;
133 return 1;
136 static void
137 sebuf_attach(device_t parent, device_t self, void *args)
139 struct sebuf_softc *sc = device_private(self);
140 struct confargs *ca = args;
141 struct sebuf_attach_args aa;
142 struct sebuf_regs *regs;
144 sc->sc_dev = self;
145 aprint_normal("\n");
147 if (ca->ca_intpri != 2)
148 panic("sebuf: bad level");
150 /* Map in the whole board. */
151 regs = (struct sebuf_regs *)bus_mapin(ca->ca_bustype, ca->ca_paddr,
152 sizeof(struct sebuf_regs));
153 if (regs == NULL)
154 panic("%s", __func__);
155 sc->sc_regs = regs;
157 /* Attach the SCSI child. */
158 aa.ca = *ca; /* structure copy */
159 aa.ca.ca_paddr = 0; /* prevent misuse */
160 aa.name = "se";
161 aa.buf = &regs->se_scsi_buf[0];
162 aa.blen = SE_NCRBUFSIZE;
163 aa.regs = &regs->se_scsi_regs;
164 (void)config_found(self, (void *)&aa, sebuf_print);
166 /* Attach the Ethernet child. */
167 aa.ca.ca_intpri++;
168 aa.ca.ca_intvec++;
169 aa.name = "ie";
170 aa.buf = &regs->se_eth_buf[0];
171 aa.blen = SE_IEBUFSIZE;
172 aa.regs = &regs->se_eth_regs;
173 (void)config_found(self, (void *)&aa, sebuf_print);
176 static int
177 sebuf_print(void *aux, const char *name)
180 if (name != NULL)
181 aprint_normal("%s: ", name);
183 return UNCONF;