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