Thu Feb 20 02:09:28 2014 UTC ()
Call memset in a loop, not loop around doing nothing and calling memset
once.


(joerg)
diff -r1.31 -r1.32 src/sys/dev/sun/bwtwo.c

cvs diff -r1.31 -r1.32 src/sys/dev/sun/bwtwo.c (switch to unified diff)

--- src/sys/dev/sun/bwtwo.c 2013/12/02 15:54:06 1.31
+++ src/sys/dev/sun/bwtwo.c 2014/02/20 02:09:28 1.32
@@ -1,471 +1,471 @@ @@ -1,471 +1,471 @@
1/* $NetBSD: bwtwo.c,v 1.31 2013/12/02 15:54:06 jdc Exp $ */ 1/* $NetBSD: bwtwo.c,v 1.32 2014/02/20 02:09:28 joerg Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. 4 * Copyright (c) 1996, 1997 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 Jason R. Thorpe. 8 * by Jason R. Thorpe.
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.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
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
32/* 32/*
33 * Copyright (c) 1992, 1993 33 * Copyright (c) 1992, 1993
34 * The Regents of the University of California. All rights reserved. 34 * The Regents of the University of California. All rights reserved.
35 * 35 *
36 * This software was developed by the Computer Systems Engineering group 36 * This software was developed by the Computer Systems Engineering group
37 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 37 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
38 * contributed to Berkeley. 38 * contributed to Berkeley.
39 * 39 *
40 * All advertising materials mentioning features or use of this software 40 * All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement: 41 * must display the following acknowledgement:
42 * This product includes software developed by the University of 42 * This product includes software developed by the University of
43 * California, Lawrence Berkeley Laboratory. 43 * California, Lawrence Berkeley Laboratory.
44 * 44 *
45 * Redistribution and use in source and binary forms, with or without 45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions 46 * modification, are permitted provided that the following conditions
47 * are met: 47 * are met:
48 * 1. Redistributions of source code must retain the above copyright 48 * 1. Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer. 49 * notice, this list of conditions and the following disclaimer.
50 * 2. Redistributions in binary form must reproduce the above copyright 50 * 2. Redistributions in binary form must reproduce the above copyright
51 * notice, this list of conditions and the following disclaimer in the 51 * notice, this list of conditions and the following disclaimer in the
52 * documentation and/or other materials provided with the distribution. 52 * documentation and/or other materials provided with the distribution.
53 * 3. Neither the name of the University nor the names of its contributors 53 * 3. Neither the name of the University nor the names of its contributors
54 * may be used to endorse or promote products derived from this software 54 * may be used to endorse or promote products derived from this software
55 * without specific prior written permission. 55 * without specific prior written permission.
56 * 56 *
57 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 57 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
58 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 58 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
59 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 59 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
60 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 60 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
61 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 61 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
62 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 62 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
63 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 63 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
64 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 64 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
65 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 65 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
66 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 66 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
67 * SUCH DAMAGE. 67 * SUCH DAMAGE.
68 * 68 *
69 * @(#)bwtwo.c 8.1 (Berkeley) 6/11/93 69 * @(#)bwtwo.c 8.1 (Berkeley) 6/11/93
70 */ 70 */
71 71
72/* 72/*
73 * black & white display (bwtwo) driver. 73 * black & white display (bwtwo) driver.
74 * 74 *
75 * Does not handle interrupts, even though they can occur. 75 * Does not handle interrupts, even though they can occur.
76 * 76 *
77 * P4 and overlay plane support by Jason R. Thorpe <thorpej@NetBSD.org>. 77 * P4 and overlay plane support by Jason R. Thorpe <thorpej@NetBSD.org>.
78 * Overlay plane handling hints and ideas provided by Brad Spencer. 78 * Overlay plane handling hints and ideas provided by Brad Spencer.
79 */ 79 */
80 80
81#include <sys/cdefs.h> 81#include <sys/cdefs.h>
82__KERNEL_RCSID(0, "$NetBSD: bwtwo.c,v 1.31 2013/12/02 15:54:06 jdc Exp $"); 82__KERNEL_RCSID(0, "$NetBSD: bwtwo.c,v 1.32 2014/02/20 02:09:28 joerg Exp $");
83 83
84#include <sys/param.h> 84#include <sys/param.h>
85#include <sys/systm.h> 85#include <sys/systm.h>
86#include <sys/device.h> 86#include <sys/device.h>
87#include <sys/ioctl.h> 87#include <sys/ioctl.h>
88#include <sys/malloc.h> 88#include <sys/malloc.h>
89#include <sys/mman.h> 89#include <sys/mman.h>
90#include <sys/tty.h> 90#include <sys/tty.h>
91#include <sys/conf.h> 91#include <sys/conf.h>
92 92
93#include <machine/autoconf.h> 93#include <machine/autoconf.h>
94#include <machine/eeprom.h> 94#include <machine/eeprom.h>
95 95
96#include <dev/sun/fbio.h> 96#include <dev/sun/fbio.h>
97#include <dev/sun/fbvar.h> 97#include <dev/sun/fbvar.h>
98 98
99#include <dev/sun/btreg.h> 99#include <dev/sun/btreg.h>
100#include <dev/sun/bwtworeg.h> 100#include <dev/sun/bwtworeg.h>
101#include <dev/sun/bwtwovar.h> 101#include <dev/sun/bwtwovar.h>
102#include <dev/sun/pfourreg.h> 102#include <dev/sun/pfourreg.h>
103 103
104#if NWSDISPLAY > 0 104#if NWSDISPLAY > 0
105#include <dev/wscons/wsconsio.h> 105#include <dev/wscons/wsconsio.h>
106#include <dev/wsfont/wsfont.h> 106#include <dev/wsfont/wsfont.h>
107#include <dev/rasops/rasops.h> 107#include <dev/rasops/rasops.h>
108 108
109#include "opt_wsemul.h" 109#include "opt_wsemul.h"
110#endif 110#endif
111 111
112#include "ioconf.h" 112#include "ioconf.h"
113 113
114dev_type_open(bwtwoopen); 114dev_type_open(bwtwoopen);
115dev_type_ioctl(bwtwoioctl); 115dev_type_ioctl(bwtwoioctl);
116dev_type_mmap(bwtwommap); 116dev_type_mmap(bwtwommap);
117 117
118const struct cdevsw bwtwo_cdevsw = { 118const struct cdevsw bwtwo_cdevsw = {
119 bwtwoopen, nullclose, noread, nowrite, bwtwoioctl, 119 bwtwoopen, nullclose, noread, nowrite, bwtwoioctl,
120 nostop, notty, nopoll, bwtwommap, nokqfilter, D_OTHER 120 nostop, notty, nopoll, bwtwommap, nokqfilter, D_OTHER
121}; 121};
122 122
123/* XXX we do not handle frame buffer interrupts (do not know how) */ 123/* XXX we do not handle frame buffer interrupts (do not know how) */
124static void bwtwounblank(device_t); 124static void bwtwounblank(device_t);
125 125
126/* frame buffer generic driver */ 126/* frame buffer generic driver */
127static struct fbdriver bwtwofbdriver = { 127static struct fbdriver bwtwofbdriver = {
128 bwtwounblank, bwtwoopen, nullclose, bwtwoioctl, nopoll, bwtwommap, 128 bwtwounblank, bwtwoopen, nullclose, bwtwoioctl, nopoll, bwtwommap,
129 nokqfilter 129 nokqfilter
130}; 130};
131 131
132#if NWSDISPLAY > 0 132#if NWSDISPLAY > 0
133#ifdef RASTERCONSOLE 133#ifdef RASTERCONSOLE
134#error RASTERCONSOLE and wsdisplay are mutually exclusive 134#error RASTERCONSOLE and wsdisplay are mutually exclusive
135#endif 135#endif
136 136
137struct wsscreen_descr bwtwo_defaultscreen = { 137struct wsscreen_descr bwtwo_defaultscreen = {
138 "std", 138 "std",
139 0, 0, /* will be filled in -- XXX shouldn't, it's global */ 139 0, 0, /* will be filled in -- XXX shouldn't, it's global */
140 NULL, /* textops */ 140 NULL, /* textops */
141 8, 16, /* font width/height */ 141 8, 16, /* font width/height */
142 0, /* capabilities */ 142 0, /* capabilities */
143 NULL /* modecookie */ 143 NULL /* modecookie */
144}; 144};
145 145
146static int bwtwo_ioctl(void *, void *, u_long, void *, int, struct lwp *); 146static int bwtwo_ioctl(void *, void *, u_long, void *, int, struct lwp *);
147static paddr_t bwtwo_mmap(void *, void *, off_t, int); 147static paddr_t bwtwo_mmap(void *, void *, off_t, int);
148static void bwtwo_init_screen(void *, struct vcons_screen *, int, long *); 148static void bwtwo_init_screen(void *, struct vcons_screen *, int, long *);
149 149
150struct wsdisplay_accessops bwtwo_accessops = { 150struct wsdisplay_accessops bwtwo_accessops = {
151 bwtwo_ioctl, 151 bwtwo_ioctl,
152 bwtwo_mmap, 152 bwtwo_mmap,
153 NULL, /* alloc_screen */ 153 NULL, /* alloc_screen */
154 NULL, /* free_screen */ 154 NULL, /* free_screen */
155 NULL, /* show_screen */ 155 NULL, /* show_screen */
156 NULL, /* load_font */ 156 NULL, /* load_font */
157 NULL, /* pollc */ 157 NULL, /* pollc */
158 NULL /* scroll */ 158 NULL /* scroll */
159}; 159};
160 160
161const struct wsscreen_descr *_bwtwo_scrlist[] = { 161const struct wsscreen_descr *_bwtwo_scrlist[] = {
162 &bwtwo_defaultscreen 162 &bwtwo_defaultscreen
163}; 163};
164 164
165struct wsscreen_list bwtwo_screenlist = { 165struct wsscreen_list bwtwo_screenlist = {
166 sizeof(_bwtwo_scrlist) / sizeof(struct wsscreen_descr *), 166 sizeof(_bwtwo_scrlist) / sizeof(struct wsscreen_descr *),
167 _bwtwo_scrlist 167 _bwtwo_scrlist
168}; 168};
169 169
170 170
171static struct vcons_screen bw2_console_screen; 171static struct vcons_screen bw2_console_screen;
172#endif /* NWSDISPLAY > 0 */ 172#endif /* NWSDISPLAY > 0 */
173 173
174int 174int
175bwtwo_pfour_probe(void *vaddr, void *arg) 175bwtwo_pfour_probe(void *vaddr, void *arg)
176{ 176{
177 cfdata_t cf = arg; 177 cfdata_t cf = arg;
178 178
179 switch (fb_pfour_id(vaddr)) { 179 switch (fb_pfour_id(vaddr)) {
180 case PFOUR_ID_BW: 180 case PFOUR_ID_BW:
181 case PFOUR_ID_COLOR8P1: /* bwtwo in ... */ 181 case PFOUR_ID_COLOR8P1: /* bwtwo in ... */
182 case PFOUR_ID_COLOR24: /* ...overlay plane */ 182 case PFOUR_ID_COLOR24: /* ...overlay plane */
183 /* This is wrong; should be done in bwtwo_attach() */ 183 /* This is wrong; should be done in bwtwo_attach() */
184 cf->cf_flags |= FB_PFOUR; 184 cf->cf_flags |= FB_PFOUR;
185 /* FALLTHROUGH */ 185 /* FALLTHROUGH */
186 case PFOUR_NOTPFOUR: 186 case PFOUR_NOTPFOUR:
187 return (1); 187 return (1);
188 } 188 }
189 return (0); 189 return (0);
190} 190}
191 191
192void 192void
193bwtwoattach(struct bwtwo_softc *sc, const char *name, int isconsole) 193bwtwoattach(struct bwtwo_softc *sc, const char *name, int isconsole)
194{ 194{
195 struct fbdevice *fb = &sc->sc_fb; 195 struct fbdevice *fb = &sc->sc_fb;
196 int isoverlay; 196 int isoverlay;
197#if NWSDISPLAY > 0 197#if NWSDISPLAY > 0
198 struct wsemuldisplaydev_attach_args aa; 198 struct wsemuldisplaydev_attach_args aa;
199 struct rasops_info *ri = &bw2_console_screen.scr_ri; 199 struct rasops_info *ri = &bw2_console_screen.scr_ri;
200 unsigned long defattr = 0; 200 unsigned long defattr = 0;
201#endif 201#endif
202 202
203 /* Fill in the remaining fbdevice values */ 203 /* Fill in the remaining fbdevice values */
204 fb->fb_driver = &bwtwofbdriver; 204 fb->fb_driver = &bwtwofbdriver;
205 fb->fb_device = sc->sc_dev; 205 fb->fb_device = sc->sc_dev;
206 fb->fb_type.fb_type = FBTYPE_SUN2BW; 206 fb->fb_type.fb_type = FBTYPE_SUN2BW;
207 fb->fb_type.fb_cmsize = 0; 207 fb->fb_type.fb_cmsize = 0;
208 fb->fb_type.fb_size = fb->fb_type.fb_height * fb->fb_linebytes; 208 fb->fb_type.fb_size = fb->fb_type.fb_height * fb->fb_linebytes;
209 printf(": %s, %d x %d", name, 209 printf(": %s, %d x %d", name,
210 fb->fb_type.fb_width, fb->fb_type.fb_height); 210 fb->fb_type.fb_width, fb->fb_type.fb_height);
211 211
212 /* Are we an overlay bw2? */ 212 /* Are we an overlay bw2? */
213 if ((fb->fb_flags & FB_PFOUR) == 0 || (sc->sc_ovtype == BWO_NONE)) 213 if ((fb->fb_flags & FB_PFOUR) == 0 || (sc->sc_ovtype == BWO_NONE))
214 isoverlay = 0; 214 isoverlay = 0;
215 else 215 else
216 isoverlay = 1; 216 isoverlay = 1;
217 217
218 /* Insure video is enabled */ 218 /* Insure video is enabled */
219 sc->sc_set_video(sc, 1); 219 sc->sc_set_video(sc, 1);
220 220
221 if (isconsole) { 221 if (isconsole) {
222 printf(" (console)\n"); 222 printf(" (console)\n");
223#ifdef RASTERCONSOLE 223#ifdef RASTERCONSOLE
224 /* 224 /*
225 * XXX rcons doesn't seem to work properly on the overlay 225 * XXX rcons doesn't seem to work properly on the overlay
226 * XXX plane. This is a temporary kludge until someone 226 * XXX plane. This is a temporary kludge until someone
227 * XXX fixes it. 227 * XXX fixes it.
228 */ 228 */
229 if (!isoverlay) 229 if (!isoverlay)
230 fbrcons_init(fb); 230 fbrcons_init(fb);
231#endif 231#endif
232 } else 232 } else
233 printf("\n"); 233 printf("\n");
234 234
235 if (isoverlay) { 235 if (isoverlay) {
236 const char *ovnam; 236 const char *ovnam;
237 237
238 switch (sc->sc_ovtype) { 238 switch (sc->sc_ovtype) {
239 case BWO_CGFOUR: 239 case BWO_CGFOUR:
240 ovnam = "cgfour"; 240 ovnam = "cgfour";
241 break; 241 break;
242 242
243 case BWO_CGEIGHT: 243 case BWO_CGEIGHT:
244 ovnam = "cgeight"; 244 ovnam = "cgeight";
245 break; 245 break;
246 246
247 default: 247 default:
248 ovnam = "unknown"; 248 ovnam = "unknown";
249 break; 249 break;
250 } 250 }
251 printf("%s: %s overlay plane\n", 251 printf("%s: %s overlay plane\n",
252 device_xname(sc->sc_dev), ovnam); 252 device_xname(sc->sc_dev), ovnam);
253 } 253 }
254 254
255 /* 255 /*
256 * If we're on an overlay plane of a color framebuffer, 256 * If we're on an overlay plane of a color framebuffer,
257 * then we don't force the issue in fb_attach() because 257 * then we don't force the issue in fb_attach() because
258 * we'd like the color framebuffer to actually be the 258 * we'd like the color framebuffer to actually be the
259 * "console framebuffer". We're only around to speed 259 * "console framebuffer". We're only around to speed
260 * up rconsole. 260 * up rconsole.
261 */ 261 */
262 if (isoverlay) 262 if (isoverlay)
263 fb_attach(fb, 0); 263 fb_attach(fb, 0);
264 else 264 else
265 fb_attach(fb, isconsole); 265 fb_attach(fb, isconsole);
266 266
267#if NWSDISPLAY > 0 267#if NWSDISPLAY > 0
268 sc->sc_width = fb->fb_type.fb_width; 268 sc->sc_width = fb->fb_type.fb_width;
269 sc->sc_stride = fb->fb_type.fb_width/8; 269 sc->sc_stride = fb->fb_type.fb_width/8;
270 sc->sc_height = fb->fb_type.fb_height; 270 sc->sc_height = fb->fb_type.fb_height;
271 271
272 /* setup rasops and so on for wsdisplay */ 272 /* setup rasops and so on for wsdisplay */
273 sc->sc_mode = WSDISPLAYIO_MODE_EMUL; 273 sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
274 274
275 vcons_init(&sc->vd, sc, &bwtwo_defaultscreen, &bwtwo_accessops); 275 vcons_init(&sc->vd, sc, &bwtwo_defaultscreen, &bwtwo_accessops);
276 sc->vd.init_screen = bwtwo_init_screen; 276 sc->vd.init_screen = bwtwo_init_screen;
277 277
278 if(isconsole && !isoverlay) { 278 if(isconsole && !isoverlay) {
279 /* we mess with bw2_console_screen only once */ 279 /* we mess with bw2_console_screen only once */
280 vcons_init_screen(&sc->vd, &bw2_console_screen, 1, 280 vcons_init_screen(&sc->vd, &bw2_console_screen, 1,
281 &defattr); 281 &defattr);
282 bw2_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC; 282 bw2_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
283 283
284 bwtwo_defaultscreen.textops = &ri->ri_ops; 284 bwtwo_defaultscreen.textops = &ri->ri_ops;
285 bwtwo_defaultscreen.capabilities = ri->ri_caps; 285 bwtwo_defaultscreen.capabilities = ri->ri_caps;
286 bwtwo_defaultscreen.nrows = ri->ri_rows; 286 bwtwo_defaultscreen.nrows = ri->ri_rows;
287 bwtwo_defaultscreen.ncols = ri->ri_cols; 287 bwtwo_defaultscreen.ncols = ri->ri_cols;
288 sc->vd.active = &bw2_console_screen; 288 sc->vd.active = &bw2_console_screen;
289 wsdisplay_cnattach(&bwtwo_defaultscreen, ri, 0, 0, defattr); 289 wsdisplay_cnattach(&bwtwo_defaultscreen, ri, 0, 0, defattr);
290 } else { 290 } else {
291 /*  291 /*
292 * we're not the console so we just clear the screen and don't  292 * we're not the console so we just clear the screen and don't
293 * set up any sort of text display 293 * set up any sort of text display
294 */ 294 */
295 if (bwtwo_defaultscreen.textops == NULL) { 295 if (bwtwo_defaultscreen.textops == NULL) {
296 /*  296 /*
297 * ugly, but... 297 * ugly, but...
298 * we want the console settings to win, so we only 298 * we want the console settings to win, so we only
299 * touch anything when we find an untouched screen 299 * touch anything when we find an untouched screen
300 * definition. In this case we fill it from fb to 300 * definition. In this case we fill it from fb to
301 * avoid problems in case no bwtwo is the console 301 * avoid problems in case no bwtwo is the console
302 */ 302 */
303 ri = &sc->sc_fb.fb_rinfo; 303 ri = &sc->sc_fb.fb_rinfo;
304 bwtwo_defaultscreen.textops = &ri->ri_ops; 304 bwtwo_defaultscreen.textops = &ri->ri_ops;
305 bwtwo_defaultscreen.capabilities = ri->ri_caps; 305 bwtwo_defaultscreen.capabilities = ri->ri_caps;
306 bwtwo_defaultscreen.nrows = ri->ri_rows; 306 bwtwo_defaultscreen.nrows = ri->ri_rows;
307 bwtwo_defaultscreen.ncols = ri->ri_cols; 307 bwtwo_defaultscreen.ncols = ri->ri_cols;
308 } 308 }
309 } 309 }
310 310
311 aa.scrdata = &bwtwo_screenlist; 311 aa.scrdata = &bwtwo_screenlist;
312 if (isoverlay) 312 if (isoverlay)
313 aa.console = 0; 313 aa.console = 0;
314 else 314 else
315 aa.console = isconsole; 315 aa.console = isconsole;
316 aa.accessops = &bwtwo_accessops; 316 aa.accessops = &bwtwo_accessops;
317 aa.accesscookie = &sc->vd; 317 aa.accesscookie = &sc->vd;
318 config_found(sc->sc_dev, &aa, wsemuldisplaydevprint); 318 config_found(sc->sc_dev, &aa, wsemuldisplaydevprint);
319#endif 319#endif
320 320
321} 321}
322 322
323int 323int
324bwtwoopen(dev_t dev, int flags, int mode, struct lwp *l) 324bwtwoopen(dev_t dev, int flags, int mode, struct lwp *l)
325{ 325{
326 int unit = minor(dev); 326 int unit = minor(dev);
327 327
328 if (device_lookup(&bwtwo_cd, unit) == NULL) 328 if (device_lookup(&bwtwo_cd, unit) == NULL)
329 return (ENXIO); 329 return (ENXIO);
330 330
331 return (0); 331 return (0);
332} 332}
333 333
334int 334int
335bwtwoioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *l) 335bwtwoioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *l)
336{ 336{
337 struct bwtwo_softc *sc = device_lookup_private(&bwtwo_cd, minor(dev)); 337 struct bwtwo_softc *sc = device_lookup_private(&bwtwo_cd, minor(dev));
338 338
339 switch (cmd) { 339 switch (cmd) {
340 340
341 case FBIOGTYPE: 341 case FBIOGTYPE:
342 *(struct fbtype *)data = sc->sc_fb.fb_type; 342 *(struct fbtype *)data = sc->sc_fb.fb_type;
343 break; 343 break;
344 344
345 case FBIOGVIDEO: 345 case FBIOGVIDEO:
346 *(int *)data = sc->sc_get_video(sc); 346 *(int *)data = sc->sc_get_video(sc);
347 break; 347 break;
348 348
349 case FBIOSVIDEO: 349 case FBIOSVIDEO:
350 sc->sc_set_video(sc, (*(int *)data)); 350 sc->sc_set_video(sc, (*(int *)data));
351 break; 351 break;
352 352
353 default: 353 default:
354 return (ENOTTY); 354 return (ENOTTY);
355 } 355 }
356 return (0); 356 return (0);
357} 357}
358 358
359static void 359static void
360bwtwounblank(device_t dev) 360bwtwounblank(device_t dev)
361{ 361{
362 struct bwtwo_softc *sc = device_private(dev); 362 struct bwtwo_softc *sc = device_private(dev);
363 363
364 sc->sc_set_video(sc, 1); 364 sc->sc_set_video(sc, 1);
365} 365}
366 366
367/* 367/*
368 * Return the address that would map the given device at the given 368 * Return the address that would map the given device at the given
369 * offset, allowing for the given protection, or return -1 for error. 369 * offset, allowing for the given protection, or return -1 for error.
370 */ 370 */
371paddr_t 371paddr_t
372bwtwommap(dev_t dev, off_t off, int prot) 372bwtwommap(dev_t dev, off_t off, int prot)
373{ 373{
374 struct bwtwo_softc *sc = device_lookup_private(&bwtwo_cd, minor(dev)); 374 struct bwtwo_softc *sc = device_lookup_private(&bwtwo_cd, minor(dev));
375 375
376 if (off & PGOFSET) 376 if (off & PGOFSET)
377 panic("bwtwommap"); 377 panic("bwtwommap");
378 378
379 if (off >= sc->sc_fb.fb_type.fb_size) 379 if (off >= sc->sc_fb.fb_type.fb_size)
380 return (-1); 380 return (-1);
381 381
382 return (bus_space_mmap(sc->sc_bustag, 382 return (bus_space_mmap(sc->sc_bustag,
383 sc->sc_paddr, sc->sc_pixeloffset + off, 383 sc->sc_paddr, sc->sc_pixeloffset + off,
384 prot, BUS_SPACE_MAP_LINEAR)); 384 prot, BUS_SPACE_MAP_LINEAR));
385} 385}
386 386
387#if NWSDISPLAY > 0 387#if NWSDISPLAY > 0
388 388
389int 389int
390bwtwo_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, 390bwtwo_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
391 struct lwp *l) 391 struct lwp *l)
392{ 392{
393 /* we'll probably need to add more stuff here */ 393 /* we'll probably need to add more stuff here */
394 struct vcons_data *vd = v; 394 struct vcons_data *vd = v;
395 struct bwtwo_softc *sc = vd->cookie; 395 struct bwtwo_softc *sc = vd->cookie;
396 struct wsdisplay_fbinfo *wdf; 396 struct wsdisplay_fbinfo *wdf;
397 struct rasops_info *ri = &sc->sc_fb.fb_rinfo; 397 struct rasops_info *ri = &sc->sc_fb.fb_rinfo;
398 struct vcons_screen *ms = sc->vd.active; 398 struct vcons_screen *ms = sc->vd.active;
399 switch (cmd) { 399 switch (cmd) {
400 case WSDISPLAYIO_GTYPE: 400 case WSDISPLAYIO_GTYPE:
401 *(u_int *)data = WSDISPLAY_TYPE_GENFB; 401 *(u_int *)data = WSDISPLAY_TYPE_GENFB;
402 return 0; 402 return 0;
403 case WSDISPLAYIO_GINFO: 403 case WSDISPLAYIO_GINFO:
404 wdf = (void *)data; 404 wdf = (void *)data;
405 wdf->height = ri->ri_height; 405 wdf->height = ri->ri_height;
406 wdf->width = ri->ri_width; 406 wdf->width = ri->ri_width;
407 wdf->depth = ri->ri_depth; 407 wdf->depth = ri->ri_depth;
408 wdf->cmsize = 0; 408 wdf->cmsize = 0;
409 return 0; 409 return 0;
410 410
411 case WSDISPLAYIO_GETCMAP: 411 case WSDISPLAYIO_GETCMAP:
412 return EINVAL; 412 return EINVAL;
413 case WSDISPLAYIO_PUTCMAP: 413 case WSDISPLAYIO_PUTCMAP:
414 return EINVAL; 414 return EINVAL;
415 415
416 case WSDISPLAYIO_SMODE: 416 case WSDISPLAYIO_SMODE:
417 { 417 {
418 int new_mode = *(int*)data; 418 int new_mode = *(int*)data;
419 if (new_mode != sc->sc_mode) 419 if (new_mode != sc->sc_mode)
420 { 420 {
421 sc->sc_mode = new_mode; 421 sc->sc_mode = new_mode;
422 if(new_mode == WSDISPLAYIO_MODE_EMUL) 422 if(new_mode == WSDISPLAYIO_MODE_EMUL)
423 { 423 {
424 vcons_redraw_screen(ms); 424 vcons_redraw_screen(ms);
425 } 425 }
426 } 426 }
427 } 427 }
428 } 428 }
429 return EPASSTHROUGH; 429 return EPASSTHROUGH;
430} 430}
431 431
432paddr_t 432paddr_t
433bwtwo_mmap(void *v, void *vs, off_t offset, int prot) 433bwtwo_mmap(void *v, void *vs, off_t offset, int prot)
434{ 434{
435 /* I'm not at all sure this is the right thing to do */ 435 /* I'm not at all sure this is the right thing to do */
436 return bwtwommap(0, offset, prot); /* assume minor dev 0 for now */ 436 return bwtwommap(0, offset, prot); /* assume minor dev 0 for now */
437} 437}
438 438
439void 439void
440bwtwo_init_screen(void *cookie, struct vcons_screen *scr, 440bwtwo_init_screen(void *cookie, struct vcons_screen *scr,
441 int existing, long *defattr) 441 int existing, long *defattr)
442{ 442{
443 struct bwtwo_softc *sc = cookie; 443 struct bwtwo_softc *sc = cookie;
444 struct rasops_info *ri = &scr->scr_ri; 444 struct rasops_info *ri = &scr->scr_ri;
445 char *bits; 445 char *bits;
446 446
447 ri->ri_depth = 1; 447 ri->ri_depth = 1;
448 ri->ri_width = sc->sc_width; 448 ri->ri_width = sc->sc_width;
449 ri->ri_height = sc->sc_height; 449 ri->ri_height = sc->sc_height;
450 ri->ri_stride = sc->sc_stride; 450 ri->ri_stride = sc->sc_stride;
451 ri->ri_flg = RI_CENTER; 451 ri->ri_flg = RI_CENTER;
452 452
453 ri->ri_bits = sc->sc_fb.fb_pixels; 453 ri->ri_bits = sc->sc_fb.fb_pixels;
454 454
455 /* 455 /*
456 * Make sure that we set a maximum of 32 bits at a time, 456 * Make sure that we set a maximum of 32 bits at a time,
457 * otherwise we'll see VME write errors if this is a P4 BW2. 457 * otherwise we'll see VME write errors if this is a P4 BW2.
458 */ 458 */
459 for (bits = (char *) ri->ri_bits; 459 for (bits = (char *) ri->ri_bits;
460 bits < (char *) ri->ri_bits + ri->ri_stride * ri->ri_height; 460 bits < (char *) ri->ri_bits + ri->ri_stride * ri->ri_height;
461 bits += 4); 461 bits += 4)
462 memset(bits, (*defattr >> 16) & 0xff, 4); 462 memset(bits, (*defattr >> 16) & 0xff, 4);
463 rasops_init(ri, 0, 0); 463 rasops_init(ri, 0, 0);
464 ri->ri_caps = 0; 464 ri->ri_caps = 0;
465 rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight, 465 rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
466 sc->sc_width / ri->ri_font->fontwidth); 466 sc->sc_width / ri->ri_font->fontwidth);
467 467
468 ri->ri_hw = scr; 468 ri->ri_hw = scr;
469} 469}
470 470
471#endif /* NWSDISPLAY > 0 */ 471#endif /* NWSDISPLAY > 0 */