1 /* $NetBSD: nextdisplay.c,v 1.3 1999/12/06 19:25:58 drochner Exp $ */ 2 3 /* 4 * Copyright (c) 1998 Matt DeBergalis 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Matt DeBergalis 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 34 35 #include <sys/param.h> 36 #include <sys/systm.h> 37 #include <sys/kernel.h> 38 #include <sys/device.h> 39 #include <sys/malloc.h> 40 41 #include <machine/cpu.h> 42 #include <machine/bus.h> 43 44 #include <next68k/next68k/nextrom.h> 45 46 #include <next68k/dev/nextdisplayvar.h> 47 #include <dev/wscons/wsconsio.h> 48 49 #include <dev/rcons/raster.h> 50 #include <dev/wscons/wscons_raster.h> 51 #include <dev/wscons/wsdisplayvar.h> 52 53 int nextdisplay_match __P((struct device *, struct cfdata *, void *)); 54 void nextdisplay_attach __P((struct device *, struct device *, void *)); 55 56 struct cfattach nextdisplay_ca = { 57 sizeof(struct nextdisplay_softc), 58 nextdisplay_match, 59 nextdisplay_attach, 60 }; 61 62 const struct wsdisplay_emulops nextdisplay_mono_emulops = { 63 rcons_cursor, 64 rcons_mapchar, 65 rcons_putchar, 66 rcons_copycols, 67 rcons_erasecols, 68 rcons_copyrows, 69 rcons_eraserows, 70 rcons_alloc_attr 71 }; 72 73 struct wsscreen_descr nextdisplay_mono = { 74 "mono", 75 0, 0, /* will be filled in -- XXX shouldn't, it's global */ 76 &nextdisplay_mono_emulops, 77 0, 0 78 }; 79 80 struct wsscreen_descr nextdisplay_color = { 81 "color", 82 0, 0, /* again, filled in */ 83 &nextdisplay_mono_emulops, 84 0, 0 85 }; 86 87 const struct wsscreen_descr *_nextdisplay_scrlist_mono[] = { 88 &nextdisplay_mono, 89 }; 90 91 const struct wsscreen_descr *_nextdisplay_scrlist_color[] = { 92 &nextdisplay_color, 93 }; 94 95 const struct wsscreen_list nextdisplay_screenlist_mono = { 96 sizeof(_nextdisplay_scrlist_mono) / sizeof(struct wsscreen_descr *), 97 _nextdisplay_scrlist_mono 98 }; 99 100 const struct wsscreen_list nextdisplay_screenlist_color = { 101 sizeof(_nextdisplay_scrlist_color) / sizeof(struct wsscreen_descr *), 102 _nextdisplay_scrlist_color 103 }; 104 105 static int nextdisplay_ioctl __P((void *, u_long, caddr_t, int, struct proc *)); 106 static int nextdisplay_mmap __P((void *, off_t, int)); 107 static int nextdisplay_alloc_screen __P((void *, const struct wsscreen_descr *, 108 void **, int *, int *, long *)); 109 static void nextdisplay_free_screen __P((void *, void *)); 110 static int nextdisplay_show_screen __P((void *, void *, int, 111 void (*) (void *, int, int), void *)); 112 static int nextdisplay_load_font __P((void *, void *, struct wsdisplay_font *)); 113 114 const struct wsdisplay_accessops nextdisplay_accessops = { 115 nextdisplay_ioctl, 116 nextdisplay_mmap, 117 nextdisplay_alloc_screen, 118 nextdisplay_free_screen, 119 nextdisplay_show_screen, 120 nextdisplay_load_font 121 }; 122 123 void nextdisplay_init(struct nextdisplay_config *, int); 124 125 paddr_t nextdisplay_consaddr; 126 static int nextdisplay_is_console __P((paddr_t addr)); 127 128 static struct nextdisplay_config nextdisplay_console_dc; 129 130 static int 131 nextdisplay_is_console(paddr_t addr) 132 { 133 return (nextdisplay_console_dc.isconsole 134 && (addr == nextdisplay_consaddr)); 135 } 136 137 int 138 nextdisplay_match(parent, match, aux) 139 struct device *parent; 140 struct cfdata *match; 141 void *aux; 142 { 143 if ((rom_machine_type == NeXT_WARP9) 144 || (rom_machine_type == NeXT_X15)) 145 return (1); 146 else 147 return (0); 148 } 149 150 void 151 nextdisplay_init(dc, color) 152 struct nextdisplay_config *dc; 153 int color; 154 { 155 struct raster *rap; 156 struct rcons *rcp; 157 paddr_t addr; 158 int i; 159 160 /* printf("in nextdisplay_init\n"); */ 161 162 if (color) 163 addr = (paddr_t)colorbase; 164 else 165 addr = (paddr_t)monobase; 166 167 dc->dc_vaddr = addr; 168 dc->dc_paddr = color ? COLORP(addr) : MONOP(addr); 169 dc->dc_size = color ? NEXT_P_C16_VIDEOSIZE : NEXT_P_VIDEOSIZE; 170 171 dc->dc_wid = 1152; /* XXX color */ 172 dc->dc_ht = 832; /* XXX color */ 173 dc->dc_depth = color ? 8 : 2; 174 dc->dc_rowbytes = dc->dc_wid * dc->dc_depth / 8; 175 176 dc->dc_videobase = dc->dc_vaddr; 177 178 #if 0 179 printf("intiobase at: %08x\n", intiobase); 180 printf("intiolimit at: %08x\n", intiolimit); 181 printf("videobase at: %08x\n", color ? colorbase : monobase); 182 printf("videolimit at: %08x\n", color ? colorlimit : monolimit); 183 184 printf("virtual fb at: %08x\n", dc->dc_vaddr); 185 printf("physical fb at: %08x\n", dc->dc_paddr); 186 printf("fb size: %08x\n", dc->dc_size); 187 188 printf("dc_wid: %08x\n", dc->dc_wid); 189 printf("dc_ht: %08x\n", dc->dc_ht); 190 printf("dc_depth: %08x\n", dc->dc_depth); 191 printf("dc_rowbytes: %08x\n", dc->dc_rowbytes); 192 printf("dc_videobase: %08x\n", dc->dc_videobase); 193 #endif 194 195 /* clear the screen */ 196 for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(u_int32_t)) 197 *(u_int32_t *)(dc->dc_videobase + i) = 0xffffffff; 198 199 rap = &dc->dc_raster; 200 rap->width = dc->dc_wid; 201 rap->height = dc->dc_ht; 202 rap->depth = color ? 8 : 2; 203 rap->linelongs = dc->dc_rowbytes / sizeof(u_int32_t); 204 rap->pixels = (u_int32_t *)dc->dc_videobase; 205 206 /* initialize the raster console blitter */ 207 rcp = &dc->dc_rcons; 208 rcp->rc_sp = rap; 209 rcp->rc_crow = rcp->rc_ccol = -1; 210 rcp->rc_crowp = &rcp->rc_crow; 211 rcp->rc_ccolp = &rcp->rc_ccol; 212 rcons_init(rcp, 34, 80); 213 214 if (color) { 215 nextdisplay_color.nrows = dc->dc_rcons.rc_maxrow; 216 nextdisplay_color.ncols = dc->dc_rcons.rc_maxcol; 217 } else { 218 nextdisplay_mono.nrows = dc->dc_rcons.rc_maxrow; 219 nextdisplay_mono.ncols = dc->dc_rcons.rc_maxcol; 220 } 221 } 222 223 void 224 nextdisplay_attach(parent, self, aux) 225 struct device *parent; 226 struct device *self; 227 void *aux; 228 { 229 struct nextdisplay_softc *sc; 230 struct wsemuldisplaydev_attach_args waa; 231 int isconsole; 232 int iscolor; 233 paddr_t addr; 234 235 sc = (struct nextdisplay_softc *)self; 236 237 if (rom_machine_type == NeXT_WARP9C) { 238 iscolor = 1; 239 addr = (paddr_t)colorbase; 240 } else { 241 iscolor = 0; 242 addr = (paddr_t)monobase; 243 } 244 245 isconsole = nextdisplay_is_console(addr); 246 247 if (isconsole) { 248 sc->sc_dc = &nextdisplay_console_dc; 249 sc->nscreens = 1; 250 } else { 251 sc->sc_dc = (struct nextdisplay_config *) 252 malloc(sizeof(struct nextdisplay_config), M_DEVBUF, M_WAITOK); 253 nextdisplay_init(sc->sc_dc, iscolor); 254 } 255 256 printf(": %d x %d, %dbpp\n", sc->sc_dc->dc_wid, sc->sc_dc->dc_ht, 257 sc->sc_dc->dc_depth); 258 259 /* initialize the raster */ 260 waa.console = isconsole; 261 waa.scrdata = iscolor ? &nextdisplay_screenlist_color : &nextdisplay_screenlist_mono; 262 waa.accessops = &nextdisplay_accessops; 263 waa.accesscookie = sc; 264 #if 0 265 printf("nextdisplay: access cookie is %p\n", sc); 266 #endif 267 config_found(self, &waa, wsemuldisplaydevprint); 268 } 269 270 271 int 272 nextdisplay_ioctl(v, cmd, data, flag, p) 273 void *v; 274 u_long cmd; 275 caddr_t data; 276 int flag; 277 struct proc *p; 278 { 279 struct nextdisplay_softc *sc = v; 280 struct nextdisplay_config *dc = sc->sc_dc; 281 282 switch (cmd) { 283 case WSDISPLAYIO_GTYPE: 284 *(int *)data = dc->dc_type; 285 return 0; 286 287 case WSDISPLAYIO_SCURSOR: 288 printf("nextdisplay_ioctl: wsdisplayio_scursor\n"); 289 return ENOTTY; 290 291 case WSDISPLAYIO_SCURPOS: 292 printf("nextdisplay_ioctl: wsdisplayio_scurpos\n"); 293 return ENOTTY; 294 295 case WSDISPLAYIO_GINFO: 296 case WSDISPLAYIO_GETCMAP: 297 case WSDISPLAYIO_PUTCMAP: 298 case WSDISPLAYIO_GVIDEO: 299 case WSDISPLAYIO_SVIDEO: 300 case WSDISPLAYIO_GCURPOS: 301 case WSDISPLAYIO_GCURMAX: 302 case WSDISPLAYIO_GCURSOR: 303 printf("nextdisplay_ioctl: listed but unsupported ioctl\n"); 304 return ENOTTY; 305 } 306 307 return ENOTTY; 308 } 309 310 static int 311 nextdisplay_mmap(v, offset, prot) 312 void *v; 313 off_t offset; 314 int prot; 315 { 316 317 /* XXX */ 318 printf("nextdisplay_mmap: failed\n"); 319 return -1; 320 } 321 322 int 323 nextdisplay_alloc_screen(v, type, cookiep, curxp, curyp, defattrp) 324 void *v; 325 const struct wsscreen_descr *type; 326 void **cookiep; 327 int *curxp, *curyp; 328 long *defattrp; 329 { 330 struct nextdisplay_softc *sc = v; 331 long defattr; 332 333 /* only allow one screen */ 334 if (sc->nscreens > 0) 335 return (ENOMEM); 336 337 *cookiep = &sc->sc_dc->dc_rcons; /* one and only for now */ 338 *curxp = 0; 339 *curyp = 0; 340 rcons_alloc_attr(&sc->sc_dc->dc_rcons, 0, 0, 341 WSATTR_REVERSE, &defattr); 342 *defattrp = defattr; 343 sc->nscreens++; 344 #if 0 345 printf("nextdisplay: allocating screen\n"); 346 #endif 347 return (0); 348 } 349 350 void 351 nextdisplay_free_screen(v, cookie) 352 void *v; 353 void *cookie; 354 { 355 struct nextdisplay_softc *sc = v; 356 357 if (sc->sc_dc == &nextdisplay_console_dc) 358 panic("nextdisplay_free_screen: console"); 359 360 sc->nscreens--; 361 } 362 363 int 364 nextdisplay_show_screen(v, cookie, waitok, cb, cbarg) 365 void *v; 366 void *cookie; 367 int waitok; 368 void (*cb) __P((void *, int, int)); 369 void *cbarg; 370 { 371 372 return (0); 373 } 374 375 static int 376 nextdisplay_load_font(v, cookie, font) 377 void *v; 378 void *cookie; 379 struct wsdisplay_font *font; 380 { 381 return (EINVAL); 382 } 383 384 int 385 nextdisplay_cnattach(void) 386 { 387 struct nextdisplay_config *dc = &nextdisplay_console_dc; 388 long defattr; 389 int iscolor; 390 391 if (rom_machine_type == NeXT_WARP9C) { 392 iscolor = 1; 393 nextdisplay_consaddr = (paddr_t)colorbase; 394 } else { 395 iscolor = 0; 396 nextdisplay_consaddr = (paddr_t)monobase; 397 } 398 399 /* set up the display */ 400 nextdisplay_init(&nextdisplay_console_dc, iscolor); 401 402 rcons_alloc_attr(&dc->dc_rcons, 0, 0, WSATTR_REVERSE, &defattr); 403 404 wsdisplay_cnattach(iscolor ? &nextdisplay_color : &nextdisplay_mono, 405 &dc->dc_rcons, 0, 0, defattr); 406 407 dc->isconsole = 1; 408 return (0); 409 } 410