1 1.13 hans /* $NetBSD: spx.c,v 1.13 2025/03/09 18:50:20 hans Exp $ */ 2 1.1 hans /* 3 1.1 hans * SPX/LCSPX/SPXg/SPXgt accelerated framebuffer driver for NetBSD/VAX 4 1.1 hans * Copyright (c) 2005 Blaz Antonic 5 1.1 hans * All rights reserved. 6 1.1 hans * 7 1.1 hans * This software contains code written by Michael L. Hitch. 8 1.1 hans * 9 1.1 hans * Redistribution and use in source and binary forms, with or without 10 1.1 hans * modification, are permitted provided that the following conditions 11 1.1 hans * are met: 12 1.1 hans * 1. Redistributions of source code must retain the above copyright 13 1.1 hans * notice, this list of conditions and the following disclaimer. 14 1.1 hans * 2. Redistributions in binary form must reproduce the above copyright 15 1.1 hans * notice, this list of conditions and the following disclaimer in the 16 1.1 hans * documentation and/or other materials provided with the distribution. 17 1.1 hans * 3. All advertising materials mentioning features or use of this software 18 1.1 hans * must display the abovementioned copyrights 19 1.1 hans * 4. The name of the author may not be used to endorse or promote products 20 1.1 hans * derived from this software without specific prior written permission 21 1.1 hans * 22 1.1 hans * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 1.1 hans * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 1.1 hans * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 1.1 hans * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 1.1 hans * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 1.1 hans * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 1.1 hans * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 1.1 hans * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 1.1 hans * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 1.1 hans * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 1.1 hans */ 33 1.1 hans 34 1.1 hans #include <sys/cdefs.h> 35 1.13 hans __KERNEL_RCSID(0, "$NetBSD: spx.c,v 1.13 2025/03/09 18:50:20 hans Exp $"); 36 1.1 hans 37 1.1 hans #include <sys/param.h> 38 1.1 hans #include <sys/systm.h> 39 1.1 hans #include <sys/callout.h> 40 1.4 matt #include <sys/conf.h> 41 1.4 matt #include <sys/cpu.h> 42 1.4 matt #include <sys/device.h> 43 1.10 thorpej #include <sys/kmem.h> 44 1.1 hans #include <sys/time.h> 45 1.1 hans 46 1.1 hans #include <machine/vsbus.h> 47 1.1 hans #include <machine/sid.h> 48 1.1 hans #include <machine/ka420.h> 49 1.1 hans 50 1.1 hans #include <dev/cons.h> 51 1.1 hans 52 1.1 hans #include <dev/dec/dzreg.h> 53 1.1 hans #include <dev/dec/dzvar.h> 54 1.1 hans #include <dev/dec/dzkbdvar.h> 55 1.1 hans 56 1.1 hans #include <dev/wscons/wsdisplayvar.h> 57 1.1 hans #include <dev/wscons/wsconsio.h> 58 1.1 hans #include <dev/wscons/wscons_callbacks.h> 59 1.1 hans #include <dev/wsfont/wsfont.h> 60 1.1 hans 61 1.1 hans #include "machine/scb.h" 62 1.1 hans 63 1.1 hans #include "dzkbd.h" 64 1.1 hans 65 1.1 hans #define CONF_LCSPX 0x02 66 1.1 hans #define CONF_SPXg 0x10 67 1.1 hans 68 1.1 hans #define FB_IS_SPX 1 69 1.1 hans #define FB_IS_SPXg 2 70 1.1 hans 71 1.1 hans /* Screen hardware defs */ 72 1.1 hans #define SPX_FB_ADDR 0x38000000 /* Frame buffer */ 73 1.1 hans #define SPXg_FB_ADDR_KA46 0x22200000 74 1.1 hans #define SPXg_FB_ADDR_KA49 0x28200000 75 1.1 hans #define SPXg_FB_ADDR ((vax_boardtype == VAX_BTYP_46) ? \ 76 1.1 hans SPXg_FB_ADDR_KA46 : SPXg_FB_ADDR_KA49) 77 1.1 hans 78 1.1 hans #define SPXg_WIN_SIZE 0x00100000 /* Window size */ 79 1.1 hans /* # of pixels that fit into single window */ 80 1.1 hans #define SPXg_WIN_LINEAR (SPXg_WIN_SIZE / 2) 81 1.1 hans 82 1.1 hans #define SPXg_DELAY 5 83 1.1 hans 84 1.1 hans /* 85 1.1 hans * off-screen font storage space 86 1.3 hans * 32x16 glyphs, 256 regular and underlined chars 87 1.1 hans */ 88 1.1 hans #define FONT_STORAGE_START (spx_xsize * spx_ysize) 89 1.1 hans #define FONT_STORAGE_SIZE (32 * 16 * 256 * 2) 90 1.1 hans 91 1.1 hans /* register space defines */ 92 1.1 hans #define SPX_REG_SIZE 0x00002000 93 1.1 hans #define SPX_REG_ADDR 0x39302000 /* 1st set of SPX registers */ 94 1.1 hans 95 1.1 hans #define SPXg_REG_SIZE 0x00004000 96 1.1 hans #define SPXg_REG_ADDR_KA46 0x22004000 97 1.1 hans #define SPXg_REG_ADDR_KA49 0x28004000 98 1.1 hans #define SPXg_REG_ADDR ((vax_boardtype == VAX_BTYP_46) ? \ 99 1.1 hans SPXg_REG_ADDR_KA46 : SPXg_REG_ADDR_KA49) 100 1.1 hans 101 1.1 hans #define SPX_REG1_SIZE 0x00001000 102 1.1 hans #define SPX_REG1_ADDR 0x39b00000 /* 2nd set of SPX registers */ 103 1.1 hans 104 1.1 hans #define SPXg_REG1_SIZE 0x00001000 105 1.1 hans #define SPXg_REG1_ADDR_KA46 0x22100000 106 1.1 hans #define SPXg_REG1_ADDR_KA49 0x28100000 107 1.1 hans #define SPXg_REG1_ADDR ((vax_boardtype == VAX_BTYP_46) ? \ 108 1.1 hans SPXg_REG1_ADDR_KA46 : SPXg_REG1_ADDR_KA49) 109 1.1 hans #define SPX_REG(reg) regaddr[(reg - 0x2000) / 4] 110 1.1 hans #define SPXg_REG(reg) regaddr[(reg - 0x2000) / 2] 111 1.1 hans 112 1.1 hans #define SPX_REG1(reg) regaddr1[(reg) / 4] 113 1.1 hans #define SPXg_REG1(reg) regaddr1[(reg) / 4] 114 1.1 hans 115 1.1 hans /* few SPX register names */ 116 1.1 hans #define SPX_COMMAND 0x21ec 117 1.1 hans #define SPX_XSTART 0x21d0 118 1.1 hans #define SPX_YSTART 0x21d4 119 1.1 hans #define SPX_XEND 0x21d8 120 1.1 hans #define SPX_YEND 0x21dc 121 1.1 hans #define SPX_DSTPIX 0x21e0 122 1.1 hans #define SPX_DSTPIX1 0x20e0 123 1.1 hans #define SPX_SRCPIX 0x21e4 124 1.1 hans #define SPX_SRCPIX1 0x20e4 125 1.1 hans #define SPX_MAIN3 0x219c 126 1.1 hans #define SPX_STRIDE 0x21e8 /* SRC | DST */ 127 1.1 hans #define SPX_SRCMASK 0x21f0 128 1.1 hans #define SPX_DSTMASK 0x21f4 129 1.1 hans #define SPX_FG 0x2260 130 1.1 hans #define SPX_BG 0x2264 131 1.1 hans #define SPX_DESTLOOP 0x2270 132 1.1 hans #define SPX_MPC 0x21fc 133 1.1 hans 134 1.1 hans /* few SPX opcodes (microcode entry points); rasterop # = opcode ? */ 135 1.1 hans #define SPX_OP_FILLRECT 0x19 136 1.1 hans #define SPX_OP_COPYRECT 0x1a 137 1.1 hans 138 1.1 hans /* bt459 locations */ 139 1.1 hans #define SPX_BT459_ADDRL 0x39b10000 140 1.1 hans #define SPX_BT459_ADDRH 0x39b14000 141 1.1 hans #define SPX_BT459_REG 0x39b18000 142 1.1 hans #define SPX_BT459_CMAP 0x39b1c000 143 1.1 hans 144 1.1 hans /* bt460 locations */ 145 1.1 hans #define SPXg_BT460_BASE_KA46 0x200f0000 146 1.1 hans #define SPXg_BT460_BASE_KA49 0x2a000000 147 1.1 hans #define SPXg_BT460_BASE ((vax_boardtype == VAX_BTYP_46) ? \ 148 1.1 hans SPXg_BT460_BASE_KA46 : SPXg_BT460_BASE_KA49) 149 1.1 hans 150 1.1 hans #define SPX_BG_COLOR WS_DEFAULT_BG 151 1.1 hans #define SPX_FG_COLOR WS_DEFAULT_FG 152 1.1 hans 153 1.1 hans /* 154 1.1 hans * cursor X = 0, Y = 0 on-screen bias 155 1.1 hans * FIXME: BIAS for various HW types 156 1.1 hans */ 157 1.1 hans #define CUR_XBIAS 360 158 1.1 hans #define CUR_YBIAS 37 159 1.1 hans 160 1.1 hans /* few BT459 & BT460 indirect register defines */ 161 1.1 hans #define SPXDAC_REG_CCOLOR_1 0x181 162 1.1 hans #define SPXDAC_REG_CCOLOR_2 0x182 163 1.1 hans #define SPXDAC_REG_CCOLOR_3 0x183 164 1.1 hans #define SPXDAC_REG_ID 0x200 165 1.1 hans #define SPXDAC_REG_CMD0 0x201 166 1.1 hans #define SPXDAC_REG_CMD1 0x202 167 1.1 hans #define SPXDAC_REG_CMD2 0x203 168 1.1 hans #define SPXDAC_REG_PRM 0x204 169 1.1 hans #define SPXDAC_REG_CCR 0x300 170 1.1 hans #define SPXDAC_REG_CXLO 0x301 171 1.1 hans #define SPXDAC_REG_CXHI 0x302 172 1.1 hans #define SPXDAC_REG_CYLO 0x303 173 1.1 hans #define SPXDAC_REG_CYHI 0x304 174 1.1 hans #define SPXDAC_REG_WXLO 0x305 175 1.1 hans #define SPXDAC_REG_WXHI 0x306 176 1.1 hans #define SPXDAC_REG_WYLO 0x307 177 1.1 hans #define SPXDAC_REG_WYHI 0x308 178 1.1 hans #define SPXDAC_REG_WWLO 0x309 179 1.1 hans #define SPXDAC_REG_WWHI 0x30a 180 1.1 hans #define SPXDAC_REG_WHLO 0x30b 181 1.1 hans #define SPXDAC_REG_WHHI 0x30c 182 1.1 hans #define SPXDAC_REG_CRAM_BASE 0x400 183 1.1 hans 184 1.1 hans /* 185 1.1 hans * used to access top/bottom 8 bits of a 16-bit argument for split RAMDAC 186 1.1 hans * addressing 187 1.1 hans */ 188 1.1 hans #define HI(x) (((x) >> 8) & 0xff) 189 1.1 hans #define LO(x) ((x) & 0xff) 190 1.1 hans 191 1.1 hans static int spx_match(device_t, cfdata_t, void *); 192 1.1 hans static void spx_attach(device_t, device_t, void *); 193 1.1 hans 194 1.1 hans struct spx_softc { 195 1.1 hans device_t ss_dev; 196 1.1 hans }; 197 1.1 hans 198 1.1 hans CFATTACH_DECL_NEW(spx, sizeof(struct spx_softc), 199 1.1 hans spx_match, spx_attach, NULL, NULL); 200 1.1 hans 201 1.1 hans static void spx_cursor(void *, int, int, int); 202 1.1 hans static int spx_mapchar(void *, int, unsigned int *); 203 1.1 hans static void spx_putchar(void *, int, int, u_int, long); 204 1.3 hans static void spx_copycols(void *, int, int, int, int); 205 1.1 hans static void spx_erasecols(void *, int, int, int, long); 206 1.1 hans static void spx_copyrows(void *, int, int, int); 207 1.1 hans static void spx_eraserows(void *, int, int, long); 208 1.1 hans static int spx_allocattr(void *, int, int, int, long *); 209 1.1 hans static int spx_get_cmap(struct wsdisplay_cmap *); 210 1.1 hans static int spx_set_cmap(struct wsdisplay_cmap *); 211 1.1 hans 212 1.1 hans static int spx_map_regs(device_t, u_int, u_int, u_int, u_int); 213 1.1 hans static void SPX_render_font(void); 214 1.1 hans static void SPXg_render_font(void); 215 1.1 hans static int SPX_map_fb(device_t, struct vsbus_attach_args *); 216 1.1 hans static int SPXg_map_fb(device_t, struct vsbus_attach_args *); 217 1.1 hans static void spx_init_common(device_t, struct vsbus_attach_args *); 218 1.1 hans 219 1.1 hans #define SPX_MAP_FB(self, va, type) if (! type ## _map_fb(self, va)) return 220 1.1 hans #define SPX_MAP_REGS(self, type) if (!spx_map_regs(self, \ 221 1.1 hans type ## _REG_ADDR, \ 222 1.1 hans type ## _REG_SIZE, \ 223 1.1 hans type ## _REG1_ADDR, \ 224 1.1 hans type ## _REG1_SIZE)) \ 225 1.1 hans return 226 1.1 hans 227 1.1 hans const struct wsdisplay_emulops spx_emulops = { 228 1.1 hans spx_cursor, 229 1.1 hans spx_mapchar, 230 1.1 hans spx_putchar, 231 1.1 hans spx_copycols, 232 1.1 hans spx_erasecols, 233 1.1 hans spx_copyrows, 234 1.1 hans spx_eraserows, 235 1.1 hans spx_allocattr 236 1.1 hans }; 237 1.1 hans 238 1.1 hans static char spx_stdscreen_name[10] = "160x128"; 239 1.1 hans struct wsscreen_descr spx_stdscreen = { 240 1.1 hans spx_stdscreen_name, 160, 128, /* dynamically set */ 241 1.1 hans &spx_emulops, 242 1.1 hans 8, 15, /* dynamically set */ 243 1.1 hans WSSCREEN_UNDERLINE|WSSCREEN_REVERSE|WSSCREEN_WSCOLORS, 244 1.1 hans }; 245 1.1 hans 246 1.1 hans const struct wsscreen_descr *_spx_scrlist[] = { 247 1.1 hans &spx_stdscreen, 248 1.1 hans }; 249 1.1 hans 250 1.1 hans const struct wsscreen_list spx_screenlist = { 251 1.1 hans sizeof(_spx_scrlist) / sizeof(struct wsscreen_descr *), 252 1.1 hans _spx_scrlist, 253 1.1 hans }; 254 1.1 hans 255 1.1 hans static volatile char *spxaddr; 256 1.1 hans static volatile long *regaddr; 257 1.1 hans static volatile long *regaddr1; 258 1.1 hans 259 1.1 hans static volatile char *bt_addrl; 260 1.1 hans static volatile char *bt_addrh; 261 1.1 hans static volatile char *bt_reg; 262 1.1 hans static volatile char *bt_cmap; 263 1.1 hans static volatile char *bt_wait; /* SPXg/gt only */ 264 1.1 hans 265 1.1 hans static int spx_xsize; 266 1.1 hans static int spx_ysize; 267 1.1 hans static int spx_depth; 268 1.1 hans static int spx_cols; 269 1.1 hans static int spx_rows; 270 1.1 hans static long spx_fb_size; 271 1.1 hans 272 1.1 hans /* Our current hardware colormap */ 273 1.1 hans static struct hwcmap256 { 274 1.1 hans #define CMAP_SIZE 256 /* 256 R/G/B entries */ 275 1.1 hans u_int8_t r[CMAP_SIZE]; 276 1.1 hans u_int8_t g[CMAP_SIZE]; 277 1.1 hans u_int8_t b[CMAP_SIZE]; 278 1.1 hans } spx_cmap; 279 1.1 hans 280 1.1 hans /* The default colormap */ 281 1.1 hans static struct { 282 1.1 hans u_int8_t r[8]; 283 1.1 hans u_int8_t g[8]; 284 1.1 hans u_int8_t b[8]; 285 1.1 hans } spx_default_cmap = { 286 1.1 hans { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff }, 287 1.1 hans { 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0xff, 0xff }, 288 1.1 hans { 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff } 289 1.1 hans }; 290 1.1 hans 291 1.1 hans static char fb_type = 0; 292 1.1 hans static char spxg_current_page = 0; 293 1.1 hans #define spxg_switch_page(nr) (SPXg_REG1(0x20) = ((1 << (nr) & 0xff)) << 16) 294 1.1 hans 295 1.1 hans struct wsdisplay_font spx_font; 296 1.1 hans static u_char *qf; 297 1.1 hans static u_short *qf2; 298 1.1 hans 299 1.1 hans #define QCHAR_INVALID(c) (((c) < spx_font.firstchar) || \ 300 1.1 hans ((c) >= spx_font.firstchar + spx_font.numchars)) 301 1.1 hans #define QCHAR(c) (QCHAR_INVALID(c) ? 0 : (c) - spx_font.firstchar) 302 1.1 hans 303 1.1 hans #define QFONT_INDEX(c, line) (QCHAR(c) * spx_font.fontheight + line) 304 1.1 hans #define QFONT_QF(c, line) qf[QFONT_INDEX(c, line)] 305 1.1 hans #define QFONT_QF2(c, line) qf2[QFONT_INDEX(c, line)] 306 1.1 hans #define QFONT(c, line) (spx_font.stride == 2 ? \ 307 1.1 hans QFONT_QF2(c, line) : \ 308 1.1 hans QFONT_QF(c, line)) 309 1.1 hans 310 1.1 hans /* replicate color value */ 311 1.1 hans #define COLOR(x) (((x) << 24) | ((x) << 16) | ((x) << 8) | (x)) 312 1.1 hans 313 1.1 hans /* convert coordinates into linear offset */ 314 1.1 hans #define LINEAR(x, y) ((y * spx_xsize) + x) 315 1.1 hans 316 1.1 hans /* Linear pixel address */ 317 1.1 hans #define SPX_POS(row, col, line, dot) \ 318 1.1 hans ((col) * spx_font.fontwidth + \ 319 1.1 hans (row) * spx_font.fontheight * spx_xsize + \ 320 1.1 hans (line) * spx_xsize + dot) 321 1.1 hans 322 1.1 hans #define SPX_ADDR(row, col, line, dot) spxaddr[SPX_POS(row, col, line, dot)] 323 1.1 hans 324 1.1 hans /* Recalculate absolute pixel address from linear address */ 325 1.1 hans #define SPXg_ADDR(linear) spxaddr[((((linear) % SPXg_WIN_LINEAR) / 4) * 8) + \ 326 1.1 hans (((linear) % SPXg_WIN_LINEAR) % 4)] 327 1.1 hans 328 1.1 hans 329 1.1 hans static int spx_ioctl(void *, void *, u_long, void *, int, struct lwp *); 330 1.1 hans static paddr_t spx_mmap(void *, void *, off_t, int); 331 1.1 hans static int spx_alloc_screen(void *, const struct wsscreen_descr *, 332 1.1 hans void **, int *, int *, long *); 333 1.1 hans static void spx_free_screen(void *, void *); 334 1.1 hans static int spx_show_screen(void *, void *, int, void (*) (void *, int, int), 335 1.1 hans void *); 336 1.1 hans 337 1.1 hans static void spx_update_cmap(int entry, char red, char green, char blue); 338 1.1 hans static void set_btreg(u_int addr, u_char value); 339 1.1 hans static u_char get_btreg(u_int addr); 340 1.1 hans 341 1.1 hans /* SPXg/gt delay */ 342 1.1 hans static void spxg_delay(void); 343 1.1 hans 344 1.1 hans /* 345 1.1 hans * SPX HW accelerated block copy 346 1.1 hans * common code in spx_blkcpy, 347 1.1 hans * HW-specific code accessed through spx_blkcpy_func pointer 348 1.1 hans */ 349 1.1 hans static void spx_blkcpy(u_int sxpos, u_int sypos, 350 1.1 hans u_int dxpos, u_int dypos, 351 1.1 hans u_int xdim, u_int ydim); 352 1.1 hans 353 1.1 hans static void SPX_blkcpy(u_int sxpos, u_int sypos, 354 1.1 hans u_int dxpos, u_int dypos, 355 1.1 hans u_int xdim, u_int ydim, 356 1.1 hans char direction); 357 1.1 hans static void SPXg_blkcpy(u_int sxpos, u_int sypos, 358 1.1 hans u_int dxpos, u_int dypos, 359 1.1 hans u_int xdim, u_int ydim, 360 1.1 hans char direction); 361 1.1 hans static void (*spx_blkcpy_func)(u_int, u_int, 362 1.1 hans u_int, u_int, 363 1.1 hans u_int, u_int, 364 1.1 hans char); 365 1.1 hans 366 1.1 hans /* SPX HW accelerated block set, no common code */ 367 1.1 hans static void SPX_blkset(u_int xpos, u_int ypos, 368 1.1 hans u_int xdim, u_int ydim, char color); 369 1.1 hans static void SPXg_blkset(u_int xpos, u_int ypos, 370 1.1 hans u_int xdim, u_int ydim, char color); 371 1.1 hans static void (*spx_blkset_func)(u_int, u_int, u_int, u_int, char); 372 1.1 hans #define spx_blkset(x, y, xd, yd, c) spx_blkset_func(x, y, xd, yd, c) 373 1.1 hans 374 1.1 hans /* SPX HW accelerated part of spx_putchar */ 375 1.1 hans static void SPX_putchar(int, int, u_int, char, char); 376 1.1 hans static void SPXg_putchar(int, int, u_int, char, char); 377 1.1 hans static void (*spx_putchar_func)(int, int, u_int, char, char); 378 1.1 hans 379 1.1 hans const struct wsdisplay_accessops spx_accessops = { 380 1.1 hans spx_ioctl, 381 1.1 hans spx_mmap, 382 1.1 hans spx_alloc_screen, 383 1.1 hans spx_free_screen, 384 1.1 hans spx_show_screen, 385 1.1 hans 0 /* load_font */ 386 1.1 hans }; 387 1.1 hans 388 1.1 hans /* TODO allocate ss_image dynamically for consoles beyond first one */ 389 1.1 hans struct spx_screen { 390 1.1 hans int ss_curx; 391 1.1 hans int ss_cury; 392 1.1 hans int ss_cur_fg; 393 1.1 hans int ss_cur_bg; 394 1.1 hans struct { 395 1.1 hans u_char data; /* Image character */ 396 1.1 hans u_char attr; /* Attribute: 80/70/08/07 */ 397 1.1 hans } ss_image[160 * 128]; /* allow for maximum possible cell matrix */ 398 1.1 hans }; 399 1.1 hans 400 1.1 hans #define SPX_ATTR_UNDERLINE 0x80 401 1.1 hans #define SPX_BG_MASK 0x70 402 1.1 hans #define SPX_ATTR_REVERSE 0x08 403 1.1 hans #define SPX_FG_MASK 0x07 404 1.1 hans 405 1.1 hans static struct spx_screen spx_conscreen; 406 1.1 hans static struct spx_screen *prevscr, *curscr; 407 1.1 hans static struct spx_screen *savescr; 408 1.1 hans 409 1.1 hans static int cur_fg, cur_bg; 410 1.1 hans static int spx_off = 1; 411 1.1 hans 412 1.1 hans static void 413 1.1 hans spx_update_cmap(int entry, char red, char green, char blue) 414 1.1 hans { 415 1.1 hans *bt_addrl = LO(entry); 416 1.1 hans *bt_addrh = HI(entry); 417 1.1 hans if ((entry >= 0x181) && (entry <= 0x183)) { 418 1.1 hans *bt_reg = red; 419 1.1 hans *bt_reg = green; 420 1.1 hans *bt_reg = blue; 421 1.1 hans } else { 422 1.1 hans *bt_cmap = red; 423 1.1 hans *bt_cmap = green; 424 1.1 hans *bt_cmap = blue; 425 1.1 hans } 426 1.1 hans } 427 1.1 hans 428 1.1 hans static void 429 1.1 hans set_btreg(u_int addr, u_char value) 430 1.1 hans { 431 1.1 hans *bt_addrl = LO(addr); 432 1.1 hans *bt_addrh = HI(addr); 433 1.1 hans *bt_reg = value; 434 1.1 hans } 435 1.1 hans 436 1.1 hans static u_char 437 1.1 hans get_btreg(u_int addr) 438 1.1 hans { 439 1.1 hans *bt_addrl = LO(addr); 440 1.1 hans *bt_addrh = HI(addr); 441 1.1 hans return *bt_reg & 0xff; 442 1.1 hans } 443 1.1 hans 444 1.1 hans static void 445 1.1 hans spxg_delay(void) 446 1.1 hans { 447 1.1 hans char i; 448 1.1 hans 449 1.1 hans for (i = 0; i <= SPXg_DELAY; i++) 450 1.1 hans *bt_wait = *bt_wait + i; 451 1.1 hans } 452 1.1 hans 453 1.1 hans static void 454 1.1 hans SPX_blkcpy(u_int sxpos, u_int sypos, 455 1.1 hans u_int dxpos, u_int dypos, 456 1.1 hans u_int xdim, u_int ydim, 457 1.1 hans char direction) 458 1.1 hans { 459 1.1 hans u_int counter = 0xffffe; 460 1.1 hans long temp = 0; 461 1.1 hans 462 1.1 hans SPX_REG(SPX_COMMAND) = 0x84884648 | direction; /* 0x848c4648? */ 463 1.1 hans SPX_REG(SPX_XSTART) = dxpos << 16; 464 1.1 hans SPX_REG(SPX_YSTART) = dypos << 16; 465 1.1 hans SPX_REG(SPX_XEND) = (dxpos + xdim) << 16; 466 1.1 hans SPX_REG(SPX_YEND) = (dypos + ydim) << 16; 467 1.1 hans 468 1.1 hans temp = ((SPX_REG1(0x10) & 0xc0) << (30 - 6)) | \ 469 1.1 hans ((SPX_REG1(0x10) & 0x3f) << 24); 470 1.1 hans 471 1.1 hans SPX_REG(SPX_DSTPIX) = temp + LINEAR(dxpos, dypos); 472 1.1 hans SPX_REG(SPX_SRCPIX) = temp + LINEAR(sxpos, sypos); 473 1.1 hans SPX_REG(SPX_SRCPIX1) = 0; 474 1.1 hans SPX_REG(SPX_STRIDE) = (spx_xsize << 16) | spx_xsize; 475 1.1 hans SPX_REG(SPX_SRCMASK) = 0xff; 476 1.1 hans SPX_REG(SPX_DSTMASK) = 0xff; 477 1.1 hans 478 1.1 hans SPX_REG(SPX_DESTLOOP) = 0x00112003; 479 1.1 hans SPX_REG(SPX_MPC) = 0x2000 | SPX_OP_COPYRECT; 480 1.1 hans 481 1.1 hans SPX_REG1(0x18) = 0xffffffff; 482 1.1 hans while ((counter) && ((SPX_REG1(0x18) & 2) == 0)) 483 1.1 hans counter--; 484 1.1 hans } 485 1.1 hans 486 1.1 hans static void 487 1.1 hans SPXg_blkcpy(u_int sxpos, u_int sypos, 488 1.1 hans u_int dxpos, u_int dypos, 489 1.1 hans u_int xdim, u_int ydim, 490 1.1 hans char direction) 491 1.1 hans { 492 1.1 hans u_int counter = 0xffffe; 493 1.1 hans long temp = 0; 494 1.1 hans 495 1.1 hans SPXg_REG(SPX_COMMAND) = 0x84884648 | direction; spxg_delay(); 496 1.1 hans SPXg_REG(SPX_XSTART) = dxpos << 16; spxg_delay(); 497 1.1 hans SPXg_REG(SPX_YSTART) = dypos << 16; spxg_delay(); 498 1.1 hans SPXg_REG(SPX_XEND) = (dxpos + xdim) << 16; spxg_delay(); 499 1.1 hans SPXg_REG(SPX_YEND) = (dypos + ydim) << 16; spxg_delay(); 500 1.1 hans 501 1.1 hans temp = 0x3f << 24; 502 1.1 hans 503 1.1 hans SPXg_REG(SPX_DSTPIX) = temp + LINEAR(dxpos, dypos); spxg_delay(); 504 1.1 hans SPXg_REG(SPX_DSTPIX1) = 0xff000000; spxg_delay(); 505 1.1 hans SPXg_REG(SPX_SRCPIX) = temp + LINEAR(sxpos, sypos); spxg_delay(); 506 1.1 hans SPXg_REG(SPX_SRCPIX1) = 0; spxg_delay(); 507 1.1 hans SPXg_REG(SPX_STRIDE) = (spx_xsize << 16) | spx_xsize; spxg_delay(); 508 1.1 hans SPXg_REG(SPX_SRCMASK) = 0xffffffff; spxg_delay(); 509 1.1 hans SPXg_REG(SPX_DSTMASK) = 0xffffffff; spxg_delay(); 510 1.1 hans 511 1.1 hans SPXg_REG(SPX_DESTLOOP) = 0x00112003; spxg_delay(); 512 1.1 hans SPXg_REG(SPX_MPC) = 0x2000 | SPX_OP_COPYRECT; spxg_delay(); 513 1.1 hans 514 1.1 hans while ((counter) && ((SPXg_REG1(0x0) & 0x8000) == 0)) 515 1.1 hans counter--; 516 1.1 hans } 517 1.1 hans 518 1.1 hans static void 519 1.1 hans spx_blkcpy(u_int sxpos, u_int sypos, 520 1.1 hans u_int dxpos, u_int dypos, 521 1.1 hans u_int xdim, u_int ydim) 522 1.1 hans { 523 1.1 hans char direction = 0; 524 1.1 hans 525 1.1 hans /* don't waste time checking whether src and dest actually overlap */ 526 1.1 hans if (sxpos < dxpos) { 527 1.1 hans direction |= 0x01; /* X decrement */ 528 1.1 hans sxpos += xdim; 529 1.1 hans dxpos += xdim; 530 1.1 hans xdim = -xdim; 531 1.1 hans } 532 1.1 hans if (sypos < dypos) { 533 1.1 hans direction |= 0x02; /* Y decrement */ 534 1.1 hans sypos += ydim; 535 1.1 hans dypos += ydim; 536 1.1 hans ydim = -ydim; 537 1.1 hans } 538 1.1 hans 539 1.1 hans spx_blkcpy_func(sxpos, sypos, dxpos, dypos, xdim, ydim, direction); 540 1.1 hans } 541 1.1 hans 542 1.1 hans static void 543 1.1 hans SPX_blkset(u_int xpos, u_int ypos, u_int xdim, u_int ydim, char color) 544 1.1 hans { 545 1.1 hans u_int counter = 0xfffe; 546 1.1 hans long temp = 0; 547 1.1 hans 548 1.1 hans SPX_REG(SPX_COMMAND) = 0x84884608; 549 1.1 hans SPX_REG(SPX_XSTART) = xpos << 16; 550 1.1 hans SPX_REG(SPX_YSTART) = ypos << 16; 551 1.1 hans SPX_REG(SPX_XEND) = (xpos + xdim) << 16; 552 1.1 hans SPX_REG(SPX_YEND) = (ypos + ydim) << 16; 553 1.1 hans SPX_REG(SPX_STRIDE) = (spx_xsize << 16) | spx_xsize; 554 1.1 hans SPX_REG(SPX_DESTLOOP) = 0x20102003; 555 1.1 hans 556 1.1 hans temp = ((SPX_REG1(0x10) & 0xc0) << (30 - 6)) | 557 1.1 hans ((SPX_REG1(0x10) & 0x3f) << 24); 558 1.1 hans SPX_REG(SPX_DSTPIX) = temp + LINEAR(xpos, ypos); 559 1.1 hans 560 1.1 hans SPX_REG(SPX_FG) = COLOR(color); 561 1.1 hans 562 1.1 hans SPX_REG(SPX_MPC) = 0x2000 | SPX_OP_FILLRECT; 563 1.1 hans 564 1.1 hans SPX_REG1(0x18) = 0xffffffff; 565 1.1 hans while ((counter) && ((SPX_REG1(0x18) & 2) == 0)) 566 1.1 hans counter--; 567 1.1 hans } 568 1.1 hans 569 1.1 hans static void 570 1.1 hans SPXg_blkset(u_int xpos, u_int ypos, u_int xdim, u_int ydim, char color) 571 1.1 hans { 572 1.1 hans u_int counter = 0xfffe; 573 1.1 hans long temp = 0; 574 1.1 hans 575 1.1 hans SPXg_REG(SPX_COMMAND) = 0x84884608; spxg_delay(); 576 1.1 hans SPXg_REG(SPX_XSTART) = xpos << 16; spxg_delay(); 577 1.1 hans SPXg_REG(SPX_YSTART) = ypos << 16; spxg_delay(); 578 1.1 hans SPXg_REG(SPX_XEND) = (xpos + xdim) << 16; spxg_delay(); 579 1.1 hans SPXg_REG(SPX_YEND) = (ypos + ydim) << 16; spxg_delay(); 580 1.1 hans SPXg_REG(SPX_STRIDE) = (spx_xsize << 16) | spx_xsize; spxg_delay(); 581 1.1 hans 582 1.1 hans temp = 0x3f << 24; 583 1.1 hans SPXg_REG(SPX_DSTPIX) = temp + LINEAR(xpos, ypos); spxg_delay(); 584 1.1 hans SPXg_REG(SPX_DSTPIX1) = 0xff000000; spxg_delay(); 585 1.1 hans 586 1.1 hans SPXg_REG(SPX_FG) = COLOR(color); spxg_delay(); 587 1.1 hans 588 1.1 hans SPXg_REG(SPX_DESTLOOP) = 0x20102003; spxg_delay(); 589 1.1 hans SPXg_REG(SPX_MPC) = 0x2000 | SPX_OP_FILLRECT; spxg_delay(); 590 1.1 hans 591 1.1 hans while ((counter) && ((SPXg_REG1(0x0) & 0x8000) == 0)) 592 1.1 hans counter--; 593 1.1 hans } 594 1.1 hans 595 1.3 hans int 596 1.3 hans spx_match(device_t parent, cfdata_t match, void *aux) 597 1.1 hans { 598 1.1 hans struct vsbus_softc *sc = device_private(parent); 599 1.1 hans #if 0 600 1.1 hans struct vsbus_attach_args *va = aux; 601 1.1 hans char *ch = (char *)va->va_addr; 602 1.1 hans #endif 603 1.1 hans 604 1.1 hans /* 605 1.1 hans * FIXME: 606 1.1 hans * add KA46 when/if ever somebody reports SPXg vax_confdata ID on VS 4000/60 607 1.1 hans * Ditto for SPX ID on KA42 & KA43 608 1.1 hans */ 609 1.3 hans if ((vax_boardtype != VAX_BTYP_49) || 610 1.3 hans ((vax_confdata & (CONF_LCSPX | CONF_SPXg)) == 0)) 611 1.1 hans return 0; 612 1.1 hans 613 1.1 hans /* FIXME add RAMDAC ID code ??? */ 614 1.1 hans #if 0 615 1.1 hans /* 616 1.1 hans * FIXME: 617 1.1 hans * are memory addresses besides va->va_addr off limits at this time ? 618 1.1 hans * RAMDAC ID register test, should read 0x4a for LCSPX, 0x4b for SPXg 619 1.1 hans */ 620 1.1 hans if (get_btreg(SPXDAC_REG_ID) != 0x4a) 621 1.1 hans return 0; 622 1.1 hans #endif 623 1.1 hans 624 1.1 hans sc->sc_mask = 0x04; /* XXX - should be generated */ 625 1.9 msaitoh scb_fake(0x14c, 0x15); 626 1.1 hans 627 1.1 hans return 20; 628 1.1 hans } 629 1.1 hans 630 1.1 hans static void 631 1.1 hans spx_attach(device_t parent, device_t self, void *aux) 632 1.1 hans { 633 1.1 hans struct spx_softc *sc = device_private(self); 634 1.1 hans struct vsbus_attach_args *va = aux; 635 1.1 hans struct wsemuldisplaydev_attach_args aa; 636 1.1 hans 637 1.1 hans sc->ss_dev = self; 638 1.1 hans 639 1.1 hans aprint_normal("\n"); 640 1.1 hans aa.console = spxaddr != NULL; 641 1.1 hans 642 1.1 hans spx_init_common(self, va); 643 1.1 hans 644 1.3 hans /* display FB type based on RAMDAC ID */ 645 1.3 hans switch (get_btreg(SPXDAC_REG_ID) & 0xff) { 646 1.3 hans case 0x4a: 647 1.3 hans aprint_normal_dev(self, 648 1.3 hans "RAMDAC ID: 0x%x, Bt459 (SPX/LCSPX) RAMDAC type\n", 649 1.3 hans get_btreg(SPXDAC_REG_ID) & 0xff); 650 1.3 hans break; 651 1.3 hans 652 1.3 hans case 0x4b: 653 1.3 hans aprint_normal_dev(self, 654 1.3 hans "RAMDAC ID: 0x%x, Bt460 (SPXg) RAMDAC type\n", 655 1.3 hans get_btreg(SPXDAC_REG_ID) & 0xff); 656 1.3 hans break; 657 1.3 hans default: 658 1.3 hans aprint_error_dev(self, "unknown RAMDAC type 0x%x\n", 659 1.3 hans get_btreg(SPXDAC_REG_ID) & 0xff); 660 1.3 hans } 661 1.3 hans 662 1.1 hans curscr = &spx_conscreen; 663 1.1 hans prevscr = curscr; 664 1.1 hans 665 1.1 hans aa.scrdata = &spx_screenlist; 666 1.1 hans aa.accessops = &spx_accessops; 667 1.1 hans 668 1.1 hans /* enable cursor */ 669 1.1 hans set_btreg(SPXDAC_REG_CCR, 0xc1); 670 1.1 hans 671 1.12 thorpej config_found(self, &aa, wsemuldisplaydevprint, CFARGS_NONE); 672 1.1 hans } 673 1.1 hans 674 1.1 hans static int cur_on; 675 1.1 hans 676 1.1 hans static void 677 1.1 hans spx_cursor(void *id, int on, int row, int col) 678 1.1 hans { 679 1.1 hans struct spx_screen *ss = id; 680 1.7 martin int attr, data __unused; 681 1.1 hans 682 1.1 hans attr = ss->ss_image[row * spx_cols + col].attr; 683 1.1 hans data = ss->ss_image[row * spx_cols + col].data; 684 1.1 hans 685 1.1 hans if (attr & SPX_ATTR_REVERSE) { 686 1.1 hans cur_bg = attr & SPX_FG_MASK; 687 1.1 hans cur_fg = (attr & SPX_BG_MASK) >> 4; 688 1.1 hans } else { 689 1.1 hans cur_fg = attr & SPX_FG_MASK; 690 1.1 hans cur_bg = (attr & SPX_BG_MASK) >> 4; 691 1.1 hans } 692 1.1 hans 693 1.1 hans if (ss == curscr) { 694 1.1 hans #ifdef SOFTCURSOR 695 1.1 hans if ((cur_on = on)) 696 1.1 hans spx_putchar_func(row, col, data, cur_bg, cur_fg); 697 1.1 hans else 698 1.1 hans spx_putchar_func(row, col, data, cur_fg, cur_bg); 699 1.1 hans #else 700 1.1 hans /* change cursor foreground color colormap entry */ 701 1.1 hans spx_update_cmap(SPXDAC_REG_CCOLOR_3, 702 1.1 hans spx_cmap.r[cur_fg], 703 1.1 hans spx_cmap.g[cur_fg], 704 1.1 hans spx_cmap.b[cur_fg]); 705 1.1 hans 706 1.1 hans /* update cursor position registers */ 707 1.1 hans set_btreg(SPXDAC_REG_CXLO, 708 1.1 hans LO(col * spx_font.fontwidth + CUR_XBIAS)); 709 1.1 hans set_btreg(SPXDAC_REG_CXHI, 710 1.1 hans HI(col * spx_font.fontwidth + CUR_XBIAS)); 711 1.1 hans set_btreg(SPXDAC_REG_CYLO, 712 1.1 hans LO(row * spx_font.fontheight + CUR_YBIAS)); 713 1.1 hans set_btreg(SPXDAC_REG_CYHI, 714 1.1 hans HI(row * spx_font.fontheight + CUR_YBIAS)); 715 1.1 hans 716 1.1 hans if ((cur_on = on)) 717 1.1 hans /* enable cursor */ 718 1.1 hans set_btreg(SPXDAC_REG_CCR, 0xc1); 719 1.1 hans else 720 1.1 hans /* disable cursor */ 721 1.1 hans set_btreg(SPXDAC_REG_CCR, 0x01); 722 1.1 hans #endif 723 1.1 hans } 724 1.1 hans 725 1.1 hans ss->ss_curx = col; 726 1.1 hans ss->ss_cury = row; 727 1.1 hans ss->ss_cur_bg = cur_bg; 728 1.1 hans ss->ss_cur_fg = cur_fg; 729 1.1 hans } 730 1.1 hans 731 1.1 hans static int 732 1.1 hans spx_mapchar(void *id, int uni, unsigned int *index) 733 1.1 hans { 734 1.1 hans if (uni < 256) { 735 1.1 hans *index = uni; 736 1.1 hans return (5); 737 1.1 hans } 738 1.1 hans *index = ' '; 739 1.1 hans return (0); 740 1.1 hans } 741 1.1 hans 742 1.1 hans static void 743 1.1 hans SPX_putchar(int row, int col, u_int c, char dot_fg, char dot_bg) 744 1.1 hans { 745 1.1 hans u_int counter = 0xffffe; 746 1.1 hans long temp = 0; 747 1.1 hans 748 1.1 hans SPX_REG(SPX_FG) = COLOR(dot_fg); 749 1.1 hans SPX_REG(SPX_BG) = COLOR(dot_bg); 750 1.1 hans SPX_REG(SPX_MAIN3) = 0x01010101; 751 1.9 msaitoh SPX_REG(SPX_COMMAND) = 0x84884648; 752 1.1 hans SPX_REG(SPX_XSTART) = (col * spx_font.fontwidth) << 16; 753 1.1 hans SPX_REG(SPX_YSTART) = (row * spx_font.fontheight) << 16; 754 1.1 hans SPX_REG(SPX_XEND) = ((col + 1) * spx_font.fontwidth) << 16; 755 1.1 hans SPX_REG(SPX_YEND) = ((row + 1) * spx_font.fontheight) << 16; 756 1.1 hans 757 1.1 hans temp = ((SPX_REG1(0x10) & 0xc0) << (30 - 6)) | \ 758 1.1 hans ((SPX_REG1(0x10) & 0x3f) << 24); 759 1.1 hans 760 1.1 hans SPX_REG(SPX_DSTPIX) = temp + LINEAR(col * spx_font.fontwidth, 761 1.1 hans row * spx_font.fontheight); 762 1.1 hans SPX_REG(SPX_SRCPIX) = temp + FONT_STORAGE_START 763 1.1 hans + (c * spx_font.fontheight * spx_font.fontwidth); 764 1.1 hans SPX_REG(SPX_SRCPIX1) = 0; 765 1.1 hans SPX_REG(SPX_STRIDE) = (spx_font.fontwidth << 16) | spx_xsize; 766 1.1 hans SPX_REG(SPX_SRCMASK) = 0xff; 767 1.1 hans SPX_REG(SPX_DSTMASK) = 0xff; 768 1.1 hans 769 1.1 hans SPX_REG(SPX_DESTLOOP) = 0x20142003; 770 1.1 hans SPX_REG(SPX_MPC) = 0x2000 | SPX_OP_COPYRECT; 771 1.1 hans 772 1.1 hans SPX_REG1(0x18) = 0xffffffff; 773 1.1 hans 774 1.1 hans while ((counter) && ((SPX_REG1(0x18) & 2) == 0)) 775 1.1 hans counter--; 776 1.1 hans } 777 1.1 hans 778 1.1 hans static void 779 1.1 hans SPXg_putchar(int row, int col, u_int c, char dot_fg, char dot_bg) 780 1.1 hans { 781 1.1 hans u_int counter = 0xffffe; 782 1.1 hans long temp = 0; 783 1.1 hans 784 1.1 hans SPXg_REG(SPX_FG) = COLOR(dot_fg); 785 1.1 hans spxg_delay(); 786 1.1 hans SPXg_REG(SPX_BG) = COLOR(dot_bg); 787 1.1 hans spxg_delay(); 788 1.1 hans SPXg_REG(SPX_MAIN3) = 0x01010101; 789 1.1 hans spxg_delay(); 790 1.1 hans SPXg_REG(SPX_COMMAND) = 0x84884648; 791 1.1 hans spxg_delay(); 792 1.1 hans SPXg_REG(SPX_XSTART) = (col * spx_font.fontwidth) << 16; 793 1.1 hans spxg_delay(); 794 1.1 hans SPXg_REG(SPX_YSTART) = (row * spx_font.fontheight) << 16; 795 1.1 hans spxg_delay(); 796 1.1 hans SPXg_REG(SPX_XEND) = ((col + 1) * spx_font.fontwidth) << 16; 797 1.1 hans spxg_delay(); 798 1.1 hans SPXg_REG(SPX_YEND) = ((row + 1) * spx_font.fontheight) << 16; 799 1.1 hans spxg_delay(); 800 1.1 hans 801 1.1 hans temp = 0x3f << 24; 802 1.1 hans 803 1.1 hans SPXg_REG(SPX_DSTPIX) = temp + LINEAR(col * spx_font.fontwidth, 804 1.1 hans row * spx_font.fontheight); 805 1.1 hans spxg_delay(); 806 1.1 hans SPXg_REG(SPX_DSTPIX1) = 0xff000000; 807 1.1 hans spxg_delay(); 808 1.1 hans SPXg_REG(SPX_SRCPIX) = temp + FONT_STORAGE_START + 809 1.1 hans (c * spx_font.fontheight * spx_font.fontwidth); 810 1.1 hans spxg_delay(); 811 1.1 hans SPXg_REG(SPX_SRCPIX1) = 0; 812 1.1 hans spxg_delay(); 813 1.1 hans SPXg_REG(SPX_STRIDE) = (spx_font.fontwidth << 16) | spx_xsize; 814 1.1 hans spxg_delay(); 815 1.1 hans SPXg_REG(SPX_SRCMASK) = 0xffffffff; 816 1.1 hans spxg_delay(); 817 1.1 hans SPXg_REG(SPX_DSTMASK) = 0xffffffff; 818 1.1 hans spxg_delay(); 819 1.1 hans 820 1.1 hans SPXg_REG(SPX_DESTLOOP) = 0x20142003; 821 1.1 hans spxg_delay(); 822 1.1 hans SPXg_REG(SPX_MPC) = 0x2000 | SPX_OP_COPYRECT; 823 1.1 hans spxg_delay(); 824 1.1 hans 825 1.1 hans while ((counter) && ((SPXg_REG1(0x0) & 0x8000) == 0)) 826 1.1 hans counter--; 827 1.1 hans } 828 1.1 hans 829 1.1 hans static void 830 1.1 hans spx_putchar(void *id, int row, int col, u_int c, long attr) 831 1.1 hans { 832 1.1 hans struct spx_screen *ss = id; 833 1.1 hans char dot_fg, dot_bg; 834 1.1 hans 835 1.1 hans c &= 0xff; 836 1.1 hans 837 1.1 hans ss->ss_image[row * spx_cols + col].data = c; 838 1.1 hans ss->ss_image[row * spx_cols + col].attr = attr; 839 1.1 hans if (ss != curscr) 840 1.1 hans return; 841 1.1 hans 842 1.1 hans dot_fg = attr & SPX_FG_MASK; 843 1.1 hans dot_bg = (attr & SPX_BG_MASK) >> 4; 844 1.1 hans if (attr & SPX_ATTR_REVERSE) { 845 1.1 hans dot_fg = (attr & SPX_BG_MASK) >> 4; 846 1.1 hans dot_bg = attr & SPX_FG_MASK; 847 1.1 hans } 848 1.1 hans 849 1.1 hans /* adjust glyph index for underlined text */ 850 1.1 hans if (attr & SPX_ATTR_UNDERLINE) 851 1.1 hans c += 0x100; 852 1.1 hans 853 1.1 hans spx_putchar_func(row, col, c, dot_fg, dot_bg); 854 1.1 hans } 855 1.1 hans 856 1.1 hans /* 857 1.1 hans * copies columns inside a row. 858 1.1 hans */ 859 1.1 hans static void 860 1.1 hans spx_copycols(void *id, int row, int srccol, int dstcol, int ncols) 861 1.1 hans { 862 1.1 hans struct spx_screen *ss = id; 863 1.1 hans 864 1.1 hans bcopy(&ss->ss_image[row * spx_cols + srccol], 865 1.1 hans &ss->ss_image[row * spx_cols + dstcol], 866 1.1 hans ncols * sizeof(ss->ss_image[0])); 867 1.1 hans 868 1.1 hans if (ss == curscr) 869 1.1 hans spx_blkcpy(srccol * spx_font.fontwidth, 870 1.1 hans row * spx_font.fontheight, 871 1.1 hans dstcol * spx_font.fontwidth, 872 1.1 hans row * spx_font.fontheight, 873 1.1 hans ncols * spx_font.fontwidth, 874 1.1 hans spx_font.fontheight); 875 1.1 hans } 876 1.1 hans 877 1.1 hans /* 878 1.1 hans * Erases a bunch of chars inside one row. 879 1.1 hans */ 880 1.1 hans static void 881 1.1 hans spx_erasecols(void *id, int row, int startcol, int ncols, long fillattr) 882 1.1 hans { 883 1.1 hans struct spx_screen *ss = id; 884 1.1 hans int offset = row * spx_cols + startcol; 885 1.1 hans int i; 886 1.1 hans 887 1.2 cegger memset(&ss->ss_image[row * spx_cols + startcol], 0, 888 1.1 hans ncols * sizeof(ss->ss_image[0])); 889 1.1 hans 890 1.1 hans for (i = offset; i < offset + ncols; ++i) 891 1.1 hans ss->ss_image[i].attr = fillattr; 892 1.1 hans 893 1.1 hans if (ss == curscr) 894 1.1 hans spx_blkset(startcol * spx_font.fontwidth, 895 1.1 hans row * spx_font.fontheight, 896 1.1 hans ncols * spx_font.fontwidth, 897 1.1 hans spx_font.fontheight, 898 1.1 hans (fillattr & SPX_BG_MASK) >> 4); 899 1.1 hans } 900 1.1 hans 901 1.1 hans static void 902 1.1 hans spx_copyrows(void *id, int srcrow, int dstrow, int nrows) 903 1.1 hans { 904 1.1 hans struct spx_screen *ss = id; 905 1.1 hans 906 1.1 hans bcopy(&ss->ss_image[srcrow * spx_cols], 907 1.1 hans &ss->ss_image[dstrow * spx_cols], 908 1.1 hans nrows * spx_cols * sizeof(ss->ss_image[0])); 909 1.1 hans 910 1.1 hans if (ss == curscr) 911 1.1 hans spx_blkcpy(0, (srcrow * spx_font.fontheight), 912 1.1 hans 0, (dstrow * spx_font.fontheight), 913 1.1 hans spx_xsize, (nrows * spx_font.fontheight)); 914 1.1 hans } 915 1.1 hans 916 1.1 hans static void 917 1.1 hans spx_eraserows(void *id, int startrow, int nrows, long fillattr) 918 1.1 hans { 919 1.1 hans struct spx_screen *ss = id; 920 1.1 hans int i; 921 1.1 hans 922 1.2 cegger memset(&ss->ss_image[startrow * spx_cols], 0, 923 1.1 hans nrows * spx_cols * sizeof(ss->ss_image[0])); 924 1.1 hans 925 1.1 hans for (i = startrow * spx_cols; i < startrow + nrows * spx_cols; ++i) 926 1.1 hans ss->ss_image[i].attr = fillattr; 927 1.1 hans 928 1.1 hans if (ss == curscr) 929 1.1 hans spx_blkset(0, (startrow * spx_font.fontheight), 930 1.1 hans spx_xsize, (nrows * spx_font.fontheight), 931 1.1 hans (fillattr & SPX_BG_MASK) >> 4); 932 1.1 hans } 933 1.1 hans 934 1.1 hans static int 935 1.1 hans spx_allocattr(void *id, int fg, int bg, int flags, long *attrp) 936 1.1 hans { 937 1.1 hans long myattr; 938 1.1 hans 939 1.1 hans if (flags & WSATTR_WSCOLORS) 940 1.1 hans myattr = (fg & SPX_FG_MASK) | ((bg << 4) & SPX_BG_MASK); 941 1.1 hans else 942 1.1 hans myattr = WSCOL_WHITE << 4; /* XXXX */ 943 1.1 hans if (flags & WSATTR_REVERSE) 944 1.1 hans myattr |= SPX_ATTR_REVERSE; 945 1.1 hans if (flags & WSATTR_UNDERLINE) 946 1.1 hans myattr |= SPX_ATTR_UNDERLINE; 947 1.1 hans *attrp = myattr; 948 1.1 hans return 0; 949 1.1 hans } 950 1.1 hans 951 1.1 hans static int 952 1.1 hans spx_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l) 953 1.1 hans { 954 1.1 hans struct wsdisplay_fbinfo *fb = data; 955 1.1 hans int i; 956 1.1 hans 957 1.1 hans switch (cmd) { 958 1.1 hans case WSDISPLAYIO_GTYPE: 959 1.1 hans *(u_int *)data = WSDISPLAY_TYPE_SPX; 960 1.1 hans break; 961 1.1 hans 962 1.1 hans case WSDISPLAYIO_GINFO: 963 1.1 hans fb->height = spx_ysize; 964 1.1 hans fb->width = spx_xsize; 965 1.1 hans fb->depth = spx_depth; 966 1.1 hans fb->cmsize = 1 << spx_depth; 967 1.1 hans break; 968 1.1 hans 969 1.1 hans case WSDISPLAYIO_GETCMAP: 970 1.1 hans return spx_get_cmap((struct wsdisplay_cmap *)data); 971 1.1 hans 972 1.1 hans case WSDISPLAYIO_PUTCMAP: 973 1.1 hans return spx_set_cmap((struct wsdisplay_cmap *)data); 974 1.1 hans 975 1.1 hans case WSDISPLAYIO_GMODE: 976 1.1 hans return EPASSTHROUGH; 977 1.1 hans 978 1.1 hans case WSDISPLAYIO_SMODE: 979 1.1 hans /* 980 1.1 hans * if setting WSDISPLAYIO_MODE_EMUL, restore console cmap, 981 1.1 hans * current screen 982 1.1 hans */ 983 1.1 hans if (*(u_int *)data == WSDISPLAYIO_MODE_EMUL) { 984 1.1 hans for (i = 0; i < 8; i++) { 985 1.1 hans spx_cmap.r[i] = spx_default_cmap.r[i]; 986 1.1 hans spx_cmap.g[i] = spx_default_cmap.g[i]; 987 1.1 hans spx_cmap.b[i] = spx_default_cmap.b[i]; 988 1.1 hans spx_update_cmap(i, spx_cmap.r[i], spx_cmap.g[i], 989 1.1 hans spx_cmap.b[i]); 990 1.1 hans } 991 1.1 hans if (savescr != NULL) 992 1.1 hans spx_show_screen(NULL, savescr, 0, NULL, NULL); 993 1.1 hans savescr = NULL; 994 1.13 hans } else { /* WSDISPLAYIO_MODE_{MAPPED,DUMBFB} */ 995 1.13 hans if (curscr != NULL) { 996 1.13 hans savescr = curscr; 997 1.13 hans curscr = NULL; 998 1.13 hans 999 1.13 hans /* disable cursor */ 1000 1.13 hans set_btreg(SPXDAC_REG_CCR, 0x01); 1001 1.13 hans } 1002 1.1 hans /* clear screen? */ 1003 1.1 hans } 1004 1.1 hans 1005 1.1 hans return EPASSTHROUGH; 1006 1.1 hans 1007 1.1 hans case WSDISPLAYIO_SVIDEO: 1008 1.1 hans if (*(u_int *)data == WSDISPLAYIO_VIDEO_ON && spx_off) { 1009 1.1 hans /* Unblank video */ 1010 1.1 hans set_btreg(SPXDAC_REG_CMD0, 0x48); 1011 1.1 hans 1012 1.1 hans /* Enable sync */ 1013 1.1 hans set_btreg(SPXDAC_REG_CMD2, 0xc0); 1014 1.1 hans 1015 1.1 hans spx_off = 0; 1016 1.1 hans } else if (*(u_int *)data == WSDISPLAYIO_VIDEO_OFF && !spx_off) { 1017 1.1 hans /* Blank video */ 1018 1.1 hans set_btreg(SPXDAC_REG_CMD0, 68); 1019 1.1 hans 1020 1.1 hans /* Disable sync */ 1021 1.1 hans set_btreg(SPXDAC_REG_CMD2, 0x40); 1022 1.1 hans spx_off = 1; 1023 1.1 hans } 1024 1.1 hans break; 1025 1.1 hans 1026 1.1 hans case WSDISPLAYIO_GVIDEO: 1027 1.1 hans *(u_int *)data = spx_off == 0 ? 1028 1.1 hans WSDISPLAYIO_VIDEO_ON : WSDISPLAYIO_VIDEO_OFF; 1029 1.1 hans break; 1030 1.1 hans 1031 1.6 abs case WSDISPLAYIO_LINEBYTES: 1032 1.6 abs *(u_int *)data = spx_xsize; 1033 1.6 abs break; 1034 1.6 abs 1035 1.1 hans default: 1036 1.1 hans return EPASSTHROUGH; 1037 1.1 hans } 1038 1.1 hans return 0; 1039 1.1 hans } 1040 1.1 hans 1041 1.1 hans /* 1042 1.1 hans * Bad idea on SPXg/gt due to windowed framebuffer access 1043 1.1 hans */ 1044 1.1 hans static paddr_t 1045 1.1 hans spx_mmap(void *v, void *vs, off_t offset, int prot) 1046 1.1 hans { 1047 1.1 hans if (fb_type != FB_IS_SPX) 1048 1.1 hans return -1; 1049 1.1 hans 1050 1.1 hans if (offset >= spx_fb_size || offset < 0) 1051 1.1 hans return -1; 1052 1.1 hans 1053 1.1 hans return (SPX_FB_ADDR + offset) >> PGSHIFT; 1054 1.1 hans } 1055 1.1 hans 1056 1.1 hans static int 1057 1.1 hans spx_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep, 1058 1.1 hans int *curxp, int *curyp, long *defattrp) 1059 1.1 hans { 1060 1.1 hans int i; 1061 1.1 hans struct spx_screen *ss; 1062 1.1 hans 1063 1.10 thorpej ss = kmem_zalloc(sizeof(struct spx_screen), KM_SLEEP); 1064 1.1 hans 1065 1.1 hans *cookiep = ss; 1066 1.1 hans *curxp = *curyp = 0; 1067 1.1 hans *defattrp = (SPX_BG_COLOR << 4) | SPX_FG_COLOR; 1068 1.1 hans 1069 1.1 hans for (i = 0; i < spx_cols * spx_rows; ++i) 1070 1.1 hans ss->ss_image[i].attr = *defattrp; 1071 1.1 hans 1072 1.1 hans return 0; 1073 1.1 hans } 1074 1.1 hans 1075 1.1 hans static void 1076 1.1 hans spx_free_screen(void *v, void *cookie) 1077 1.1 hans { 1078 1.10 thorpej /* FIXME add something to actually free kmem_zalloc()ed screen? */ 1079 1.1 hans } 1080 1.1 hans 1081 1.1 hans static int 1082 1.1 hans spx_show_screen(void *v, void *cookie, int waitok, 1083 1.1 hans void (*cb)(void *, int, int), void *cbarg) 1084 1.1 hans { 1085 1.1 hans struct spx_screen *ss = cookie; 1086 1.1 hans u_int row, col, attr; 1087 1.1 hans u_char c; 1088 1.1 hans 1089 1.1 hans if (ss == curscr) 1090 1.1 hans return (0); 1091 1.1 hans 1092 1.1 hans prevscr = curscr; 1093 1.1 hans curscr = ss; 1094 1.1 hans 1095 1.1 hans for (row = 0; row < spx_rows; row++) { 1096 1.1 hans for (col = 0; col < spx_cols; col++) { 1097 1.1 hans u_int idx = row * spx_cols + col; 1098 1.1 hans attr = ss->ss_image[idx].attr; 1099 1.1 hans c = ss->ss_image[idx].data; 1100 1.1 hans 1101 1.1 hans /* check if cell requires updating */ 1102 1.13 hans if (prevscr == NULL || 1103 1.13 hans (c != prevscr->ss_image[idx].data) || 1104 1.1 hans (attr != prevscr->ss_image[idx].attr)) { 1105 1.13 hans if (c < 32) 1106 1.13 hans c = 32; 1107 1.1 hans spx_putchar(ss, row, col, c, attr); 1108 1.1 hans } 1109 1.1 hans } 1110 1.1 hans } 1111 1.1 hans 1112 1.1 hans row = ss->ss_cury; col = ss->ss_curx; 1113 1.1 hans 1114 1.1 hans spx_cursor(ss, cur_on, row, col); 1115 1.1 hans 1116 1.1 hans cur_fg = ss->ss_cur_fg; 1117 1.1 hans cur_bg = ss->ss_cur_bg; 1118 1.1 hans 1119 1.1 hans return (0); 1120 1.1 hans } 1121 1.1 hans 1122 1.1 hans static int 1123 1.1 hans spx_get_cmap(struct wsdisplay_cmap *p) 1124 1.1 hans { 1125 1.1 hans u_int index = p->index, count = p->count; 1126 1.1 hans int error; 1127 1.1 hans 1128 1.1 hans if (index >= (1 << spx_depth) || count > (1 << spx_depth) - index) 1129 1.1 hans return (EINVAL); 1130 1.1 hans 1131 1.1 hans error = copyout(&spx_cmap.r[index], p->red, count); 1132 1.1 hans if (error) 1133 1.1 hans return error; 1134 1.1 hans 1135 1.1 hans error = copyout(&spx_cmap.g[index], p->green, count); 1136 1.1 hans if (error) 1137 1.1 hans return error; 1138 1.1 hans 1139 1.1 hans error = copyout(&spx_cmap.b[index], p->blue, count); 1140 1.1 hans return error; 1141 1.1 hans } 1142 1.1 hans 1143 1.1 hans static int 1144 1.1 hans spx_set_cmap(struct wsdisplay_cmap *p) 1145 1.1 hans { 1146 1.1 hans u_int index = p->index, count = p->count; 1147 1.1 hans int error, s; 1148 1.1 hans 1149 1.1 hans if (index >= (1 << spx_depth) || count > (1 << spx_depth) - index) 1150 1.1 hans return (EINVAL); 1151 1.1 hans 1152 1.1 hans error = copyin(p->red, &spx_cmap.r[index], count); 1153 1.1 hans if (error) 1154 1.1 hans return error; 1155 1.1 hans 1156 1.1 hans error = copyin(p->green, &spx_cmap.g[index], count); 1157 1.1 hans if (error) 1158 1.1 hans return error; 1159 1.1 hans 1160 1.1 hans error = copyin(p->blue, &spx_cmap.b[index], count); 1161 1.1 hans 1162 1.1 hans if (error) 1163 1.1 hans return error; 1164 1.1 hans 1165 1.1 hans s = spltty(); 1166 1.1 hans while (count-- > 0) { 1167 1.1 hans spx_update_cmap(index, 1168 1.1 hans spx_cmap.r[index], 1169 1.1 hans spx_cmap.g[index], 1170 1.1 hans spx_cmap.b[index]); 1171 1.1 hans index++; 1172 1.1 hans } 1173 1.1 hans splx(s); 1174 1.1 hans return (0); 1175 1.1 hans } 1176 1.1 hans 1177 1.1 hans cons_decl(spx); 1178 1.1 hans 1179 1.1 hans void 1180 1.1 hans spxcninit(struct consdev *cndev) 1181 1.1 hans { 1182 1.1 hans int i; 1183 1.1 hans 1184 1.1 hans spx_blkset(0, 0, spx_xsize, spx_ysize, SPX_BG_COLOR); 1185 1.1 hans 1186 1.1 hans curscr = &spx_conscreen; 1187 1.3 hans 1188 1.1 hans for (i = 0; i < spx_cols * spx_rows; i++) 1189 1.1 hans spx_conscreen.ss_image[i].attr = 1190 1.1 hans (SPX_BG_COLOR << 4) | SPX_FG_COLOR; 1191 1.1 hans wsdisplay_cnattach(&spx_stdscreen, &spx_conscreen, 0, 0, 1192 1.1 hans (SPX_BG_COLOR << 4) | SPX_FG_COLOR); 1193 1.1 hans cn_tab->cn_pri = CN_INTERNAL; 1194 1.1 hans 1195 1.1 hans #if NDZKBD > 0 1196 1.1 hans dzkbd_cnattach(0); /* Connect keyboard and screen together */ 1197 1.1 hans #endif 1198 1.1 hans } 1199 1.1 hans 1200 1.1 hans /* 1201 1.1 hans * Called very early to setup the glass tty as console. 1202 1.1 hans * Because it's called before the VM system is inited, virtual memory 1203 1.1 hans * for the framebuffer can be stolen directly without disturbing anything. 1204 1.1 hans */ 1205 1.1 hans void 1206 1.1 hans spxcnprobe(struct consdev *cndev) 1207 1.1 hans { 1208 1.1 hans extern const struct cdevsw wsdisplay_cdevsw; 1209 1.1 hans 1210 1.1 hans /* Only for VS 4000/90, 90A and 96 with LCSPX or SPXg/gt*/ 1211 1.1 hans if ((vax_boardtype != VAX_BTYP_49) || 1212 1.3 hans ((vax_confdata & (CONF_LCSPX | CONF_SPXg)) == 0)) 1213 1.1 hans return; 1214 1.1 hans 1215 1.1 hans if (((vax_confdata & 8) && (vax_boardtype == VAX_BTYP_49)) || 1216 1.1 hans (((vax_confdata & KA420_CFG_L3CON) || 1217 1.1 hans (vax_confdata & KA420_CFG_MULTU)) && 1218 1.1 hans ((vax_boardtype == VAX_BTYP_420) || 1219 1.1 hans (vax_boardtype == VAX_BTYP_43)))) { 1220 1.1 hans aprint_normal("spxcnprobe: Diagnostic console\n"); 1221 1.1 hans return; /* Diagnostic console */ 1222 1.1 hans } 1223 1.1 hans 1224 1.1 hans spx_init_common(NULL, NULL); 1225 1.1 hans 1226 1.1 hans cndev->cn_pri = CN_INTERNAL; 1227 1.1 hans cndev->cn_dev = makedev(cdevsw_lookup_major(&wsdisplay_cdevsw), 0); 1228 1.1 hans } 1229 1.1 hans 1230 1.1 hans static int 1231 1.1 hans spx_map_regs(device_t self, 1232 1.1 hans u_int raddr, u_int rsize, u_int r1addr, u_int r1size) 1233 1.1 hans { 1234 1.1 hans extern vaddr_t virtual_avail; 1235 1.1 hans 1236 1.1 hans if (!self) { 1237 1.1 hans regaddr = (long*)virtual_avail; 1238 1.1 hans virtual_avail += rsize; 1239 1.1 hans ioaccess((vaddr_t)regaddr, raddr, rsize/VAX_NBPG); 1240 1.1 hans 1241 1.1 hans regaddr1 = (long*)virtual_avail; 1242 1.1 hans virtual_avail += r1size; 1243 1.1 hans ioaccess((vaddr_t)regaddr1, r1addr, r1size/VAX_NBPG); 1244 1.1 hans 1245 1.1 hans return 1; 1246 1.1 hans } 1247 1.1 hans 1248 1.1 hans regaddr = (long*)vax_map_physmem(raddr, rsize/VAX_NBPG); 1249 1.1 hans if (regaddr == 0) { 1250 1.1 hans aprint_error_dev(self, 1251 1.1 hans "unable to allocate register memory (1).\n"); 1252 1.1 hans return 0; 1253 1.1 hans } 1254 1.1 hans 1255 1.1 hans regaddr1 = (long*)vax_map_physmem(r1addr, r1size/VAX_NBPG); 1256 1.1 hans if (regaddr1 == 0) { 1257 1.1 hans aprint_error_dev(self, 1258 1.1 hans "unable to allocate register memory (2).\n"); 1259 1.1 hans return 0; 1260 1.1 hans } 1261 1.1 hans 1262 1.1 hans return 1; 1263 1.1 hans } 1264 1.1 hans 1265 1.1 hans static int 1266 1.1 hans SPX_map_fb(device_t self, struct vsbus_attach_args *va) 1267 1.1 hans { 1268 1.1 hans int fbsize = (spx_fb_size + FONT_STORAGE_SIZE)/VAX_NBPG; 1269 1.1 hans extern vaddr_t virtual_avail; 1270 1.1 hans 1271 1.1 hans if (!self) { 1272 1.1 hans spxaddr = (char *)virtual_avail; 1273 1.1 hans virtual_avail += (spx_fb_size + FONT_STORAGE_SIZE); 1274 1.1 hans ioaccess((vaddr_t)spxaddr, SPX_FB_ADDR, fbsize); 1275 1.1 hans 1276 1.1 hans bt_addrl = (char *)virtual_avail; 1277 1.1 hans virtual_avail += VAX_NBPG; 1278 1.1 hans ioaccess((vaddr_t)bt_addrl, SPX_BT459_ADDRL, 1); 1279 1.1 hans 1280 1.1 hans bt_addrh = (char *)virtual_avail; 1281 1.1 hans virtual_avail += VAX_NBPG; 1282 1.1 hans ioaccess((vaddr_t)bt_addrh, SPX_BT459_ADDRH, 1); 1283 1.1 hans 1284 1.1 hans bt_reg = (char *)virtual_avail; 1285 1.1 hans virtual_avail += VAX_NBPG; 1286 1.1 hans ioaccess((vaddr_t)bt_reg, SPX_BT459_REG, 1); 1287 1.1 hans 1288 1.1 hans bt_cmap = (char *)virtual_avail; 1289 1.1 hans virtual_avail += VAX_NBPG; 1290 1.1 hans ioaccess((vaddr_t)bt_cmap, SPX_BT459_CMAP, 1); 1291 1.1 hans 1292 1.1 hans return 1; 1293 1.1 hans } 1294 1.1 hans 1295 1.1 hans spxaddr = (char *)vax_map_physmem(va->va_paddr, fbsize); 1296 1.1 hans if (spxaddr == 0) { 1297 1.1 hans aprint_error_dev(self, "unable to map framebuffer memory.\n"); 1298 1.1 hans return 0; 1299 1.1 hans } 1300 1.1 hans 1301 1.1 hans /* map all four RAMDAC registers */ 1302 1.1 hans bt_addrl = (char *)vax_map_physmem(SPX_BT459_ADDRL, 1); 1303 1.1 hans if (bt_addrl == 0) { 1304 1.1 hans aprint_error_dev(self, 1305 1.1 hans "unable to map BT459 Low Address register.\n"); 1306 1.1 hans return 0; 1307 1.1 hans } 1308 1.1 hans 1309 1.1 hans bt_addrh = (char *)vax_map_physmem(SPX_BT459_ADDRH, 1); 1310 1.1 hans if (bt_addrh == 0) { 1311 1.1 hans aprint_error_dev(self, 1312 1.1 hans "unable to map BT459 High Address register.\n"); 1313 1.1 hans return 0; 1314 1.1 hans } 1315 1.1 hans 1316 1.1 hans bt_reg = (char *)vax_map_physmem(SPX_BT459_REG, 1); 1317 1.1 hans if (bt_reg == 0) { 1318 1.1 hans aprint_error_dev(self, 1319 1.1 hans "unable to map BT459 I/O Register.\n"); 1320 1.1 hans return 0; 1321 1.1 hans } 1322 1.1 hans 1323 1.1 hans bt_cmap = (char *)vax_map_physmem(SPX_BT459_CMAP, 1); 1324 1.1 hans if (bt_cmap == 0) { 1325 1.1 hans aprint_error_dev(self, 1326 1.1 hans "unable to map BT459 Color Map register.\n"); 1327 1.1 hans return 0; 1328 1.1 hans } 1329 1.1 hans 1330 1.1 hans return 1; 1331 1.1 hans } 1332 1.1 hans 1333 1.1 hans static int 1334 1.1 hans SPXg_map_fb(device_t self, struct vsbus_attach_args *va) 1335 1.1 hans { 1336 1.1 hans int fbsize = SPXg_WIN_SIZE/VAX_NBPG; 1337 1.1 hans extern vaddr_t virtual_avail; 1338 1.1 hans 1339 1.1 hans if (!self) { 1340 1.1 hans spxaddr = (char *)virtual_avail; 1341 1.1 hans virtual_avail += SPXg_WIN_SIZE; 1342 1.1 hans ioaccess((vaddr_t)spxaddr, SPXg_FB_ADDR, fbsize); 1343 1.1 hans 1344 1.1 hans bt_addrl = (char *)virtual_avail; 1345 1.1 hans virtual_avail += VAX_NBPG; 1346 1.1 hans ioaccess((vaddr_t)bt_addrl, SPXg_BT460_BASE, 1); 1347 1.1 hans 1348 1.1 hans bt_addrh = bt_addrl + 0x04; 1349 1.1 hans bt_reg = bt_addrl + 0x08; 1350 1.1 hans bt_cmap = bt_addrl + 0x0c; 1351 1.1 hans bt_wait = bt_addrl + 0x34; 1352 1.1 hans 1353 1.1 hans return 1; 1354 1.1 hans } 1355 1.1 hans 1356 1.1 hans spxaddr = (char *)vax_map_physmem(va->va_paddr, fbsize); 1357 1.1 hans if (spxaddr == 0) { 1358 1.1 hans aprint_error_dev(self, 1359 1.1 hans "unable to map framebuffer memory window.\n"); 1360 1.1 hans return 0; 1361 1.1 hans } 1362 1.1 hans 1363 1.1 hans bt_addrl = (char *)vax_map_physmem(SPXg_BT460_BASE, 1); 1364 1.1 hans if (bt_addrl == 0) { 1365 1.1 hans aprint_error_dev(self, 1366 1.1 hans "unable to map BT460 Low Address register.\n"); 1367 1.1 hans return 0; 1368 1.1 hans } 1369 1.1 hans bt_addrh = bt_addrl + 0x04; 1370 1.1 hans bt_reg = bt_addrl + 0x08; 1371 1.1 hans bt_cmap = bt_addrl + 0x0c; 1372 1.1 hans bt_wait = bt_addrl + 0x34; 1373 1.1 hans 1374 1.1 hans return 1; 1375 1.1 hans } 1376 1.1 hans 1377 1.1 hans static void 1378 1.1 hans SPX_render_font(void) 1379 1.1 hans { 1380 1.1 hans volatile char *fontaddr = spxaddr + FONT_STORAGE_START; 1381 1.1 hans int i, j, k, ch, pixel; 1382 1.1 hans 1383 1.1 hans for (i = 0; i < 256; i++) for (j = 0; j < spx_font.fontheight; j++) { 1384 1.1 hans ch = QFONT(i, j); 1385 1.1 hans 1386 1.1 hans /* regular characters */ 1387 1.1 hans pixel = ((i * spx_font.fontheight)+ j) * spx_font.fontwidth; 1388 1.1 hans for (k = 0; k < spx_font.fontwidth; k++) 1389 1.1 hans if (ch & (1 << k)) 1390 1.1 hans fontaddr[pixel++] = 0xff; 1391 1.1 hans else 1392 1.1 hans fontaddr[pixel++] = 0x00; 1393 1.1 hans 1394 1.1 hans /* underlined characters */ 1395 1.1 hans pixel = (((i + 256) * spx_font.fontheight) + j) 1396 1.1 hans * spx_font.fontwidth; 1397 1.1 hans for (k = 0; k < spx_font.fontwidth; k++) 1398 1.1 hans if ((ch & (1 << k)) || (j == (spx_font.fontheight - 1))) 1399 1.1 hans fontaddr[pixel++] = 0xff; 1400 1.1 hans else 1401 1.1 hans fontaddr[pixel++] = 0x00; 1402 1.1 hans } 1403 1.1 hans } 1404 1.1 hans 1405 1.1 hans static void 1406 1.1 hans SPXg_render_font(void) 1407 1.1 hans { 1408 1.1 hans int i, j, k, ch, pixel; 1409 1.1 hans 1410 1.1 hans for (i = 0; i < 256; i++) for (j = 0; j < spx_font.fontheight; j++) { 1411 1.1 hans ch = QFONT(i, j); 1412 1.1 hans /* regular characters */ 1413 1.1 hans for (k = 0; k < spx_font.fontwidth; k++) { 1414 1.1 hans pixel = FONT_STORAGE_START 1415 1.1 hans + (((i * spx_font.fontheight) + j) 1416 1.1 hans * spx_font.fontwidth) + k; 1417 1.1 hans if ((pixel / SPXg_WIN_LINEAR) != spxg_current_page) { 1418 1.1 hans spxg_switch_page(pixel / SPXg_WIN_LINEAR); 1419 1.1 hans spxg_current_page = (pixel / SPXg_WIN_LINEAR); 1420 1.1 hans } 1421 1.1 hans SPXg_ADDR(pixel) = ch & (1 << k) ? 0xff : 0x00; 1422 1.1 hans spxg_delay(); 1423 1.1 hans } 1424 1.1 hans 1425 1.1 hans /* underlined characters */ 1426 1.1 hans for (k = 0; k < spx_font.fontwidth; k++) { 1427 1.1 hans pixel = FONT_STORAGE_START 1428 1.1 hans + ((((i + 256) * spx_font.fontheight) + j) 1429 1.1 hans * spx_font.fontwidth) + k; 1430 1.1 hans if ((pixel / SPXg_WIN_LINEAR) != spxg_current_page) { 1431 1.1 hans spxg_switch_page(pixel / SPXg_WIN_LINEAR); 1432 1.1 hans spxg_current_page = (pixel / SPXg_WIN_LINEAR); 1433 1.1 hans } 1434 1.1 hans if ((ch & (1 << k)) || (j == (spx_font.fontheight - 1))) 1435 1.1 hans SPXg_ADDR(pixel) = 0xff; 1436 1.1 hans else 1437 1.1 hans SPXg_ADDR(pixel) = 0x00; 1438 1.1 hans spxg_delay(); 1439 1.1 hans } 1440 1.1 hans } 1441 1.1 hans } 1442 1.1 hans 1443 1.1 hans static void 1444 1.1 hans spx_init_common(device_t self, struct vsbus_attach_args *va) 1445 1.1 hans { 1446 1.1 hans u_int i, j, k; 1447 1.1 hans int cookie; 1448 1.1 hans struct wsdisplay_font *wf; 1449 1.3 hans static int init_done; 1450 1.3 hans 1451 1.3 hans if (init_done) 1452 1.3 hans return; 1453 1.3 hans 1454 1.3 hans /* KA49: Identify framebuffer type */ 1455 1.3 hans switch (vax_confdata & (CONF_LCSPX | CONF_SPXg)) { 1456 1.3 hans case CONF_LCSPX: 1457 1.3 hans fb_type = FB_IS_SPX; 1458 1.3 hans spx_blkcpy_func = SPX_blkcpy; 1459 1.3 hans spx_blkset_func = SPX_blkset; 1460 1.3 hans spx_putchar_func = SPX_putchar; 1461 1.3 hans break; 1462 1.3 hans case CONF_SPXg: 1463 1.3 hans fb_type = FB_IS_SPXg; 1464 1.3 hans spx_blkcpy_func = SPXg_blkcpy; 1465 1.3 hans spx_blkset_func = SPXg_blkset; 1466 1.3 hans spx_putchar_func = SPXg_putchar; 1467 1.3 hans break; 1468 1.3 hans case CONF_LCSPX | CONF_SPXg: 1469 1.3 hans panic("spxcnprobe: incorrect FB configuration\n"); 1470 1.3 hans break; 1471 1.3 hans } 1472 1.1 hans 1473 1.1 hans /* map SPX registers first */ 1474 1.1 hans if (fb_type == FB_IS_SPX) { 1475 1.1 hans SPX_MAP_REGS(self, SPX); 1476 1.1 hans } else if(fb_type == FB_IS_SPXg) { 1477 1.1 hans SPX_MAP_REGS(self, SPXg); 1478 1.1 hans } 1479 1.1 hans 1480 1.1 hans if (fb_type == FB_IS_SPXg) 1481 1.1 hans spxg_switch_page(0); 1482 1.1 hans 1483 1.1 hans /* any KA42/43 SPX resolution detection code should be placed here */ 1484 1.1 hans spx_depth = 8; 1485 1.1 hans spx_xsize = 1280; 1486 1.1 hans spx_ysize = 1024; 1487 1.1 hans 1488 1.1 hans wsfont_init(); 1489 1.1 hans 1490 1.1 hans cookie = wsfont_find(NULL, 12, 21, 0, WSDISPLAY_FONTORDER_R2L, 1491 1.5 macallan WSDISPLAY_FONTORDER_L2R, WSFONT_FIND_BITMAP); 1492 1.1 hans if (cookie == -1) 1493 1.5 macallan cookie = wsfont_find(NULL, 16, 0, 0, WSDISPLAY_FONTORDER_R2L, 0, 1494 1.5 macallan WSFONT_FIND_BITMAP); 1495 1.1 hans if (cookie == -1) 1496 1.5 macallan cookie = wsfont_find(NULL, 12, 0, 0, WSDISPLAY_FONTORDER_R2L, 0, 1497 1.5 macallan WSFONT_FIND_BITMAP); 1498 1.1 hans if (cookie == -1) 1499 1.5 macallan cookie = wsfont_find(NULL, 8, 0, 0, WSDISPLAY_FONTORDER_R2L, 0, 1500 1.5 macallan WSFONT_FIND_BITMAP); 1501 1.1 hans if (cookie == -1) 1502 1.1 hans cookie = wsfont_find(NULL, 0, 0, 0, WSDISPLAY_FONTORDER_R2L, 1503 1.5 macallan WSDISPLAY_FONTORDER_L2R, WSFONT_FIND_BITMAP); 1504 1.1 hans 1505 1.1 hans if (cookie == -1 || wsfont_lock(cookie, &wf)) 1506 1.1 hans panic("spx_common_init: unable to load console font"); 1507 1.1 hans 1508 1.1 hans spx_font = *wf; 1509 1.1 hans 1510 1.1 hans if (self != NULL) { 1511 1.1 hans aprint_normal_dev(self, "Using %s %dx%d font\n", wf->name, 1512 1.1 hans spx_font.fontwidth, spx_font.fontheight); 1513 1.1 hans } 1514 1.1 hans 1515 1.1 hans spx_cols = spx_xsize / spx_font.fontwidth; 1516 1.1 hans spx_rows = spx_ysize / spx_font.fontheight; 1517 1.1 hans spx_fb_size = spx_xsize * spx_ysize; 1518 1.1 hans spx_stdscreen.ncols = spx_cols; 1519 1.1 hans spx_stdscreen.nrows = spx_rows; 1520 1.1 hans spx_stdscreen.fontwidth = spx_font.fontwidth; 1521 1.1 hans spx_stdscreen.fontheight = spx_font.fontheight; 1522 1.8 ozaki snprintf(spx_stdscreen_name, sizeof(spx_stdscreen_name), 1523 1.8 ozaki "%dx%d", spx_cols, spx_rows); 1524 1.1 hans 1525 1.1 hans /* for SPXg spx_fb_size represents FB window size, not FB length */ 1526 1.1 hans if (fb_type == FB_IS_SPXg) 1527 1.1 hans spx_fb_size = SPXg_WIN_SIZE; 1528 1.1 hans 1529 1.1 hans qf = spx_font.data; 1530 1.1 hans qf2 = (u_short *)spx_font.data; 1531 1.1 hans 1532 1.1 hans if (fb_type == FB_IS_SPX) { 1533 1.1 hans SPX_MAP_FB(self, va, SPX); 1534 1.1 hans } else if (fb_type == FB_IS_SPXg) { 1535 1.1 hans SPX_MAP_FB(self, va, SPXg); 1536 1.1 hans } 1537 1.1 hans 1538 1.1 hans /* render font glyphs to off-screen memory */ 1539 1.1 hans if (fb_type == FB_IS_SPX) 1540 1.1 hans SPX_render_font(); 1541 1.1 hans else if (fb_type == FB_IS_SPXg) 1542 1.1 hans SPXg_render_font(); 1543 1.1 hans 1544 1.1 hans /* set up default console color palette */ 1545 1.1 hans for (i = 0; i < 8; i++) { 1546 1.1 hans spx_cmap.r[i] = spx_default_cmap.r[i]; 1547 1.1 hans spx_cmap.g[i] = spx_default_cmap.g[i]; 1548 1.1 hans spx_cmap.b[i] = spx_default_cmap.b[i]; 1549 1.1 hans spx_update_cmap(i, spx_cmap.r[i], spx_cmap.g[i], spx_cmap.b[i]); 1550 1.1 hans } 1551 1.1 hans 1552 1.1 hans /* 1553 1.1 hans * Build 64x64 console cursor bitmap based on font dimensions. 1554 1.1 hans * Palette colors are not used, but 4 pixels 2bpp of cursor sprite, 1555 1.1 hans * fg/bg respectively. 1556 1.1 hans */ 1557 1.1 hans for (i = 0; i < 1024; i++) 1558 1.1 hans set_btreg(SPXDAC_REG_CRAM_BASE + i, 0); 1559 1.1 hans 1560 1.1 hans /* build cursor line, 1 to 3 pixels high depending on font height */ 1561 1.1 hans if (spx_font.fontheight > 26) 1562 1.1 hans i = spx_font.fontheight - 3; 1563 1.1 hans else if (spx_font.fontheight > 16) 1564 1.1 hans i = spx_font.fontheight - 2; 1565 1.1 hans else 1566 1.1 hans i = spx_font.fontheight - 1; 1567 1.1 hans 1568 1.1 hans for (; i <= spx_font.fontheight - 1; i++) { 1569 1.1 hans for (j = 0; j < (spx_font.fontwidth >> 2); j++) 1570 1.1 hans set_btreg(SPXDAC_REG_CRAM_BASE + i*16 + j, 0xff); 1571 1.1 hans k = (spx_font.fontwidth & 3) << 1; 1572 1.1 hans set_btreg(SPXDAC_REG_CRAM_BASE + i*16 + j, (1 << k) - 1); 1573 1.1 hans } 1574 1.1 hans 1575 1.1 hans if (fb_type == FB_IS_SPX) { 1576 1.1 hans /* set SPX write/read plane masks */ 1577 1.1 hans SPX_REG(0x3170) = 0xffffffff; 1578 1.1 hans SPX_REG(0x3174) = 0xffffffff; 1579 1.1 hans } 1580 1.1 hans 1581 1.1 hans /* RAMDAC type-specific configuration */ 1582 1.1 hans if (fb_type == FB_IS_SPX) 1583 1.1 hans set_btreg(SPXDAC_REG_CMD2, 0xc0); 1584 1.1 hans 1585 1.1 hans /* common configuration */ 1586 1.1 hans set_btreg(SPXDAC_REG_CMD0, 0x48); 1587 1.1 hans set_btreg(SPXDAC_REG_CMD1, 0x00); 1588 1.1 hans set_btreg(SPXDAC_REG_PRM, 0xff); 1589 1.1 hans 1590 1.1 hans set_btreg(SPXDAC_REG_CXLO, 0); 1591 1.1 hans set_btreg(SPXDAC_REG_CXHI, 0); 1592 1.1 hans set_btreg(SPXDAC_REG_CYLO, 0); 1593 1.1 hans set_btreg(SPXDAC_REG_CYHI, 0); 1594 1.1 hans 1595 1.1 hans set_btreg(SPXDAC_REG_WXLO, 0); 1596 1.1 hans set_btreg(SPXDAC_REG_WXHI, 0); 1597 1.1 hans set_btreg(SPXDAC_REG_WYLO, 0); 1598 1.1 hans set_btreg(SPXDAC_REG_WYHI, 0); 1599 1.1 hans 1600 1.1 hans set_btreg(SPXDAC_REG_WWLO, 0); 1601 1.1 hans set_btreg(SPXDAC_REG_WWHI, 0); 1602 1.1 hans set_btreg(SPXDAC_REG_WHLO, 0); 1603 1.1 hans set_btreg(SPXDAC_REG_WHHI, 0); 1604 1.3 hans 1605 1.3 hans init_done = 1; 1606 1.1 hans } 1607