1*c7fb772bSthorpej /* $NetBSD: vga_raster.c,v 1.50 2021/08/07 16:19:12 thorpej Exp $ */
21ce9af54Sjunyoung
31ce9af54Sjunyoung /*
41ce9af54Sjunyoung * Copyright (c) 2001, 2002 Bang Jun-Young
59a001938Sjmmv * Copyright (c) 2004 Julio M. Merino Vidal
61ce9af54Sjunyoung * All rights reserved.
71ce9af54Sjunyoung *
81ce9af54Sjunyoung * Redistribution and use in source and binary forms, with or without
91ce9af54Sjunyoung * modification, are permitted provided that the following conditions
101ce9af54Sjunyoung * are met:
111ce9af54Sjunyoung * 1. Redistributions of source code must retain the above copyright
121ce9af54Sjunyoung * notice, this list of conditions and the following disclaimer.
131ce9af54Sjunyoung * 2. Redistributions in binary form must reproduce the above copyright
141ce9af54Sjunyoung * notice, this list of conditions and the following disclaimer in the
151ce9af54Sjunyoung * documentation and/or other materials provided with the distribution.
161ce9af54Sjunyoung * 3. The name of the author may not be used to endorse or promote products
170c51bd60Sjunyoung * derived from this software without specific prior written permission.
181ce9af54Sjunyoung *
191ce9af54Sjunyoung * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
201ce9af54Sjunyoung * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
211ce9af54Sjunyoung * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
221ce9af54Sjunyoung * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
231ce9af54Sjunyoung * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
241ce9af54Sjunyoung * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
251ce9af54Sjunyoung * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
261ce9af54Sjunyoung * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
271ce9af54Sjunyoung * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
281ce9af54Sjunyoung * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
291ce9af54Sjunyoung */
301ce9af54Sjunyoung
311ce9af54Sjunyoung /*
321ce9af54Sjunyoung * Copyright (c) 1995, 1996 Carnegie-Mellon University.
331ce9af54Sjunyoung * All rights reserved.
341ce9af54Sjunyoung *
351ce9af54Sjunyoung * Author: Chris G. Demetriou
361ce9af54Sjunyoung *
371ce9af54Sjunyoung * Permission to use, copy, modify and distribute this software and
381ce9af54Sjunyoung * its documentation is hereby granted, provided that both the copyright
391ce9af54Sjunyoung * notice and this permission notice appear in all copies of the
401ce9af54Sjunyoung * software, derivative works or modified versions, and any portions
411ce9af54Sjunyoung * thereof, and that both notices appear in supporting documentation.
421ce9af54Sjunyoung *
431ce9af54Sjunyoung * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
441ce9af54Sjunyoung * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
451ce9af54Sjunyoung * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
461ce9af54Sjunyoung *
471ce9af54Sjunyoung * Carnegie Mellon requests users of this software to return to
481ce9af54Sjunyoung *
491ce9af54Sjunyoung * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
501ce9af54Sjunyoung * School of Computer Science
511ce9af54Sjunyoung * Carnegie Mellon University
521ce9af54Sjunyoung * Pittsburgh PA 15213-3890
531ce9af54Sjunyoung *
541ce9af54Sjunyoung * any improvements or extensions that they make and grant Carnegie the
551ce9af54Sjunyoung * rights to redistribute these changes.
561ce9af54Sjunyoung */
571ce9af54Sjunyoung
58365cbd94Slukem #include <sys/cdefs.h>
59*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: vga_raster.c,v 1.50 2021/08/07 16:19:12 thorpej Exp $");
609a001938Sjmmv
61a5784f96Smlelstv #include "opt_vga.h"
629a001938Sjmmv #include "opt_wsmsgattrs.h" /* for WSDISPLAY_CUSTOM_OUTPUT */
63365cbd94Slukem
641ce9af54Sjunyoung #include <sys/param.h>
651ce9af54Sjunyoung #include <sys/systm.h>
661ce9af54Sjunyoung #include <sys/callout.h>
671ce9af54Sjunyoung #include <sys/kernel.h>
681ce9af54Sjunyoung #include <sys/device.h>
691ce9af54Sjunyoung #include <sys/malloc.h>
701ce9af54Sjunyoung #include <sys/queue.h>
71a2a38285Sad #include <sys/bus.h>
721ce9af54Sjunyoung
731ce9af54Sjunyoung #include <dev/ic/mc6845reg.h>
741ce9af54Sjunyoung #include <dev/ic/pcdisplayvar.h>
751ce9af54Sjunyoung #include <dev/ic/vgareg.h>
761ce9af54Sjunyoung #include <dev/ic/vgavar.h>
777c4a3fc1Stnn #include <dev/videomode/videomode.h>
781ce9af54Sjunyoung
791ce9af54Sjunyoung #include <dev/wscons/wsdisplayvar.h>
801ce9af54Sjunyoung #include <dev/wscons/wsconsio.h>
811ce9af54Sjunyoung #include <dev/wsfont/wsfont.h>
821ce9af54Sjunyoung
831ce9af54Sjunyoung #include <dev/ic/pcdisplay.h>
841ce9af54Sjunyoung
85ef47e3f6Stsutsui int vga_no_builtinfont = 0;
86ef47e3f6Stsutsui
871ce9af54Sjunyoung u_int8_t builtinfont_data[256 * 16];
881ce9af54Sjunyoung
891ce9af54Sjunyoung struct wsdisplay_font builtinfont = {
901ce9af54Sjunyoung "builtin", /* typeface name */
911ce9af54Sjunyoung 0, /* firstchar */
921ce9af54Sjunyoung 256, /* numchars */
931ce9af54Sjunyoung WSDISPLAY_FONTENC_IBM, /* encoding */
941ce9af54Sjunyoung 8, /* width */
951ce9af54Sjunyoung 16, /* height */
961ce9af54Sjunyoung 1, /* stride */
971ce9af54Sjunyoung WSDISPLAY_FONTORDER_L2R, /* bit order */
981ce9af54Sjunyoung WSDISPLAY_FONTORDER_L2R, /* byte order */
991ce9af54Sjunyoung builtinfont_data /* data */
1001ce9af54Sjunyoung };
1011ce9af54Sjunyoung
1021ce9af54Sjunyoung struct vga_scrmem {
1031ce9af54Sjunyoung u_int16_t ch;
1041ce9af54Sjunyoung u_int8_t attr;
1051ce9af54Sjunyoung u_int8_t second; /* XXXBJY should be u_int8_t len; */
1061ce9af54Sjunyoung u_int8_t enc;
1071ce9af54Sjunyoung };
1081ce9af54Sjunyoung
109c6326ab1Sjunyoung #ifdef VGA_CONSOLE_SCREENTYPE
110c6326ab1Sjunyoung #define VGA_SCRMEM_SIZE (80 * 30)
111c6326ab1Sjunyoung #else
112c6326ab1Sjunyoung #define VGA_SCRMEM_SIZE (80 * 25)
113c6326ab1Sjunyoung #endif
114c6326ab1Sjunyoung
115c6326ab1Sjunyoung struct vga_scrmem boot_scrmem[VGA_SCRMEM_SIZE];
1161ce9af54Sjunyoung
1171ce9af54Sjunyoung struct vga_raster_font {
1181ce9af54Sjunyoung LIST_ENTRY(vga_raster_font) next;
1191ce9af54Sjunyoung struct wsdisplay_font *font;
1201ce9af54Sjunyoung };
1211ce9af54Sjunyoung
1221ce9af54Sjunyoung struct vgascreen {
1231ce9af54Sjunyoung LIST_ENTRY(vgascreen) next;
1241ce9af54Sjunyoung struct vga_config *cfg;
1251ce9af54Sjunyoung struct vga_handle *hdl;
1261ce9af54Sjunyoung const struct wsscreen_descr *type;
1271ce9af54Sjunyoung
1281ce9af54Sjunyoung int active;
1291ce9af54Sjunyoung struct vga_scrmem *mem;
1301ce9af54Sjunyoung int encoding;
1311ce9af54Sjunyoung
1321ce9af54Sjunyoung int dispoffset;
1331ce9af54Sjunyoung int mindispoffset;
1341ce9af54Sjunyoung int maxdispoffset;
1351ce9af54Sjunyoung
1361ce9af54Sjunyoung int cursoron; /* Is cursor displayed? */
1371ce9af54Sjunyoung int cursorcol; /* Current cursor column */
1381ce9af54Sjunyoung int cursorrow; /* Current cursor row */
1391ce9af54Sjunyoung struct vga_scrmem cursortmp;
1401ce9af54Sjunyoung int cursorstride;
1411ce9af54Sjunyoung
1421ce9af54Sjunyoung LIST_HEAD(, vga_raster_font) fontset;
1431ce9af54Sjunyoung };
1441ce9af54Sjunyoung
1451ce9af54Sjunyoung struct vga_moderegs {
1461ce9af54Sjunyoung u_int8_t miscout; /* Misc. output */
14789b4d622Stsutsui u_int8_t crtc[MC6845_NREGS]; /* CRTC controller */
1481ce9af54Sjunyoung u_int8_t atc[VGA_ATC_NREGS]; /* Attribute controller */
1491ce9af54Sjunyoung u_int8_t ts[VGA_TS_NREGS]; /* Time sequencer */
1501ce9af54Sjunyoung u_int8_t gdc[VGA_GDC_NREGS]; /* Graphics display controller */
1511ce9af54Sjunyoung };
1521ce9af54Sjunyoung
1531ce9af54Sjunyoung static int vgaconsole, vga_console_type, vga_console_attached;
1541ce9af54Sjunyoung static struct vgascreen vga_console_screen;
1551ce9af54Sjunyoung static struct vga_config vga_console_vc;
1561ce9af54Sjunyoung static struct vga_raster_font vga_console_fontset_ascii;
1571ce9af54Sjunyoung static struct videomode vga_console_modes[2] = {
1581ce9af54Sjunyoung /* 640x400 for 80x25, 80x40 and 80x50 modes */
1591ce9af54Sjunyoung {
16000c11ed9Schristos 25175, 640, 664, 760, 800, 400, 409, 411, 450, 0, NULL,
1611ce9af54Sjunyoung },
1621ce9af54Sjunyoung /* 640x480 for 80x30 mode */
1631ce9af54Sjunyoung {
16400c11ed9Schristos 25175, 640, 664, 760, 800, 480, 491, 493, 525, 0, NULL,
1651ce9af54Sjunyoung }
1661ce9af54Sjunyoung };
1671ce9af54Sjunyoung
1681ce9af54Sjunyoung static void vga_raster_init(struct vga_config *, bus_space_tag_t,
1691ce9af54Sjunyoung bus_space_tag_t);
1701ce9af54Sjunyoung static void vga_raster_init_screen(struct vga_config *, struct vgascreen *,
1711ce9af54Sjunyoung const struct wsscreen_descr *, int, long *);
1721ce9af54Sjunyoung static void vga_raster_setup_font(struct vga_config *, struct vgascreen *);
1731ce9af54Sjunyoung static void vga_setup_regs(struct videomode *, struct vga_moderegs *);
1741ce9af54Sjunyoung static void vga_set_mode(struct vga_handle *, struct vga_moderegs *);
1751ce9af54Sjunyoung static void vga_restore_screen(struct vgascreen *,
1761ce9af54Sjunyoung const struct wsscreen_descr *, struct vga_scrmem *);
1771ce9af54Sjunyoung static void vga_raster_cursor_init(struct vgascreen *, int);
1781ce9af54Sjunyoung static void _vga_raster_putchar(void *, int, int, u_int, long,
1791ce9af54Sjunyoung struct vga_raster_font *);
1801ce9af54Sjunyoung
1811ce9af54Sjunyoung static void vga_raster_cursor(void *, int, int, int);
1821ce9af54Sjunyoung static int vga_raster_mapchar(void *, int, u_int *);
1831ce9af54Sjunyoung static void vga_raster_putchar(void *, int, int, u_int, long);
1841ce9af54Sjunyoung static void vga_raster_copycols(void *, int, int, int, int);
1851ce9af54Sjunyoung static void vga_raster_erasecols(void *, int, int, int, long);
1861ce9af54Sjunyoung static void vga_raster_copyrows(void *, int, int, int);
1871ce9af54Sjunyoung static void vga_raster_eraserows(void *, int, int, long);
1881ce9af54Sjunyoung static int vga_raster_allocattr(void *, int, int, int, long *);
1899a001938Sjmmv #ifdef WSDISPLAY_CUSTOM_OUTPUT
1909a001938Sjmmv static void vga_raster_replaceattr(void *, long, long);
1919a001938Sjmmv #endif /* WSDISPLAY_CUSTOM_OUTPUT */
1921ce9af54Sjunyoung
1931ce9af54Sjunyoung const struct wsdisplay_emulops vga_raster_emulops = {
1941ce9af54Sjunyoung vga_raster_cursor,
1951ce9af54Sjunyoung vga_raster_mapchar,
1961ce9af54Sjunyoung vga_raster_putchar,
1971ce9af54Sjunyoung vga_raster_copycols,
1981ce9af54Sjunyoung vga_raster_erasecols,
1991ce9af54Sjunyoung vga_raster_copyrows,
2001ce9af54Sjunyoung vga_raster_eraserows,
2011ce9af54Sjunyoung vga_raster_allocattr,
2029a001938Sjmmv #ifdef WSDISPLAY_CUSTOM_OUTPUT
2039a001938Sjmmv vga_raster_replaceattr,
2049a001938Sjmmv #else /* WSDISPLAY_CUSTOM_OUTPUT */
2059a001938Sjmmv NULL,
2069a001938Sjmmv #endif /* WSDISPLAY_CUSTOM_OUTPUT */
2071ce9af54Sjunyoung };
2081ce9af54Sjunyoung
2091ce9af54Sjunyoung /*
2101ce9af54Sjunyoung * translate WS(=ANSI) color codes to standard pc ones
2111ce9af54Sjunyoung */
2121ce9af54Sjunyoung static const unsigned char fgansitopc[] = {
2131ce9af54Sjunyoung #ifdef __alpha__
2141ce9af54Sjunyoung /*
2151ce9af54Sjunyoung * XXX DEC HAS SWITCHED THE CODES FOR BLUE AND RED!!!
2161ce9af54Sjunyoung * XXX We should probably not bother with this
2171ce9af54Sjunyoung * XXX (reinitialize the palette registers).
2181ce9af54Sjunyoung */
2191ce9af54Sjunyoung FG_BLACK, FG_BLUE, FG_GREEN, FG_CYAN, FG_RED,
2201ce9af54Sjunyoung FG_MAGENTA, FG_BROWN, FG_LIGHTGREY
2211ce9af54Sjunyoung #else
2221ce9af54Sjunyoung FG_BLACK, FG_RED, FG_GREEN, FG_BROWN, FG_BLUE,
2231ce9af54Sjunyoung FG_MAGENTA, FG_CYAN, FG_LIGHTGREY
2241ce9af54Sjunyoung #endif
2251ce9af54Sjunyoung }, bgansitopc[] = {
2261ce9af54Sjunyoung #ifdef __alpha__
2271ce9af54Sjunyoung BG_BLACK, BG_BLUE, BG_GREEN, BG_CYAN, BG_RED,
2281ce9af54Sjunyoung BG_MAGENTA, BG_BROWN, BG_LIGHTGREY
2291ce9af54Sjunyoung #else
2301ce9af54Sjunyoung BG_BLACK, BG_RED, BG_GREEN, BG_BROWN, BG_BLUE,
2311ce9af54Sjunyoung BG_MAGENTA, BG_CYAN, BG_LIGHTGREY
2321ce9af54Sjunyoung #endif
2331ce9af54Sjunyoung };
2341ce9af54Sjunyoung
2351ce9af54Sjunyoung const struct wsscreen_descr vga_25lscreen = {
2361ce9af54Sjunyoung "80x25", 80, 25,
2371ce9af54Sjunyoung &vga_raster_emulops,
2381ce9af54Sjunyoung 8, 16,
2391ce9af54Sjunyoung WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK,
2401ce9af54Sjunyoung &vga_console_modes[0]
2411ce9af54Sjunyoung }, vga_25lscreen_mono = {
2421ce9af54Sjunyoung "80x25", 80, 25,
2431ce9af54Sjunyoung &vga_raster_emulops,
2441ce9af54Sjunyoung 8, 16,
2451ce9af54Sjunyoung WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE,
2461ce9af54Sjunyoung &vga_console_modes[0]
2471ce9af54Sjunyoung }, vga_30lscreen = {
2481ce9af54Sjunyoung "80x30", 80, 30,
2491ce9af54Sjunyoung &vga_raster_emulops,
2501ce9af54Sjunyoung 8, 16,
2511ce9af54Sjunyoung WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK,
2521ce9af54Sjunyoung &vga_console_modes[1]
2531ce9af54Sjunyoung }, vga_30lscreen_mono = {
2541ce9af54Sjunyoung "80x30", 80, 30,
2551ce9af54Sjunyoung &vga_raster_emulops,
2561ce9af54Sjunyoung 8, 16,
2571ce9af54Sjunyoung WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE,
2581ce9af54Sjunyoung &vga_console_modes[1]
2591ce9af54Sjunyoung }, vga_40lscreen = {
2601ce9af54Sjunyoung "80x40", 80, 40,
2611ce9af54Sjunyoung &vga_raster_emulops,
2621ce9af54Sjunyoung 8, 10,
2631ce9af54Sjunyoung WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK,
2641ce9af54Sjunyoung &vga_console_modes[0]
2651ce9af54Sjunyoung }, vga_40lscreen_mono = {
2661ce9af54Sjunyoung "80x40", 80, 40,
2671ce9af54Sjunyoung &vga_raster_emulops,
2681ce9af54Sjunyoung 8, 10,
2691ce9af54Sjunyoung WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE,
2701ce9af54Sjunyoung &vga_console_modes[0]
2711ce9af54Sjunyoung }, vga_50lscreen = {
2721ce9af54Sjunyoung "80x50", 80, 50,
2731ce9af54Sjunyoung &vga_raster_emulops,
2741ce9af54Sjunyoung 8, 8,
2751ce9af54Sjunyoung WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK,
2761ce9af54Sjunyoung &vga_console_modes[0]
2771ce9af54Sjunyoung }, vga_50lscreen_mono = {
2781ce9af54Sjunyoung "80x50", 80, 50,
2791ce9af54Sjunyoung &vga_raster_emulops,
2801ce9af54Sjunyoung 8, 8,
2811ce9af54Sjunyoung WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE,
2821ce9af54Sjunyoung &vga_console_modes[0]
2831ce9af54Sjunyoung };
2841ce9af54Sjunyoung
2851ce9af54Sjunyoung const struct wsscreen_descr *_vga_scrlist[] = {
2861ce9af54Sjunyoung &vga_25lscreen,
2871ce9af54Sjunyoung &vga_30lscreen,
2881ce9af54Sjunyoung &vga_40lscreen,
2891ce9af54Sjunyoung &vga_50lscreen,
2901ce9af54Sjunyoung }, *_vga_scrlist_mono[] = {
2911ce9af54Sjunyoung &vga_25lscreen_mono,
2921ce9af54Sjunyoung &vga_30lscreen_mono,
2931ce9af54Sjunyoung &vga_40lscreen_mono,
2941ce9af54Sjunyoung &vga_50lscreen_mono,
2951ce9af54Sjunyoung };
2961ce9af54Sjunyoung
2971ce9af54Sjunyoung const struct wsscreen_list vga_screenlist = {
2981ce9af54Sjunyoung sizeof(_vga_scrlist) / sizeof(struct wsscreen_descr *),
2991ce9af54Sjunyoung _vga_scrlist
3001ce9af54Sjunyoung }, vga_screenlist_mono = {
3011ce9af54Sjunyoung sizeof(_vga_scrlist_mono) / sizeof(struct wsscreen_descr *),
3021ce9af54Sjunyoung _vga_scrlist_mono
3031ce9af54Sjunyoung };
3041ce9af54Sjunyoung
30553524e44Schristos static int vga_raster_ioctl(void *, void *, u_long, void *, int,
3067a51d4ddSjmmv struct lwp *);
3077a51d4ddSjmmv static paddr_t vga_raster_mmap(void *, void *, off_t, int);
3081ce9af54Sjunyoung static int vga_raster_alloc_screen(void *, const struct wsscreen_descr *,
3091ce9af54Sjunyoung void **, int *, int *, long *);
3101ce9af54Sjunyoung static void vga_raster_free_screen(void *, void *);
3111ce9af54Sjunyoung static int vga_raster_show_screen(void *, void *, int,
3121ce9af54Sjunyoung void (*)(void *, int, int), void *);
3131ce9af54Sjunyoung static int vga_raster_load_font(void *, void *, struct wsdisplay_font *);
3141ce9af54Sjunyoung
3151ce9af54Sjunyoung static void vga_switch_screen(struct vga_config *);
3161ce9af54Sjunyoung static void vga_raster_setscreentype(struct vga_config *,
3171ce9af54Sjunyoung const struct wsscreen_descr *);
3181ce9af54Sjunyoung
3191ce9af54Sjunyoung const struct wsdisplay_accessops vga_raster_accessops = {
3201ce9af54Sjunyoung vga_raster_ioctl,
3211ce9af54Sjunyoung vga_raster_mmap,
3221ce9af54Sjunyoung vga_raster_alloc_screen,
3231ce9af54Sjunyoung vga_raster_free_screen,
3241ce9af54Sjunyoung vga_raster_show_screen,
3251ce9af54Sjunyoung vga_raster_load_font,
32600c11ed9Schristos NULL, /* pollc */
32700c11ed9Schristos NULL, /* scroll */
3281ce9af54Sjunyoung };
3291ce9af54Sjunyoung
3301ce9af54Sjunyoung int
vga_cnattach(bus_space_tag_t iot,bus_space_tag_t memt,int type,int check)3311ce9af54Sjunyoung vga_cnattach(bus_space_tag_t iot, bus_space_tag_t memt, int type, int check)
3321ce9af54Sjunyoung {
3331ce9af54Sjunyoung long defattr;
3341ce9af54Sjunyoung const struct wsscreen_descr *scr;
3353bfa71c0Sjunyoung #ifdef VGA_CONSOLE_SCREENTYPE
3366805a4a4Srpaulo const char *typestr = NULL;
3373bfa71c0Sjunyoung #endif
3381ce9af54Sjunyoung
3391ce9af54Sjunyoung if (check && !vga_common_probe(iot, memt))
3401ce9af54Sjunyoung return (ENXIO);
3411ce9af54Sjunyoung
3421ce9af54Sjunyoung /* set up bus-independent VGA configuration */
3431ce9af54Sjunyoung vga_raster_init(&vga_console_vc, iot, memt);
3441ce9af54Sjunyoung #ifdef VGA_CONSOLE_SCREENTYPE
3451ce9af54Sjunyoung scr = wsdisplay_screentype_pick(vga_console_vc.hdl.vh_mono ?
3461ce9af54Sjunyoung &vga_screenlist_mono : &vga_screenlist, VGA_CONSOLE_SCREENTYPE);
3471ce9af54Sjunyoung if (!scr)
348c6326ab1Sjunyoung /* Invalid screen type, continue with the default mode. */
349c6326ab1Sjunyoung typestr = "80x25";
350c6326ab1Sjunyoung else if (scr->nrows > 30)
351c6326ab1Sjunyoung /* Unsupported screen type, try 80x30. */
352c6326ab1Sjunyoung typestr = "80x30";
3530215b24dSjmcneill if (typestr)
354c6326ab1Sjunyoung scr = wsdisplay_screentype_pick(vga_console_vc.hdl.vh_mono ?
355c6326ab1Sjunyoung &vga_screenlist_mono : &vga_screenlist, typestr);
356c6326ab1Sjunyoung if (scr != vga_console_vc.currenttype)
3571ce9af54Sjunyoung vga_console_vc.currenttype = scr;
3581ce9af54Sjunyoung #else
3591ce9af54Sjunyoung scr = vga_console_vc.currenttype;
3601ce9af54Sjunyoung #endif
3611ce9af54Sjunyoung vga_raster_init_screen(&vga_console_vc, &vga_console_screen, scr, 1,
3621ce9af54Sjunyoung &defattr);
3631ce9af54Sjunyoung
3641ce9af54Sjunyoung vga_console_screen.active = 1;
3651ce9af54Sjunyoung vga_console_vc.active = &vga_console_screen;
3661ce9af54Sjunyoung
3671ce9af54Sjunyoung wsdisplay_cnattach(scr, &vga_console_screen,
3681ce9af54Sjunyoung vga_console_screen.cursorcol, vga_console_screen.cursorrow,
3691ce9af54Sjunyoung defattr);
3701ce9af54Sjunyoung
3711ce9af54Sjunyoung vgaconsole = 1;
3721ce9af54Sjunyoung vga_console_type = type;
3731ce9af54Sjunyoung return (0);
3741ce9af54Sjunyoung }
3751ce9af54Sjunyoung
376b054bec0Smlelstv static void
vga_raster_init(struct vga_config * vc,bus_space_tag_t iot,bus_space_tag_t memt)3771ce9af54Sjunyoung vga_raster_init(struct vga_config *vc, bus_space_tag_t iot,
3781ce9af54Sjunyoung bus_space_tag_t memt)
3791ce9af54Sjunyoung {
3801ce9af54Sjunyoung struct vga_handle *vh = &vc->hdl;
3811ce9af54Sjunyoung u_int8_t mor;
3821ce9af54Sjunyoung struct vga_raster_font *vf;
3831ce9af54Sjunyoung
3841ce9af54Sjunyoung vh->vh_iot = iot;
3851ce9af54Sjunyoung vh->vh_memt = memt;
3861ce9af54Sjunyoung
3871ce9af54Sjunyoung if (bus_space_map(vh->vh_iot, 0x3c0, 0x10, 0, &vh->vh_ioh_vga))
3881ce9af54Sjunyoung panic("vga_raster_init: couldn't map vga io");
3891ce9af54Sjunyoung
3901ce9af54Sjunyoung /* read "misc output register" */
39189b4d622Stsutsui mor = bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_MISC_DATAR);
3921ce9af54Sjunyoung vh->vh_mono = !(mor & 1);
3931ce9af54Sjunyoung
3941ce9af54Sjunyoung if (bus_space_map(vh->vh_iot, (vh->vh_mono ? 0x3b0 : 0x3d0), 0x10, 0,
3951ce9af54Sjunyoung &vh->vh_ioh_6845))
3961ce9af54Sjunyoung panic("vga_raster_init: couldn't map 6845 io");
3971ce9af54Sjunyoung
3982ca6e3ffSad if (bus_space_map(vh->vh_memt, 0xa0000, 0x20000,
3996dfea3c2Sad BUS_SPACE_MAP_CACHEABLE, &vh->vh_allmemh))
4002ca6e3ffSad panic("vga_init: couldn't map memory");
4011ce9af54Sjunyoung
4021ce9af54Sjunyoung if (bus_space_subregion(vh->vh_memt, vh->vh_allmemh, 0, 0x10000,
4031ce9af54Sjunyoung &vh->vh_memh))
4041ce9af54Sjunyoung panic("vga_raster_init: mem subrange failed");
4051ce9af54Sjunyoung
4061ce9af54Sjunyoung vc->nscreens = 0;
4071ce9af54Sjunyoung LIST_INIT(&vc->screens);
4081ce9af54Sjunyoung vc->active = NULL;
4091ce9af54Sjunyoung vc->currenttype = vh->vh_mono ? &vga_25lscreen_mono : &vga_25lscreen;
41088ab7da9Sad callout_init(&vc->vc_switch_callout, 0);
4111ce9af54Sjunyoung
412ef47e3f6Stsutsui wsfont_init();
4131ce9af54Sjunyoung vc->nfonts = 1;
4141ce9af54Sjunyoung LIST_INIT(&vc->vc_fontlist);
4151ce9af54Sjunyoung vf = &vga_console_fontset_ascii;
416ef47e3f6Stsutsui if (vga_no_builtinfont) {
417ef47e3f6Stsutsui struct wsdisplay_font *wf;
418ef47e3f6Stsutsui int cookie;
419ef47e3f6Stsutsui
420ef47e3f6Stsutsui /* prefer 8x16 pixel font */
421247328b1Sjunyoung cookie = wsfont_find(NULL, 8, 16, 0, WSDISPLAY_FONTORDER_L2R,
42256e33f11Smacallan 0, WSFONT_FIND_BITMAP);
423ef47e3f6Stsutsui if (cookie == -1)
424ef47e3f6Stsutsui cookie = wsfont_find(NULL, 0, 0, 0,
42556e33f11Smacallan WSDISPLAY_FONTORDER_L2R, WSDISPLAY_FONTORDER_L2R,
42656e33f11Smacallan WSFONT_FIND_BITMAP);
427ef47e3f6Stsutsui if (cookie == -1 || wsfont_lock(cookie, &wf))
428ef47e3f6Stsutsui panic("vga_raster_init: can't load console font");
429ef47e3f6Stsutsui vf->font = wf;
430ef47e3f6Stsutsui } else {
4311ce9af54Sjunyoung vga_load_builtinfont(vh, builtinfont_data, 0, 256);
4321ce9af54Sjunyoung vf->font = &builtinfont;
433ef47e3f6Stsutsui }
4341ce9af54Sjunyoung LIST_INSERT_HEAD(&vc->vc_fontlist, vf, next);
4351ce9af54Sjunyoung }
4361ce9af54Sjunyoung
437b054bec0Smlelstv static void
vga_raster_init_screen(struct vga_config * vc,struct vgascreen * scr,const struct wsscreen_descr * type,int existing,long * attrp)4381ce9af54Sjunyoung vga_raster_init_screen(struct vga_config *vc, struct vgascreen *scr,
4391ce9af54Sjunyoung const struct wsscreen_descr *type, int existing, long *attrp)
4401ce9af54Sjunyoung {
4411ce9af54Sjunyoung int cpos;
442d10b865fSriastradh int res __diagused;
4431ce9af54Sjunyoung struct vga_handle *vh;
4441ce9af54Sjunyoung
4451ce9af54Sjunyoung scr->cfg = vc;
4461ce9af54Sjunyoung scr->hdl = &vc->hdl;
4471ce9af54Sjunyoung scr->type = type;
4481ce9af54Sjunyoung scr->mindispoffset = 0;
44948100f10Sjmcneill scr->maxdispoffset = scr->dispoffset +
45048100f10Sjmcneill type->nrows * type->ncols * type->fontheight;
4511ce9af54Sjunyoung vh = &vc->hdl;
4521ce9af54Sjunyoung
4531ce9af54Sjunyoung LIST_INIT(&scr->fontset);
4541ce9af54Sjunyoung vga_raster_setup_font(vc, scr);
4551ce9af54Sjunyoung
4561ce9af54Sjunyoung if (existing) {
457c6326ab1Sjunyoung int i;
458c6326ab1Sjunyoung
4591ce9af54Sjunyoung cpos = vga_6845_read(vh, cursorh) << 8;
4601ce9af54Sjunyoung cpos |= vga_6845_read(vh, cursorl);
4611ce9af54Sjunyoung
4621ce9af54Sjunyoung /* make sure we have a valid cursor position */
4631ce9af54Sjunyoung if (cpos < 0 || cpos >= type->nrows * type->ncols)
4641ce9af54Sjunyoung cpos = 0;
4651ce9af54Sjunyoung
4661ce9af54Sjunyoung scr->dispoffset = vga_6845_read(vh, startadrh) << 9;
4671ce9af54Sjunyoung scr->dispoffset |= vga_6845_read(vh, startadrl) << 1;
4681ce9af54Sjunyoung
4691ce9af54Sjunyoung /* make sure we have a valid memory offset */
4701ce9af54Sjunyoung if (scr->dispoffset < scr->mindispoffset ||
4711ce9af54Sjunyoung scr->dispoffset > scr->maxdispoffset)
4721ce9af54Sjunyoung scr->dispoffset = scr->mindispoffset;
4731ce9af54Sjunyoung
4741ce9af54Sjunyoung scr->mem = boot_scrmem;
4751ce9af54Sjunyoung scr->active = 1;
4761ce9af54Sjunyoung
477c6326ab1Sjunyoung /* Save the current screen to memory. XXXBJY assume 80x25 */
478c6326ab1Sjunyoung for (i = 0; i < 80 * 25; i++) {
479c6326ab1Sjunyoung scr->mem[i].ch = bus_space_read_1(vh->vh_memt,
480c6326ab1Sjunyoung vh->vh_allmemh, 0x18000 + i * 2);
481c6326ab1Sjunyoung scr->mem[i].attr = bus_space_read_1(vh->vh_memt,
482c6326ab1Sjunyoung vh->vh_allmemh, 0x18000 + i * 2 + 1);
483ef47e3f6Stsutsui scr->mem[i].enc = scr->encoding;
484c6326ab1Sjunyoung }
485c6326ab1Sjunyoung
48678e97058Sjunyoung vga_raster_setscreentype(vc, type);
4871ce9af54Sjunyoung
4881ce9af54Sjunyoung /* Clear the entire screen. */
4891ce9af54Sjunyoung vga_gdc_write(vh, mode, 0x02);
4901ce9af54Sjunyoung bus_space_set_region_4(vh->vh_memt, vh->vh_allmemh, 0, 0,
4911ce9af54Sjunyoung 0x4000);
4921ce9af54Sjunyoung
4931ce9af54Sjunyoung vga_restore_screen(scr, type, scr->mem);
4941ce9af54Sjunyoung } else {
4951ce9af54Sjunyoung cpos = 0;
4961ce9af54Sjunyoung scr->dispoffset = scr->mindispoffset;
4971ce9af54Sjunyoung scr->mem = NULL;
4981ce9af54Sjunyoung scr->active = 0;
4991ce9af54Sjunyoung }
5001ce9af54Sjunyoung
5011ce9af54Sjunyoung scr->cursorrow = cpos / type->ncols;
5021ce9af54Sjunyoung scr->cursorcol = cpos % type->ncols;
5031ce9af54Sjunyoung vga_raster_cursor_init(scr, existing);
5041ce9af54Sjunyoung
5051ce9af54Sjunyoung #ifdef __alpha__
5061ce9af54Sjunyoung if (!vc->hdl.vh_mono)
5071ce9af54Sjunyoung /*
5081ce9af54Sjunyoung * DEC firmware uses a blue background.
5091ce9af54Sjunyoung */
5101ce9af54Sjunyoung res = vga_raster_allocattr(scr, WSCOL_WHITE, WSCOL_BLUE,
5111ce9af54Sjunyoung WSATTR_WSCOLORS, attrp);
5121ce9af54Sjunyoung else
5131ce9af54Sjunyoung #endif
5141ce9af54Sjunyoung res = vga_raster_allocattr(scr, 0, 0, 0, attrp);
515d10b865fSriastradh KASSERTMSG(res == 0, "attribute botch");
5161ce9af54Sjunyoung
5171ce9af54Sjunyoung vc->nscreens++;
5181ce9af54Sjunyoung LIST_INSERT_HEAD(&vc->screens, scr, next);
5191ce9af54Sjunyoung }
5201ce9af54Sjunyoung
5211ce9af54Sjunyoung void
vga_common_attach(struct vga_softc * sc,bus_space_tag_t iot,bus_space_tag_t memt,int type,int quirks,const struct vga_funcs * vf)5221ce9af54Sjunyoung vga_common_attach(struct vga_softc *sc, bus_space_tag_t iot,
523168cd830Schristos bus_space_tag_t memt, int type, int quirks,
5244d595fd7Schristos const struct vga_funcs *vf)
5251ce9af54Sjunyoung {
5261ce9af54Sjunyoung int console;
5271ce9af54Sjunyoung struct vga_config *vc;
5281ce9af54Sjunyoung struct wsemuldisplaydev_attach_args aa;
5291ce9af54Sjunyoung
5301ce9af54Sjunyoung console = vga_is_console(iot, type);
5311ce9af54Sjunyoung
5321ce9af54Sjunyoung if (console) {
5331ce9af54Sjunyoung vc = &vga_console_vc;
5341ce9af54Sjunyoung vga_console_attached = 1;
5351ce9af54Sjunyoung } else {
536a8c7515fStsutsui vc = malloc(sizeof(struct vga_config), M_DEVBUF, M_WAITOK);
5371ce9af54Sjunyoung vga_raster_init(vc, iot, memt);
5381ce9af54Sjunyoung }
5391ce9af54Sjunyoung
5401ce9af54Sjunyoung vc->vc_type = type;
5411ce9af54Sjunyoung vc->vc_funcs = vf;
5421ce9af54Sjunyoung
5431ce9af54Sjunyoung sc->sc_vc = vc;
5441ce9af54Sjunyoung vc->softc = sc;
5451ce9af54Sjunyoung
5461ce9af54Sjunyoung aa.console = console;
5471ce9af54Sjunyoung aa.scrdata = (vc->hdl.vh_mono ? &vga_screenlist_mono : &vga_screenlist);
5481ce9af54Sjunyoung aa.accessops = &vga_raster_accessops;
5491ce9af54Sjunyoung aa.accesscookie = vc;
5501ce9af54Sjunyoung
5512685996bSthorpej config_found(sc->sc_dev, &aa, wsemuldisplaydevprint,
552*c7fb772bSthorpej CFARGS(.iattr = "wsemuldisplaydev"));
5531ce9af54Sjunyoung }
5541ce9af54Sjunyoung
5551ce9af54Sjunyoung int
vga_cndetach(void)556d515e7b7Sdogcow vga_cndetach(void)
557d515e7b7Sdogcow {
558d515e7b7Sdogcow struct vga_config *vc;
559d515e7b7Sdogcow struct vga_handle *vh;
560d515e7b7Sdogcow
561d515e7b7Sdogcow vc = &vga_console_vc;
562d515e7b7Sdogcow vh = &vc->hdl;
563d515e7b7Sdogcow
564d515e7b7Sdogcow if (vgaconsole) {
565a0d0c26cSmlelstv wsdisplay_cndetach();
566a0d0c26cSmlelstv
567d515e7b7Sdogcow bus_space_unmap(vh->vh_iot, vh->vh_ioh_vga, 0x10);
568d515e7b7Sdogcow bus_space_unmap(vh->vh_iot, vh->vh_ioh_6845, 0x10);
5693a26d93cSmlelstv bus_space_unmap(vh->vh_memt, vh->vh_allmemh, 0x20000);
570d515e7b7Sdogcow
571a0d0c26cSmlelstv vga_console_attached = 0;
572a0d0c26cSmlelstv vgaconsole = 0;
573a0d0c26cSmlelstv
574d515e7b7Sdogcow return 1;
575d515e7b7Sdogcow }
576d515e7b7Sdogcow
577d515e7b7Sdogcow return 0;
578d515e7b7Sdogcow }
579d515e7b7Sdogcow
580d515e7b7Sdogcow int
vga_is_console(bus_space_tag_t iot,int type)5811ce9af54Sjunyoung vga_is_console(bus_space_tag_t iot, int type)
5821ce9af54Sjunyoung {
5831ce9af54Sjunyoung if (vgaconsole &&
5841ce9af54Sjunyoung !vga_console_attached &&
5851ce9af54Sjunyoung iot == vga_console_vc.hdl.vh_iot &&
5861ce9af54Sjunyoung (vga_console_type == -1 || (type == vga_console_type)))
5871ce9af54Sjunyoung return (1);
5881ce9af54Sjunyoung return (0);
5891ce9af54Sjunyoung }
5901ce9af54Sjunyoung
5911ce9af54Sjunyoung static int
vga_get_video(struct vga_config * vc)5921ce9af54Sjunyoung vga_get_video(struct vga_config *vc)
5931ce9af54Sjunyoung {
59489b4d622Stsutsui
59589b4d622Stsutsui return (vga_ts_read(&vc->hdl, mode) & VGA_TS_MODE_BLANK) == 0;
5961ce9af54Sjunyoung }
5971ce9af54Sjunyoung
5981ce9af54Sjunyoung static void
vga_set_video(struct vga_config * vc,int state)5991ce9af54Sjunyoung vga_set_video(struct vga_config *vc, int state)
6001ce9af54Sjunyoung {
6011ce9af54Sjunyoung int val;
6021ce9af54Sjunyoung
6031ce9af54Sjunyoung vga_ts_write(&vc->hdl, syncreset, 0x01);
6041ce9af54Sjunyoung if (state) { /* unblank screen */
6051ce9af54Sjunyoung val = vga_ts_read(&vc->hdl, mode);
60689b4d622Stsutsui vga_ts_write(&vc->hdl, mode, val & ~VGA_TS_MODE_BLANK);
6071ce9af54Sjunyoung #ifndef VGA_NO_VBLANK
6081ce9af54Sjunyoung val = vga_6845_read(&vc->hdl, mode);
6091ce9af54Sjunyoung vga_6845_write(&vc->hdl, mode, val | 0x80);
6101ce9af54Sjunyoung #endif
6111ce9af54Sjunyoung } else { /* blank screen */
6121ce9af54Sjunyoung val = vga_ts_read(&vc->hdl, mode);
61389b4d622Stsutsui vga_ts_write(&vc->hdl, mode, val | VGA_TS_MODE_BLANK);
6141ce9af54Sjunyoung #ifndef VGA_NO_VBLANK
6151ce9af54Sjunyoung val = vga_6845_read(&vc->hdl, mode);
6161ce9af54Sjunyoung vga_6845_write(&vc->hdl, mode, val & ~0x80);
6171ce9af54Sjunyoung #endif
6181ce9af54Sjunyoung }
6191ce9af54Sjunyoung vga_ts_write(&vc->hdl, syncreset, 0x03);
6201ce9af54Sjunyoung }
6211ce9af54Sjunyoung
6221ce9af54Sjunyoung int
vga_raster_ioctl(void * v,void * vs,u_long cmd,void * data,int flag,struct lwp * l)62353524e44Schristos vga_raster_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
6247a51d4ddSjmmv struct lwp *l)
6251ce9af54Sjunyoung {
6261ce9af54Sjunyoung struct vga_config *vc = v;
6271ce9af54Sjunyoung const struct vga_funcs *vf = vc->vc_funcs;
6281ce9af54Sjunyoung
6291ce9af54Sjunyoung switch (cmd) {
6301ce9af54Sjunyoung case WSDISPLAYIO_GTYPE:
6311ce9af54Sjunyoung *(int *)data = vc->vc_type;
6321ce9af54Sjunyoung return 0;
6331ce9af54Sjunyoung
634ccb780c1Schristos case WSDISPLAYIO_GINFO: {
635ccb780c1Schristos struct wsdisplay_fbinfo *fbi = data;
636ccb780c1Schristos const struct wsscreen_descr *wd = vc->currenttype;
637ccb780c1Schristos const struct videomode *vm = wd->modecookie;
638ccb780c1Schristos fbi->width = vm->hdisplay;
639ccb780c1Schristos fbi->height = vm->vdisplay;
640ccb780c1Schristos fbi->depth = 24; /* xxx: ? */
641ccb780c1Schristos fbi->cmsize = 256; /* xxx: from palette */
642ccb780c1Schristos return 0;
643ccb780c1Schristos }
6441ce9af54Sjunyoung
6451ce9af54Sjunyoung case WSDISPLAYIO_GVIDEO:
646a8c7515fStsutsui *(int *)data = (vga_get_video(vc) ?
647a8c7515fStsutsui WSDISPLAYIO_VIDEO_ON : WSDISPLAYIO_VIDEO_OFF);
6481ce9af54Sjunyoung return 0;
6491ce9af54Sjunyoung
6501ce9af54Sjunyoung case WSDISPLAYIO_SVIDEO:
6511ce9af54Sjunyoung vga_set_video(vc, *(int *)data == WSDISPLAYIO_VIDEO_ON);
6521ce9af54Sjunyoung return 0;
6531ce9af54Sjunyoung
6541ce9af54Sjunyoung case WSDISPLAYIO_GETCMAP:
6551ce9af54Sjunyoung case WSDISPLAYIO_PUTCMAP:
6561ce9af54Sjunyoung case WSDISPLAYIO_GCURPOS:
6571ce9af54Sjunyoung case WSDISPLAYIO_SCURPOS:
6581ce9af54Sjunyoung case WSDISPLAYIO_GCURMAX:
6591ce9af54Sjunyoung case WSDISPLAYIO_GCURSOR:
6601ce9af54Sjunyoung case WSDISPLAYIO_SCURSOR:
661ccb780c1Schristos #ifdef DIAGNOSTIC
662ccb780c1Schristos printf("%s: 0x%lx unsupported\n", __func__, cmd);
663ccb780c1Schristos #endif
6641ce9af54Sjunyoung /* NONE of these operations are by the generic VGA driver. */
6651ce9af54Sjunyoung return EPASSTHROUGH;
6661ce9af54Sjunyoung }
6671ce9af54Sjunyoung
668ccb780c1Schristos if (vc->vc_funcs == NULL) {
669ccb780c1Schristos #ifdef DIAGNOSTIC
670ccb780c1Schristos printf("%s: no vc_funcs\n", __func__);
671ccb780c1Schristos #endif
672ccb780c1Schristos return EPASSTHROUGH;
673ccb780c1Schristos }
6741ce9af54Sjunyoung
675ccb780c1Schristos if (vf->vf_ioctl == NULL) {
676ccb780c1Schristos #ifdef DIAGNOSTIC
677ccb780c1Schristos printf("%s: no vf_ioctl\n", __func__);
678ccb780c1Schristos #endif
679ccb780c1Schristos return EPASSTHROUGH;
680ccb780c1Schristos }
6811ce9af54Sjunyoung
682d014803bSchristos return ((*vf->vf_ioctl)(v, cmd, data, flag, l));
6831ce9af54Sjunyoung }
6841ce9af54Sjunyoung
6851ce9af54Sjunyoung static paddr_t
vga_raster_mmap(void * v,void * vs,off_t offset,int prot)686168cd830Schristos vga_raster_mmap(void *v, void *vs, off_t offset, int prot)
6871ce9af54Sjunyoung {
6881ce9af54Sjunyoung struct vga_config *vc = v;
6891ce9af54Sjunyoung const struct vga_funcs *vf = vc->vc_funcs;
6901ce9af54Sjunyoung
6911ce9af54Sjunyoung if (vc->vc_funcs == NULL)
6921ce9af54Sjunyoung return (-1);
6931ce9af54Sjunyoung
6941ce9af54Sjunyoung if (vf->vf_mmap == NULL)
6951ce9af54Sjunyoung return (-1);
6961ce9af54Sjunyoung
6971ce9af54Sjunyoung return ((*vf->vf_mmap)(v, offset, prot));
6981ce9af54Sjunyoung }
6991ce9af54Sjunyoung
700b054bec0Smlelstv static int
vga_raster_alloc_screen(void * v,const struct wsscreen_descr * type,void ** cookiep,int * curxp,int * curyp,long * defattrp)7011ce9af54Sjunyoung vga_raster_alloc_screen(void *v, const struct wsscreen_descr *type,
7021ce9af54Sjunyoung void **cookiep, int *curxp, int *curyp, long *defattrp)
7031ce9af54Sjunyoung {
7041ce9af54Sjunyoung struct vga_config *vc = v;
7051ce9af54Sjunyoung struct vgascreen *scr;
7061ce9af54Sjunyoung
7071ce9af54Sjunyoung if (vc->nscreens == 1) {
7081ce9af54Sjunyoung vc->screens.lh_first->mem = boot_scrmem;
7091ce9af54Sjunyoung }
7101ce9af54Sjunyoung
7111ce9af54Sjunyoung scr = malloc(sizeof(struct vgascreen), M_DEVBUF, M_WAITOK);
7121ce9af54Sjunyoung vga_raster_init_screen(vc, scr, type, vc->nscreens == 0, defattrp);
7131ce9af54Sjunyoung
7141ce9af54Sjunyoung if (vc->nscreens == 1) {
7151ce9af54Sjunyoung scr->active = 1;
7161ce9af54Sjunyoung vc->active = scr;
7171ce9af54Sjunyoung vc->currenttype = type;
7181ce9af54Sjunyoung } else {
7191ce9af54Sjunyoung scr->mem = malloc(sizeof(struct vga_scrmem) *
7201ce9af54Sjunyoung type->ncols * type->nrows, M_DEVBUF, M_WAITOK);
7211ce9af54Sjunyoung vga_raster_eraserows(scr, 0, type->nrows, *defattrp);
7221ce9af54Sjunyoung }
7231ce9af54Sjunyoung
7241ce9af54Sjunyoung *cookiep = scr;
7251ce9af54Sjunyoung *curxp = scr->cursorcol;
7261ce9af54Sjunyoung *curyp = scr->cursorrow;
7271ce9af54Sjunyoung
7281ce9af54Sjunyoung return (0);
7291ce9af54Sjunyoung }
7301ce9af54Sjunyoung
731b054bec0Smlelstv static void
vga_raster_free_screen(void * v,void * cookie)732168cd830Schristos vga_raster_free_screen(void *v, void *cookie)
7331ce9af54Sjunyoung {
7341ce9af54Sjunyoung struct vgascreen *vs = cookie;
7351ce9af54Sjunyoung struct vga_config *vc = vs->cfg;
7361ce9af54Sjunyoung
7371ce9af54Sjunyoung LIST_REMOVE(vs, next);
73837e4b2f6Sdbj vc->nscreens--;
7391ce9af54Sjunyoung if (vs != &vga_console_screen)
7401ce9af54Sjunyoung free(vs, M_DEVBUF);
7411ce9af54Sjunyoung else
7421ce9af54Sjunyoung panic("vga_raster_free_screen: console");
7431ce9af54Sjunyoung
7441ce9af54Sjunyoung if (vc->active == vs)
7451ce9af54Sjunyoung vc->active = 0;
7461ce9af54Sjunyoung }
7471ce9af54Sjunyoung
748b054bec0Smlelstv static int
vga_raster_show_screen(void * v,void * cookie,int waitok,void (* cb)(void *,int,int),void * cbarg)749168cd830Schristos vga_raster_show_screen(void *v, void *cookie, int waitok,
7501ce9af54Sjunyoung void (*cb)(void *, int, int), void *cbarg)
7511ce9af54Sjunyoung {
7521ce9af54Sjunyoung struct vgascreen *scr = cookie, *oldscr;
7531ce9af54Sjunyoung struct vga_config *vc = scr->cfg;
7541ce9af54Sjunyoung
7551ce9af54Sjunyoung oldscr = vc->active; /* can be NULL! */
7561ce9af54Sjunyoung if (scr == oldscr) {
7571ce9af54Sjunyoung return (0);
7581ce9af54Sjunyoung }
7591ce9af54Sjunyoung
7601ce9af54Sjunyoung vc->wantedscreen = cookie;
7611ce9af54Sjunyoung vc->switchcb = cb;
7621ce9af54Sjunyoung vc->switchcbarg = cbarg;
7631ce9af54Sjunyoung if (cb) {
7641ce9af54Sjunyoung callout_reset(&vc->vc_switch_callout, 0,
7651ce9af54Sjunyoung (void(*)(void *))vga_switch_screen, vc);
7661ce9af54Sjunyoung return (EAGAIN);
7671ce9af54Sjunyoung }
7681ce9af54Sjunyoung
7691ce9af54Sjunyoung vga_switch_screen(vc);
7701ce9af54Sjunyoung return (0);
7711ce9af54Sjunyoung }
7721ce9af54Sjunyoung
773b054bec0Smlelstv static void
vga_switch_screen(struct vga_config * vc)7741ce9af54Sjunyoung vga_switch_screen(struct vga_config *vc)
7751ce9af54Sjunyoung {
7761ce9af54Sjunyoung struct vgascreen *scr, *oldscr;
7771ce9af54Sjunyoung struct vga_handle *vh = &vc->hdl;
7781ce9af54Sjunyoung const struct wsscreen_descr *type;
7791ce9af54Sjunyoung
7801ce9af54Sjunyoung scr = vc->wantedscreen;
7811ce9af54Sjunyoung if (!scr) {
7821ce9af54Sjunyoung printf("vga_switch_screen: disappeared\n");
7831ce9af54Sjunyoung (*vc->switchcb)(vc->switchcbarg, EIO, 0);
7841ce9af54Sjunyoung return;
7851ce9af54Sjunyoung }
7861ce9af54Sjunyoung type = scr->type;
7871ce9af54Sjunyoung oldscr = vc->active; /* can be NULL! */
7881ce9af54Sjunyoung #ifdef DIAGNOSTIC
7891ce9af54Sjunyoung if (oldscr) {
7901ce9af54Sjunyoung if (!oldscr->active)
7911ce9af54Sjunyoung panic("vga_raster_show_screen: not active");
7921ce9af54Sjunyoung if (oldscr->type != vc->currenttype)
7931ce9af54Sjunyoung panic("vga_raster_show_screen: bad type");
7941ce9af54Sjunyoung }
7951ce9af54Sjunyoung #endif
7961ce9af54Sjunyoung if (scr == oldscr) {
7971ce9af54Sjunyoung return;
7981ce9af54Sjunyoung }
7991ce9af54Sjunyoung #ifdef DIAGNOSTIC
8001ce9af54Sjunyoung if (scr->active)
8011ce9af54Sjunyoung panic("vga_raster_show_screen: active");
8021ce9af54Sjunyoung #endif
8031ce9af54Sjunyoung
8041ce9af54Sjunyoung if (oldscr)
8051ce9af54Sjunyoung oldscr->active = 0;
8061ce9af54Sjunyoung
8071ce9af54Sjunyoung if (vc->currenttype != type) {
8081ce9af54Sjunyoung vga_raster_setscreentype(vc, type);
8091ce9af54Sjunyoung vc->currenttype = type;
8101ce9af54Sjunyoung }
8111ce9af54Sjunyoung
8121ce9af54Sjunyoung scr->dispoffset = scr->mindispoffset;
8131ce9af54Sjunyoung
8141ce9af54Sjunyoung if (!oldscr || (scr->dispoffset != oldscr->dispoffset)) {
8151ce9af54Sjunyoung vga_6845_write(vh, startadrh, scr->dispoffset >> 8);
8161ce9af54Sjunyoung vga_6845_write(vh, startadrl, scr->dispoffset);
8171ce9af54Sjunyoung }
8181ce9af54Sjunyoung
8191ce9af54Sjunyoung /* Clear the entire screen. */
8201ce9af54Sjunyoung vga_gdc_write(vh, mode, 0x02);
8211ce9af54Sjunyoung bus_space_set_region_4(vh->vh_memt, vh->vh_allmemh, 0, 0, 0x2000);
8221ce9af54Sjunyoung
8231ce9af54Sjunyoung scr->active = 1;
8241ce9af54Sjunyoung vga_restore_screen(scr, type, scr->mem);
8251ce9af54Sjunyoung
8261ce9af54Sjunyoung vc->active = scr;
8271ce9af54Sjunyoung
8281ce9af54Sjunyoung vga_raster_cursor(scr, scr->cursoron, scr->cursorrow, scr->cursorcol);
8291ce9af54Sjunyoung
8301ce9af54Sjunyoung vc->wantedscreen = 0;
8311ce9af54Sjunyoung if (vc->switchcb)
8321ce9af54Sjunyoung (*vc->switchcb)(vc->switchcbarg, 0, 0);
8331ce9af54Sjunyoung }
8341ce9af54Sjunyoung
8351ce9af54Sjunyoung static int
vga_raster_load_font(void * v,void * id,struct wsdisplay_font * data)836168cd830Schristos vga_raster_load_font(void *v, void *id,
837168cd830Schristos struct wsdisplay_font *data)
8381ce9af54Sjunyoung {
8391ce9af54Sjunyoung /* XXX */
840247328b1Sjunyoung printf("vga_raster_load_font: called\n");
8411ce9af54Sjunyoung
8421ce9af54Sjunyoung return (0);
8431ce9af54Sjunyoung }
8441ce9af54Sjunyoung
845b054bec0Smlelstv static void
vga_raster_setup_font(struct vga_config * vc,struct vgascreen * scr)8461ce9af54Sjunyoung vga_raster_setup_font(struct vga_config *vc, struct vgascreen *scr)
8471ce9af54Sjunyoung {
8481ce9af54Sjunyoung struct vga_raster_font *vf;
8491ce9af54Sjunyoung struct wsdisplay_font *wf;
8501ce9af54Sjunyoung int cookie;
8511ce9af54Sjunyoung
8521ce9af54Sjunyoung LIST_FOREACH(vf, &vc->vc_fontlist, next) {
85356e33f11Smacallan if (wsfont_matches(vf->font, 0, 0, scr->type->fontheight, 0,
85456e33f11Smacallan WSFONT_FIND_BITMAP)) {
855ef47e3f6Stsutsui scr->encoding = vf->font->encoding;
8561ce9af54Sjunyoung LIST_INSERT_HEAD(&scr->fontset, vf, next);
8571ce9af54Sjunyoung return;
8581ce9af54Sjunyoung }
8591ce9af54Sjunyoung }
8601ce9af54Sjunyoung
861a8c7515fStsutsui cookie = wsfont_find(NULL, 0, scr->type->fontheight, 0,
86256e33f11Smacallan WSDISPLAY_FONTORDER_L2R, 0, WSFONT_FIND_BITMAP);
8631ce9af54Sjunyoung if (cookie == -1)
8641ce9af54Sjunyoung return;
8651ce9af54Sjunyoung
8661ce9af54Sjunyoung if (wsfont_lock(cookie, &wf))
8671ce9af54Sjunyoung return;
8681ce9af54Sjunyoung
869d47bcd29Schs vf = malloc(sizeof(struct vga_raster_font), M_DEVBUF, M_WAITOK);
8701ce9af54Sjunyoung vf->font = wf;
871ef47e3f6Stsutsui scr->encoding = vf->font->encoding;
8721ce9af54Sjunyoung LIST_INSERT_HEAD(&scr->fontset, vf, next);
8731ce9af54Sjunyoung }
8741ce9af54Sjunyoung
875b054bec0Smlelstv static void
vga_setup_regs(struct videomode * mode,struct vga_moderegs * regs)8761ce9af54Sjunyoung vga_setup_regs(struct videomode *mode, struct vga_moderegs *regs)
8771ce9af54Sjunyoung {
8781ce9af54Sjunyoung int i;
8791ce9af54Sjunyoung int depth = 4; /* XXXBJY hardcoded for now */
880289b9289Stsutsui const u_int8_t palette[] = {
8811ce9af54Sjunyoung 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07,
8821ce9af54Sjunyoung 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f
8831ce9af54Sjunyoung };
8841ce9af54Sjunyoung
8851ce9af54Sjunyoung /*
8861ce9af54Sjunyoung * Compute hsync and vsync polarity.
8871ce9af54Sjunyoung */
8881ce9af54Sjunyoung if ((mode->flags & (VID_PHSYNC | VID_NHSYNC))
8891ce9af54Sjunyoung && (mode->flags & (VID_PVSYNC | VID_NVSYNC))) {
8901ce9af54Sjunyoung regs->miscout = 0x23;
8911ce9af54Sjunyoung if (mode->flags & VID_NHSYNC)
8921ce9af54Sjunyoung regs->miscout |= 0x40;
8931ce9af54Sjunyoung if (mode->flags & VID_NVSYNC)
8941ce9af54Sjunyoung regs->miscout |= 0x80;
8951ce9af54Sjunyoung } else {
8961ce9af54Sjunyoung if (mode->flags & VID_DBLSCAN)
8971ce9af54Sjunyoung mode->vdisplay *= 2;
8981ce9af54Sjunyoung if (mode->vdisplay < 400)
8991ce9af54Sjunyoung regs->miscout = 0xa3;
900934e3c5aStsutsui else if (mode->vdisplay < 480)
9011ce9af54Sjunyoung regs->miscout = 0x63;
902934e3c5aStsutsui else if (mode->vdisplay < 768)
9031ce9af54Sjunyoung regs->miscout = 0xe3;
9041ce9af54Sjunyoung else
9051ce9af54Sjunyoung regs->miscout = 0x23;
9061ce9af54Sjunyoung }
9071ce9af54Sjunyoung
9081ce9af54Sjunyoung /*
9091ce9af54Sjunyoung * Time sequencer
9101ce9af54Sjunyoung */
9111ce9af54Sjunyoung if (depth == 4)
9121ce9af54Sjunyoung regs->ts[0] = 0x02;
9131ce9af54Sjunyoung else
9141ce9af54Sjunyoung regs->ts[0] = 0x00;
9151ce9af54Sjunyoung if (mode->flags & VID_CLKDIV2)
9161ce9af54Sjunyoung regs->ts[1] = 0x09;
9171ce9af54Sjunyoung else
9181ce9af54Sjunyoung regs->ts[1] = 0x01;
9191ce9af54Sjunyoung regs->ts[2] = 0x0f;
9201ce9af54Sjunyoung regs->ts[3] = 0x00;
9211ce9af54Sjunyoung if (depth < 8)
9221ce9af54Sjunyoung regs->ts[4] = 0x06;
9231ce9af54Sjunyoung else
9241ce9af54Sjunyoung regs->ts[4] = 0x0e;
9251ce9af54Sjunyoung
9261ce9af54Sjunyoung /*
9271ce9af54Sjunyoung * CRTC controller
9281ce9af54Sjunyoung */
9291ce9af54Sjunyoung regs->crtc[0] = (mode->htotal >> 3) - 5;
9301ce9af54Sjunyoung regs->crtc[1] = (mode->hdisplay >> 3) - 1;
9311ce9af54Sjunyoung regs->crtc[2] = (mode->hsync_start >> 3) - 1;
9321ce9af54Sjunyoung regs->crtc[3] = (((mode->hsync_end >> 3) - 1) & 0x1f) | 0x80;
9331ce9af54Sjunyoung regs->crtc[4] = mode->hsync_start >> 3;
9341ce9af54Sjunyoung regs->crtc[5] = ((((mode->hsync_end >> 3) - 1) & 0x20) << 2)
9351ce9af54Sjunyoung | (((mode->hsync_end >> 3)) & 0x1f);
9361ce9af54Sjunyoung regs->crtc[6] = (mode->vtotal - 2) & 0xff;
9371ce9af54Sjunyoung regs->crtc[7] = (((mode->vtotal - 2) & 0x100) >> 8)
9381ce9af54Sjunyoung | (((mode->vdisplay - 1) & 0x100) >> 7)
9391ce9af54Sjunyoung | ((mode->vsync_start & 0x100) >> 6)
9401ce9af54Sjunyoung | (((mode->vsync_start - 1) & 0x100) >> 5)
9411ce9af54Sjunyoung | 0x10
9421ce9af54Sjunyoung | (((mode->vtotal - 2) & 0x200) >> 4)
9431ce9af54Sjunyoung | (((mode->vdisplay - 1) & 0x200) >> 3)
9441ce9af54Sjunyoung | ((mode->vsync_start & 0x200) >> 2);
9451ce9af54Sjunyoung regs->crtc[8] = 0x00;
9461ce9af54Sjunyoung regs->crtc[9] = (((mode->vsync_start - 1) & 0x200) >> 4) | 0x40;
9471ce9af54Sjunyoung if (mode->flags & VID_DBLSCAN)
9481ce9af54Sjunyoung regs->crtc[9] |= 0x80;
9491ce9af54Sjunyoung regs->crtc[10] = 0x00;
9501ce9af54Sjunyoung regs->crtc[11] = 0x00;
9511ce9af54Sjunyoung regs->crtc[12] = 0x00;
9521ce9af54Sjunyoung regs->crtc[13] = 0x00;
9531ce9af54Sjunyoung regs->crtc[14] = 0x00;
9541ce9af54Sjunyoung regs->crtc[15] = 0x00;
9551ce9af54Sjunyoung regs->crtc[16] = mode->vsync_start & 0xff;
9561ce9af54Sjunyoung regs->crtc[17] = (mode->vsync_end & 0x0f) | 0x20;
9571ce9af54Sjunyoung regs->crtc[18] = (mode->vdisplay - 1) & 0xff;
9581ce9af54Sjunyoung regs->crtc[19] = mode->hdisplay >> 4; /* XXXBJY */
9591ce9af54Sjunyoung regs->crtc[20] = 0x00;
9601ce9af54Sjunyoung regs->crtc[21] = (mode->vsync_start - 1) & 0xff;
9611ce9af54Sjunyoung regs->crtc[22] = (mode->vsync_end - 1) & 0xff;
9621ce9af54Sjunyoung if (depth < 8)
9631ce9af54Sjunyoung regs->crtc[23] = 0xe3;
9641ce9af54Sjunyoung else
9651ce9af54Sjunyoung regs->crtc[23] = 0xc3;
9661ce9af54Sjunyoung regs->crtc[24] = 0xff;
9671ce9af54Sjunyoung
9681ce9af54Sjunyoung /*
9691ce9af54Sjunyoung * Graphics display controller
9701ce9af54Sjunyoung */
9711ce9af54Sjunyoung regs->gdc[0] = 0x00;
9721ce9af54Sjunyoung regs->gdc[1] = 0x00;
9731ce9af54Sjunyoung regs->gdc[2] = 0x00;
9741ce9af54Sjunyoung regs->gdc[3] = 0x00;
9751ce9af54Sjunyoung regs->gdc[4] = 0x00;
9761ce9af54Sjunyoung if (depth == 4)
9771ce9af54Sjunyoung regs->gdc[5] = 0x02;
9781ce9af54Sjunyoung else
9791ce9af54Sjunyoung regs->gdc[5] = 0x40;
9801ce9af54Sjunyoung regs->gdc[6] = 0x01;
9811ce9af54Sjunyoung regs->gdc[7] = 0x0f;
9821ce9af54Sjunyoung regs->gdc[8] = 0xff;
9831ce9af54Sjunyoung
9841ce9af54Sjunyoung /*
9851ce9af54Sjunyoung * Attribute controller
9861ce9af54Sjunyoung */
9871ce9af54Sjunyoung /* Set palette registers. */
9881ce9af54Sjunyoung for (i = 0; i < 16; i++)
9891ce9af54Sjunyoung regs->atc[i] = palette[i];
9901ce9af54Sjunyoung if (depth == 4)
9911ce9af54Sjunyoung regs->atc[16] = 0x01; /* XXXBJY was 0x81 in XFree86 */
9921ce9af54Sjunyoung else
9931ce9af54Sjunyoung regs->atc[16] = 0x41;
9941ce9af54Sjunyoung regs->atc[17] = 0x00; /* XXXBJY just a guess */
9951ce9af54Sjunyoung regs->atc[18] = 0x0f;
9961ce9af54Sjunyoung regs->atc[19] = 0x00;
9971ce9af54Sjunyoung regs->atc[20] = 0x00;
9981ce9af54Sjunyoung }
9991ce9af54Sjunyoung
1000b054bec0Smlelstv static void
vga_set_mode(struct vga_handle * vh,struct vga_moderegs * regs)10011ce9af54Sjunyoung vga_set_mode(struct vga_handle *vh, struct vga_moderegs *regs)
10021ce9af54Sjunyoung {
10031ce9af54Sjunyoung int i;
10041ce9af54Sjunyoung
10051ce9af54Sjunyoung /* Disable display. */
100689b4d622Stsutsui vga_ts_write(vh, mode, vga_ts_read(vh, mode) | VGA_TS_MODE_BLANK);
10071ce9af54Sjunyoung
10081ce9af54Sjunyoung /* Write misc output register. */
10091ce9af54Sjunyoung bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_MISC_DATAW,
10101ce9af54Sjunyoung regs->miscout);
10111ce9af54Sjunyoung
10121ce9af54Sjunyoung /* Set synchronous reset. */
10131ce9af54Sjunyoung vga_ts_write(vh, syncreset, 0x01);
101489b4d622Stsutsui vga_ts_write(vh, mode, regs->ts[1] | VGA_TS_MODE_BLANK);
10151ce9af54Sjunyoung for (i = 2; i < VGA_TS_NREGS; i++)
10161ce9af54Sjunyoung _vga_ts_write(vh, i, regs->ts[i]);
10171ce9af54Sjunyoung /* Clear synchronous reset. */
10181ce9af54Sjunyoung vga_ts_write(vh, syncreset, 0x03);
10191ce9af54Sjunyoung
10201ce9af54Sjunyoung /* Unprotect CRTC registers 0-7. */
102189b4d622Stsutsui vga_6845_write(vh, vsynce, vga_6845_read(vh, vsynce) & ~0x80);
10221ce9af54Sjunyoung /* Write CRTC registers. */
102389b4d622Stsutsui for (i = 0; i < MC6845_NREGS; i++)
102489b4d622Stsutsui _vga_6845_write(vh, i, regs->crtc[i]);
10251ce9af54Sjunyoung
10261ce9af54Sjunyoung /* Write graphics display registers. */
10271ce9af54Sjunyoung for (i = 0; i < VGA_GDC_NREGS; i++)
10281ce9af54Sjunyoung _vga_gdc_write(vh, i, regs->gdc[i]);
10291ce9af54Sjunyoung
10301ce9af54Sjunyoung /* Write attribute controller registers. */
10311ce9af54Sjunyoung for (i = 0; i < VGA_ATC_NREGS; i++)
10321ce9af54Sjunyoung _vga_attr_write(vh, i, regs->atc[i]);
10331ce9af54Sjunyoung
10341ce9af54Sjunyoung /* Enable display. */
103589b4d622Stsutsui vga_ts_write(vh, mode, vga_ts_read(vh, mode) & ~VGA_TS_MODE_BLANK);
10361ce9af54Sjunyoung }
10371ce9af54Sjunyoung
1038b054bec0Smlelstv static void
vga_raster_cursor_init(struct vgascreen * scr,int existing)10391ce9af54Sjunyoung vga_raster_cursor_init(struct vgascreen *scr, int existing)
10401ce9af54Sjunyoung {
10411ce9af54Sjunyoung int off;
10421ce9af54Sjunyoung
10431ce9af54Sjunyoung if (existing) {
10441ce9af54Sjunyoung /*
10451ce9af54Sjunyoung * This is the first screen. At this point, scr->active is
10461ce9af54Sjunyoung * false, so we can't use vga_raster_cursor() to do this.
10471ce9af54Sjunyoung */
10481ce9af54Sjunyoung off = (scr->cursorrow * scr->type->ncols + scr->cursorcol) +
10491ce9af54Sjunyoung scr->dispoffset / 8;
10501ce9af54Sjunyoung
10511ce9af54Sjunyoung scr->cursortmp = scr->mem[off];
10521ce9af54Sjunyoung vga_raster_putchar(scr, scr->cursorrow, scr->cursorcol,
10531ce9af54Sjunyoung scr->cursortmp.ch, scr->cursortmp.attr ^ 0x77);
10541ce9af54Sjunyoung } else {
10551ce9af54Sjunyoung scr->cursortmp.ch = 0;
10561ce9af54Sjunyoung scr->cursortmp.attr = 0;
10571ce9af54Sjunyoung scr->cursortmp.second = 0;
1058ef47e3f6Stsutsui scr->cursortmp.enc = scr->encoding;
10591ce9af54Sjunyoung }
10601ce9af54Sjunyoung
10611ce9af54Sjunyoung scr->cursoron = 1;
10621ce9af54Sjunyoung }
10631ce9af54Sjunyoung
1064b054bec0Smlelstv static void
vga_raster_cursor(void * id,int on,int row,int col)10651ce9af54Sjunyoung vga_raster_cursor(void *id, int on, int row, int col)
10661ce9af54Sjunyoung {
10671ce9af54Sjunyoung struct vgascreen *scr = id;
10681ce9af54Sjunyoung int off, tmp;
10691ce9af54Sjunyoung
10701ce9af54Sjunyoung /* Remove old cursor image */
10711ce9af54Sjunyoung if (scr->cursoron) {
10721ce9af54Sjunyoung off = scr->cursorrow * scr->type->ncols + scr->cursorcol;
10731ce9af54Sjunyoung if (scr->active) {
10741ce9af54Sjunyoung tmp = scr->encoding;
10751ce9af54Sjunyoung scr->encoding = scr->cursortmp.enc;
10761ce9af54Sjunyoung if (scr->cursortmp.second)
10771ce9af54Sjunyoung vga_raster_putchar(id, scr->cursorrow,
10781ce9af54Sjunyoung scr->cursorcol - 1, scr->cursortmp.ch,
10791ce9af54Sjunyoung scr->cursortmp.attr);
10801ce9af54Sjunyoung else
10811ce9af54Sjunyoung vga_raster_putchar(id, scr->cursorrow,
10821ce9af54Sjunyoung scr->cursorcol, scr->cursortmp.ch,
10831ce9af54Sjunyoung scr->cursortmp.attr);
10841ce9af54Sjunyoung scr->encoding = tmp;
10851ce9af54Sjunyoung }
10861ce9af54Sjunyoung }
10871ce9af54Sjunyoung
10881ce9af54Sjunyoung scr->cursorrow = row;
10891ce9af54Sjunyoung scr->cursorcol = col;
10901ce9af54Sjunyoung
10911ce9af54Sjunyoung if ((scr->cursoron = on) == 0)
10921ce9af54Sjunyoung return;
10931ce9af54Sjunyoung
10941ce9af54Sjunyoung off = scr->cursorrow * scr->type->ncols + scr->cursorcol;
10951ce9af54Sjunyoung scr->cursortmp = scr->mem[off];
10961ce9af54Sjunyoung if (scr->active) {
10971ce9af54Sjunyoung tmp = scr->encoding;
10981ce9af54Sjunyoung scr->encoding = scr->cursortmp.enc;
10991ce9af54Sjunyoung if (scr->cursortmp.second)
11001ce9af54Sjunyoung vga_raster_putchar(id, scr->cursorrow,
11011ce9af54Sjunyoung scr->cursorcol - 1, scr->cursortmp.ch,
11021ce9af54Sjunyoung scr->cursortmp.attr ^ 0x77);
11031ce9af54Sjunyoung else
11041ce9af54Sjunyoung vga_raster_putchar(id, scr->cursorrow,
11051ce9af54Sjunyoung scr->cursorcol, scr->cursortmp.ch,
11061ce9af54Sjunyoung scr->cursortmp.attr ^ 0x77);
11071ce9af54Sjunyoung scr->encoding = tmp;
11081ce9af54Sjunyoung }
11091ce9af54Sjunyoung }
11101ce9af54Sjunyoung
11111ce9af54Sjunyoung static int
vga_raster_mapchar(void * id,int uni,u_int * index)11121ce9af54Sjunyoung vga_raster_mapchar(void *id, int uni, u_int *index)
11131ce9af54Sjunyoung {
11141ce9af54Sjunyoung struct vgascreen *scr = id;
11151ce9af54Sjunyoung
11161ce9af54Sjunyoung if (scr->encoding == WSDISPLAY_FONTENC_IBM)
11171ce9af54Sjunyoung return pcdisplay_mapchar(id, uni, index);
11181ce9af54Sjunyoung else {
11191ce9af54Sjunyoung *index = uni;
11201ce9af54Sjunyoung return 5;
11211ce9af54Sjunyoung }
11221ce9af54Sjunyoung }
11231ce9af54Sjunyoung
1124b054bec0Smlelstv static void
vga_raster_putchar(void * id,int row,int col,u_int c,long attr)11251ce9af54Sjunyoung vga_raster_putchar(void *id, int row, int col, u_int c, long attr)
11261ce9af54Sjunyoung {
11271ce9af54Sjunyoung struct vgascreen *scr = id;
112805619021Smjf size_t off;
11291ce9af54Sjunyoung struct vga_raster_font *fs;
11301ce9af54Sjunyoung u_int tmp_ch;
11311ce9af54Sjunyoung
11321ce9af54Sjunyoung off = row * scr->type->ncols + col;
11331ce9af54Sjunyoung
113405619021Smjf if (__predict_false(off >= (scr->type->ncols * scr->type->nrows)))
113505619021Smjf return;
113605619021Smjf
11371ce9af54Sjunyoung LIST_FOREACH(fs, &scr->fontset, next) {
11381ce9af54Sjunyoung if ((scr->encoding == fs->font->encoding) &&
11391ce9af54Sjunyoung (c >= fs->font->firstchar) &&
11401ce9af54Sjunyoung (c < fs->font->firstchar + fs->font->numchars) &&
11411ce9af54Sjunyoung (scr->type->fontheight == fs->font->fontheight)) {
11421ce9af54Sjunyoung if (scr->active) {
11431ce9af54Sjunyoung tmp_ch = c - fs->font->firstchar;
11441ce9af54Sjunyoung _vga_raster_putchar(scr, row, col, tmp_ch,
11451ce9af54Sjunyoung attr, fs);
11461ce9af54Sjunyoung }
11471ce9af54Sjunyoung
11481ce9af54Sjunyoung scr->mem[off].ch = c;
11491ce9af54Sjunyoung scr->mem[off].attr = attr;
11501ce9af54Sjunyoung scr->mem[off].second = 0;
11511ce9af54Sjunyoung scr->mem[off].enc = fs->font->encoding;
11521ce9af54Sjunyoung
11531ce9af54Sjunyoung if (fs->font->stride == 2) {
11541ce9af54Sjunyoung scr->mem[off + 1].ch = c;
11551ce9af54Sjunyoung scr->mem[off + 1].attr = attr;
11561ce9af54Sjunyoung scr->mem[off + 1].second = 1;
11571ce9af54Sjunyoung scr->mem[off + 1].enc = fs->font->encoding;
11581ce9af54Sjunyoung }
11591ce9af54Sjunyoung
11601ce9af54Sjunyoung return;
11611ce9af54Sjunyoung }
11621ce9af54Sjunyoung }
11631ce9af54Sjunyoung
11641ce9af54Sjunyoung /*
11651ce9af54Sjunyoung * No match found.
11661ce9af54Sjunyoung */
11671ce9af54Sjunyoung if (scr->active)
1168a8c7515fStsutsui /*
1169a8c7515fStsutsui * Put a single width space character no matter what the
1170a8c7515fStsutsui * actual width of the character is.
1171a8c7515fStsutsui */
117289b4d622Stsutsui _vga_raster_putchar(scr, row, col, ' ', attr,
11731ce9af54Sjunyoung &vga_console_fontset_ascii);
11741ce9af54Sjunyoung scr->mem[off].ch = c;
11751ce9af54Sjunyoung scr->mem[off].attr = attr;
11761ce9af54Sjunyoung scr->mem[off].second = 0;
1177ef47e3f6Stsutsui scr->mem[off].enc = scr->encoding;
11781ce9af54Sjunyoung }
11791ce9af54Sjunyoung
11801ce9af54Sjunyoung static void
_vga_raster_putchar(void * id,int row,int col,u_int c,long attr,struct vga_raster_font * fs)11811ce9af54Sjunyoung _vga_raster_putchar(void *id, int row, int col, u_int c, long attr,
11821ce9af54Sjunyoung struct vga_raster_font *fs)
11831ce9af54Sjunyoung {
11841ce9af54Sjunyoung struct vgascreen *scr = id;
11851ce9af54Sjunyoung struct vga_handle *vh = scr->hdl;
11861ce9af54Sjunyoung bus_space_tag_t memt = vh->vh_memt;
11871ce9af54Sjunyoung bus_space_handle_t memh = vh->vh_memh;
11881ce9af54Sjunyoung int i;
11891ce9af54Sjunyoung int rasoff, rasoff2;
11901ce9af54Sjunyoung int fheight = scr->type->fontheight;
11915d7b5c8eSmlelstv volatile u_int8_t pattern;
11921ce9af54Sjunyoung u_int8_t fgcolor, bgcolor;
11931ce9af54Sjunyoung
11941ce9af54Sjunyoung rasoff = scr->dispoffset + row * scr->type->ncols * fheight + col;
11951ce9af54Sjunyoung rasoff2 = rasoff;
11961ce9af54Sjunyoung
11971ce9af54Sjunyoung #if 0
11981ce9af54Sjunyoung bgcolor = bgansitopc[attr >> 4];
11991ce9af54Sjunyoung fgcolor = fgansitopc[attr & 0x0f];
12001ce9af54Sjunyoung #else
12011ce9af54Sjunyoung bgcolor = ((attr >> 4) & 0x0f);
12021ce9af54Sjunyoung fgcolor = attr & 0x0f;
12031ce9af54Sjunyoung #endif
12041ce9af54Sjunyoung
12051ce9af54Sjunyoung if (fs->font->stride == 1) {
12061ce9af54Sjunyoung /* Paint background. */
12071ce9af54Sjunyoung vga_gdc_write(vh, mode, 0x02);
12081ce9af54Sjunyoung for (i = 0; i < fheight; i++) {
12091ce9af54Sjunyoung bus_space_write_1(memt, memh, rasoff, bgcolor);
12101ce9af54Sjunyoung rasoff += scr->type->ncols;
12111ce9af54Sjunyoung }
12121ce9af54Sjunyoung
12131ce9af54Sjunyoung /* Draw a single width character. */
12141ce9af54Sjunyoung vga_gdc_write(vh, mode, 0x03);
12151ce9af54Sjunyoung vga_gdc_write(vh, setres, fgcolor);
12161ce9af54Sjunyoung for (i = 0; i < fheight; i++) {
12171ce9af54Sjunyoung pattern = ((u_int8_t *)fs->font->data)[c * fheight + i];
12181ce9af54Sjunyoung /* When pattern is 0, skip output for speed-up. */
12191ce9af54Sjunyoung if (pattern != 0) {
12205d7b5c8eSmlelstv bus_space_read_1(memt, memh, rasoff2);
12211ce9af54Sjunyoung bus_space_write_1(memt, memh, rasoff2, pattern);
12221ce9af54Sjunyoung }
12231ce9af54Sjunyoung rasoff2 += scr->type->ncols;
12241ce9af54Sjunyoung }
12251ce9af54Sjunyoung } else if (fs->font->stride == 2) {
12261ce9af54Sjunyoung /* Paint background. */
12271ce9af54Sjunyoung vga_gdc_write(vh, mode, 0x02);
12281ce9af54Sjunyoung for (i = 0; i < fheight; i++) {
12291ce9af54Sjunyoung bus_space_write_1(memt, memh, rasoff, bgcolor);
12301ce9af54Sjunyoung bus_space_write_1(memt, memh, rasoff + 1, bgcolor);
12311ce9af54Sjunyoung rasoff += scr->type->ncols;
12321ce9af54Sjunyoung }
12331ce9af54Sjunyoung
12341ce9af54Sjunyoung /* Draw a double width character. */
12351ce9af54Sjunyoung vga_gdc_write(vh, mode, 0x03);
12361ce9af54Sjunyoung vga_gdc_write(vh, setres, fgcolor);
12371ce9af54Sjunyoung for (i = 0; i < fheight; i++) {
12381ce9af54Sjunyoung pattern = ((u_int8_t *)fs->font->data)
12391ce9af54Sjunyoung [(c * fheight + i) * 2];
12401ce9af54Sjunyoung if (pattern != 0) {
12415d7b5c8eSmlelstv bus_space_read_1(memt, memh, rasoff2);
12421ce9af54Sjunyoung bus_space_write_1(memt, memh, rasoff2, pattern);
12431ce9af54Sjunyoung }
12441ce9af54Sjunyoung pattern = ((u_int8_t *)fs->font->data)
12451ce9af54Sjunyoung [(c * fheight + i) * 2 + 1];
12461ce9af54Sjunyoung if (pattern != 0) {
12471ce9af54Sjunyoung rasoff2++;
12485d7b5c8eSmlelstv bus_space_read_1(memt, memh, rasoff2);
12491ce9af54Sjunyoung bus_space_write_1(memt, memh, rasoff2, pattern);
12501ce9af54Sjunyoung rasoff2--;
12511ce9af54Sjunyoung }
12521ce9af54Sjunyoung rasoff2 += scr->type->ncols;
12531ce9af54Sjunyoung }
12541ce9af54Sjunyoung }
12551ce9af54Sjunyoung }
12561ce9af54Sjunyoung
1257b054bec0Smlelstv static void
vga_raster_copycols(void * id,int row,int srccol,int dstcol,int ncols)12581ce9af54Sjunyoung vga_raster_copycols(void *id, int row, int srccol, int dstcol, int ncols)
12591ce9af54Sjunyoung {
12601ce9af54Sjunyoung struct vgascreen *scr = id;
12611ce9af54Sjunyoung struct vga_handle *vh = scr->hdl;
12621ce9af54Sjunyoung bus_space_tag_t memt = vh->vh_memt;
12631ce9af54Sjunyoung bus_space_handle_t memh = vh->vh_memh;
12641ce9af54Sjunyoung bus_size_t srcoff, dstoff;
12651ce9af54Sjunyoung bus_size_t rassrcoff, rasdstoff;
12661ce9af54Sjunyoung int i;
12671ce9af54Sjunyoung int fheight = scr->type->fontheight;
12681ce9af54Sjunyoung
12691ce9af54Sjunyoung srcoff = row * scr->type->ncols + srccol;
12701ce9af54Sjunyoung dstoff = row * scr->type->ncols + dstcol;
12711ce9af54Sjunyoung rassrcoff = scr->dispoffset + row * scr->type->ncols * fheight + srccol;
12721ce9af54Sjunyoung rasdstoff = scr->dispoffset + row * scr->type->ncols * fheight + dstcol;
12731ce9af54Sjunyoung
12741ce9af54Sjunyoung memcpy(&scr->mem[dstoff], &scr->mem[srcoff],
12751ce9af54Sjunyoung ncols * sizeof(struct vga_scrmem));
12761ce9af54Sjunyoung
12771ce9af54Sjunyoung vga_gdc_write(vh, mode, 0x01);
12781ce9af54Sjunyoung if (scr->active) {
12791ce9af54Sjunyoung for (i = 0; i < fheight; i++) {
12801ce9af54Sjunyoung bus_space_copy_region_1(memt, memh,
12811ce9af54Sjunyoung rassrcoff + i * scr->type->ncols, memh,
12821ce9af54Sjunyoung rasdstoff + i * scr->type->ncols, ncols);
12831ce9af54Sjunyoung }
12841ce9af54Sjunyoung }
12851ce9af54Sjunyoung }
12861ce9af54Sjunyoung
1287b054bec0Smlelstv static void
vga_raster_erasecols(void * id,int row,int startcol,int ncols,long fillattr)12881ce9af54Sjunyoung vga_raster_erasecols(void *id, int row, int startcol, int ncols, long fillattr)
12891ce9af54Sjunyoung {
12901ce9af54Sjunyoung struct vgascreen *scr = id;
12911ce9af54Sjunyoung int i;
12921ce9af54Sjunyoung
12931ce9af54Sjunyoung if (scr->active == 0)
12941ce9af54Sjunyoung return;
12951ce9af54Sjunyoung
12961ce9af54Sjunyoung for (i = startcol; i < startcol + ncols; i++)
12971ce9af54Sjunyoung vga_raster_putchar(id, row, i, ' ', fillattr);
12981ce9af54Sjunyoung }
12991ce9af54Sjunyoung
1300b054bec0Smlelstv static void
vga_raster_copyrows(void * id,int srcrow,int dstrow,int nrows)13011ce9af54Sjunyoung vga_raster_copyrows(void *id, int srcrow, int dstrow, int nrows)
13021ce9af54Sjunyoung {
13031ce9af54Sjunyoung struct vgascreen *scr = id;
13041ce9af54Sjunyoung struct vga_handle *vh = scr->hdl;
13051ce9af54Sjunyoung bus_space_tag_t memt = vh->vh_memt;
13061ce9af54Sjunyoung bus_space_handle_t memh = vh->vh_memh;
13071ce9af54Sjunyoung int ncols;
13081ce9af54Sjunyoung bus_size_t srcoff, dstoff;
13091ce9af54Sjunyoung bus_size_t rassrcoff, rasdstoff;
13101ce9af54Sjunyoung int fheight;
13111ce9af54Sjunyoung
13121ce9af54Sjunyoung ncols = scr->type->ncols;
13131ce9af54Sjunyoung fheight = scr->type->fontheight;
13141ce9af54Sjunyoung
13151ce9af54Sjunyoung srcoff = srcrow * ncols;
13161ce9af54Sjunyoung dstoff = dstrow * ncols;
13171ce9af54Sjunyoung rassrcoff = srcoff * fheight;
13181ce9af54Sjunyoung rasdstoff = dstoff * fheight;
13191ce9af54Sjunyoung
13201ce9af54Sjunyoung if (scr->active) {
13211ce9af54Sjunyoung vga_gdc_write(vh, mode, 0x01);
13221ce9af54Sjunyoung if (dstrow == 0 && (srcrow + nrows == scr->type->nrows)) {
13231ce9af54Sjunyoung int cursoron = scr->cursoron;
13241ce9af54Sjunyoung
13251ce9af54Sjunyoung if (cursoron)
13261ce9af54Sjunyoung /* Disable cursor. */
13271ce9af54Sjunyoung vga_raster_cursor(scr, 0,
13281ce9af54Sjunyoung scr->cursorrow, scr->cursorcol);
13291ce9af54Sjunyoung
13301ce9af54Sjunyoung /* scroll up whole screen */
13311ce9af54Sjunyoung if ((scr->dispoffset + srcrow * ncols * fheight)
13321ce9af54Sjunyoung <= scr->maxdispoffset)
13331ce9af54Sjunyoung scr->dispoffset += srcrow * ncols * fheight;
13341ce9af54Sjunyoung else {
13351ce9af54Sjunyoung bus_space_copy_region_1(memt, memh,
13361ce9af54Sjunyoung scr->dispoffset + rassrcoff,
13371ce9af54Sjunyoung memh, scr->mindispoffset,
13381ce9af54Sjunyoung nrows * ncols * fheight);
13391ce9af54Sjunyoung scr->dispoffset = scr->mindispoffset;
13401ce9af54Sjunyoung }
13411ce9af54Sjunyoung vga_6845_write(vh, startadrh, scr->dispoffset >> 8);
13421ce9af54Sjunyoung vga_6845_write(vh, startadrl, scr->dispoffset);
13431ce9af54Sjunyoung
13441ce9af54Sjunyoung if (cursoron)
13451ce9af54Sjunyoung /* Enable cursor. */
13461ce9af54Sjunyoung vga_raster_cursor(scr, 1, scr->cursorrow,
13471ce9af54Sjunyoung scr->cursorcol);
13481ce9af54Sjunyoung } else
13491ce9af54Sjunyoung bus_space_copy_region_1(memt, memh,
13501ce9af54Sjunyoung scr->dispoffset + rassrcoff, memh,
13511ce9af54Sjunyoung scr->dispoffset + rasdstoff,
13521ce9af54Sjunyoung nrows * ncols * fheight);
13531ce9af54Sjunyoung }
13541ce9af54Sjunyoung memcpy(&scr->mem[dstoff], &scr->mem[srcoff],
13551ce9af54Sjunyoung nrows * ncols * sizeof(struct vga_scrmem));
13561ce9af54Sjunyoung }
13571ce9af54Sjunyoung
1358b054bec0Smlelstv static void
vga_raster_eraserows(void * id,int startrow,int nrows,long fillattr)13591ce9af54Sjunyoung vga_raster_eraserows(void *id, int startrow, int nrows, long fillattr)
13601ce9af54Sjunyoung {
13611ce9af54Sjunyoung struct vgascreen *scr = id;
13621ce9af54Sjunyoung struct vga_handle *vh = scr->hdl;
13631ce9af54Sjunyoung bus_space_tag_t memt = vh->vh_memt;
13641ce9af54Sjunyoung bus_space_handle_t memh = vh->vh_memh;
13651ce9af54Sjunyoung bus_size_t off, count;
13661ce9af54Sjunyoung bus_size_t rasoff, rascount;
13671ce9af54Sjunyoung int i;
13681ce9af54Sjunyoung
13691ce9af54Sjunyoung off = startrow * scr->type->ncols;
13701ce9af54Sjunyoung count = nrows * scr->type->ncols;
13711ce9af54Sjunyoung rasoff = off * scr->type->fontheight;
13721ce9af54Sjunyoung rascount = count * scr->type->fontheight;
13731ce9af54Sjunyoung
13741ce9af54Sjunyoung if (scr->active) {
13751dea55ccSjmmv u_int8_t bgcolor = (fillattr >> 4) & 0x0F;
13761dea55ccSjmmv
13771ce9af54Sjunyoung /* Paint background. */
13781ce9af54Sjunyoung vga_gdc_write(vh, mode, 0x02);
13791dea55ccSjmmv if (scr->type->ncols % 4 == 0) {
13801dea55ccSjmmv u_int32_t fill = bgcolor | (bgcolor << 8) |
13811dea55ccSjmmv (bgcolor << 16) | (bgcolor << 24);
13821ce9af54Sjunyoung /* We can speed up I/O */
13831ce9af54Sjunyoung for (i = rasoff; i < rasoff + rascount; i += 4)
13841ce9af54Sjunyoung bus_space_write_4(memt, memh,
13851dea55ccSjmmv scr->dispoffset + i, fill);
13861dea55ccSjmmv } else {
13871dea55ccSjmmv u_int16_t fill = bgcolor | (bgcolor << 8);
13881ce9af54Sjunyoung for (i = rasoff; i < rasoff + rascount; i += 2)
13891ce9af54Sjunyoung bus_space_write_2(memt, memh,
13901dea55ccSjmmv scr->dispoffset + i, fill);
13911dea55ccSjmmv }
13921ce9af54Sjunyoung }
13931ce9af54Sjunyoung for (i = 0; i < count; i++) {
13941ce9af54Sjunyoung scr->mem[off + i].ch = ' ';
13951ce9af54Sjunyoung scr->mem[off + i].attr = fillattr;
13961ce9af54Sjunyoung scr->mem[off + i].second = 0;
1397ef47e3f6Stsutsui scr->mem[off + i].enc = scr->encoding;
13981ce9af54Sjunyoung }
13991ce9af54Sjunyoung }
14001ce9af54Sjunyoung
14011ce9af54Sjunyoung static int
vga_raster_allocattr(void * id,int fg,int bg,int flags,long * attrp)14021ce9af54Sjunyoung vga_raster_allocattr(void *id, int fg, int bg, int flags, long *attrp)
14031ce9af54Sjunyoung {
14041ce9af54Sjunyoung struct vgascreen *scr = id;
14051ce9af54Sjunyoung struct vga_config *vc = scr->cfg;
14061ce9af54Sjunyoung
140705619021Smjf if (__predict_false((unsigned int)fg >= sizeof(fgansitopc) ||
140805619021Smjf (unsigned int)bg >= sizeof(bgansitopc)))
140905619021Smjf return (EINVAL);
141005619021Smjf
14111ce9af54Sjunyoung if (vc->hdl.vh_mono) {
14121ce9af54Sjunyoung if (flags & WSATTR_WSCOLORS)
14131ce9af54Sjunyoung return (EINVAL);
14141ce9af54Sjunyoung if (flags & WSATTR_REVERSE)
14151ce9af54Sjunyoung *attrp = 0x70;
14161ce9af54Sjunyoung else
14171ce9af54Sjunyoung *attrp = 0x07;
14181ce9af54Sjunyoung if (flags & WSATTR_UNDERLINE)
14191ce9af54Sjunyoung *attrp |= FG_UNDERLINE;
14201ce9af54Sjunyoung if (flags & WSATTR_HILIT)
14211ce9af54Sjunyoung *attrp |= FG_INTENSE;
14221ce9af54Sjunyoung } else {
14231ce9af54Sjunyoung if (flags & (WSATTR_UNDERLINE | WSATTR_REVERSE))
14241ce9af54Sjunyoung return (EINVAL);
14251ce9af54Sjunyoung if (flags & WSATTR_WSCOLORS)
14261ce9af54Sjunyoung *attrp = fgansitopc[fg] | bgansitopc[bg];
14271ce9af54Sjunyoung else
14281ce9af54Sjunyoung *attrp = 7;
14291ce9af54Sjunyoung if (flags & WSATTR_HILIT)
14301ce9af54Sjunyoung *attrp += 8;
14311ce9af54Sjunyoung }
14321ce9af54Sjunyoung if (flags & WSATTR_BLINK)
14331ce9af54Sjunyoung *attrp |= FG_BLINK;
14341ce9af54Sjunyoung return (0);
14351ce9af54Sjunyoung }
14361ce9af54Sjunyoung
1437b054bec0Smlelstv static void
vga_restore_screen(struct vgascreen * scr,const struct wsscreen_descr * type,struct vga_scrmem * mem)14381ce9af54Sjunyoung vga_restore_screen(struct vgascreen *scr,
14391ce9af54Sjunyoung const struct wsscreen_descr *type, struct vga_scrmem *mem)
14401ce9af54Sjunyoung {
14411ce9af54Sjunyoung int i, j, off, tmp;
14421ce9af54Sjunyoung
14431ce9af54Sjunyoung tmp = scr->encoding;
14441ce9af54Sjunyoung for (i = 0; i < type->nrows; i++) {
14451ce9af54Sjunyoung for (j = 0; j < type->ncols; j++) {
14461ce9af54Sjunyoung off = i * type->ncols + j;
14471ce9af54Sjunyoung if (mem[off].second != 1) {
14481ce9af54Sjunyoung scr->encoding = mem[off].enc;
14491ce9af54Sjunyoung vga_raster_putchar(scr, i, j, mem[off].ch,
14501ce9af54Sjunyoung mem[off].attr);
14511ce9af54Sjunyoung }
14521ce9af54Sjunyoung }
14531ce9af54Sjunyoung }
14541ce9af54Sjunyoung scr->encoding = tmp;
14551ce9af54Sjunyoung }
14561ce9af54Sjunyoung
1457b054bec0Smlelstv static void
vga_raster_setscreentype(struct vga_config * vc,const struct wsscreen_descr * type)14581ce9af54Sjunyoung vga_raster_setscreentype(struct vga_config *vc,
14591ce9af54Sjunyoung const struct wsscreen_descr *type)
14601ce9af54Sjunyoung {
14611ce9af54Sjunyoung struct vga_handle *vh = &vc->hdl;
146278e97058Sjunyoung struct vga_moderegs moderegs;
14631ce9af54Sjunyoung
146478e97058Sjunyoung vga_setup_regs((struct videomode *)type->modecookie, &moderegs);
14651ce9af54Sjunyoung vga_set_mode(vh, &moderegs);
14661ce9af54Sjunyoung }
14679a001938Sjmmv
14689a001938Sjmmv #ifdef WSDISPLAY_CUSTOM_OUTPUT
1469b054bec0Smlelstv static void
vga_raster_replaceattr(void * id,long oldattr,long newattr)14709a001938Sjmmv vga_raster_replaceattr(void *id, long oldattr, long newattr)
14719a001938Sjmmv {
14729a001938Sjmmv struct vgascreen *scr = id;
14739a001938Sjmmv const struct wsscreen_descr *type = scr->type;
14749a001938Sjmmv int off;
14759a001938Sjmmv
14769a001938Sjmmv for (off = 0; off < type->nrows * type->ncols; off++) {
14779a001938Sjmmv if (scr->mem[off].attr == oldattr)
14789a001938Sjmmv scr->mem[off].attr = newattr;
14799a001938Sjmmv }
14809a001938Sjmmv
14819a001938Sjmmv /* Repaint the whole screen, if needed */
14829a001938Sjmmv if (scr->active)
14839a001938Sjmmv vga_restore_screen(scr, type, scr->mem);
14849a001938Sjmmv }
14859a001938Sjmmv #endif /* WSDISPLAY_CUSTOM_OUTPUT */
148684993899Snonaka
148784993899Snonaka void
vga_resume(struct vga_softc * sc)148884993899Snonaka vga_resume(struct vga_softc *sc)
148984993899Snonaka {
149084993899Snonaka #ifdef VGA_RESET_ON_RESUME
149184993899Snonaka vga_initregs(&sc->sc_vc->hdl);
149284993899Snonaka #endif
149384993899Snonaka }
1494