1 /* $NetBSD: nextdisplay.c,v 1.33 2026/04/25 01:07:09 thorpej 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.33 2026/04/25 01:07:09 thorpej 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/kmem.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(device_t, cfdata_t, void *); 61 void nextdisplay_attach(device_t, device_t, void *); 62 63 CFATTACH_DECL_NEW(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 *, void *, u_long, void *, int, 110 struct lwp *); 111 static paddr_t nextdisplay_mmap(void *, void *, off_t, int); 112 static int nextdisplay_alloc_screen(void *, const struct wsscreen_descr *, 113 void **, int *, int *, long *); 114 static void nextdisplay_free_screen(void *, void *); 115 static int nextdisplay_show_screen(void *, void *, int, 116 void (*) (void *, int, int), void *); 117 static int nextdisplay_load_font(void *, void *, struct wsdisplay_font *); 118 119 const struct wsdisplay_accessops nextdisplay_accessops = { 120 nextdisplay_ioctl, 121 nextdisplay_mmap, 122 nextdisplay_alloc_screen, 123 nextdisplay_free_screen, 124 nextdisplay_show_screen, 125 nextdisplay_load_font 126 }; 127 128 void nextdisplay_init(struct nextdisplay_config *, int); 129 int nextdisplay_intr(void *); 130 131 vaddr_t nextdisplay_consaddr; 132 static int nextdisplay_is_console(vaddr_t); 133 134 static struct nextdisplay_config nextdisplay_console_dc; 135 136 static int 137 nextdisplay_is_console(vaddr_t addr) 138 { 139 return nextdisplay_console_dc.isconsole && 140 addr == nextdisplay_consaddr; 141 } 142 143 int 144 nextdisplay_match(device_t parent, cfdata_t match, void *aux) 145 { 146 if (rom_machine_type == NeXT_WARP9 || 147 rom_machine_type == NeXT_X15 || 148 rom_machine_type == NeXT_WARP9C || 149 rom_machine_type == NeXT_TURBO_MONO || 150 rom_machine_type == NeXT_TURBO_COLOR || 151 rom_machine_type == NeXT_CUBE_TURBO) 152 return 1; 153 else 154 return 0; 155 } 156 157 void 158 nextdisplay_init(struct nextdisplay_config *dc, int color) 159 { 160 struct raster *rap; 161 struct rcons *rcp; 162 int i; 163 164 /* printf("in nextdisplay_init\n"); */ 165 166 dc->dc_vaddr = fbbase; 167 dc->dc_paddr = fbbasepa; 168 dc->dc_size = color ? NEXT_P_C16_VIDEOSIZE : NEXT_P_VIDEOSIZE; 169 170 dc->dc_wid = 1120; 171 dc->dc_ht = 832; 172 dc->dc_depth = color ? 16 : 2; 173 dc->dc_cmsize = color ? 256 : 4; 174 dc->dc_rowbytes = (turbo ? 1120 : 1152) * 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("videobase at: %08x\n", fbbase); 181 printf("video mapsize: %08x\n", fbmapsize); 182 183 printf("virtual fb at: %08x\n", dc->dc_vaddr); 184 printf("physical fb at: %08x\n", dc->dc_paddr); 185 printf("fb size: %08x\n", dc->dc_size); 186 187 printf("dc_wid: %08x\n", dc->dc_wid); 188 printf("dc_ht: %08x\n", dc->dc_ht); 189 printf("dc_depth: %08x\n", dc->dc_depth); 190 printf("dc_rowbytes: %08x\n", dc->dc_rowbytes); 191 printf("dc_videobase: %08x\n", dc->dc_videobase); 192 #endif 193 194 /* clear the screen */ 195 for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(uint32_t)) 196 *(uint32_t *)(dc->dc_videobase + i) = 197 color ? 0x0 : 0xffffffff; 198 199 rap = &dc->dc_raster; 200 rap->width = dc->dc_wid; 201 rap->height = dc->dc_ht; 202 rap->depth = color ? 16 : 2; 203 rap->linelongs = dc->dc_rowbytes / sizeof(uint32_t); 204 rap->pixels = (uint32_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(device_t parent, device_t self, void *aux) 225 { 226 struct nextdisplay_softc *sc = device_private(self); 227 struct wsemuldisplaydev_attach_args waa; 228 int isconsole; 229 vaddr_t addr; 230 231 sc->sc_dev = self; 232 233 addr = fbbase; 234 235 isconsole = nextdisplay_is_console(addr); 236 237 if (isconsole) { 238 sc->sc_dc = &nextdisplay_console_dc; 239 sc->nscreens = 1; 240 } else { 241 sc->sc_dc = kmem_alloc(sizeof(struct nextdisplay_config), 242 KM_SLEEP); 243 nextdisplay_init(sc->sc_dc, iscolor); 244 } 245 246 printf(": %d x %d, %dbpp\n", sc->sc_dc->dc_wid, sc->sc_dc->dc_ht, 247 sc->sc_dc->dc_depth); 248 249 if (iscolor && !turbo) { 250 #if 0 251 uint8_t x; 252 253 x = *(volatile uint8_t *)IIOV(NEXT_P_C16_CMD_REG); 254 aprint_debug_dev(sc->sc_dev, "cmd=%02x\n", x); 255 #endif 256 *(volatile uint8_t *)IIOV(NEXT_P_C16_CMD_REG) = 0x05; 257 isrlink_autovec(nextdisplay_intr, sc, 258 NEXT_I_IPL(NEXT_I_C16_VIDEO), 1, NULL); 259 INTR_ENABLE(NEXT_I_C16_VIDEO); 260 } 261 262 sc->sc_mode = WSDISPLAYIO_MODE_EMUL; 263 264 /* initialize the raster */ 265 waa.console = isconsole; 266 waa.scrdata = iscolor ? 267 &nextdisplay_screenlist_color : &nextdisplay_screenlist_mono; 268 waa.accessops = &nextdisplay_accessops; 269 waa.accesscookie = sc; 270 #if 0 271 printf("nextdisplay: access cookie is %p\n", sc); 272 #endif 273 config_found(self, &waa, wsemuldisplaydevprint, CFARGS_NONE); 274 } 275 276 int 277 nextdisplay_intr(void *arg) 278 { 279 #if 0 280 uint8_t x; 281 #endif 282 283 if (!INTR_OCCURRED(NEXT_I_C16_VIDEO)) 284 return 0; 285 #if 0 286 x = *(volatile uint8_t *)IIOV(NEXT_P_C16_CMD_REG); 287 printf("I%02x", x); 288 #endif 289 *(volatile uint8_t *)IIOV(NEXT_P_C16_CMD_REG) = 0x05; 290 return 1; 291 } 292 293 int 294 nextdisplay_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, 295 struct lwp *l) 296 { 297 struct nextdisplay_softc *sc = v; 298 struct nextdisplay_config *dc = sc->sc_dc; 299 int new_mode; 300 301 switch (cmd) { 302 case WSDISPLAYIO_GTYPE: 303 *(int *)data = dc->dc_type; 304 return 0; 305 306 case WSDISPLAYIO_SCURSOR: 307 printf("nextdisplay_ioctl: wsdisplayio_scursor\n"); 308 return EPASSTHROUGH; 309 310 case WSDISPLAYIO_SCURPOS: 311 printf("nextdisplay_ioctl: wsdisplayio_scurpos\n"); 312 return EPASSTHROUGH; 313 314 case WSDISPLAYIO_GINFO: 315 #define wsd_fbip ((struct wsdisplay_fbinfo *)data) 316 wsd_fbip->height = dc->dc_ht; 317 wsd_fbip->width = dc->dc_wid; 318 wsd_fbip->depth = dc->dc_depth; 319 wsd_fbip->cmsize = dc->dc_cmsize; 320 #undef wsd_fbip 321 return 0; 322 323 case WSDISPLAYIO_LINEBYTES: 324 *(u_int *)data = dc->dc_rowbytes; 325 return 0; 326 327 case WSDISPLAYIO_SMODE: 328 new_mode = *(int *)data; 329 if (new_mode != sc->sc_mode) { 330 sc->sc_mode = new_mode; 331 } 332 return 0; 333 334 case WSDISPLAYIO_GETCMAP: 335 case WSDISPLAYIO_PUTCMAP: 336 case WSDISPLAYIO_GVIDEO: 337 case WSDISPLAYIO_SVIDEO: 338 case WSDISPLAYIO_GCURPOS: 339 case WSDISPLAYIO_GCURMAX: 340 case WSDISPLAYIO_GCURSOR: 341 printf("nextdisplay_ioctl: listed but unsupported ioctl\n"); 342 return EPASSTHROUGH; 343 } 344 345 return EPASSTHROUGH; 346 } 347 348 static paddr_t 349 nextdisplay_mmap(void *v, void *vs, off_t offset, int prot) 350 { 351 struct nextdisplay_softc *sc = v; 352 struct nextdisplay_config *dc = sc->sc_dc; 353 paddr_t cookie = -1; 354 355 switch (sc->sc_mode) { 356 case WSDISPLAYIO_MODE_DUMBFB: 357 if (offset >= 0 && offset < dc->dc_size) 358 cookie = m68k_btop(dc->dc_paddr + offset); 359 break; 360 } 361 362 return cookie; 363 } 364 365 int 366 nextdisplay_alloc_screen(void *v, const struct wsscreen_descr *type, 367 void **cookiep, int *curxp, int *curyp, long *defattrp) 368 { 369 struct nextdisplay_softc *sc = v; 370 long defattr; 371 372 /* only allow one screen */ 373 if (sc->nscreens > 0) 374 return ENOMEM; 375 376 *cookiep = &sc->sc_dc->dc_rcons; /* one and only for now */ 377 *curxp = 0; 378 *curyp = 0; 379 rcons_allocattr(&sc->sc_dc->dc_rcons, 0, 0, 380 (strcmp(type->name, "color") == 0) ? 0 : WSATTR_REVERSE, &defattr); 381 *defattrp = defattr; 382 sc->nscreens++; 383 #if 0 384 printf("nextdisplay: allocating screen\n"); 385 #endif 386 return 0; 387 } 388 389 void 390 nextdisplay_free_screen(void *v, void *cookie) 391 { 392 struct nextdisplay_softc *sc = v; 393 394 if (sc->sc_dc == &nextdisplay_console_dc) 395 panic("nextdisplay_free_screen: console"); 396 397 sc->nscreens--; 398 } 399 400 int 401 nextdisplay_show_screen(void *v, void *cookie, int waitok, 402 void (*cb)(void *, int, int), void *cbarg) 403 { 404 405 return 0; 406 } 407 408 static int 409 nextdisplay_load_font(void *v, void *cookie, struct wsdisplay_font *font) 410 { 411 412 return EPASSTHROUGH; 413 } 414 415 int 416 nextdisplay_cnattach(void) 417 { 418 struct nextdisplay_config *dc = &nextdisplay_console_dc; 419 long defattr; 420 421 /* set up the display */ 422 nextdisplay_init(&nextdisplay_console_dc, iscolor); 423 nextdisplay_consaddr = nextdisplay_console_dc.dc_vaddr; 424 425 rcons_allocattr(&dc->dc_rcons, 0, 0, 426 iscolor ? 0 : WSATTR_REVERSE, &defattr); 427 428 wsdisplay_cnattach(iscolor ? &nextdisplay_color : &nextdisplay_mono, 429 &dc->dc_rcons, 0, 0, defattr); 430 431 dc->isconsole = 1; 432 return 0; 433 } 434