1 /* $NetBSD: nextdisplay.c,v 1.18 2005/12/11 12:18:25 christos 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> 34 __KERNEL_RCSID(0, "$NetBSD: nextdisplay.c,v 1.18 2005/12/11 12:18:25 christos Exp $"); 35 36 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 37 38 #include <sys/param.h> 39 #include <sys/systm.h> 40 #include <sys/kernel.h> 41 #include <sys/device.h> 42 #include <sys/malloc.h> 43 44 #include <machine/bus.h> 45 #include <machine/cpu.h> 46 47 #include <next68k/next68k/nextrom.h> 48 #include <next68k/next68k/isr.h> 49 50 #include <next68k/dev/intiovar.h> 51 #include <next68k/dev/nextdisplayvar.h> 52 #include <dev/wscons/wsconsio.h> 53 54 #include <dev/rcons/raster.h> 55 #include <dev/wscons/wscons_raster.h> 56 #include <dev/wscons/wsdisplayvar.h> 57 58 extern int turbo; 59 60 int nextdisplay_match(struct device *, struct cfdata *, void *); 61 void nextdisplay_attach(struct device *, struct device *, void *); 62 63 CFATTACH_DECL(nextdisplay, sizeof(struct nextdisplay_softc), 64 nextdisplay_match, nextdisplay_attach, NULL, NULL); 65 66 const struct wsdisplay_emulops nextdisplay_mono_emulops = { 67 rcons_cursor, 68 rcons_mapchar, 69 rcons_putchar, 70 rcons_copycols, 71 rcons_erasecols, 72 rcons_copyrows, 73 rcons_eraserows, 74 rcons_allocattr 75 }; 76 77 struct wsscreen_descr nextdisplay_mono = { 78 "mono", 79 0, 0, /* will be filled in -- XXX shouldn't, it's global */ 80 &nextdisplay_mono_emulops, 81 0, 0 82 }; 83 84 struct wsscreen_descr nextdisplay_color = { 85 "color", 86 0, 0, /* again, filled in */ 87 &nextdisplay_mono_emulops, 88 0, 0 89 }; 90 91 const struct wsscreen_descr *_nextdisplay_scrlist_mono[] = { 92 &nextdisplay_mono, 93 }; 94 95 const struct wsscreen_descr *_nextdisplay_scrlist_color[] = { 96 &nextdisplay_color, 97 }; 98 99 const struct wsscreen_list nextdisplay_screenlist_mono = { 100 sizeof(_nextdisplay_scrlist_mono) / sizeof(struct wsscreen_descr *), 101 _nextdisplay_scrlist_mono 102 }; 103 104 const struct wsscreen_list nextdisplay_screenlist_color = { 105 sizeof(_nextdisplay_scrlist_color) / sizeof(struct wsscreen_descr *), 106 _nextdisplay_scrlist_color 107 }; 108 109 static int nextdisplay_ioctl(void *, u_long, caddr_t, int, struct lwp *); 110 static paddr_t nextdisplay_mmap(void *, off_t, int); 111 static int nextdisplay_alloc_screen(void *, const struct wsscreen_descr *, 112 void **, int *, int *, long *); 113 static void nextdisplay_free_screen(void *, void *); 114 static int nextdisplay_show_screen(void *, void *, int, 115 void (*) (void *, int, int), void *); 116 static int nextdisplay_load_font(void *, void *, struct wsdisplay_font *); 117 118 const struct wsdisplay_accessops nextdisplay_accessops = { 119 nextdisplay_ioctl, 120 nextdisplay_mmap, 121 nextdisplay_alloc_screen, 122 nextdisplay_free_screen, 123 nextdisplay_show_screen, 124 nextdisplay_load_font 125 }; 126 127 void nextdisplay_init(struct nextdisplay_config *, int); 128 int nextdisplay_intr(void *); 129 130 vaddr_t nextdisplay_consaddr; 131 static int nextdisplay_is_console(vaddr_t); 132 133 static struct nextdisplay_config nextdisplay_console_dc; 134 135 static int 136 nextdisplay_is_console(vaddr_t addr) 137 { 138 return (nextdisplay_console_dc.isconsole 139 && (addr == nextdisplay_consaddr)); 140 } 141 142 int 143 nextdisplay_match(struct device *parent, struct cfdata *match, void *aux) 144 { 145 if (rom_machine_type == NeXT_WARP9 || 146 rom_machine_type == NeXT_X15 || 147 rom_machine_type == NeXT_WARP9C || 148 rom_machine_type == NeXT_TURBO_MONO || 149 rom_machine_type == NeXT_TURBO_COLOR) 150 return (1); 151 else 152 return (0); 153 } 154 155 void 156 nextdisplay_init(struct nextdisplay_config *dc, int color) 157 { 158 struct raster *rap; 159 struct rcons *rcp; 160 int i; 161 162 /* printf("in nextdisplay_init\n"); */ 163 164 if (color) { 165 dc->dc_vaddr = colorbase; 166 dc->dc_paddr = COLORBASE; 167 dc->dc_size = NEXT_P_C16_VIDEOSIZE; 168 } else { 169 dc->dc_vaddr = monobase; 170 dc->dc_paddr = MONOBASE; 171 dc->dc_size = NEXT_P_VIDEOSIZE; 172 } 173 174 dc->dc_wid = 1120; 175 dc->dc_ht = 832; 176 dc->dc_depth = color ? 16 : 2; 177 dc->dc_rowbytes = (turbo ? 1120 : 1152) * dc->dc_depth / 8; 178 179 dc->dc_videobase = dc->dc_vaddr; 180 181 #if 0 182 printf("intiobase at: %08x\n", intiobase); 183 printf("intiolimit at: %08x\n", intiolimit); 184 printf("videobase at: %08x\n", color ? colorbase : monobase); 185 printf("videolimit at: %08x\n", color ? colorlimit : monolimit); 186 187 printf("virtual fb at: %08x\n", dc->dc_vaddr); 188 printf("physical fb at: %08x\n", dc->dc_paddr); 189 printf("fb size: %08x\n", dc->dc_size); 190 191 printf("dc_wid: %08x\n", dc->dc_wid); 192 printf("dc_ht: %08x\n", dc->dc_ht); 193 printf("dc_depth: %08x\n", dc->dc_depth); 194 printf("dc_rowbytes: %08x\n", dc->dc_rowbytes); 195 printf("dc_videobase: %08x\n", dc->dc_videobase); 196 #endif 197 198 /* clear the screen */ 199 for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(u_int32_t)) 200 *(u_int32_t *)(dc->dc_videobase + i) = 201 (color ? 0x0 : 0xffffffff); 202 203 rap = &dc->dc_raster; 204 rap->width = dc->dc_wid; 205 rap->height = dc->dc_ht; 206 rap->depth = color ? 16 : 2; 207 rap->linelongs = dc->dc_rowbytes / sizeof(u_int32_t); 208 rap->pixels = (u_int32_t *)dc->dc_videobase; 209 210 /* initialize the raster console blitter */ 211 rcp = &dc->dc_rcons; 212 rcp->rc_sp = rap; 213 rcp->rc_crow = rcp->rc_ccol = -1; 214 rcp->rc_crowp = &rcp->rc_crow; 215 rcp->rc_ccolp = &rcp->rc_ccol; 216 rcons_init(rcp, 34, 80); 217 218 if (color) { 219 nextdisplay_color.nrows = dc->dc_rcons.rc_maxrow; 220 nextdisplay_color.ncols = dc->dc_rcons.rc_maxcol; 221 } else { 222 nextdisplay_mono.nrows = dc->dc_rcons.rc_maxrow; 223 nextdisplay_mono.ncols = dc->dc_rcons.rc_maxcol; 224 } 225 } 226 227 void 228 nextdisplay_attach(struct device *parent, struct device *self, void *aux) 229 { 230 struct nextdisplay_softc *sc = (void *)self; 231 struct wsemuldisplaydev_attach_args waa; 232 int isconsole; 233 int iscolor; 234 paddr_t addr; 235 236 if (rom_machine_type == NeXT_WARP9C || 237 rom_machine_type == NeXT_TURBO_COLOR) { 238 iscolor = 1; 239 addr = colorbase; 240 } else { 241 iscolor = 0; 242 addr = 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 if (iscolor) { 260 #if 0 261 uint8_t x; 262 263 x = *(volatile uint8_t *)IIOV(NEXT_P_C16_CMD_REG); 264 printf("%s: cmd=%02x\n", sc->sc_dev.dv_xname, x); 265 #endif 266 *(volatile uint8_t *)IIOV(NEXT_P_C16_CMD_REG) = 0x05; 267 isrlink_autovec(nextdisplay_intr, sc, NEXT_I_IPL(NEXT_I_C16_VIDEO), 1, NULL); 268 INTR_ENABLE(NEXT_I_C16_VIDEO); 269 } 270 271 /* initialize the raster */ 272 waa.console = isconsole; 273 waa.scrdata = iscolor ? &nextdisplay_screenlist_color : &nextdisplay_screenlist_mono; 274 waa.accessops = &nextdisplay_accessops; 275 waa.accesscookie = sc; 276 #if 0 277 printf("nextdisplay: access cookie is %p\n", sc); 278 #endif 279 config_found(self, &waa, wsemuldisplaydevprint); 280 } 281 282 int 283 nextdisplay_intr(void *arg) 284 { 285 #if 0 286 uint8_t x; 287 #endif 288 289 if (!INTR_OCCURRED(NEXT_I_C16_VIDEO)) 290 return (0); 291 #if 0 292 x = *(volatile uint8_t *)IIOV(NEXT_P_C16_CMD_REG); 293 printf("I%02x", x); 294 #endif 295 *(volatile uint8_t *)IIOV(NEXT_P_C16_CMD_REG) = 0x05; 296 return (1); 297 } 298 299 int 300 nextdisplay_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct lwp *l) 301 { 302 struct nextdisplay_softc *sc = v; 303 struct nextdisplay_config *dc = sc->sc_dc; 304 305 switch (cmd) { 306 case WSDISPLAYIO_GTYPE: 307 *(int *)data = dc->dc_type; 308 return 0; 309 310 case WSDISPLAYIO_SCURSOR: 311 printf("nextdisplay_ioctl: wsdisplayio_scursor\n"); 312 return EPASSTHROUGH; 313 314 case WSDISPLAYIO_SCURPOS: 315 printf("nextdisplay_ioctl: wsdisplayio_scurpos\n"); 316 return EPASSTHROUGH; 317 318 case WSDISPLAYIO_GINFO: 319 case WSDISPLAYIO_GETCMAP: 320 case WSDISPLAYIO_PUTCMAP: 321 case WSDISPLAYIO_GVIDEO: 322 case WSDISPLAYIO_SVIDEO: 323 case WSDISPLAYIO_GCURPOS: 324 case WSDISPLAYIO_GCURMAX: 325 case WSDISPLAYIO_GCURSOR: 326 printf("nextdisplay_ioctl: listed but unsupported ioctl\n"); 327 return EPASSTHROUGH; 328 } 329 330 return EPASSTHROUGH; 331 } 332 333 static paddr_t 334 nextdisplay_mmap(void *v, off_t offset, int prot) 335 { 336 337 /* XXX */ 338 printf("nextdisplay_mmap: failed\n"); 339 return -1; 340 } 341 342 int 343 nextdisplay_alloc_screen(void *v, const struct wsscreen_descr *type, 344 void **cookiep, int *curxp, int *curyp, long *defattrp) 345 { 346 struct nextdisplay_softc *sc = v; 347 long defattr; 348 349 /* only allow one screen */ 350 if (sc->nscreens > 0) 351 return (ENOMEM); 352 353 *cookiep = &sc->sc_dc->dc_rcons; /* one and only for now */ 354 *curxp = 0; 355 *curyp = 0; 356 rcons_allocattr(&sc->sc_dc->dc_rcons, 0, 0, 357 (strcmp(type->name, "color") == 0) 358 ? 0 359 : WSATTR_REVERSE, &defattr); 360 *defattrp = defattr; 361 sc->nscreens++; 362 #if 0 363 printf("nextdisplay: allocating screen\n"); 364 #endif 365 return (0); 366 } 367 368 void 369 nextdisplay_free_screen(void *v, void *cookie) 370 { 371 struct nextdisplay_softc *sc = v; 372 373 if (sc->sc_dc == &nextdisplay_console_dc) 374 panic("nextdisplay_free_screen: console"); 375 376 sc->nscreens--; 377 } 378 379 int 380 nextdisplay_show_screen(void *v, void *cookie, int waitok, 381 void (*cb)(void *, int, int), void *cbarg) 382 { 383 384 return (0); 385 } 386 387 static int 388 nextdisplay_load_font(void *v, void *cookie, struct wsdisplay_font *font) 389 { 390 return (EPASSTHROUGH); 391 } 392 393 int 394 nextdisplay_cnattach(void) 395 { 396 struct nextdisplay_config *dc = &nextdisplay_console_dc; 397 long defattr; 398 int iscolor; 399 400 if (rom_machine_type == NeXT_WARP9C || 401 rom_machine_type == NeXT_TURBO_COLOR) 402 iscolor = 1; 403 else 404 iscolor = 0; 405 406 /* set up the display */ 407 nextdisplay_init(&nextdisplay_console_dc, iscolor); 408 nextdisplay_consaddr = nextdisplay_console_dc.dc_vaddr; 409 410 rcons_allocattr(&dc->dc_rcons, 0, 0, 411 iscolor ? 0 : WSATTR_REVERSE, &defattr); 412 413 wsdisplay_cnattach(iscolor ? &nextdisplay_color : &nextdisplay_mono, 414 &dc->dc_rcons, 0, 0, defattr); 415 416 dc->isconsole = 1; 417 return (0); 418 } 419