Sun Feb 2 15:35:06 2014 UTC ()
Misc cleanup of sio drivers.

- register softc of child devices as an argument of the sio interrupt
  handler to avoid device_lookup_private() calls on every interrupt
- change type of sc_reg from (void *) to (struct sioreg *)
  to avoid weird address offset calculations with redundant casts
- rename struct sio_softc members for consistency
- use a channel number passed via sio_attach_args in lunaws_attach()

No functional chnages.  Tested on LUNA.


(tsutsui)
diff -r1.27 -r1.28 src/sys/arch/luna68k/dev/lunaws.c
diff -r1.12 -r1.13 src/sys/arch/luna68k/dev/sio.c
diff -r1.38 -r1.39 src/sys/arch/luna68k/dev/siotty.c
diff -r1.7 -r1.8 src/sys/arch/luna68k/dev/siovar.h

cvs diff -r1.27 -r1.28 src/sys/arch/luna68k/dev/lunaws.c (expand / switch to unified diff)

--- src/sys/arch/luna68k/dev/lunaws.c 2013/09/23 17:27:09 1.27
+++ src/sys/arch/luna68k/dev/lunaws.c 2014/02/02 15:35:06 1.28
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lunaws.c,v 1.27 2013/09/23 17:27:09 tsutsui Exp $ */ 1/* $NetBSD: lunaws.c,v 1.28 2014/02/02 15:35:06 tsutsui Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc. 4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Tohru Nishimura. 8 * by Tohru Nishimura.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 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 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 32#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
33 33
34__KERNEL_RCSID(0, "$NetBSD: lunaws.c,v 1.27 2013/09/23 17:27:09 tsutsui Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: lunaws.c,v 1.28 2014/02/02 15:35:06 tsutsui Exp $");
35 35
36#include "wsmouse.h" 36#include "wsmouse.h"
37 37
38#include <sys/param.h> 38#include <sys/param.h>
39#include <sys/systm.h> 39#include <sys/systm.h>
40#include <sys/conf.h> 40#include <sys/conf.h>
41#include <sys/device.h> 41#include <sys/device.h>
42 42
43#include <dev/wscons/wsconsio.h> 43#include <dev/wscons/wsconsio.h>
44#include <dev/wscons/wskbdvar.h> 44#include <dev/wscons/wskbdvar.h>
45#include <dev/wscons/wsksymdef.h> 45#include <dev/wscons/wsksymdef.h>
46#include <dev/wscons/wsksymvar.h> 46#include <dev/wscons/wsksymvar.h>
47#include <dev/wscons/wsmousevar.h> 47#include <dev/wscons/wsmousevar.h>
@@ -108,60 +108,62 @@ static const struct wskbd_consops ws_con @@ -108,60 +108,62 @@ static const struct wskbd_consops ws_con
108 108
109#if NWSMOUSE > 0 109#if NWSMOUSE > 0
110static int omms_enable(void *); 110static int omms_enable(void *);
111static int omms_ioctl(void *, u_long, void *, int, struct lwp *); 111static int omms_ioctl(void *, u_long, void *, int, struct lwp *);
112static void omms_disable(void *); 112static void omms_disable(void *);
113 113
114static const struct wsmouse_accessops omms_accessops = { 114static const struct wsmouse_accessops omms_accessops = {
115 omms_enable, 115 omms_enable,
116 omms_ioctl, 116 omms_ioctl,
117 omms_disable, 117 omms_disable,
118}; 118};
119#endif 119#endif
120 120
121static void wsintr(int); 121static void wsintr(void *);
122static void wssoftintr(void *); 122static void wssoftintr(void *);
123 123
124static int wsmatch(device_t, cfdata_t, void *); 124static int wsmatch(device_t, cfdata_t, void *);
125static void wsattach(device_t, device_t, void *); 125static void wsattach(device_t, device_t, void *);
126 126
127CFATTACH_DECL_NEW(ws, sizeof(struct ws_softc), 127CFATTACH_DECL_NEW(ws, sizeof(struct ws_softc),
128 wsmatch, wsattach, NULL, NULL); 128 wsmatch, wsattach, NULL, NULL);
129 129
130extern int syscngetc(dev_t); 130extern int syscngetc(dev_t);
131extern void syscnputc(dev_t, int); 131extern void syscnputc(dev_t, int);
132 132
133static int 133static int
134wsmatch(device_t parent, cfdata_t cf, void *aux) 134wsmatch(device_t parent, cfdata_t cf, void *aux)
135{ 135{
136 struct sio_attach_args *args = aux; 136 struct sio_attach_args *args = aux;
137 137
138 if (args->channel != 1) 138 if (args->channel != 1)
139 return 0; 139 return 0;
140 return 1; 140 return 1;
141} 141}
142 142
143static void 143static void
144wsattach(device_t parent, device_t self, void *aux) 144wsattach(device_t parent, device_t self, void *aux)
145{ 145{
146 struct ws_softc *sc = device_private(self); 146 struct ws_softc *sc = device_private(self);
147 struct sio_softc *scp = device_private(parent); 147 struct sio_softc *siosc = device_private(parent);
148 struct sio_attach_args *args = aux; 148 struct sio_attach_args *args = aux;
 149 int channel = args->channel;
149 struct wskbddev_attach_args a; 150 struct wskbddev_attach_args a;
150 151
151 sc->sc_dev = self; 152 sc->sc_dev = self;
152 sc->sc_ctl = (struct sioreg *)scp->scp_ctl + 1; 153 sc->sc_ctl = &siosc->sc_ctl[channel];
153 memcpy(sc->sc_wr, ch1_regs, sizeof(ch1_regs)); 154 memcpy(sc->sc_wr, ch1_regs, sizeof(ch1_regs));
154 scp->scp_intr[1] = wsintr; 155 siosc->sc_intrhand[channel].ih_func = wsintr;
 156 siosc->sc_intrhand[channel].ih_arg = sc;
155 157
156 setsioreg(sc->sc_ctl, WR0, sc->sc_wr[WR0]); 158 setsioreg(sc->sc_ctl, WR0, sc->sc_wr[WR0]);
157 setsioreg(sc->sc_ctl, WR4, sc->sc_wr[WR4]); 159 setsioreg(sc->sc_ctl, WR4, sc->sc_wr[WR4]);
158 setsioreg(sc->sc_ctl, WR3, sc->sc_wr[WR3]); 160 setsioreg(sc->sc_ctl, WR3, sc->sc_wr[WR3]);
159 setsioreg(sc->sc_ctl, WR5, sc->sc_wr[WR5]); 161 setsioreg(sc->sc_ctl, WR5, sc->sc_wr[WR5]);
160 setsioreg(sc->sc_ctl, WR0, sc->sc_wr[WR0]); 162 setsioreg(sc->sc_ctl, WR0, sc->sc_wr[WR0]);
161 setsioreg(sc->sc_ctl, WR1, sc->sc_wr[WR1]); 163 setsioreg(sc->sc_ctl, WR1, sc->sc_wr[WR1]);
162 164
163 syscnputc((dev_t)1, 0x20); /* keep quiet mouse */ 165 syscnputc((dev_t)1, 0x20); /* keep quiet mouse */
164 166
165 sc->sc_rxqhead = 0; 167 sc->sc_rxqhead = 0;
166 sc->sc_rxqtail = 0; 168 sc->sc_rxqtail = 0;
167 169
@@ -179,29 +181,29 @@ wsattach(device_t parent, device_t self, @@ -179,29 +181,29 @@ wsattach(device_t parent, device_t self,
179 { 181 {
180 struct wsmousedev_attach_args b; 182 struct wsmousedev_attach_args b;
181 b.accessops = &omms_accessops; 183 b.accessops = &omms_accessops;
182 b.accesscookie = (void *)sc; 184 b.accesscookie = (void *)sc;
183 sc->sc_wsmousedev = 185 sc->sc_wsmousedev =
184 config_found_ia(self, "wsmousedev", &b, wsmousedevprint); 186 config_found_ia(self, "wsmousedev", &b, wsmousedevprint);
185 sc->sc_msreport = 0; 187 sc->sc_msreport = 0;
186 } 188 }
187#endif 189#endif
188} 190}
189 191
190/*ARGSUSED*/ 192/*ARGSUSED*/
191static void 193static void
192wsintr(int chan) 194wsintr(void *arg)
193{ 195{
194 struct ws_softc *sc = device_lookup_private(&ws_cd, 0); 196 struct ws_softc *sc = arg;
195 struct sioreg *sio = sc->sc_ctl; 197 struct sioreg *sio = sc->sc_ctl;
196 uint8_t code; 198 uint8_t code;
197 int rr; 199 int rr;
198 200
199 rr = getsiocsr(sio); 201 rr = getsiocsr(sio);
200 if (rr & RR_RXRDY) { 202 if (rr & RR_RXRDY) {
201 do { 203 do {
202 code = sio->sio_data; 204 code = sio->sio_data;
203 if (rr & (RR_FRAMING | RR_OVERRUN | RR_PARITY)) { 205 if (rr & (RR_FRAMING | RR_OVERRUN | RR_PARITY)) {
204 sio->sio_cmd = WR0_ERRRST; 206 sio->sio_cmd = WR0_ERRRST;
205 continue; 207 continue;
206 } 208 }
207 sc->sc_rxq[sc->sc_rxqtail] = code; 209 sc->sc_rxq[sc->sc_rxqtail] = code;

cvs diff -r1.12 -r1.13 src/sys/arch/luna68k/dev/sio.c (expand / switch to unified diff)

--- src/sys/arch/luna68k/dev/sio.c 2013/09/23 17:27:09 1.12
+++ src/sys/arch/luna68k/dev/sio.c 2014/02/02 15:35:06 1.13
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sio.c,v 1.12 2013/09/23 17:27:09 tsutsui Exp $ */ 1/* $NetBSD: sio.c,v 1.13 2014/02/02 15:35:06 tsutsui Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc. 4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Tohru Nishimura. 8 * by Tohru Nishimura.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -21,77 +21,77 @@ @@ -21,77 +21,77 @@
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 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 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 32#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
33 33
34__KERNEL_RCSID(0, "$NetBSD: sio.c,v 1.12 2013/09/23 17:27:09 tsutsui Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: sio.c,v 1.13 2014/02/02 15:35:06 tsutsui Exp $");
35 35
36#include <sys/param.h> 36#include <sys/param.h>
37#include <sys/systm.h> 37#include <sys/systm.h>
38#include <sys/device.h> 38#include <sys/device.h>
39 39
40#include <machine/cpu.h> 40#include <machine/cpu.h>
41#include <machine/autoconf.h> 41#include <machine/autoconf.h>
42 42
43#include <luna68k/luna68k/isr.h> 43#include <luna68k/luna68k/isr.h>
44#include <luna68k/dev/siovar.h> 44#include <luna68k/dev/siovar.h>
45 45
46#include "ioconf.h" 46#include "ioconf.h"
47 47
48static int sio_match(device_t, cfdata_t, void *); 48static int sio_match(device_t, cfdata_t, void *);
49static void sio_attach(device_t, device_t, void *); 49static void sio_attach(device_t, device_t, void *);
50static int sio_print(void *, const char *); 50static int sio_print(void *, const char *);
51 51
52CFATTACH_DECL_NEW(sio, sizeof(struct sio_softc), 52CFATTACH_DECL_NEW(sio, sizeof(struct sio_softc),
53 sio_match, sio_attach, NULL, NULL); 53 sio_match, sio_attach, NULL, NULL);
54 54
55static void nullintr(int); 55static void nullintr(void *);
56static int xsiointr(void *); 56static int xsiointr(void *);
57 57
58static int 58static int
59sio_match(device_t parent, cfdata_t cf, void *aux) 59sio_match(device_t parent, cfdata_t cf, void *aux)
60{ 60{
61 struct mainbus_attach_args *ma = aux; 61 struct mainbus_attach_args *ma = aux;
62 62
63 if (strcmp(ma->ma_name, sio_cd.cd_name)) 63 if (strcmp(ma->ma_name, sio_cd.cd_name))
64 return 0; 64 return 0;
65 if (badaddr((void *)ma->ma_addr, 4)) 65 if (badaddr((void *)ma->ma_addr, 4))
66 return 0; 66 return 0;
67 return 1; 67 return 1;
68} 68}
69 69
70static void 70static void
71sio_attach(device_t parent, device_t self, void *aux) 71sio_attach(device_t parent, device_t self, void *aux)
72{ 72{
73 struct sio_softc *sc = device_private(self); 73 struct sio_softc *sc = device_private(self);
74 struct mainbus_attach_args *ma = aux; 74 struct mainbus_attach_args *ma = aux;
75 struct sio_attach_args sio_args; 75 struct sio_attach_args sio_args;
76 int channel; 76 int channel;
77 extern int sysconsole; /* console: 0 for ttya, 1 for desktop */ 77 extern int sysconsole; /* console: 0 for ttya, 1 for desktop */
78 78
79 aprint_normal(": uPD7201A\n"); 79 aprint_normal(": uPD7201A\n");
80 80
81 sc->scp_dev = self; 81 sc->sc_dev = self;
82 sc->scp_ctl = (void *)ma->ma_addr; 82 sc->sc_ctl = (void *)ma->ma_addr;
83 sc->scp_intr[0] = sc->scp_intr[1] = nullintr; 
84 for (channel = 0; channel < 2; channel++) { 83 for (channel = 0; channel < 2; channel++) {
 84 sc->sc_intrhand[channel].ih_func = nullintr;
85 sio_args.channel = channel; 85 sio_args.channel = channel;
86 sio_args.hwflags = (channel == sysconsole); 86 sio_args.hwflags = (channel == sysconsole);
87 config_found(self, (void *)&sio_args, sio_print); 87 config_found(self, (void *)&sio_args, sio_print);
88 } 88 }
89 89
90 isrlink_autovec(xsiointr, sc, ma->ma_ilvl, ISRPRI_TTYNOBUF); 90 isrlink_autovec(xsiointr, sc, ma->ma_ilvl, ISRPRI_TTYNOBUF);
91} 91}
92 92
93static int 93static int
94sio_print(void *aux, const char *name) 94sio_print(void *aux, const char *name)
95{ 95{
96 struct sio_attach_args *args = aux; 96 struct sio_attach_args *args = aux;
97 97
@@ -99,22 +99,26 @@ sio_print(void *aux, const char *name) @@ -99,22 +99,26 @@ sio_print(void *aux, const char *name)
99 aprint_normal("%s: ", name); 99 aprint_normal("%s: ", name);
100 100
101 if (args->channel != -1) 101 if (args->channel != -1)
102 aprint_normal(" channel %d", args->channel); 102 aprint_normal(" channel %d", args->channel);
103 103
104 return UNCONF; 104 return UNCONF;
105} 105}
106 106
107static int 107static int
108xsiointr(void *arg) 108xsiointr(void *arg)
109{ 109{
110 struct sio_softc *sc = arg; 110 struct sio_softc *sc = arg;
111 111
112 (*sc->scp_intr[0])(0); /* 0: ttya system serial port */ 112 /* channel 0: ttya system serial port */
113 (*sc->scp_intr[1])(1); /* 1: keyboard and mouse */ 113 (*sc->sc_intrhand[0].ih_func)(sc->sc_intrhand[0].ih_arg);
 114
 115 /* channel 1: keyboard and mouse */
 116 (*sc->sc_intrhand[1].ih_func)(sc->sc_intrhand[1].ih_arg);
 117
114 return 1; 118 return 1;
115} 119}
116 120
117static void 121static void
118nullintr(int v) 122nullintr(void *arg)
119{ 123{
120} 124}

cvs diff -r1.38 -r1.39 src/sys/arch/luna68k/dev/siotty.c (expand / switch to unified diff)

--- src/sys/arch/luna68k/dev/siotty.c 2014/01/02 03:32:35 1.38
+++ src/sys/arch/luna68k/dev/siotty.c 2014/02/02 15:35:06 1.39
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: siotty.c,v 1.38 2014/01/02 03:32:35 tsutsui Exp $ */ 1/* $NetBSD: siotty.c,v 1.39 2014/02/02 15:35:06 tsutsui Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc. 4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Tohru Nishimura. 8 * by Tohru Nishimura.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 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 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 32#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
33 33
34__KERNEL_RCSID(0, "$NetBSD: siotty.c,v 1.38 2014/01/02 03:32:35 tsutsui Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: siotty.c,v 1.39 2014/02/02 15:35:06 tsutsui Exp $");
35 35
36#include "opt_ddb.h" 36#include "opt_ddb.h"
37 37
38#include <sys/param.h> 38#include <sys/param.h>
39#include <sys/systm.h> 39#include <sys/systm.h>
40#include <sys/device.h> 40#include <sys/device.h>
41#include <sys/conf.h> 41#include <sys/conf.h>
42#include <sys/ioctl.h> 42#include <sys/ioctl.h>
43#include <sys/proc.h> 43#include <sys/proc.h>
44#include <sys/tty.h> 44#include <sys/tty.h>
45#include <sys/uio.h> 45#include <sys/uio.h>
46#include <sys/callout.h> 46#include <sys/callout.h>
47#include <sys/fcntl.h> 47#include <sys/fcntl.h>
@@ -96,27 +96,27 @@ struct siotty_softc { @@ -96,27 +96,27 @@ struct siotty_softc {
96 bool sc_rx_ready; 96 bool sc_rx_ready;
97 bool sc_tx_busy; 97 bool sc_tx_busy;
98 bool sc_tx_done; 98 bool sc_tx_done;
99}; 99};
100 100
101#define SIOTTY_RING_SIZE 2048 101#define SIOTTY_RING_SIZE 2048
102u_int siotty_rbuf_size = SIOTTY_RING_SIZE; 102u_int siotty_rbuf_size = SIOTTY_RING_SIZE;
103 103
104static struct cnm_state siotty_cnm_state; 104static struct cnm_state siotty_cnm_state;
105 105
106#include "siotty.h" 106#include "siotty.h"
107static void siostart(struct tty *); 107static void siostart(struct tty *);
108static int sioparam(struct tty *, struct termios *); 108static int sioparam(struct tty *, struct termios *);
109static void siottyintr(int); 109static void siottyintr(void *);
110static void siottysoft(void *); 110static void siottysoft(void *);
111static void siotty_rxsoft(struct siotty_softc *, struct tty *); 111static void siotty_rxsoft(struct siotty_softc *, struct tty *);
112static void siotty_txsoft(struct siotty_softc *, struct tty *); 112static void siotty_txsoft(struct siotty_softc *, struct tty *);
113static int siomctl(struct siotty_softc *, int, int); 113static int siomctl(struct siotty_softc *, int, int);
114 114
115static int siotty_match(device_t, cfdata_t, void *); 115static int siotty_match(device_t, cfdata_t, void *);
116static void siotty_attach(device_t, device_t, void *); 116static void siotty_attach(device_t, device_t, void *);
117 117
118CFATTACH_DECL_NEW(siotty, sizeof(struct siotty_softc), 118CFATTACH_DECL_NEW(siotty, sizeof(struct siotty_softc),
119 siotty_match, siotty_attach, NULL, NULL); 119 siotty_match, siotty_attach, NULL, NULL);
120 120
121dev_type_open(sioopen); 121dev_type_open(sioopen);
122dev_type_close(sioclose); 122dev_type_close(sioclose);
@@ -135,35 +135,38 @@ const struct cdevsw siotty_cdevsw = { @@ -135,35 +135,38 @@ const struct cdevsw siotty_cdevsw = {
135static int 135static int
136siotty_match(device_t parent, cfdata_t cf, void *aux) 136siotty_match(device_t parent, cfdata_t cf, void *aux)
137{ 137{
138 struct sio_attach_args *args = aux; 138 struct sio_attach_args *args = aux;
139 139
140 if (args->channel != 0) /* XXX allow tty on Ch.B XXX */ 140 if (args->channel != 0) /* XXX allow tty on Ch.B XXX */
141 return 0; 141 return 0;
142 return 1; 142 return 1;
143} 143}
144 144
145static void 145static void
146siotty_attach(device_t parent, device_t self, void *aux) 146siotty_attach(device_t parent, device_t self, void *aux)
147{ 147{
148 struct sio_softc *scp = device_private(parent); 148 struct sio_softc *siosc = device_private(parent);
149 struct siotty_softc *sc = device_private(self); 149 struct siotty_softc *sc = device_private(self);
150 struct sio_attach_args *args = aux; 150 struct sio_attach_args *args = aux;
 151 int channel;
151 struct tty *tp; 152 struct tty *tp;
152 153
153 sc->sc_dev = self; 154 sc->sc_dev = self;
154 sc->sc_ctl = (struct sioreg *)scp->scp_ctl + args->channel; 155 channel = args->channel;
 156 sc->sc_ctl = &siosc->sc_ctl[channel];
155 memcpy(sc->sc_wr, ch0_regs, sizeof(ch0_regs)); 157 memcpy(sc->sc_wr, ch0_regs, sizeof(ch0_regs));
156 scp->scp_intr[args->channel] = siottyintr; 158 siosc->sc_intrhand[channel].ih_func = siottyintr;
 159 siosc->sc_intrhand[channel].ih_arg = sc;
157 if (args->hwflags == 1) 160 if (args->hwflags == 1)
158 sc->sc_hwflags |= SIOTTY_HW_CONSOLE; 161 sc->sc_hwflags |= SIOTTY_HW_CONSOLE;
159 162
160 if ((sc->sc_hwflags & SIOTTY_HW_CONSOLE) != 0) { 163 if ((sc->sc_hwflags & SIOTTY_HW_CONSOLE) != 0) {
161 aprint_normal(" (console)"); 164 aprint_normal(" (console)");
162 sc->sc_flags = TIOCFLAG_SOFTCAR; 165 sc->sc_flags = TIOCFLAG_SOFTCAR;
163 } else { 166 } else {
164 setsioreg(sc->sc_ctl, WR0, WR0_CHANRST); 167 setsioreg(sc->sc_ctl, WR0, WR0_CHANRST);
165 setsioreg(sc->sc_ctl, WR2A, WR2_VEC86 | WR2_INTR_1); 168 setsioreg(sc->sc_ctl, WR2A, WR2_VEC86 | WR2_INTR_1);
166 setsioreg(sc->sc_ctl, WR2B, 0); 169 setsioreg(sc->sc_ctl, WR2B, 0);
167 setsioreg(sc->sc_ctl, WR0, sc->sc_wr[WR0]); 170 setsioreg(sc->sc_ctl, WR0, sc->sc_wr[WR0]);
168 setsioreg(sc->sc_ctl, WR4, sc->sc_wr[WR4]); 171 setsioreg(sc->sc_ctl, WR4, sc->sc_wr[WR4]);
169 setsioreg(sc->sc_ctl, WR3, sc->sc_wr[WR3]); 172 setsioreg(sc->sc_ctl, WR3, sc->sc_wr[WR3]);
@@ -189,39 +192,36 @@ siotty_attach(device_t parent, device_t  @@ -189,39 +192,36 @@ siotty_attach(device_t parent, device_t
189 tp->t_hwiflow = NULL /* XXX siohwiflow XXX */; 192 tp->t_hwiflow = NULL /* XXX siohwiflow XXX */;
190 if ((sc->sc_hwflags & SIOTTY_HW_CONSOLE) != 0) 193 if ((sc->sc_hwflags & SIOTTY_HW_CONSOLE) != 0)
191 tp->t_dev = cn_tab->cn_dev; 194 tp->t_dev = cn_tab->cn_dev;
192 sc->sc_tty = tp; 195 sc->sc_tty = tp;
193 196
194 tty_attach(tp); 197 tty_attach(tp);
195 198
196 sc->sc_si = softint_establish(SOFTINT_SERIAL, siottysoft, sc); 199 sc->sc_si = softint_establish(SOFTINT_SERIAL, siottysoft, sc);
197} 200}
198 201
199/*-------------------- low level routine --------------------*/ 202/*-------------------- low level routine --------------------*/
200 203
201static void 204static void
202siottyintr(int chan) 205siottyintr(void *arg)
203{ 206{
204 struct siotty_softc *sc; 207 struct siotty_softc *sc;
205 struct sioreg *sio; 208 struct sioreg *sio;
206 uint8_t *put, *end; 209 uint8_t *put, *end;
207 uint8_t c; 210 uint8_t c;
208 uint16_t rr; 211 uint16_t rr;
209 int cc; 212 int cc;
210 213
211 sc = device_lookup_private(&siotty_cd, chan); 214 sc = arg;
212 if (sc == NULL) 
213 return; 
214 
215 end = sc->sc_rbufend; 215 end = sc->sc_rbufend;
216 put = sc->sc_rbput; 216 put = sc->sc_rbput;
217 cc = sc->sc_rbavail; 217 cc = sc->sc_rbavail;
218 218
219 sio = sc->sc_ctl; 219 sio = sc->sc_ctl;
220 rr = getsiocsr(sio); 220 rr = getsiocsr(sio);
221 if ((rr & RR_BREAK) != 0) { 221 if ((rr & RR_BREAK) != 0) {
222 sio->sio_cmd = WR0_RSTINT; 222 sio->sio_cmd = WR0_RSTINT;
223 cn_check_magic(sc->sc_tty->t_dev, CNC_BREAK, siotty_cnm_state); 223 cn_check_magic(sc->sc_tty->t_dev, CNC_BREAK, siotty_cnm_state);
224 } 224 }
225 if (rr & RR_RXRDY) { 225 if (rr & RR_RXRDY) {
226 do { 226 do {
227 if (cc > 0) { 227 if (cc > 0) {

cvs diff -r1.7 -r1.8 src/sys/arch/luna68k/dev/siovar.h (expand / switch to unified diff)

--- src/sys/arch/luna68k/dev/siovar.h 2013/12/31 14:24:09 1.7
+++ src/sys/arch/luna68k/dev/siovar.h 2014/02/02 15:35:06 1.8
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: siovar.h,v 1.7 2013/12/31 14:24:09 tsutsui Exp $ */ 1/* $NetBSD: siovar.h,v 1.8 2014/02/02 15:35:06 tsutsui Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc. 4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Tohru Nishimura. 8 * by Tohru Nishimura.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -19,34 +19,37 @@ @@ -19,34 +19,37 @@
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 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 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 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 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 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32struct sio_softc { 
33 device_t scp_dev; 
34 void *scp_ctl; 
35 void (*scp_intr[2])(int); 
36}; 
37 
38struct sio_attach_args { 32struct sio_attach_args {
39 int channel; 33 int channel;
40 int hwflags; 34 int hwflags;
41}; 35};
42 36
43struct sioreg { 37struct sioreg {
44 volatile uint8_t sio_data; 38 volatile uint8_t sio_data;
45 uint8_t pad0; 39 uint8_t pad0;
46 volatile uint8_t sio_cmd; 40 volatile uint8_t sio_cmd;
47 uint8_t pad1; 41 uint8_t pad1;
48#define sio_stat sio_cmd 42#define sio_stat sio_cmd
49}; 43};
50 44
 45struct sio_softc {
 46 device_t sc_dev;
 47 struct sioreg *sc_ctl;
 48 struct {
 49 void (*ih_func)(void *);
 50 void *ih_arg;
 51 } sc_intrhand[2];
 52};
 53
51uint16_t getsiocsr(struct sioreg *); 54uint16_t getsiocsr(struct sioreg *);
52void setsioreg(struct sioreg *, int, int); 55void setsioreg(struct sioreg *, int, int);