1 1.50 thorpej /* $NetBSD: vga_raster.c,v 1.50 2021/08/07 16:19:12 thorpej Exp $ */ 2 1.1 junyoung 3 1.1 junyoung /* 4 1.1 junyoung * Copyright (c) 2001, 2002 Bang Jun-Young 5 1.14 jmmv * Copyright (c) 2004 Julio M. Merino Vidal 6 1.1 junyoung * All rights reserved. 7 1.1 junyoung * 8 1.1 junyoung * Redistribution and use in source and binary forms, with or without 9 1.1 junyoung * modification, are permitted provided that the following conditions 10 1.1 junyoung * are met: 11 1.1 junyoung * 1. Redistributions of source code must retain the above copyright 12 1.1 junyoung * notice, this list of conditions and the following disclaimer. 13 1.1 junyoung * 2. Redistributions in binary form must reproduce the above copyright 14 1.1 junyoung * notice, this list of conditions and the following disclaimer in the 15 1.1 junyoung * documentation and/or other materials provided with the distribution. 16 1.1 junyoung * 3. The name of the author may not be used to endorse or promote products 17 1.4 junyoung * derived from this software without specific prior written permission. 18 1.1 junyoung * 19 1.1 junyoung * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 1.1 junyoung * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 1.1 junyoung * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 1.1 junyoung * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 1.1 junyoung * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 1.1 junyoung * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 1.1 junyoung * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 1.1 junyoung * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 1.1 junyoung * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 1.1 junyoung * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 1.1 junyoung */ 30 1.6 tsutsui 31 1.1 junyoung /* 32 1.1 junyoung * Copyright (c) 1995, 1996 Carnegie-Mellon University. 33 1.1 junyoung * All rights reserved. 34 1.1 junyoung * 35 1.1 junyoung * Author: Chris G. Demetriou 36 1.16 perry * 37 1.1 junyoung * Permission to use, copy, modify and distribute this software and 38 1.1 junyoung * its documentation is hereby granted, provided that both the copyright 39 1.1 junyoung * notice and this permission notice appear in all copies of the 40 1.1 junyoung * software, derivative works or modified versions, and any portions 41 1.1 junyoung * thereof, and that both notices appear in supporting documentation. 42 1.16 perry * 43 1.16 perry * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 44 1.16 perry * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 45 1.1 junyoung * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 46 1.16 perry * 47 1.1 junyoung * Carnegie Mellon requests users of this software to return to 48 1.1 junyoung * 49 1.1 junyoung * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU 50 1.1 junyoung * School of Computer Science 51 1.1 junyoung * Carnegie Mellon University 52 1.1 junyoung * Pittsburgh PA 15213-3890 53 1.1 junyoung * 54 1.1 junyoung * any improvements or extensions that they make and grant Carnegie the 55 1.1 junyoung * rights to redistribute these changes. 56 1.1 junyoung */ 57 1.12 lukem 58 1.12 lukem #include <sys/cdefs.h> 59 1.50 thorpej __KERNEL_RCSID(0, "$NetBSD: vga_raster.c,v 1.50 2021/08/07 16:19:12 thorpej Exp $"); 60 1.14 jmmv 61 1.39 mlelstv #include "opt_vga.h" 62 1.14 jmmv #include "opt_wsmsgattrs.h" /* for WSDISPLAY_CUSTOM_OUTPUT */ 63 1.1 junyoung 64 1.1 junyoung #include <sys/param.h> 65 1.1 junyoung #include <sys/systm.h> 66 1.1 junyoung #include <sys/callout.h> 67 1.1 junyoung #include <sys/kernel.h> 68 1.1 junyoung #include <sys/device.h> 69 1.1 junyoung #include <sys/malloc.h> 70 1.1 junyoung #include <sys/queue.h> 71 1.30 ad #include <sys/bus.h> 72 1.1 junyoung 73 1.1 junyoung #include <dev/ic/mc6845reg.h> 74 1.1 junyoung #include <dev/ic/pcdisplayvar.h> 75 1.1 junyoung #include <dev/ic/vgareg.h> 76 1.1 junyoung #include <dev/ic/vgavar.h> 77 1.34 tnn #include <dev/videomode/videomode.h> 78 1.1 junyoung 79 1.1 junyoung #include <dev/wscons/wsdisplayvar.h> 80 1.1 junyoung #include <dev/wscons/wsconsio.h> 81 1.1 junyoung #include <dev/wsfont/wsfont.h> 82 1.1 junyoung 83 1.1 junyoung #include <dev/ic/pcdisplay.h> 84 1.1 junyoung 85 1.10 tsutsui int vga_no_builtinfont = 0; 86 1.10 tsutsui 87 1.1 junyoung u_int8_t builtinfont_data[256 * 16]; 88 1.1 junyoung 89 1.1 junyoung struct wsdisplay_font builtinfont = { 90 1.1 junyoung "builtin", /* typeface name */ 91 1.1 junyoung 0, /* firstchar */ 92 1.1 junyoung 256, /* numchars */ 93 1.1 junyoung WSDISPLAY_FONTENC_IBM, /* encoding */ 94 1.1 junyoung 8, /* width */ 95 1.1 junyoung 16, /* height */ 96 1.1 junyoung 1, /* stride */ 97 1.1 junyoung WSDISPLAY_FONTORDER_L2R, /* bit order */ 98 1.1 junyoung WSDISPLAY_FONTORDER_L2R, /* byte order */ 99 1.1 junyoung builtinfont_data /* data */ 100 1.1 junyoung }; 101 1.1 junyoung 102 1.1 junyoung struct vga_scrmem { 103 1.1 junyoung u_int16_t ch; 104 1.1 junyoung u_int8_t attr; 105 1.1 junyoung u_int8_t second; /* XXXBJY should be u_int8_t len; */ 106 1.1 junyoung u_int8_t enc; 107 1.1 junyoung }; 108 1.1 junyoung 109 1.3 junyoung #ifdef VGA_CONSOLE_SCREENTYPE 110 1.3 junyoung #define VGA_SCRMEM_SIZE (80 * 30) 111 1.3 junyoung #else 112 1.3 junyoung #define VGA_SCRMEM_SIZE (80 * 25) 113 1.3 junyoung #endif 114 1.3 junyoung 115 1.3 junyoung struct vga_scrmem boot_scrmem[VGA_SCRMEM_SIZE]; 116 1.1 junyoung 117 1.1 junyoung struct vga_raster_font { 118 1.1 junyoung LIST_ENTRY(vga_raster_font) next; 119 1.1 junyoung struct wsdisplay_font *font; 120 1.1 junyoung }; 121 1.1 junyoung 122 1.1 junyoung struct vgascreen { 123 1.1 junyoung LIST_ENTRY(vgascreen) next; 124 1.1 junyoung struct vga_config *cfg; 125 1.1 junyoung struct vga_handle *hdl; 126 1.1 junyoung const struct wsscreen_descr *type; 127 1.1 junyoung 128 1.1 junyoung int active; 129 1.1 junyoung struct vga_scrmem *mem; 130 1.1 junyoung int encoding; 131 1.6 tsutsui 132 1.1 junyoung int dispoffset; 133 1.1 junyoung int mindispoffset; 134 1.1 junyoung int maxdispoffset; 135 1.1 junyoung 136 1.1 junyoung int cursoron; /* Is cursor displayed? */ 137 1.1 junyoung int cursorcol; /* Current cursor column */ 138 1.1 junyoung int cursorrow; /* Current cursor row */ 139 1.1 junyoung struct vga_scrmem cursortmp; 140 1.1 junyoung int cursorstride; 141 1.1 junyoung 142 1.1 junyoung LIST_HEAD(, vga_raster_font) fontset; 143 1.1 junyoung }; 144 1.1 junyoung 145 1.1 junyoung struct vga_moderegs { 146 1.1 junyoung u_int8_t miscout; /* Misc. output */ 147 1.7 tsutsui u_int8_t crtc[MC6845_NREGS]; /* CRTC controller */ 148 1.1 junyoung u_int8_t atc[VGA_ATC_NREGS]; /* Attribute controller */ 149 1.1 junyoung u_int8_t ts[VGA_TS_NREGS]; /* Time sequencer */ 150 1.1 junyoung u_int8_t gdc[VGA_GDC_NREGS]; /* Graphics display controller */ 151 1.1 junyoung }; 152 1.1 junyoung 153 1.1 junyoung static int vgaconsole, vga_console_type, vga_console_attached; 154 1.1 junyoung static struct vgascreen vga_console_screen; 155 1.1 junyoung static struct vga_config vga_console_vc; 156 1.1 junyoung static struct vga_raster_font vga_console_fontset_ascii; 157 1.1 junyoung static struct videomode vga_console_modes[2] = { 158 1.1 junyoung /* 640x400 for 80x25, 80x40 and 80x50 modes */ 159 1.1 junyoung { 160 1.23 christos 25175, 640, 664, 760, 800, 400, 409, 411, 450, 0, NULL, 161 1.1 junyoung }, 162 1.1 junyoung /* 640x480 for 80x30 mode */ 163 1.1 junyoung { 164 1.23 christos 25175, 640, 664, 760, 800, 480, 491, 493, 525, 0, NULL, 165 1.6 tsutsui } 166 1.1 junyoung }; 167 1.1 junyoung 168 1.1 junyoung static void vga_raster_init(struct vga_config *, bus_space_tag_t, 169 1.1 junyoung bus_space_tag_t); 170 1.1 junyoung static void vga_raster_init_screen(struct vga_config *, struct vgascreen *, 171 1.1 junyoung const struct wsscreen_descr *, int, long *); 172 1.1 junyoung static void vga_raster_setup_font(struct vga_config *, struct vgascreen *); 173 1.1 junyoung static void vga_setup_regs(struct videomode *, struct vga_moderegs *); 174 1.1 junyoung static void vga_set_mode(struct vga_handle *, struct vga_moderegs *); 175 1.6 tsutsui static void vga_restore_screen(struct vgascreen *, 176 1.1 junyoung const struct wsscreen_descr *, struct vga_scrmem *); 177 1.1 junyoung static void vga_raster_cursor_init(struct vgascreen *, int); 178 1.1 junyoung static void _vga_raster_putchar(void *, int, int, u_int, long, 179 1.1 junyoung struct vga_raster_font *); 180 1.1 junyoung 181 1.1 junyoung static void vga_raster_cursor(void *, int, int, int); 182 1.1 junyoung static int vga_raster_mapchar(void *, int, u_int *); 183 1.1 junyoung static void vga_raster_putchar(void *, int, int, u_int, long); 184 1.1 junyoung static void vga_raster_copycols(void *, int, int, int, int); 185 1.1 junyoung static void vga_raster_erasecols(void *, int, int, int, long); 186 1.1 junyoung static void vga_raster_copyrows(void *, int, int, int); 187 1.1 junyoung static void vga_raster_eraserows(void *, int, int, long); 188 1.1 junyoung static int vga_raster_allocattr(void *, int, int, int, long *); 189 1.14 jmmv #ifdef WSDISPLAY_CUSTOM_OUTPUT 190 1.14 jmmv static void vga_raster_replaceattr(void *, long, long); 191 1.14 jmmv #endif /* WSDISPLAY_CUSTOM_OUTPUT */ 192 1.1 junyoung 193 1.1 junyoung const struct wsdisplay_emulops vga_raster_emulops = { 194 1.1 junyoung vga_raster_cursor, 195 1.1 junyoung vga_raster_mapchar, 196 1.1 junyoung vga_raster_putchar, 197 1.1 junyoung vga_raster_copycols, 198 1.1 junyoung vga_raster_erasecols, 199 1.1 junyoung vga_raster_copyrows, 200 1.1 junyoung vga_raster_eraserows, 201 1.1 junyoung vga_raster_allocattr, 202 1.14 jmmv #ifdef WSDISPLAY_CUSTOM_OUTPUT 203 1.14 jmmv vga_raster_replaceattr, 204 1.14 jmmv #else /* WSDISPLAY_CUSTOM_OUTPUT */ 205 1.14 jmmv NULL, 206 1.14 jmmv #endif /* WSDISPLAY_CUSTOM_OUTPUT */ 207 1.1 junyoung }; 208 1.1 junyoung 209 1.1 junyoung /* 210 1.1 junyoung * translate WS(=ANSI) color codes to standard pc ones 211 1.1 junyoung */ 212 1.1 junyoung static const unsigned char fgansitopc[] = { 213 1.1 junyoung #ifdef __alpha__ 214 1.1 junyoung /* 215 1.1 junyoung * XXX DEC HAS SWITCHED THE CODES FOR BLUE AND RED!!! 216 1.1 junyoung * XXX We should probably not bother with this 217 1.1 junyoung * XXX (reinitialize the palette registers). 218 1.1 junyoung */ 219 1.1 junyoung FG_BLACK, FG_BLUE, FG_GREEN, FG_CYAN, FG_RED, 220 1.1 junyoung FG_MAGENTA, FG_BROWN, FG_LIGHTGREY 221 1.1 junyoung #else 222 1.1 junyoung FG_BLACK, FG_RED, FG_GREEN, FG_BROWN, FG_BLUE, 223 1.1 junyoung FG_MAGENTA, FG_CYAN, FG_LIGHTGREY 224 1.1 junyoung #endif 225 1.1 junyoung }, bgansitopc[] = { 226 1.1 junyoung #ifdef __alpha__ 227 1.1 junyoung BG_BLACK, BG_BLUE, BG_GREEN, BG_CYAN, BG_RED, 228 1.1 junyoung BG_MAGENTA, BG_BROWN, BG_LIGHTGREY 229 1.1 junyoung #else 230 1.1 junyoung BG_BLACK, BG_RED, BG_GREEN, BG_BROWN, BG_BLUE, 231 1.1 junyoung BG_MAGENTA, BG_CYAN, BG_LIGHTGREY 232 1.1 junyoung #endif 233 1.1 junyoung }; 234 1.1 junyoung 235 1.1 junyoung const struct wsscreen_descr vga_25lscreen = { 236 1.1 junyoung "80x25", 80, 25, 237 1.1 junyoung &vga_raster_emulops, 238 1.1 junyoung 8, 16, 239 1.1 junyoung WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK, 240 1.1 junyoung &vga_console_modes[0] 241 1.1 junyoung }, vga_25lscreen_mono = { 242 1.1 junyoung "80x25", 80, 25, 243 1.1 junyoung &vga_raster_emulops, 244 1.1 junyoung 8, 16, 245 1.1 junyoung WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE, 246 1.1 junyoung &vga_console_modes[0] 247 1.1 junyoung }, vga_30lscreen = { 248 1.1 junyoung "80x30", 80, 30, 249 1.1 junyoung &vga_raster_emulops, 250 1.1 junyoung 8, 16, 251 1.1 junyoung WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK, 252 1.1 junyoung &vga_console_modes[1] 253 1.1 junyoung }, vga_30lscreen_mono = { 254 1.1 junyoung "80x30", 80, 30, 255 1.1 junyoung &vga_raster_emulops, 256 1.1 junyoung 8, 16, 257 1.1 junyoung WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE, 258 1.1 junyoung &vga_console_modes[1] 259 1.1 junyoung }, vga_40lscreen = { 260 1.1 junyoung "80x40", 80, 40, 261 1.1 junyoung &vga_raster_emulops, 262 1.1 junyoung 8, 10, 263 1.1 junyoung WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK, 264 1.1 junyoung &vga_console_modes[0] 265 1.1 junyoung }, vga_40lscreen_mono = { 266 1.1 junyoung "80x40", 80, 40, 267 1.1 junyoung &vga_raster_emulops, 268 1.1 junyoung 8, 10, 269 1.1 junyoung WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE, 270 1.1 junyoung &vga_console_modes[0] 271 1.1 junyoung }, vga_50lscreen = { 272 1.1 junyoung "80x50", 80, 50, 273 1.1 junyoung &vga_raster_emulops, 274 1.1 junyoung 8, 8, 275 1.1 junyoung WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK, 276 1.1 junyoung &vga_console_modes[0] 277 1.1 junyoung }, vga_50lscreen_mono = { 278 1.1 junyoung "80x50", 80, 50, 279 1.1 junyoung &vga_raster_emulops, 280 1.1 junyoung 8, 8, 281 1.1 junyoung WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE, 282 1.1 junyoung &vga_console_modes[0] 283 1.1 junyoung }; 284 1.1 junyoung 285 1.1 junyoung const struct wsscreen_descr *_vga_scrlist[] = { 286 1.1 junyoung &vga_25lscreen, 287 1.1 junyoung &vga_30lscreen, 288 1.1 junyoung &vga_40lscreen, 289 1.6 tsutsui &vga_50lscreen, 290 1.1 junyoung }, *_vga_scrlist_mono[] = { 291 1.1 junyoung &vga_25lscreen_mono, 292 1.1 junyoung &vga_30lscreen_mono, 293 1.1 junyoung &vga_40lscreen_mono, 294 1.6 tsutsui &vga_50lscreen_mono, 295 1.1 junyoung }; 296 1.1 junyoung 297 1.1 junyoung const struct wsscreen_list vga_screenlist = { 298 1.1 junyoung sizeof(_vga_scrlist) / sizeof(struct wsscreen_descr *), 299 1.1 junyoung _vga_scrlist 300 1.1 junyoung }, vga_screenlist_mono = { 301 1.1 junyoung sizeof(_vga_scrlist_mono) / sizeof(struct wsscreen_descr *), 302 1.1 junyoung _vga_scrlist_mono 303 1.1 junyoung }; 304 1.1 junyoung 305 1.26 christos static int vga_raster_ioctl(void *, void *, u_long, void *, int, 306 1.21 jmmv struct lwp *); 307 1.21 jmmv static paddr_t vga_raster_mmap(void *, void *, off_t, int); 308 1.1 junyoung static int vga_raster_alloc_screen(void *, const struct wsscreen_descr *, 309 1.1 junyoung void **, int *, int *, long *); 310 1.1 junyoung static void vga_raster_free_screen(void *, void *); 311 1.1 junyoung static int vga_raster_show_screen(void *, void *, int, 312 1.1 junyoung void (*)(void *, int, int), void *); 313 1.1 junyoung static int vga_raster_load_font(void *, void *, struct wsdisplay_font *); 314 1.1 junyoung 315 1.1 junyoung static void vga_switch_screen(struct vga_config *); 316 1.1 junyoung static void vga_raster_setscreentype(struct vga_config *, 317 1.1 junyoung const struct wsscreen_descr *); 318 1.1 junyoung 319 1.1 junyoung const struct wsdisplay_accessops vga_raster_accessops = { 320 1.1 junyoung vga_raster_ioctl, 321 1.1 junyoung vga_raster_mmap, 322 1.1 junyoung vga_raster_alloc_screen, 323 1.1 junyoung vga_raster_free_screen, 324 1.1 junyoung vga_raster_show_screen, 325 1.1 junyoung vga_raster_load_font, 326 1.23 christos NULL, /* pollc */ 327 1.23 christos NULL, /* scroll */ 328 1.1 junyoung }; 329 1.1 junyoung 330 1.1 junyoung int 331 1.1 junyoung vga_cnattach(bus_space_tag_t iot, bus_space_tag_t memt, int type, int check) 332 1.1 junyoung { 333 1.1 junyoung long defattr; 334 1.1 junyoung const struct wsscreen_descr *scr; 335 1.5 junyoung #ifdef VGA_CONSOLE_SCREENTYPE 336 1.22 rpaulo const char *typestr = NULL; 337 1.5 junyoung #endif 338 1.1 junyoung 339 1.1 junyoung if (check && !vga_common_probe(iot, memt)) 340 1.1 junyoung return (ENXIO); 341 1.1 junyoung 342 1.1 junyoung /* set up bus-independent VGA configuration */ 343 1.1 junyoung vga_raster_init(&vga_console_vc, iot, memt); 344 1.1 junyoung #ifdef VGA_CONSOLE_SCREENTYPE 345 1.1 junyoung scr = wsdisplay_screentype_pick(vga_console_vc.hdl.vh_mono ? 346 1.1 junyoung &vga_screenlist_mono : &vga_screenlist, VGA_CONSOLE_SCREENTYPE); 347 1.1 junyoung if (!scr) 348 1.3 junyoung /* Invalid screen type, continue with the default mode. */ 349 1.3 junyoung typestr = "80x25"; 350 1.3 junyoung else if (scr->nrows > 30) 351 1.3 junyoung /* Unsupported screen type, try 80x30. */ 352 1.3 junyoung typestr = "80x30"; 353 1.32 jmcneill if (typestr) 354 1.32 jmcneill scr = wsdisplay_screentype_pick(vga_console_vc.hdl.vh_mono ? 355 1.32 jmcneill &vga_screenlist_mono : &vga_screenlist, typestr); 356 1.3 junyoung if (scr != vga_console_vc.currenttype) 357 1.1 junyoung vga_console_vc.currenttype = scr; 358 1.1 junyoung #else 359 1.1 junyoung scr = vga_console_vc.currenttype; 360 1.1 junyoung #endif 361 1.6 tsutsui vga_raster_init_screen(&vga_console_vc, &vga_console_screen, scr, 1, 362 1.1 junyoung &defattr); 363 1.1 junyoung 364 1.1 junyoung vga_console_screen.active = 1; 365 1.1 junyoung vga_console_vc.active = &vga_console_screen; 366 1.1 junyoung 367 1.1 junyoung wsdisplay_cnattach(scr, &vga_console_screen, 368 1.1 junyoung vga_console_screen.cursorcol, vga_console_screen.cursorrow, 369 1.1 junyoung defattr); 370 1.1 junyoung 371 1.1 junyoung vgaconsole = 1; 372 1.1 junyoung vga_console_type = type; 373 1.1 junyoung return (0); 374 1.1 junyoung } 375 1.1 junyoung 376 1.36 mlelstv static void 377 1.1 junyoung vga_raster_init(struct vga_config *vc, bus_space_tag_t iot, 378 1.1 junyoung bus_space_tag_t memt) 379 1.1 junyoung { 380 1.1 junyoung struct vga_handle *vh = &vc->hdl; 381 1.1 junyoung u_int8_t mor; 382 1.1 junyoung struct vga_raster_font *vf; 383 1.1 junyoung 384 1.6 tsutsui vh->vh_iot = iot; 385 1.6 tsutsui vh->vh_memt = memt; 386 1.1 junyoung 387 1.6 tsutsui if (bus_space_map(vh->vh_iot, 0x3c0, 0x10, 0, &vh->vh_ioh_vga)) 388 1.6 tsutsui panic("vga_raster_init: couldn't map vga io"); 389 1.1 junyoung 390 1.1 junyoung /* read "misc output register" */ 391 1.7 tsutsui mor = bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_MISC_DATAR); 392 1.1 junyoung vh->vh_mono = !(mor & 1); 393 1.1 junyoung 394 1.1 junyoung if (bus_space_map(vh->vh_iot, (vh->vh_mono ? 0x3b0 : 0x3d0), 0x10, 0, 395 1.6 tsutsui &vh->vh_ioh_6845)) 396 1.6 tsutsui panic("vga_raster_init: couldn't map 6845 io"); 397 1.1 junyoung 398 1.46 ad if (bus_space_map(vh->vh_memt, 0xa0000, 0x20000, 399 1.48 ad BUS_SPACE_MAP_CACHEABLE, &vh->vh_allmemh)) 400 1.46 ad panic("vga_init: couldn't map memory"); 401 1.1 junyoung 402 1.6 tsutsui if (bus_space_subregion(vh->vh_memt, vh->vh_allmemh, 0, 0x10000, 403 1.6 tsutsui &vh->vh_memh)) 404 1.6 tsutsui panic("vga_raster_init: mem subrange failed"); 405 1.1 junyoung 406 1.1 junyoung vc->nscreens = 0; 407 1.1 junyoung LIST_INIT(&vc->screens); 408 1.1 junyoung vc->active = NULL; 409 1.1 junyoung vc->currenttype = vh->vh_mono ? &vga_25lscreen_mono : &vga_25lscreen; 410 1.28 ad callout_init(&vc->vc_switch_callout, 0); 411 1.1 junyoung 412 1.10 tsutsui wsfont_init(); 413 1.1 junyoung vc->nfonts = 1; 414 1.1 junyoung LIST_INIT(&vc->vc_fontlist); 415 1.1 junyoung vf = &vga_console_fontset_ascii; 416 1.10 tsutsui if (vga_no_builtinfont) { 417 1.10 tsutsui struct wsdisplay_font *wf; 418 1.10 tsutsui int cookie; 419 1.10 tsutsui 420 1.10 tsutsui /* prefer 8x16 pixel font */ 421 1.11 junyoung cookie = wsfont_find(NULL, 8, 16, 0, WSDISPLAY_FONTORDER_L2R, 422 1.35 macallan 0, WSFONT_FIND_BITMAP); 423 1.10 tsutsui if (cookie == -1) 424 1.10 tsutsui cookie = wsfont_find(NULL, 0, 0, 0, 425 1.35 macallan WSDISPLAY_FONTORDER_L2R, WSDISPLAY_FONTORDER_L2R, 426 1.35 macallan WSFONT_FIND_BITMAP); 427 1.10 tsutsui if (cookie == -1 || wsfont_lock(cookie, &wf)) 428 1.10 tsutsui panic("vga_raster_init: can't load console font"); 429 1.10 tsutsui vf->font = wf; 430 1.10 tsutsui } else { 431 1.10 tsutsui vga_load_builtinfont(vh, builtinfont_data, 0, 256); 432 1.10 tsutsui vf->font = &builtinfont; 433 1.10 tsutsui } 434 1.1 junyoung LIST_INSERT_HEAD(&vc->vc_fontlist, vf, next); 435 1.1 junyoung } 436 1.1 junyoung 437 1.36 mlelstv static void 438 1.1 junyoung vga_raster_init_screen(struct vga_config *vc, struct vgascreen *scr, 439 1.1 junyoung const struct wsscreen_descr *type, int existing, long *attrp) 440 1.1 junyoung { 441 1.1 junyoung int cpos; 442 1.47 riastrad int res __diagused; 443 1.1 junyoung struct vga_handle *vh; 444 1.6 tsutsui 445 1.1 junyoung scr->cfg = vc; 446 1.1 junyoung scr->hdl = &vc->hdl; 447 1.1 junyoung scr->type = type; 448 1.1 junyoung scr->mindispoffset = 0; 449 1.33 jmcneill scr->maxdispoffset = scr->dispoffset + 450 1.33 jmcneill type->nrows * type->ncols * type->fontheight; 451 1.1 junyoung vh = &vc->hdl; 452 1.1 junyoung 453 1.1 junyoung LIST_INIT(&scr->fontset); 454 1.1 junyoung vga_raster_setup_font(vc, scr); 455 1.1 junyoung 456 1.1 junyoung if (existing) { 457 1.3 junyoung int i; 458 1.3 junyoung 459 1.1 junyoung cpos = vga_6845_read(vh, cursorh) << 8; 460 1.1 junyoung cpos |= vga_6845_read(vh, cursorl); 461 1.1 junyoung 462 1.1 junyoung /* make sure we have a valid cursor position */ 463 1.1 junyoung if (cpos < 0 || cpos >= type->nrows * type->ncols) 464 1.1 junyoung cpos = 0; 465 1.1 junyoung 466 1.1 junyoung scr->dispoffset = vga_6845_read(vh, startadrh) << 9; 467 1.1 junyoung scr->dispoffset |= vga_6845_read(vh, startadrl) << 1; 468 1.1 junyoung 469 1.1 junyoung /* make sure we have a valid memory offset */ 470 1.1 junyoung if (scr->dispoffset < scr->mindispoffset || 471 1.1 junyoung scr->dispoffset > scr->maxdispoffset) 472 1.1 junyoung scr->dispoffset = scr->mindispoffset; 473 1.1 junyoung 474 1.1 junyoung scr->mem = boot_scrmem; 475 1.1 junyoung scr->active = 1; 476 1.6 tsutsui 477 1.3 junyoung /* Save the current screen to memory. XXXBJY assume 80x25 */ 478 1.3 junyoung for (i = 0; i < 80 * 25; i++) { 479 1.6 tsutsui scr->mem[i].ch = bus_space_read_1(vh->vh_memt, 480 1.3 junyoung vh->vh_allmemh, 0x18000 + i * 2); 481 1.6 tsutsui scr->mem[i].attr = bus_space_read_1(vh->vh_memt, 482 1.6 tsutsui vh->vh_allmemh, 0x18000 + i * 2 + 1); 483 1.10 tsutsui scr->mem[i].enc = scr->encoding; 484 1.3 junyoung } 485 1.3 junyoung 486 1.2 junyoung vga_raster_setscreentype(vc, type); 487 1.1 junyoung 488 1.6 tsutsui /* Clear the entire screen. */ 489 1.1 junyoung vga_gdc_write(vh, mode, 0x02); 490 1.6 tsutsui bus_space_set_region_4(vh->vh_memt, vh->vh_allmemh, 0, 0, 491 1.1 junyoung 0x4000); 492 1.1 junyoung 493 1.1 junyoung vga_restore_screen(scr, type, scr->mem); 494 1.1 junyoung } else { 495 1.1 junyoung cpos = 0; 496 1.1 junyoung scr->dispoffset = scr->mindispoffset; 497 1.1 junyoung scr->mem = NULL; 498 1.1 junyoung scr->active = 0; 499 1.1 junyoung } 500 1.1 junyoung 501 1.1 junyoung scr->cursorrow = cpos / type->ncols; 502 1.1 junyoung scr->cursorcol = cpos % type->ncols; 503 1.1 junyoung vga_raster_cursor_init(scr, existing); 504 1.1 junyoung 505 1.1 junyoung #ifdef __alpha__ 506 1.1 junyoung if (!vc->hdl.vh_mono) 507 1.1 junyoung /* 508 1.1 junyoung * DEC firmware uses a blue background. 509 1.1 junyoung */ 510 1.1 junyoung res = vga_raster_allocattr(scr, WSCOL_WHITE, WSCOL_BLUE, 511 1.1 junyoung WSATTR_WSCOLORS, attrp); 512 1.1 junyoung else 513 1.1 junyoung #endif 514 1.1 junyoung res = vga_raster_allocattr(scr, 0, 0, 0, attrp); 515 1.47 riastrad KASSERTMSG(res == 0, "attribute botch"); 516 1.1 junyoung 517 1.1 junyoung vc->nscreens++; 518 1.1 junyoung LIST_INSERT_HEAD(&vc->screens, scr, next); 519 1.1 junyoung } 520 1.1 junyoung 521 1.1 junyoung void 522 1.1 junyoung vga_common_attach(struct vga_softc *sc, bus_space_tag_t iot, 523 1.25 christos bus_space_tag_t memt, int type, int quirks, 524 1.24 christos const struct vga_funcs *vf) 525 1.1 junyoung { 526 1.1 junyoung int console; 527 1.1 junyoung struct vga_config *vc; 528 1.1 junyoung struct wsemuldisplaydev_attach_args aa; 529 1.1 junyoung 530 1.1 junyoung console = vga_is_console(iot, type); 531 1.1 junyoung 532 1.1 junyoung if (console) { 533 1.1 junyoung vc = &vga_console_vc; 534 1.1 junyoung vga_console_attached = 1; 535 1.1 junyoung } else { 536 1.6 tsutsui vc = malloc(sizeof(struct vga_config), M_DEVBUF, M_WAITOK); 537 1.1 junyoung vga_raster_init(vc, iot, memt); 538 1.1 junyoung } 539 1.1 junyoung 540 1.1 junyoung vc->vc_type = type; 541 1.1 junyoung vc->vc_funcs = vf; 542 1.1 junyoung 543 1.1 junyoung sc->sc_vc = vc; 544 1.1 junyoung vc->softc = sc; 545 1.1 junyoung 546 1.1 junyoung aa.console = console; 547 1.1 junyoung aa.scrdata = (vc->hdl.vh_mono ? &vga_screenlist_mono : &vga_screenlist); 548 1.1 junyoung aa.accessops = &vga_raster_accessops; 549 1.1 junyoung aa.accesscookie = vc; 550 1.1 junyoung 551 1.49 thorpej config_found(sc->sc_dev, &aa, wsemuldisplaydevprint, 552 1.50 thorpej CFARGS(.iattr = "wsemuldisplaydev")); 553 1.1 junyoung } 554 1.1 junyoung 555 1.1 junyoung int 556 1.27 dogcow vga_cndetach(void) 557 1.27 dogcow { 558 1.27 dogcow struct vga_config *vc; 559 1.27 dogcow struct vga_handle *vh; 560 1.27 dogcow 561 1.27 dogcow vc = &vga_console_vc; 562 1.27 dogcow vh = &vc->hdl; 563 1.27 dogcow 564 1.27 dogcow if (vgaconsole) { 565 1.41 mlelstv wsdisplay_cndetach(); 566 1.41 mlelstv 567 1.27 dogcow bus_space_unmap(vh->vh_iot, vh->vh_ioh_vga, 0x10); 568 1.27 dogcow bus_space_unmap(vh->vh_iot, vh->vh_ioh_6845, 0x10); 569 1.44 mlelstv bus_space_unmap(vh->vh_memt, vh->vh_allmemh, 0x20000); 570 1.27 dogcow 571 1.41 mlelstv vga_console_attached = 0; 572 1.41 mlelstv vgaconsole = 0; 573 1.41 mlelstv 574 1.27 dogcow return 1; 575 1.27 dogcow } 576 1.27 dogcow 577 1.27 dogcow return 0; 578 1.27 dogcow } 579 1.27 dogcow 580 1.27 dogcow int 581 1.1 junyoung vga_is_console(bus_space_tag_t iot, int type) 582 1.1 junyoung { 583 1.1 junyoung if (vgaconsole && 584 1.1 junyoung !vga_console_attached && 585 1.1 junyoung iot == vga_console_vc.hdl.vh_iot && 586 1.1 junyoung (vga_console_type == -1 || (type == vga_console_type))) 587 1.1 junyoung return (1); 588 1.1 junyoung return (0); 589 1.1 junyoung } 590 1.1 junyoung 591 1.1 junyoung static int 592 1.1 junyoung vga_get_video(struct vga_config *vc) 593 1.1 junyoung { 594 1.7 tsutsui 595 1.7 tsutsui return (vga_ts_read(&vc->hdl, mode) & VGA_TS_MODE_BLANK) == 0; 596 1.1 junyoung } 597 1.1 junyoung 598 1.1 junyoung static void 599 1.1 junyoung vga_set_video(struct vga_config *vc, int state) 600 1.1 junyoung { 601 1.1 junyoung int val; 602 1.1 junyoung 603 1.1 junyoung vga_ts_write(&vc->hdl, syncreset, 0x01); 604 1.1 junyoung if (state) { /* unblank screen */ 605 1.1 junyoung val = vga_ts_read(&vc->hdl, mode); 606 1.7 tsutsui vga_ts_write(&vc->hdl, mode, val & ~VGA_TS_MODE_BLANK); 607 1.1 junyoung #ifndef VGA_NO_VBLANK 608 1.1 junyoung val = vga_6845_read(&vc->hdl, mode); 609 1.1 junyoung vga_6845_write(&vc->hdl, mode, val | 0x80); 610 1.1 junyoung #endif 611 1.1 junyoung } else { /* blank screen */ 612 1.1 junyoung val = vga_ts_read(&vc->hdl, mode); 613 1.7 tsutsui vga_ts_write(&vc->hdl, mode, val | VGA_TS_MODE_BLANK); 614 1.1 junyoung #ifndef VGA_NO_VBLANK 615 1.1 junyoung val = vga_6845_read(&vc->hdl, mode); 616 1.1 junyoung vga_6845_write(&vc->hdl, mode, val & ~0x80); 617 1.1 junyoung #endif 618 1.1 junyoung } 619 1.1 junyoung vga_ts_write(&vc->hdl, syncreset, 0x03); 620 1.1 junyoung } 621 1.1 junyoung 622 1.1 junyoung int 623 1.26 christos vga_raster_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, 624 1.21 jmmv struct lwp *l) 625 1.1 junyoung { 626 1.1 junyoung struct vga_config *vc = v; 627 1.1 junyoung const struct vga_funcs *vf = vc->vc_funcs; 628 1.1 junyoung 629 1.1 junyoung switch (cmd) { 630 1.1 junyoung case WSDISPLAYIO_GTYPE: 631 1.1 junyoung *(int *)data = vc->vc_type; 632 1.1 junyoung return 0; 633 1.1 junyoung 634 1.37 christos case WSDISPLAYIO_GINFO: { 635 1.37 christos struct wsdisplay_fbinfo *fbi = data; 636 1.37 christos const struct wsscreen_descr *wd = vc->currenttype; 637 1.37 christos const struct videomode *vm = wd->modecookie; 638 1.37 christos fbi->width = vm->hdisplay; 639 1.37 christos fbi->height = vm->vdisplay; 640 1.37 christos fbi->depth = 24; /* xxx: ? */ 641 1.37 christos fbi->cmsize = 256; /* xxx: from palette */ 642 1.37 christos return 0; 643 1.37 christos } 644 1.1 junyoung 645 1.1 junyoung case WSDISPLAYIO_GVIDEO: 646 1.6 tsutsui *(int *)data = (vga_get_video(vc) ? 647 1.6 tsutsui WSDISPLAYIO_VIDEO_ON : WSDISPLAYIO_VIDEO_OFF); 648 1.1 junyoung return 0; 649 1.1 junyoung 650 1.1 junyoung case WSDISPLAYIO_SVIDEO: 651 1.1 junyoung vga_set_video(vc, *(int *)data == WSDISPLAYIO_VIDEO_ON); 652 1.1 junyoung return 0; 653 1.1 junyoung 654 1.1 junyoung case WSDISPLAYIO_GETCMAP: 655 1.1 junyoung case WSDISPLAYIO_PUTCMAP: 656 1.1 junyoung case WSDISPLAYIO_GCURPOS: 657 1.1 junyoung case WSDISPLAYIO_SCURPOS: 658 1.1 junyoung case WSDISPLAYIO_GCURMAX: 659 1.1 junyoung case WSDISPLAYIO_GCURSOR: 660 1.1 junyoung case WSDISPLAYIO_SCURSOR: 661 1.37 christos #ifdef DIAGNOSTIC 662 1.37 christos printf("%s: 0x%lx unsupported\n", __func__, cmd); 663 1.37 christos #endif 664 1.1 junyoung /* NONE of these operations are by the generic VGA driver. */ 665 1.1 junyoung return EPASSTHROUGH; 666 1.1 junyoung } 667 1.1 junyoung 668 1.37 christos if (vc->vc_funcs == NULL) { 669 1.37 christos #ifdef DIAGNOSTIC 670 1.37 christos printf("%s: no vc_funcs\n", __func__); 671 1.37 christos #endif 672 1.37 christos return EPASSTHROUGH; 673 1.37 christos } 674 1.1 junyoung 675 1.37 christos if (vf->vf_ioctl == NULL) { 676 1.37 christos #ifdef DIAGNOSTIC 677 1.37 christos printf("%s: no vf_ioctl\n", __func__); 678 1.37 christos #endif 679 1.37 christos return EPASSTHROUGH; 680 1.37 christos } 681 1.1 junyoung 682 1.20 christos return ((*vf->vf_ioctl)(v, cmd, data, flag, l)); 683 1.1 junyoung } 684 1.1 junyoung 685 1.1 junyoung static paddr_t 686 1.25 christos vga_raster_mmap(void *v, void *vs, off_t offset, int prot) 687 1.1 junyoung { 688 1.1 junyoung struct vga_config *vc = v; 689 1.1 junyoung const struct vga_funcs *vf = vc->vc_funcs; 690 1.1 junyoung 691 1.1 junyoung if (vc->vc_funcs == NULL) 692 1.1 junyoung return (-1); 693 1.1 junyoung 694 1.1 junyoung if (vf->vf_mmap == NULL) 695 1.1 junyoung return (-1); 696 1.1 junyoung 697 1.1 junyoung return ((*vf->vf_mmap)(v, offset, prot)); 698 1.1 junyoung } 699 1.1 junyoung 700 1.36 mlelstv static int 701 1.1 junyoung vga_raster_alloc_screen(void *v, const struct wsscreen_descr *type, 702 1.11 junyoung void **cookiep, int *curxp, int *curyp, long *defattrp) 703 1.1 junyoung { 704 1.1 junyoung struct vga_config *vc = v; 705 1.1 junyoung struct vgascreen *scr; 706 1.1 junyoung 707 1.1 junyoung if (vc->nscreens == 1) { 708 1.1 junyoung vc->screens.lh_first->mem = boot_scrmem; 709 1.1 junyoung } 710 1.1 junyoung 711 1.1 junyoung scr = malloc(sizeof(struct vgascreen), M_DEVBUF, M_WAITOK); 712 1.1 junyoung vga_raster_init_screen(vc, scr, type, vc->nscreens == 0, defattrp); 713 1.1 junyoung 714 1.1 junyoung if (vc->nscreens == 1) { 715 1.1 junyoung scr->active = 1; 716 1.1 junyoung vc->active = scr; 717 1.1 junyoung vc->currenttype = type; 718 1.1 junyoung } else { 719 1.6 tsutsui scr->mem = malloc(sizeof(struct vga_scrmem) * 720 1.1 junyoung type->ncols * type->nrows, M_DEVBUF, M_WAITOK); 721 1.1 junyoung vga_raster_eraserows(scr, 0, type->nrows, *defattrp); 722 1.1 junyoung } 723 1.1 junyoung 724 1.1 junyoung *cookiep = scr; 725 1.1 junyoung *curxp = scr->cursorcol; 726 1.1 junyoung *curyp = scr->cursorrow; 727 1.1 junyoung 728 1.1 junyoung return (0); 729 1.1 junyoung } 730 1.1 junyoung 731 1.36 mlelstv static void 732 1.25 christos vga_raster_free_screen(void *v, void *cookie) 733 1.1 junyoung { 734 1.1 junyoung struct vgascreen *vs = cookie; 735 1.1 junyoung struct vga_config *vc = vs->cfg; 736 1.1 junyoung 737 1.1 junyoung LIST_REMOVE(vs, next); 738 1.18 dbj vc->nscreens--; 739 1.1 junyoung if (vs != &vga_console_screen) 740 1.1 junyoung free(vs, M_DEVBUF); 741 1.1 junyoung else 742 1.1 junyoung panic("vga_raster_free_screen: console"); 743 1.1 junyoung 744 1.1 junyoung if (vc->active == vs) 745 1.1 junyoung vc->active = 0; 746 1.1 junyoung } 747 1.1 junyoung 748 1.36 mlelstv static int 749 1.25 christos vga_raster_show_screen(void *v, void *cookie, int waitok, 750 1.11 junyoung void (*cb)(void *, int, int), void *cbarg) 751 1.1 junyoung { 752 1.1 junyoung struct vgascreen *scr = cookie, *oldscr; 753 1.1 junyoung struct vga_config *vc = scr->cfg; 754 1.1 junyoung 755 1.1 junyoung oldscr = vc->active; /* can be NULL! */ 756 1.1 junyoung if (scr == oldscr) { 757 1.1 junyoung return (0); 758 1.1 junyoung } 759 1.1 junyoung 760 1.1 junyoung vc->wantedscreen = cookie; 761 1.1 junyoung vc->switchcb = cb; 762 1.1 junyoung vc->switchcbarg = cbarg; 763 1.1 junyoung if (cb) { 764 1.1 junyoung callout_reset(&vc->vc_switch_callout, 0, 765 1.1 junyoung (void(*)(void *))vga_switch_screen, vc); 766 1.1 junyoung return (EAGAIN); 767 1.1 junyoung } 768 1.1 junyoung 769 1.1 junyoung vga_switch_screen(vc); 770 1.1 junyoung return (0); 771 1.1 junyoung } 772 1.1 junyoung 773 1.36 mlelstv static void 774 1.1 junyoung vga_switch_screen(struct vga_config *vc) 775 1.1 junyoung { 776 1.1 junyoung struct vgascreen *scr, *oldscr; 777 1.1 junyoung struct vga_handle *vh = &vc->hdl; 778 1.1 junyoung const struct wsscreen_descr *type; 779 1.1 junyoung 780 1.1 junyoung scr = vc->wantedscreen; 781 1.1 junyoung if (!scr) { 782 1.1 junyoung printf("vga_switch_screen: disappeared\n"); 783 1.1 junyoung (*vc->switchcb)(vc->switchcbarg, EIO, 0); 784 1.1 junyoung return; 785 1.1 junyoung } 786 1.1 junyoung type = scr->type; 787 1.1 junyoung oldscr = vc->active; /* can be NULL! */ 788 1.1 junyoung #ifdef DIAGNOSTIC 789 1.1 junyoung if (oldscr) { 790 1.1 junyoung if (!oldscr->active) 791 1.1 junyoung panic("vga_raster_show_screen: not active"); 792 1.1 junyoung if (oldscr->type != vc->currenttype) 793 1.1 junyoung panic("vga_raster_show_screen: bad type"); 794 1.1 junyoung } 795 1.1 junyoung #endif 796 1.1 junyoung if (scr == oldscr) { 797 1.1 junyoung return; 798 1.1 junyoung } 799 1.1 junyoung #ifdef DIAGNOSTIC 800 1.1 junyoung if (scr->active) 801 1.1 junyoung panic("vga_raster_show_screen: active"); 802 1.1 junyoung #endif 803 1.1 junyoung 804 1.1 junyoung if (oldscr) 805 1.1 junyoung oldscr->active = 0; 806 1.1 junyoung 807 1.1 junyoung if (vc->currenttype != type) { 808 1.1 junyoung vga_raster_setscreentype(vc, type); 809 1.1 junyoung vc->currenttype = type; 810 1.1 junyoung } 811 1.1 junyoung 812 1.1 junyoung scr->dispoffset = scr->mindispoffset; 813 1.1 junyoung 814 1.1 junyoung if (!oldscr || (scr->dispoffset != oldscr->dispoffset)) { 815 1.1 junyoung vga_6845_write(vh, startadrh, scr->dispoffset >> 8); 816 1.1 junyoung vga_6845_write(vh, startadrl, scr->dispoffset); 817 1.1 junyoung } 818 1.1 junyoung 819 1.6 tsutsui /* Clear the entire screen. */ 820 1.1 junyoung vga_gdc_write(vh, mode, 0x02); 821 1.1 junyoung bus_space_set_region_4(vh->vh_memt, vh->vh_allmemh, 0, 0, 0x2000); 822 1.1 junyoung 823 1.1 junyoung scr->active = 1; 824 1.1 junyoung vga_restore_screen(scr, type, scr->mem); 825 1.1 junyoung 826 1.1 junyoung vc->active = scr; 827 1.1 junyoung 828 1.1 junyoung vga_raster_cursor(scr, scr->cursoron, scr->cursorrow, scr->cursorcol); 829 1.1 junyoung 830 1.1 junyoung vc->wantedscreen = 0; 831 1.1 junyoung if (vc->switchcb) 832 1.1 junyoung (*vc->switchcb)(vc->switchcbarg, 0, 0); 833 1.1 junyoung } 834 1.1 junyoung 835 1.1 junyoung static int 836 1.25 christos vga_raster_load_font(void *v, void *id, 837 1.25 christos struct wsdisplay_font *data) 838 1.1 junyoung { 839 1.1 junyoung /* XXX */ 840 1.11 junyoung printf("vga_raster_load_font: called\n"); 841 1.1 junyoung 842 1.1 junyoung return (0); 843 1.1 junyoung } 844 1.1 junyoung 845 1.36 mlelstv static void 846 1.1 junyoung vga_raster_setup_font(struct vga_config *vc, struct vgascreen *scr) 847 1.1 junyoung { 848 1.1 junyoung struct vga_raster_font *vf; 849 1.1 junyoung struct wsdisplay_font *wf; 850 1.1 junyoung int cookie; 851 1.1 junyoung 852 1.1 junyoung LIST_FOREACH(vf, &vc->vc_fontlist, next) { 853 1.35 macallan if (wsfont_matches(vf->font, 0, 0, scr->type->fontheight, 0, 854 1.35 macallan WSFONT_FIND_BITMAP)) { 855 1.10 tsutsui scr->encoding = vf->font->encoding; 856 1.1 junyoung LIST_INSERT_HEAD(&scr->fontset, vf, next); 857 1.1 junyoung return; 858 1.1 junyoung } 859 1.1 junyoung } 860 1.6 tsutsui 861 1.6 tsutsui cookie = wsfont_find(NULL, 0, scr->type->fontheight, 0, 862 1.35 macallan WSDISPLAY_FONTORDER_L2R, 0, WSFONT_FIND_BITMAP); 863 1.1 junyoung if (cookie == -1) 864 1.1 junyoung return; 865 1.1 junyoung 866 1.1 junyoung if (wsfont_lock(cookie, &wf)) 867 1.1 junyoung return; 868 1.1 junyoung 869 1.45 chs vf = malloc(sizeof(struct vga_raster_font), M_DEVBUF, M_WAITOK); 870 1.1 junyoung vf->font = wf; 871 1.10 tsutsui scr->encoding = vf->font->encoding; 872 1.1 junyoung LIST_INSERT_HEAD(&scr->fontset, vf, next); 873 1.1 junyoung } 874 1.1 junyoung 875 1.36 mlelstv static void 876 1.1 junyoung vga_setup_regs(struct videomode *mode, struct vga_moderegs *regs) 877 1.1 junyoung { 878 1.1 junyoung int i; 879 1.1 junyoung int depth = 4; /* XXXBJY hardcoded for now */ 880 1.8 tsutsui const u_int8_t palette[] = { 881 1.1 junyoung 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 882 1.1 junyoung 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f 883 1.1 junyoung }; 884 1.6 tsutsui 885 1.1 junyoung /* 886 1.1 junyoung * Compute hsync and vsync polarity. 887 1.1 junyoung */ 888 1.1 junyoung if ((mode->flags & (VID_PHSYNC | VID_NHSYNC)) 889 1.1 junyoung && (mode->flags & (VID_PVSYNC | VID_NVSYNC))) { 890 1.1 junyoung regs->miscout = 0x23; 891 1.1 junyoung if (mode->flags & VID_NHSYNC) 892 1.1 junyoung regs->miscout |= 0x40; 893 1.1 junyoung if (mode->flags & VID_NVSYNC) 894 1.1 junyoung regs->miscout |= 0x80; 895 1.1 junyoung } else { 896 1.1 junyoung if (mode->flags & VID_DBLSCAN) 897 1.1 junyoung mode->vdisplay *= 2; 898 1.1 junyoung if (mode->vdisplay < 400) 899 1.1 junyoung regs->miscout = 0xa3; 900 1.9 tsutsui else if (mode->vdisplay < 480) 901 1.1 junyoung regs->miscout = 0x63; 902 1.9 tsutsui else if (mode->vdisplay < 768) 903 1.1 junyoung regs->miscout = 0xe3; 904 1.1 junyoung else 905 1.1 junyoung regs->miscout = 0x23; 906 1.1 junyoung } 907 1.6 tsutsui 908 1.1 junyoung /* 909 1.1 junyoung * Time sequencer 910 1.1 junyoung */ 911 1.1 junyoung if (depth == 4) 912 1.1 junyoung regs->ts[0] = 0x02; 913 1.1 junyoung else 914 1.1 junyoung regs->ts[0] = 0x00; 915 1.1 junyoung if (mode->flags & VID_CLKDIV2) 916 1.1 junyoung regs->ts[1] = 0x09; 917 1.1 junyoung else 918 1.1 junyoung regs->ts[1] = 0x01; 919 1.1 junyoung regs->ts[2] = 0x0f; 920 1.1 junyoung regs->ts[3] = 0x00; 921 1.1 junyoung if (depth < 8) 922 1.1 junyoung regs->ts[4] = 0x06; 923 1.1 junyoung else 924 1.1 junyoung regs->ts[4] = 0x0e; 925 1.6 tsutsui 926 1.1 junyoung /* 927 1.1 junyoung * CRTC controller 928 1.1 junyoung */ 929 1.1 junyoung regs->crtc[0] = (mode->htotal >> 3) - 5; 930 1.1 junyoung regs->crtc[1] = (mode->hdisplay >> 3) - 1; 931 1.1 junyoung regs->crtc[2] = (mode->hsync_start >> 3) - 1; 932 1.1 junyoung regs->crtc[3] = (((mode->hsync_end >> 3) - 1) & 0x1f) | 0x80; 933 1.1 junyoung regs->crtc[4] = mode->hsync_start >> 3; 934 1.1 junyoung regs->crtc[5] = ((((mode->hsync_end >> 3) - 1) & 0x20) << 2) 935 1.6 tsutsui | (((mode->hsync_end >> 3)) & 0x1f); 936 1.1 junyoung regs->crtc[6] = (mode->vtotal - 2) & 0xff; 937 1.1 junyoung regs->crtc[7] = (((mode->vtotal - 2) & 0x100) >> 8) 938 1.1 junyoung | (((mode->vdisplay - 1) & 0x100) >> 7) 939 1.1 junyoung | ((mode->vsync_start & 0x100) >> 6) 940 1.1 junyoung | (((mode->vsync_start - 1) & 0x100) >> 5) 941 1.1 junyoung | 0x10 942 1.1 junyoung | (((mode->vtotal - 2) & 0x200) >> 4) 943 1.1 junyoung | (((mode->vdisplay - 1) & 0x200) >> 3) 944 1.1 junyoung | ((mode->vsync_start & 0x200) >> 2); 945 1.1 junyoung regs->crtc[8] = 0x00; 946 1.1 junyoung regs->crtc[9] = (((mode->vsync_start - 1) & 0x200) >> 4) | 0x40; 947 1.1 junyoung if (mode->flags & VID_DBLSCAN) 948 1.1 junyoung regs->crtc[9] |= 0x80; 949 1.1 junyoung regs->crtc[10] = 0x00; 950 1.1 junyoung regs->crtc[11] = 0x00; 951 1.1 junyoung regs->crtc[12] = 0x00; 952 1.1 junyoung regs->crtc[13] = 0x00; 953 1.1 junyoung regs->crtc[14] = 0x00; 954 1.1 junyoung regs->crtc[15] = 0x00; 955 1.1 junyoung regs->crtc[16] = mode->vsync_start & 0xff; 956 1.1 junyoung regs->crtc[17] = (mode->vsync_end & 0x0f) | 0x20; 957 1.1 junyoung regs->crtc[18] = (mode->vdisplay - 1) & 0xff; 958 1.1 junyoung regs->crtc[19] = mode->hdisplay >> 4; /* XXXBJY */ 959 1.1 junyoung regs->crtc[20] = 0x00; 960 1.1 junyoung regs->crtc[21] = (mode->vsync_start - 1) & 0xff; 961 1.1 junyoung regs->crtc[22] = (mode->vsync_end - 1) & 0xff; 962 1.1 junyoung if (depth < 8) 963 1.1 junyoung regs->crtc[23] = 0xe3; 964 1.1 junyoung else 965 1.1 junyoung regs->crtc[23] = 0xc3; 966 1.1 junyoung regs->crtc[24] = 0xff; 967 1.6 tsutsui 968 1.1 junyoung /* 969 1.1 junyoung * Graphics display controller 970 1.1 junyoung */ 971 1.1 junyoung regs->gdc[0] = 0x00; 972 1.1 junyoung regs->gdc[1] = 0x00; 973 1.1 junyoung regs->gdc[2] = 0x00; 974 1.1 junyoung regs->gdc[3] = 0x00; 975 1.1 junyoung regs->gdc[4] = 0x00; 976 1.1 junyoung if (depth == 4) 977 1.1 junyoung regs->gdc[5] = 0x02; 978 1.1 junyoung else 979 1.1 junyoung regs->gdc[5] = 0x40; 980 1.1 junyoung regs->gdc[6] = 0x01; 981 1.1 junyoung regs->gdc[7] = 0x0f; 982 1.1 junyoung regs->gdc[8] = 0xff; 983 1.1 junyoung 984 1.1 junyoung /* 985 1.1 junyoung * Attribute controller 986 1.1 junyoung */ 987 1.1 junyoung /* Set palette registers. */ 988 1.1 junyoung for (i = 0; i < 16; i++) 989 1.1 junyoung regs->atc[i] = palette[i]; 990 1.1 junyoung if (depth == 4) 991 1.1 junyoung regs->atc[16] = 0x01; /* XXXBJY was 0x81 in XFree86 */ 992 1.1 junyoung else 993 1.1 junyoung regs->atc[16] = 0x41; 994 1.1 junyoung regs->atc[17] = 0x00; /* XXXBJY just a guess */ 995 1.1 junyoung regs->atc[18] = 0x0f; 996 1.1 junyoung regs->atc[19] = 0x00; 997 1.1 junyoung regs->atc[20] = 0x00; 998 1.1 junyoung } 999 1.1 junyoung 1000 1.36 mlelstv static void 1001 1.1 junyoung vga_set_mode(struct vga_handle *vh, struct vga_moderegs *regs) 1002 1.1 junyoung { 1003 1.1 junyoung int i; 1004 1.1 junyoung 1005 1.1 junyoung /* Disable display. */ 1006 1.7 tsutsui vga_ts_write(vh, mode, vga_ts_read(vh, mode) | VGA_TS_MODE_BLANK); 1007 1.6 tsutsui 1008 1.1 junyoung /* Write misc output register. */ 1009 1.1 junyoung bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_MISC_DATAW, 1010 1.1 junyoung regs->miscout); 1011 1.1 junyoung 1012 1.6 tsutsui /* Set synchronous reset. */ 1013 1.1 junyoung vga_ts_write(vh, syncreset, 0x01); 1014 1.7 tsutsui vga_ts_write(vh, mode, regs->ts[1] | VGA_TS_MODE_BLANK); 1015 1.1 junyoung for (i = 2; i < VGA_TS_NREGS; i++) 1016 1.1 junyoung _vga_ts_write(vh, i, regs->ts[i]); 1017 1.1 junyoung /* Clear synchronous reset. */ 1018 1.1 junyoung vga_ts_write(vh, syncreset, 0x03); 1019 1.1 junyoung 1020 1.1 junyoung /* Unprotect CRTC registers 0-7. */ 1021 1.7 tsutsui vga_6845_write(vh, vsynce, vga_6845_read(vh, vsynce) & ~0x80); 1022 1.1 junyoung /* Write CRTC registers. */ 1023 1.7 tsutsui for (i = 0; i < MC6845_NREGS; i++) 1024 1.7 tsutsui _vga_6845_write(vh, i, regs->crtc[i]); 1025 1.6 tsutsui 1026 1.6 tsutsui /* Write graphics display registers. */ 1027 1.1 junyoung for (i = 0; i < VGA_GDC_NREGS; i++) 1028 1.1 junyoung _vga_gdc_write(vh, i, regs->gdc[i]); 1029 1.6 tsutsui 1030 1.6 tsutsui /* Write attribute controller registers. */ 1031 1.6 tsutsui for (i = 0; i < VGA_ATC_NREGS; i++) 1032 1.1 junyoung _vga_attr_write(vh, i, regs->atc[i]); 1033 1.1 junyoung 1034 1.1 junyoung /* Enable display. */ 1035 1.7 tsutsui vga_ts_write(vh, mode, vga_ts_read(vh, mode) & ~VGA_TS_MODE_BLANK); 1036 1.1 junyoung } 1037 1.1 junyoung 1038 1.36 mlelstv static void 1039 1.1 junyoung vga_raster_cursor_init(struct vgascreen *scr, int existing) 1040 1.1 junyoung { 1041 1.1 junyoung int off; 1042 1.1 junyoung 1043 1.1 junyoung if (existing) { 1044 1.1 junyoung /* 1045 1.1 junyoung * This is the first screen. At this point, scr->active is 1046 1.1 junyoung * false, so we can't use vga_raster_cursor() to do this. 1047 1.1 junyoung */ 1048 1.6 tsutsui off = (scr->cursorrow * scr->type->ncols + scr->cursorcol) + 1049 1.1 junyoung scr->dispoffset / 8; 1050 1.1 junyoung 1051 1.1 junyoung scr->cursortmp = scr->mem[off]; 1052 1.6 tsutsui vga_raster_putchar(scr, scr->cursorrow, scr->cursorcol, 1053 1.1 junyoung scr->cursortmp.ch, scr->cursortmp.attr ^ 0x77); 1054 1.1 junyoung } else { 1055 1.1 junyoung scr->cursortmp.ch = 0; 1056 1.1 junyoung scr->cursortmp.attr = 0; 1057 1.1 junyoung scr->cursortmp.second = 0; 1058 1.10 tsutsui scr->cursortmp.enc = scr->encoding; 1059 1.1 junyoung } 1060 1.6 tsutsui 1061 1.1 junyoung scr->cursoron = 1; 1062 1.1 junyoung } 1063 1.1 junyoung 1064 1.36 mlelstv static void 1065 1.1 junyoung vga_raster_cursor(void *id, int on, int row, int col) 1066 1.1 junyoung { 1067 1.1 junyoung struct vgascreen *scr = id; 1068 1.1 junyoung int off, tmp; 1069 1.1 junyoung 1070 1.1 junyoung /* Remove old cursor image */ 1071 1.1 junyoung if (scr->cursoron) { 1072 1.1 junyoung off = scr->cursorrow * scr->type->ncols + scr->cursorcol; 1073 1.1 junyoung if (scr->active) { 1074 1.1 junyoung tmp = scr->encoding; 1075 1.6 tsutsui scr->encoding = scr->cursortmp.enc; 1076 1.1 junyoung if (scr->cursortmp.second) 1077 1.6 tsutsui vga_raster_putchar(id, scr->cursorrow, 1078 1.1 junyoung scr->cursorcol - 1, scr->cursortmp.ch, 1079 1.1 junyoung scr->cursortmp.attr); 1080 1.1 junyoung else 1081 1.6 tsutsui vga_raster_putchar(id, scr->cursorrow, 1082 1.1 junyoung scr->cursorcol, scr->cursortmp.ch, 1083 1.6 tsutsui scr->cursortmp.attr); 1084 1.1 junyoung scr->encoding = tmp; 1085 1.6 tsutsui } 1086 1.1 junyoung } 1087 1.6 tsutsui 1088 1.1 junyoung scr->cursorrow = row; 1089 1.1 junyoung scr->cursorcol = col; 1090 1.1 junyoung 1091 1.1 junyoung if ((scr->cursoron = on) == 0) 1092 1.1 junyoung return; 1093 1.1 junyoung 1094 1.1 junyoung off = scr->cursorrow * scr->type->ncols + scr->cursorcol; 1095 1.1 junyoung scr->cursortmp = scr->mem[off]; 1096 1.1 junyoung if (scr->active) { 1097 1.1 junyoung tmp = scr->encoding; 1098 1.1 junyoung scr->encoding = scr->cursortmp.enc; 1099 1.1 junyoung if (scr->cursortmp.second) 1100 1.6 tsutsui vga_raster_putchar(id, scr->cursorrow, 1101 1.1 junyoung scr->cursorcol - 1, scr->cursortmp.ch, 1102 1.1 junyoung scr->cursortmp.attr ^ 0x77); 1103 1.1 junyoung else 1104 1.6 tsutsui vga_raster_putchar(id, scr->cursorrow, 1105 1.1 junyoung scr->cursorcol, scr->cursortmp.ch, 1106 1.6 tsutsui scr->cursortmp.attr ^ 0x77); 1107 1.1 junyoung scr->encoding = tmp; 1108 1.1 junyoung } 1109 1.1 junyoung } 1110 1.1 junyoung 1111 1.1 junyoung static int 1112 1.1 junyoung vga_raster_mapchar(void *id, int uni, u_int *index) 1113 1.1 junyoung { 1114 1.1 junyoung struct vgascreen *scr = id; 1115 1.6 tsutsui 1116 1.1 junyoung if (scr->encoding == WSDISPLAY_FONTENC_IBM) 1117 1.1 junyoung return pcdisplay_mapchar(id, uni, index); 1118 1.1 junyoung else { 1119 1.1 junyoung *index = uni; 1120 1.1 junyoung return 5; 1121 1.6 tsutsui } 1122 1.1 junyoung } 1123 1.1 junyoung 1124 1.36 mlelstv static void 1125 1.1 junyoung vga_raster_putchar(void *id, int row, int col, u_int c, long attr) 1126 1.1 junyoung { 1127 1.1 junyoung struct vgascreen *scr = id; 1128 1.29 mjf size_t off; 1129 1.1 junyoung struct vga_raster_font *fs; 1130 1.1 junyoung u_int tmp_ch; 1131 1.6 tsutsui 1132 1.1 junyoung off = row * scr->type->ncols + col; 1133 1.6 tsutsui 1134 1.29 mjf if (__predict_false(off >= (scr->type->ncols * scr->type->nrows))) 1135 1.29 mjf return; 1136 1.29 mjf 1137 1.1 junyoung LIST_FOREACH(fs, &scr->fontset, next) { 1138 1.1 junyoung if ((scr->encoding == fs->font->encoding) && 1139 1.1 junyoung (c >= fs->font->firstchar) && 1140 1.1 junyoung (c < fs->font->firstchar + fs->font->numchars) && 1141 1.1 junyoung (scr->type->fontheight == fs->font->fontheight)) { 1142 1.1 junyoung if (scr->active) { 1143 1.1 junyoung tmp_ch = c - fs->font->firstchar; 1144 1.6 tsutsui _vga_raster_putchar(scr, row, col, tmp_ch, 1145 1.1 junyoung attr, fs); 1146 1.1 junyoung } 1147 1.1 junyoung 1148 1.1 junyoung scr->mem[off].ch = c; 1149 1.1 junyoung scr->mem[off].attr = attr; 1150 1.1 junyoung scr->mem[off].second = 0; 1151 1.1 junyoung scr->mem[off].enc = fs->font->encoding; 1152 1.6 tsutsui 1153 1.1 junyoung if (fs->font->stride == 2) { 1154 1.1 junyoung scr->mem[off + 1].ch = c; 1155 1.1 junyoung scr->mem[off + 1].attr = attr; 1156 1.1 junyoung scr->mem[off + 1].second = 1; 1157 1.1 junyoung scr->mem[off + 1].enc = fs->font->encoding; 1158 1.1 junyoung } 1159 1.1 junyoung 1160 1.6 tsutsui return; 1161 1.1 junyoung } 1162 1.1 junyoung } 1163 1.1 junyoung 1164 1.1 junyoung /* 1165 1.6 tsutsui * No match found. 1166 1.1 junyoung */ 1167 1.1 junyoung if (scr->active) 1168 1.6 tsutsui /* 1169 1.6 tsutsui * Put a single width space character no matter what the 1170 1.6 tsutsui * actual width of the character is. 1171 1.6 tsutsui */ 1172 1.7 tsutsui _vga_raster_putchar(scr, row, col, ' ', attr, 1173 1.1 junyoung &vga_console_fontset_ascii); 1174 1.1 junyoung scr->mem[off].ch = c; 1175 1.1 junyoung scr->mem[off].attr = attr; 1176 1.1 junyoung scr->mem[off].second = 0; 1177 1.10 tsutsui scr->mem[off].enc = scr->encoding; 1178 1.1 junyoung } 1179 1.1 junyoung 1180 1.1 junyoung static void 1181 1.1 junyoung _vga_raster_putchar(void *id, int row, int col, u_int c, long attr, 1182 1.11 junyoung struct vga_raster_font *fs) 1183 1.1 junyoung { 1184 1.1 junyoung struct vgascreen *scr = id; 1185 1.1 junyoung struct vga_handle *vh = scr->hdl; 1186 1.1 junyoung bus_space_tag_t memt = vh->vh_memt; 1187 1.1 junyoung bus_space_handle_t memh = vh->vh_memh; 1188 1.1 junyoung int i; 1189 1.1 junyoung int rasoff, rasoff2; 1190 1.1 junyoung int fheight = scr->type->fontheight; 1191 1.40 mlelstv volatile u_int8_t pattern; 1192 1.1 junyoung u_int8_t fgcolor, bgcolor; 1193 1.1 junyoung 1194 1.1 junyoung rasoff = scr->dispoffset + row * scr->type->ncols * fheight + col; 1195 1.1 junyoung rasoff2 = rasoff; 1196 1.1 junyoung 1197 1.1 junyoung #if 0 1198 1.1 junyoung bgcolor = bgansitopc[attr >> 4]; 1199 1.1 junyoung fgcolor = fgansitopc[attr & 0x0f]; 1200 1.1 junyoung #else 1201 1.1 junyoung bgcolor = ((attr >> 4) & 0x0f); 1202 1.6 tsutsui fgcolor = attr & 0x0f; 1203 1.1 junyoung #endif 1204 1.1 junyoung 1205 1.1 junyoung if (fs->font->stride == 1) { 1206 1.1 junyoung /* Paint background. */ 1207 1.1 junyoung vga_gdc_write(vh, mode, 0x02); 1208 1.1 junyoung for (i = 0; i < fheight; i++) { 1209 1.1 junyoung bus_space_write_1(memt, memh, rasoff, bgcolor); 1210 1.1 junyoung rasoff += scr->type->ncols; 1211 1.1 junyoung } 1212 1.1 junyoung 1213 1.1 junyoung /* Draw a single width character. */ 1214 1.1 junyoung vga_gdc_write(vh, mode, 0x03); 1215 1.1 junyoung vga_gdc_write(vh, setres, fgcolor); 1216 1.1 junyoung for (i = 0; i < fheight; i++) { 1217 1.1 junyoung pattern = ((u_int8_t *)fs->font->data)[c * fheight + i]; 1218 1.1 junyoung /* When pattern is 0, skip output for speed-up. */ 1219 1.1 junyoung if (pattern != 0) { 1220 1.40 mlelstv bus_space_read_1(memt, memh, rasoff2); 1221 1.1 junyoung bus_space_write_1(memt, memh, rasoff2, pattern); 1222 1.1 junyoung } 1223 1.1 junyoung rasoff2 += scr->type->ncols; 1224 1.1 junyoung } 1225 1.1 junyoung } else if (fs->font->stride == 2) { 1226 1.1 junyoung /* Paint background. */ 1227 1.1 junyoung vga_gdc_write(vh, mode, 0x02); 1228 1.1 junyoung for (i = 0; i < fheight; i++) { 1229 1.1 junyoung bus_space_write_1(memt, memh, rasoff, bgcolor); 1230 1.6 tsutsui bus_space_write_1(memt, memh, rasoff + 1, bgcolor); 1231 1.1 junyoung rasoff += scr->type->ncols; 1232 1.1 junyoung } 1233 1.1 junyoung 1234 1.1 junyoung /* Draw a double width character. */ 1235 1.1 junyoung vga_gdc_write(vh, mode, 0x03); 1236 1.1 junyoung vga_gdc_write(vh, setres, fgcolor); 1237 1.1 junyoung for (i = 0; i < fheight; i++) { 1238 1.1 junyoung pattern = ((u_int8_t *)fs->font->data) 1239 1.1 junyoung [(c * fheight + i) * 2]; 1240 1.1 junyoung if (pattern != 0) { 1241 1.40 mlelstv bus_space_read_1(memt, memh, rasoff2); 1242 1.1 junyoung bus_space_write_1(memt, memh, rasoff2, pattern); 1243 1.1 junyoung } 1244 1.1 junyoung pattern = ((u_int8_t *)fs->font->data) 1245 1.1 junyoung [(c * fheight + i) * 2 + 1]; 1246 1.1 junyoung if (pattern != 0) { 1247 1.1 junyoung rasoff2++; 1248 1.40 mlelstv bus_space_read_1(memt, memh, rasoff2); 1249 1.1 junyoung bus_space_write_1(memt, memh, rasoff2, pattern); 1250 1.1 junyoung rasoff2--; 1251 1.1 junyoung } 1252 1.1 junyoung rasoff2 += scr->type->ncols; 1253 1.1 junyoung } 1254 1.1 junyoung } 1255 1.1 junyoung } 1256 1.1 junyoung 1257 1.36 mlelstv static void 1258 1.1 junyoung vga_raster_copycols(void *id, int row, int srccol, int dstcol, int ncols) 1259 1.1 junyoung { 1260 1.1 junyoung struct vgascreen *scr = id; 1261 1.1 junyoung struct vga_handle *vh = scr->hdl; 1262 1.1 junyoung bus_space_tag_t memt = vh->vh_memt; 1263 1.1 junyoung bus_space_handle_t memh = vh->vh_memh; 1264 1.1 junyoung bus_size_t srcoff, dstoff; 1265 1.1 junyoung bus_size_t rassrcoff, rasdstoff; 1266 1.1 junyoung int i; 1267 1.1 junyoung int fheight = scr->type->fontheight; 1268 1.1 junyoung 1269 1.1 junyoung srcoff = row * scr->type->ncols + srccol; 1270 1.1 junyoung dstoff = row * scr->type->ncols + dstcol; 1271 1.1 junyoung rassrcoff = scr->dispoffset + row * scr->type->ncols * fheight + srccol; 1272 1.1 junyoung rasdstoff = scr->dispoffset + row * scr->type->ncols * fheight + dstcol; 1273 1.1 junyoung 1274 1.1 junyoung memcpy(&scr->mem[dstoff], &scr->mem[srcoff], 1275 1.1 junyoung ncols * sizeof(struct vga_scrmem)); 1276 1.1 junyoung 1277 1.1 junyoung vga_gdc_write(vh, mode, 0x01); 1278 1.1 junyoung if (scr->active) { 1279 1.1 junyoung for (i = 0; i < fheight; i++) { 1280 1.1 junyoung bus_space_copy_region_1(memt, memh, 1281 1.6 tsutsui rassrcoff + i * scr->type->ncols, memh, 1282 1.1 junyoung rasdstoff + i * scr->type->ncols, ncols); 1283 1.1 junyoung } 1284 1.1 junyoung } 1285 1.1 junyoung } 1286 1.1 junyoung 1287 1.36 mlelstv static void 1288 1.1 junyoung vga_raster_erasecols(void *id, int row, int startcol, int ncols, long fillattr) 1289 1.1 junyoung { 1290 1.1 junyoung struct vgascreen *scr = id; 1291 1.1 junyoung int i; 1292 1.1 junyoung 1293 1.1 junyoung if (scr->active == 0) 1294 1.6 tsutsui return; 1295 1.1 junyoung 1296 1.1 junyoung for (i = startcol; i < startcol + ncols; i++) 1297 1.1 junyoung vga_raster_putchar(id, row, i, ' ', fillattr); 1298 1.1 junyoung } 1299 1.1 junyoung 1300 1.36 mlelstv static void 1301 1.1 junyoung vga_raster_copyrows(void *id, int srcrow, int dstrow, int nrows) 1302 1.1 junyoung { 1303 1.1 junyoung struct vgascreen *scr = id; 1304 1.1 junyoung struct vga_handle *vh = scr->hdl; 1305 1.1 junyoung bus_space_tag_t memt = vh->vh_memt; 1306 1.1 junyoung bus_space_handle_t memh = vh->vh_memh; 1307 1.1 junyoung int ncols; 1308 1.1 junyoung bus_size_t srcoff, dstoff; 1309 1.1 junyoung bus_size_t rassrcoff, rasdstoff; 1310 1.1 junyoung int fheight; 1311 1.6 tsutsui 1312 1.1 junyoung ncols = scr->type->ncols; 1313 1.1 junyoung fheight = scr->type->fontheight; 1314 1.6 tsutsui 1315 1.1 junyoung srcoff = srcrow * ncols; 1316 1.1 junyoung dstoff = dstrow * ncols; 1317 1.1 junyoung rassrcoff = srcoff * fheight; 1318 1.1 junyoung rasdstoff = dstoff * fheight; 1319 1.1 junyoung 1320 1.1 junyoung if (scr->active) { 1321 1.1 junyoung vga_gdc_write(vh, mode, 0x01); 1322 1.1 junyoung if (dstrow == 0 && (srcrow + nrows == scr->type->nrows)) { 1323 1.1 junyoung int cursoron = scr->cursoron; 1324 1.1 junyoung 1325 1.1 junyoung if (cursoron) 1326 1.1 junyoung /* Disable cursor. */ 1327 1.1 junyoung vga_raster_cursor(scr, 0, 1328 1.1 junyoung scr->cursorrow, scr->cursorcol); 1329 1.1 junyoung 1330 1.1 junyoung /* scroll up whole screen */ 1331 1.1 junyoung if ((scr->dispoffset + srcrow * ncols * fheight) 1332 1.1 junyoung <= scr->maxdispoffset) 1333 1.1 junyoung scr->dispoffset += srcrow * ncols * fheight; 1334 1.1 junyoung else { 1335 1.6 tsutsui bus_space_copy_region_1(memt, memh, 1336 1.1 junyoung scr->dispoffset + rassrcoff, 1337 1.1 junyoung memh, scr->mindispoffset, 1338 1.1 junyoung nrows * ncols * fheight); 1339 1.1 junyoung scr->dispoffset = scr->mindispoffset; 1340 1.1 junyoung } 1341 1.1 junyoung vga_6845_write(vh, startadrh, scr->dispoffset >> 8); 1342 1.1 junyoung vga_6845_write(vh, startadrl, scr->dispoffset); 1343 1.6 tsutsui 1344 1.1 junyoung if (cursoron) 1345 1.1 junyoung /* Enable cursor. */ 1346 1.1 junyoung vga_raster_cursor(scr, 1, scr->cursorrow, 1347 1.1 junyoung scr->cursorcol); 1348 1.1 junyoung } else 1349 1.1 junyoung bus_space_copy_region_1(memt, memh, 1350 1.1 junyoung scr->dispoffset + rassrcoff, memh, 1351 1.1 junyoung scr->dispoffset + rasdstoff, 1352 1.1 junyoung nrows * ncols * fheight); 1353 1.6 tsutsui } 1354 1.1 junyoung memcpy(&scr->mem[dstoff], &scr->mem[srcoff], 1355 1.1 junyoung nrows * ncols * sizeof(struct vga_scrmem)); 1356 1.1 junyoung } 1357 1.1 junyoung 1358 1.36 mlelstv static void 1359 1.1 junyoung vga_raster_eraserows(void *id, int startrow, int nrows, long fillattr) 1360 1.1 junyoung { 1361 1.1 junyoung struct vgascreen *scr = id; 1362 1.1 junyoung struct vga_handle *vh = scr->hdl; 1363 1.1 junyoung bus_space_tag_t memt = vh->vh_memt; 1364 1.1 junyoung bus_space_handle_t memh = vh->vh_memh; 1365 1.1 junyoung bus_size_t off, count; 1366 1.1 junyoung bus_size_t rasoff, rascount; 1367 1.1 junyoung int i; 1368 1.1 junyoung 1369 1.6 tsutsui off = startrow * scr->type->ncols; 1370 1.1 junyoung count = nrows * scr->type->ncols; 1371 1.1 junyoung rasoff = off * scr->type->fontheight; 1372 1.1 junyoung rascount = count * scr->type->fontheight; 1373 1.1 junyoung 1374 1.1 junyoung if (scr->active) { 1375 1.13 jmmv u_int8_t bgcolor = (fillattr >> 4) & 0x0F; 1376 1.13 jmmv 1377 1.1 junyoung /* Paint background. */ 1378 1.1 junyoung vga_gdc_write(vh, mode, 0x02); 1379 1.13 jmmv if (scr->type->ncols % 4 == 0) { 1380 1.13 jmmv u_int32_t fill = bgcolor | (bgcolor << 8) | 1381 1.13 jmmv (bgcolor << 16) | (bgcolor << 24); 1382 1.1 junyoung /* We can speed up I/O */ 1383 1.1 junyoung for (i = rasoff; i < rasoff + rascount; i += 4) 1384 1.6 tsutsui bus_space_write_4(memt, memh, 1385 1.13 jmmv scr->dispoffset + i, fill); 1386 1.13 jmmv } else { 1387 1.13 jmmv u_int16_t fill = bgcolor | (bgcolor << 8); 1388 1.1 junyoung for (i = rasoff; i < rasoff + rascount; i += 2) 1389 1.6 tsutsui bus_space_write_2(memt, memh, 1390 1.13 jmmv scr->dispoffset + i, fill); 1391 1.13 jmmv } 1392 1.1 junyoung } 1393 1.1 junyoung for (i = 0; i < count; i++) { 1394 1.1 junyoung scr->mem[off + i].ch = ' '; 1395 1.1 junyoung scr->mem[off + i].attr = fillattr; 1396 1.1 junyoung scr->mem[off + i].second = 0; 1397 1.10 tsutsui scr->mem[off + i].enc = scr->encoding; 1398 1.1 junyoung } 1399 1.1 junyoung } 1400 1.1 junyoung 1401 1.1 junyoung static int 1402 1.1 junyoung vga_raster_allocattr(void *id, int fg, int bg, int flags, long *attrp) 1403 1.1 junyoung { 1404 1.1 junyoung struct vgascreen *scr = id; 1405 1.1 junyoung struct vga_config *vc = scr->cfg; 1406 1.1 junyoung 1407 1.29 mjf if (__predict_false((unsigned int)fg >= sizeof(fgansitopc) || 1408 1.29 mjf (unsigned int)bg >= sizeof(bgansitopc))) 1409 1.29 mjf return (EINVAL); 1410 1.29 mjf 1411 1.1 junyoung if (vc->hdl.vh_mono) { 1412 1.1 junyoung if (flags & WSATTR_WSCOLORS) 1413 1.1 junyoung return (EINVAL); 1414 1.1 junyoung if (flags & WSATTR_REVERSE) 1415 1.1 junyoung *attrp = 0x70; 1416 1.1 junyoung else 1417 1.1 junyoung *attrp = 0x07; 1418 1.1 junyoung if (flags & WSATTR_UNDERLINE) 1419 1.1 junyoung *attrp |= FG_UNDERLINE; 1420 1.1 junyoung if (flags & WSATTR_HILIT) 1421 1.1 junyoung *attrp |= FG_INTENSE; 1422 1.1 junyoung } else { 1423 1.1 junyoung if (flags & (WSATTR_UNDERLINE | WSATTR_REVERSE)) 1424 1.1 junyoung return (EINVAL); 1425 1.1 junyoung if (flags & WSATTR_WSCOLORS) 1426 1.1 junyoung *attrp = fgansitopc[fg] | bgansitopc[bg]; 1427 1.1 junyoung else 1428 1.1 junyoung *attrp = 7; 1429 1.1 junyoung if (flags & WSATTR_HILIT) 1430 1.1 junyoung *attrp += 8; 1431 1.1 junyoung } 1432 1.1 junyoung if (flags & WSATTR_BLINK) 1433 1.1 junyoung *attrp |= FG_BLINK; 1434 1.1 junyoung return (0); 1435 1.1 junyoung } 1436 1.1 junyoung 1437 1.36 mlelstv static void 1438 1.1 junyoung vga_restore_screen(struct vgascreen *scr, 1439 1.1 junyoung const struct wsscreen_descr *type, struct vga_scrmem *mem) 1440 1.1 junyoung { 1441 1.1 junyoung int i, j, off, tmp; 1442 1.1 junyoung 1443 1.6 tsutsui tmp = scr->encoding; 1444 1.1 junyoung for (i = 0; i < type->nrows; i++) { 1445 1.1 junyoung for (j = 0; j < type->ncols; j++) { 1446 1.1 junyoung off = i * type->ncols + j; 1447 1.1 junyoung if (mem[off].second != 1) { 1448 1.1 junyoung scr->encoding = mem[off].enc; 1449 1.1 junyoung vga_raster_putchar(scr, i, j, mem[off].ch, 1450 1.1 junyoung mem[off].attr); 1451 1.1 junyoung } 1452 1.1 junyoung } 1453 1.1 junyoung } 1454 1.1 junyoung scr->encoding = tmp; 1455 1.1 junyoung } 1456 1.1 junyoung 1457 1.36 mlelstv static void 1458 1.1 junyoung vga_raster_setscreentype(struct vga_config *vc, 1459 1.1 junyoung const struct wsscreen_descr *type) 1460 1.1 junyoung { 1461 1.2 junyoung struct vga_handle *vh = &vc->hdl; 1462 1.1 junyoung struct vga_moderegs moderegs; 1463 1.6 tsutsui 1464 1.2 junyoung vga_setup_regs((struct videomode *)type->modecookie, &moderegs); 1465 1.2 junyoung vga_set_mode(vh, &moderegs); 1466 1.1 junyoung } 1467 1.14 jmmv 1468 1.14 jmmv #ifdef WSDISPLAY_CUSTOM_OUTPUT 1469 1.36 mlelstv static void 1470 1.14 jmmv vga_raster_replaceattr(void *id, long oldattr, long newattr) 1471 1.14 jmmv { 1472 1.14 jmmv struct vgascreen *scr = id; 1473 1.14 jmmv const struct wsscreen_descr *type = scr->type; 1474 1.14 jmmv int off; 1475 1.14 jmmv 1476 1.14 jmmv for (off = 0; off < type->nrows * type->ncols; off++) { 1477 1.14 jmmv if (scr->mem[off].attr == oldattr) 1478 1.14 jmmv scr->mem[off].attr = newattr; 1479 1.14 jmmv } 1480 1.14 jmmv 1481 1.14 jmmv /* Repaint the whole screen, if needed */ 1482 1.14 jmmv if (scr->active) 1483 1.14 jmmv vga_restore_screen(scr, type, scr->mem); 1484 1.14 jmmv } 1485 1.14 jmmv #endif /* WSDISPLAY_CUSTOM_OUTPUT */ 1486 1.31 nonaka 1487 1.31 nonaka void 1488 1.31 nonaka vga_resume(struct vga_softc *sc) 1489 1.31 nonaka { 1490 1.31 nonaka #ifdef VGA_RESET_ON_RESUME 1491 1.31 nonaka vga_initregs(&sc->sc_vc->hdl); 1492 1.31 nonaka #endif 1493 1.31 nonaka } 1494