1fc1821feSrugrat /*
2fc1821feSrugrat * CDDL HEADER START
3fc1821feSrugrat *
4fc1821feSrugrat * The contents of this file are subject to the terms of the
54ab75253Smrj * Common Development and Distribution License (the "License").
64ab75253Smrj * You may not use this file except in compliance with the License.
7fc1821feSrugrat *
8fc1821feSrugrat * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fc1821feSrugrat * or http://www.opensolaris.org/os/licensing.
10fc1821feSrugrat * See the License for the specific language governing permissions
11fc1821feSrugrat * and limitations under the License.
12fc1821feSrugrat *
13fc1821feSrugrat * When distributing Covered Code, include this CDDL HEADER in each
14fc1821feSrugrat * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fc1821feSrugrat * If applicable, add the following below this CDDL HEADER, with the
16fc1821feSrugrat * fields enclosed by brackets "[]" replaced with your own identifying
17fc1821feSrugrat * information: Portions Copyright [yyyy] [name of copyright owner]
18fc1821feSrugrat *
19fc1821feSrugrat * CDDL HEADER END
20fc1821feSrugrat */
214ab75253Smrj
22fc1821feSrugrat /*
2393a18d6dSEnrico Perla - Sun Microsystems * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24fc1821feSrugrat * Use is subject to license terms.
25fc1821feSrugrat */
26fc1821feSrugrat
27f67ca41aSrugrat /* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
28f67ca41aSrugrat /* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T */
293ef9594aSToomas Soome /* All Rights Reserved */
30f67ca41aSrugrat
31fc1821feSrugrat #include <sys/errno.h>
32fc1821feSrugrat #include <sys/types.h>
33fc1821feSrugrat #include <sys/conf.h>
34fc1821feSrugrat #include <sys/kmem.h>
35fc1821feSrugrat #include <sys/visual_io.h>
36fc1821feSrugrat #include <sys/font.h>
37fc1821feSrugrat #include <sys/fbio.h>
38fc1821feSrugrat #include <sys/ddi.h>
39fc1821feSrugrat #include <sys/stat.h>
40fc1821feSrugrat #include <sys/sunddi.h>
41fc1821feSrugrat #include <sys/open.h>
42fc1821feSrugrat #include <sys/modctl.h>
43fc1821feSrugrat #include <sys/pci.h>
44fc1821feSrugrat #include <sys/kd.h>
45fc1821feSrugrat #include <sys/ddi_impldefs.h>
46dc1b2691SGordon Ross #include <sys/gfx_private.h>
47cbc8e155SToomas Soome #include <sys/vgareg.h>
4830165b7fSToomas Soome #include "gfxp_fb.h"
49fc1821feSrugrat
50fc1821feSrugrat #define MYNAME "gfxp_vgatext"
51fc1821feSrugrat
52fc1821feSrugrat static ddi_device_acc_attr_t dev_attr = {
53fc1821feSrugrat DDI_DEVICE_ATTR_V0,
54fc1821feSrugrat DDI_NEVERSWAP_ACC,
55fc1821feSrugrat DDI_STRICTORDER_ACC,
56fc1821feSrugrat };
57fc1821feSrugrat
58fc1821feSrugrat /* default structure for FBIOGATTR ioctl */
59fc1821feSrugrat static struct fbgattr vgatext_attr = {
60fc1821feSrugrat /* real_type owner */
61fc1821feSrugrat FBTYPE_SUNFAST_COLOR, 0,
62fc1821feSrugrat /* fbtype: type h w depth cms size */
6382bb7c22SToomas Soome { FBTYPE_SUNFAST_COLOR, VGA_TEXT_ROWS, VGA_TEXT_COLS, 1, 256, 0 },
64fc1821feSrugrat /* fbsattr: flags emu_type dev_specific */
65fc1821feSrugrat { 0, FBTYPE_SUN4COLOR, { 0 } },
66fc1821feSrugrat /* emu_types */
67fc1821feSrugrat { -1 }
68fc1821feSrugrat };
69fc1821feSrugrat
7082bb7c22SToomas Soome static struct vis_identifier gfxp_vgatext_ident = { "illumos_text" };
712df1fe9cSrandyf
7230165b7fSToomas Soome static int vgatext_devinit(struct gfxp_fb_softc *, struct vis_devinit *data);
7330165b7fSToomas Soome static void vgatext_cons_copy(struct gfxp_fb_softc *,
7460405de4Skz struct vis_conscopy *);
7530165b7fSToomas Soome static void vgatext_cons_display(struct gfxp_fb_softc *,
7660405de4Skz struct vis_consdisplay *);
7782bb7c22SToomas Soome static int vgatext_cons_clear(struct gfxp_fb_softc *,
7882bb7c22SToomas Soome struct vis_consclear *);
7930165b7fSToomas Soome static void vgatext_cons_cursor(struct gfxp_fb_softc *,
8060405de4Skz struct vis_conscursor *);
8160405de4Skz static void vgatext_polled_copy(struct vis_polledio_arg *,
8260405de4Skz struct vis_conscopy *);
8360405de4Skz static void vgatext_polled_display(struct vis_polledio_arg *,
8460405de4Skz struct vis_consdisplay *);
8560405de4Skz static void vgatext_polled_cursor(struct vis_polledio_arg *,
8660405de4Skz struct vis_conscursor *);
8730165b7fSToomas Soome static void vgatext_init(struct gfxp_fb_softc *);
8830165b7fSToomas Soome static void vgatext_set_text(struct gfxp_fb_softc *);
892df1fe9cSrandyf
9082bb7c22SToomas Soome static void vgatext_get_text(struct gfxp_fb_softc *softc);
9130165b7fSToomas Soome static void vgatext_save_text(struct gfxp_fb_softc *softc);
9282bb7c22SToomas Soome static void vgatext_kdsettext(struct gfxp_fb_softc *softc);
9330165b7fSToomas Soome static int vgatext_suspend(struct gfxp_fb_softc *softc);
9430165b7fSToomas Soome static void vgatext_resume(struct gfxp_fb_softc *softc);
9582bb7c22SToomas Soome static int vgatext_devmap(dev_t, devmap_cookie_t, offset_t, size_t,
9682bb7c22SToomas Soome size_t *, uint_t, void *);
972df1fe9cSrandyf
9860405de4Skz #if defined(USE_BORDERS)
9930165b7fSToomas Soome static void vgatext_init_graphics(struct gfxp_fb_softc *);
10060405de4Skz #endif
1012df1fe9cSrandyf
10230165b7fSToomas Soome static int vgatext_kdsetmode(struct gfxp_fb_softc *softc, int mode);
10330165b7fSToomas Soome static void vgatext_setfont(struct gfxp_fb_softc *softc);
10430165b7fSToomas Soome static void vgatext_get_cursor(struct gfxp_fb_softc *softc,
10582bb7c22SToomas Soome screen_pos_t *row, screen_pos_t *col);
10630165b7fSToomas Soome static void vgatext_set_cursor(struct gfxp_fb_softc *softc, int row, int col);
10730165b7fSToomas Soome static void vgatext_hide_cursor(struct gfxp_fb_softc *softc);
10830165b7fSToomas Soome static void vgatext_save_colormap(struct gfxp_fb_softc *softc);
10930165b7fSToomas Soome static void vgatext_restore_colormap(struct gfxp_fb_softc *softc);
11060405de4Skz static int vgatext_get_pci_reg_index(dev_info_t *const devi,
11182bb7c22SToomas Soome unsigned long himask, unsigned long hival, unsigned long addr,
11260405de4Skz off_t *offset);
11360405de4Skz static int vgatext_get_isa_reg_index(dev_info_t *const devi,
11460405de4Skz unsigned long hival, unsigned long addr, off_t *offset);
11560405de4Skz
11682bb7c22SToomas Soome static struct gfxp_ops gfxp_vgatext_ops = {
11782bb7c22SToomas Soome .ident = &gfxp_vgatext_ident,
11882bb7c22SToomas Soome .kdsetmode = vgatext_kdsetmode,
11982bb7c22SToomas Soome .devinit = vgatext_devinit,
12082bb7c22SToomas Soome .cons_copy = vgatext_cons_copy,
12182bb7c22SToomas Soome .cons_display = vgatext_cons_display,
12282bb7c22SToomas Soome .cons_cursor = vgatext_cons_cursor,
12382bb7c22SToomas Soome .cons_clear = vgatext_cons_clear,
12482bb7c22SToomas Soome .suspend = vgatext_suspend,
12582bb7c22SToomas Soome .resume = vgatext_resume,
12682bb7c22SToomas Soome .devmap = vgatext_devmap
12782bb7c22SToomas Soome };
12893a18d6dSEnrico Perla - Sun Microsystems
1294e93fb0fSrugrat #define STREQ(a, b) (strcmp((a), (b)) == 0)
1304e93fb0fSrugrat
131fc1821feSrugrat int
gfxp_vga_attach(dev_info_t * devi,struct gfxp_fb_softc * softc)13282bb7c22SToomas Soome gfxp_vga_attach(dev_info_t *devi, struct gfxp_fb_softc *softc)
133fc1821feSrugrat {
134fc1821feSrugrat int unit = ddi_get_instance(devi);
135fc1821feSrugrat int error;
136fc1821feSrugrat char *parent_type = NULL;
137fc1821feSrugrat int reg_rnumber;
138fc1821feSrugrat off_t reg_offset;
139fc1821feSrugrat off_t mem_offset;
140fc1821feSrugrat char *cons;
14182bb7c22SToomas Soome struct gfx_vga *vga;
142fc1821feSrugrat
143fc1821feSrugrat
144fc1821feSrugrat softc->polledio.display = vgatext_polled_display;
145fc1821feSrugrat softc->polledio.copy = vgatext_polled_copy;
146fc1821feSrugrat softc->polledio.cursor = vgatext_polled_cursor;
14782bb7c22SToomas Soome softc->gfxp_ops = &gfxp_vgatext_ops;
14882bb7c22SToomas Soome softc->fbgattr = &vgatext_attr;
14982bb7c22SToomas Soome vga = kmem_zalloc(sizeof (*vga), KM_SLEEP);
15082bb7c22SToomas Soome softc->console = (union gfx_console *)vga;
15148633f18SJan Setje-Eilers
152fc1821feSrugrat error = ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_get_parent(devi),
1532df1fe9cSrandyf DDI_PROP_DONTPASS, "device_type", &parent_type);
154fc1821feSrugrat if (error != DDI_SUCCESS) {
155fc1821feSrugrat cmn_err(CE_WARN, MYNAME ": can't determine parent type.");
156fc1821feSrugrat goto fail;
157fc1821feSrugrat }
158fc1821feSrugrat
15960405de4Skz /* Not enable AGP and DRM by default */
160fc1821feSrugrat if (STREQ(parent_type, "isa") || STREQ(parent_type, "eisa")) {
161fc1821feSrugrat reg_rnumber = vgatext_get_isa_reg_index(devi, 1, VGA_REG_ADDR,
1622df1fe9cSrandyf ®_offset);
163fc1821feSrugrat if (reg_rnumber < 0) {
164fc1821feSrugrat cmn_err(CE_WARN,
1652df1fe9cSrandyf MYNAME
1662df1fe9cSrandyf ": can't find reg entry for registers");
1677ae111d4Sms error = DDI_FAILURE;
168fc1821feSrugrat goto fail;
169fc1821feSrugrat }
17082bb7c22SToomas Soome vga->fb_regno = vgatext_get_isa_reg_index(devi, 0,
1712df1fe9cSrandyf VGA_MEM_ADDR, &mem_offset);
17282bb7c22SToomas Soome if (vga->fb_regno < 0) {
173fc1821feSrugrat cmn_err(CE_WARN,
17482bb7c22SToomas Soome MYNAME ": can't find reg entry for memory");
1757ae111d4Sms error = DDI_FAILURE;
176fc1821feSrugrat goto fail;
177fc1821feSrugrat }
178f40ecdebSrugrat } else if (STREQ(parent_type, "pci") || STREQ(parent_type, "pciex")) {
179fc1821feSrugrat reg_rnumber = vgatext_get_pci_reg_index(devi,
1802df1fe9cSrandyf PCI_REG_ADDR_M|PCI_REG_REL_M,
1812df1fe9cSrandyf PCI_ADDR_IO|PCI_RELOCAT_B, VGA_REG_ADDR,
1822df1fe9cSrandyf ®_offset);
183fc1821feSrugrat if (reg_rnumber < 0) {
184fc1821feSrugrat cmn_err(CE_WARN,
18582bb7c22SToomas Soome MYNAME ": can't find reg entry for registers");
1867ae111d4Sms error = DDI_FAILURE;
187fc1821feSrugrat goto fail;
188fc1821feSrugrat }
18982bb7c22SToomas Soome vga->fb_regno = vgatext_get_pci_reg_index(devi,
1902df1fe9cSrandyf PCI_REG_ADDR_M|PCI_REG_REL_M,
1912df1fe9cSrandyf PCI_ADDR_MEM32|PCI_RELOCAT_B, VGA_MEM_ADDR,
1922df1fe9cSrandyf &mem_offset);
19382bb7c22SToomas Soome if (vga->fb_regno < 0) {
194fc1821feSrugrat cmn_err(CE_WARN,
19582bb7c22SToomas Soome MYNAME ": can't find reg entry for memory");
1967ae111d4Sms error = DDI_FAILURE;
197fc1821feSrugrat goto fail;
198fc1821feSrugrat }
199fc1821feSrugrat } else {
200fc1821feSrugrat cmn_err(CE_WARN, MYNAME ": unknown parent type \"%s\".",
2012df1fe9cSrandyf parent_type);
2027ae111d4Sms error = DDI_FAILURE;
203fc1821feSrugrat goto fail;
204fc1821feSrugrat }
205fc1821feSrugrat ddi_prop_free(parent_type);
206fc1821feSrugrat parent_type = NULL;
207fc1821feSrugrat
208fc1821feSrugrat error = ddi_regs_map_setup(devi, reg_rnumber,
20982bb7c22SToomas Soome (caddr_t *)&vga->regs.addr, reg_offset, VGA_REG_SIZE,
21082bb7c22SToomas Soome &dev_attr, &vga->regs.handle);
211fc1821feSrugrat if (error != DDI_SUCCESS)
212fc1821feSrugrat goto fail;
21382bb7c22SToomas Soome vga->regs.mapped = B_TRUE;
214fc1821feSrugrat
21582bb7c22SToomas Soome vga->fb_size = VGA_MEM_SIZE;
216fc1821feSrugrat
21782bb7c22SToomas Soome error = ddi_regs_map_setup(devi, vga->fb_regno,
21882bb7c22SToomas Soome (caddr_t *)&vga->fb.addr, mem_offset, vga->fb_size, &dev_attr,
21982bb7c22SToomas Soome &vga->fb.handle);
220fc1821feSrugrat if (error != DDI_SUCCESS)
221fc1821feSrugrat goto fail;
22282bb7c22SToomas Soome vga->fb.mapped = B_TRUE;
223fc1821feSrugrat
22482bb7c22SToomas Soome if (ddi_get8(vga->regs.handle,
22582bb7c22SToomas Soome vga->regs.addr + VGA_MISC_R) & VGA_MISC_IOA_SEL)
22682bb7c22SToomas Soome vga->text_base = (caddr_t)vga->fb.addr + VGA_COLOR_BASE;
227fc1821feSrugrat else
22882bb7c22SToomas Soome vga->text_base = (caddr_t)vga->fb.addr + VGA_MONO_BASE;
229fc1821feSrugrat
230fc1821feSrugrat if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(),
2312df1fe9cSrandyf DDI_PROP_DONTPASS, "console", &cons) == DDI_SUCCESS) {
232fc1821feSrugrat if (strcmp(cons, "graphics") == 0) {
23382bb7c22SToomas Soome softc->happyface_boot = 1;
23482bb7c22SToomas Soome softc->silent = 1;
23582bb7c22SToomas Soome vga->current_base = vga->shadow;
23648633f18SJan Setje-Eilers } else {
23782bb7c22SToomas Soome vga->current_base = vga->text_base;
238fc1821feSrugrat }
239fc1821feSrugrat ddi_prop_free(cons);
24048633f18SJan Setje-Eilers } else {
24182bb7c22SToomas Soome vga->current_base = vga->text_base;
242fc1821feSrugrat }
243fc1821feSrugrat
24482bb7c22SToomas Soome /* Set cursor info. */
24582bb7c22SToomas Soome vga->cursor.visible = fb_info.cursor.visible;
24682bb7c22SToomas Soome vga->cursor.row = fb_info.cursor.pos.y;
24782bb7c22SToomas Soome vga->cursor.col = fb_info.cursor.pos.x;
24882bb7c22SToomas Soome
24948633f18SJan Setje-Eilers error = ddi_prop_create(makedevice(DDI_MAJOR_T_UNKNOWN, unit),
25048633f18SJan Setje-Eilers devi, DDI_PROP_CANSLEEP, DDI_KERNEL_IOCTL, NULL, 0);
25148633f18SJan Setje-Eilers if (error != DDI_SUCCESS)
25248633f18SJan Setje-Eilers goto fail;
25348633f18SJan Setje-Eilers
254fc1821feSrugrat /* only do this if not in graphics mode */
25582bb7c22SToomas Soome if ((softc->silent == 0) && (GFXP_IS_CONSOLE(softc))) {
256fc1821feSrugrat vgatext_init(softc);
257fc1821feSrugrat vgatext_save_colormap(softc);
258fc1821feSrugrat }
259fc1821feSrugrat
260fc1821feSrugrat return (DDI_SUCCESS);
261fc1821feSrugrat
262fc1821feSrugrat fail:
26382bb7c22SToomas Soome kmem_free(vga, sizeof (*vga));
264fc1821feSrugrat if (parent_type != NULL)
265fc1821feSrugrat ddi_prop_free(parent_type);
266fc1821feSrugrat return (error);
267fc1821feSrugrat }
268fc1821feSrugrat
26948633f18SJan Setje-Eilers int
gfxp_vga_detach(dev_info_t * devi __unused,struct gfxp_fb_softc * softc)27082bb7c22SToomas Soome gfxp_vga_detach(dev_info_t *devi __unused, struct gfxp_fb_softc *softc)
27148633f18SJan Setje-Eilers {
27282bb7c22SToomas Soome if (softc->console->vga.fb.mapped)
27382bb7c22SToomas Soome ddi_regs_map_free(&softc->console->vga.fb.handle);
27482bb7c22SToomas Soome if (softc->console->vga.regs.mapped)
27582bb7c22SToomas Soome ddi_regs_map_free(&softc->console->vga.regs.handle);
27682bb7c22SToomas Soome kmem_free(softc->console, sizeof (struct gfx_vga));
27782bb7c22SToomas Soome return (DDI_SUCCESS);
27848633f18SJan Setje-Eilers }
27948633f18SJan Setje-Eilers
2802df1fe9cSrandyf /*
2812df1fe9cSrandyf * vgatext_save_text
2822df1fe9cSrandyf * vgatext_suspend
2832df1fe9cSrandyf * vgatext_resume
2842df1fe9cSrandyf *
2853ef9594aSToomas Soome * Routines to save and restore contents of the VGA text area
2862df1fe9cSrandyf * Mostly, this is to support Suspend/Resume operation for graphics
2872df1fe9cSrandyf * device drivers. Here in the VGAtext common code, we simply squirrel
2882df1fe9cSrandyf * away the contents of the hardware's text area during Suspend and then
2892df1fe9cSrandyf * put it back during Resume
2902df1fe9cSrandyf */
2912df1fe9cSrandyf static void
vgatext_save_text(struct gfxp_fb_softc * softc)29230165b7fSToomas Soome vgatext_save_text(struct gfxp_fb_softc *softc)
2932df1fe9cSrandyf {
29482bb7c22SToomas Soome union gfx_console *console = softc->console;
29582bb7c22SToomas Soome unsigned i;
2962df1fe9cSrandyf
29782bb7c22SToomas Soome for (i = 0; i < sizeof (console->vga.shadow); i++)
29882bb7c22SToomas Soome console->vga.shadow[i] = console->vga.current_base[i];
2992df1fe9cSrandyf }
3002df1fe9cSrandyf
3012df1fe9cSrandyf static int
vgatext_suspend(struct gfxp_fb_softc * softc)30230165b7fSToomas Soome vgatext_suspend(struct gfxp_fb_softc *softc)
3032df1fe9cSrandyf {
3042df1fe9cSrandyf switch (softc->mode) {
3052df1fe9cSrandyf case KD_TEXT:
3062df1fe9cSrandyf vgatext_save_text(softc);
3072df1fe9cSrandyf break;
3082df1fe9cSrandyf
3092df1fe9cSrandyf case KD_GRAPHICS:
3102df1fe9cSrandyf break;
3112df1fe9cSrandyf
3122df1fe9cSrandyf default:
3132df1fe9cSrandyf cmn_err(CE_WARN, MYNAME ": unknown mode in vgatext_suspend.");
3142df1fe9cSrandyf return (DDI_FAILURE);
3152df1fe9cSrandyf }
3162df1fe9cSrandyf return (DDI_SUCCESS);
3172df1fe9cSrandyf }
3182df1fe9cSrandyf
3192df1fe9cSrandyf static void
vgatext_resume(struct gfxp_fb_softc * softc)32030165b7fSToomas Soome vgatext_resume(struct gfxp_fb_softc *softc)
3212df1fe9cSrandyf {
3222df1fe9cSrandyf
3232df1fe9cSrandyf switch (softc->mode) {
3242df1fe9cSrandyf case KD_TEXT:
32582bb7c22SToomas Soome vgatext_kdsettext(softc);
3262df1fe9cSrandyf break;
3272df1fe9cSrandyf
3282df1fe9cSrandyf case KD_GRAPHICS:
3292df1fe9cSrandyf
3302df1fe9cSrandyf /*
3312df1fe9cSrandyf * Upon RESUME, the graphics device will always actually
3322df1fe9cSrandyf * be in TEXT mode even though the Xorg server did not
3332df1fe9cSrandyf * make that mode change itself (the suspend code did).
3342df1fe9cSrandyf * We want first, therefore, to restore textmode
3352df1fe9cSrandyf * operation fully, and then the Xorg server will
3362df1fe9cSrandyf * do the rest to restore the device to its
3372df1fe9cSrandyf * (hi resolution) graphics mode
3382df1fe9cSrandyf */
33982bb7c22SToomas Soome vgatext_kdsettext(softc);
3402df1fe9cSrandyf #if defined(USE_BORDERS)
3412df1fe9cSrandyf vgatext_init_graphics(softc);
3422df1fe9cSrandyf #endif
3432df1fe9cSrandyf break;
3442df1fe9cSrandyf default:
3452df1fe9cSrandyf cmn_err(CE_WARN, MYNAME ": unknown mode in vgatext_resume.");
3462df1fe9cSrandyf break;
3472df1fe9cSrandyf }
3482df1fe9cSrandyf }
3492df1fe9cSrandyf
35048633f18SJan Setje-Eilers static void
vgatext_progressbar_stop(struct gfxp_fb_softc * softc)35182bb7c22SToomas Soome vgatext_progressbar_stop(struct gfxp_fb_softc *softc)
35248633f18SJan Setje-Eilers {
35348633f18SJan Setje-Eilers extern void progressbar_stop(void);
35448633f18SJan Setje-Eilers
35582bb7c22SToomas Soome if (softc->silent == 1) {
35682bb7c22SToomas Soome softc->silent = 0;
35748633f18SJan Setje-Eilers progressbar_stop();
35848633f18SJan Setje-Eilers }
35948633f18SJan Setje-Eilers }
36048633f18SJan Setje-Eilers
36148633f18SJan Setje-Eilers static void
vgatext_kdsettext(struct gfxp_fb_softc * softc)36230165b7fSToomas Soome vgatext_kdsettext(struct gfxp_fb_softc *softc)
363fc1821feSrugrat {
36482bb7c22SToomas Soome union gfx_console *console = softc->console;
365fc1821feSrugrat int i;
366fc1821feSrugrat
36748633f18SJan Setje-Eilers vgatext_init(softc);
36882bb7c22SToomas Soome for (i = 0; i < sizeof (console->vga.shadow); i++) {
36982bb7c22SToomas Soome console->vga.text_base[i] = console->vga.shadow[i];
37048633f18SJan Setje-Eilers }
37182bb7c22SToomas Soome console->vga.current_base = console->vga.text_base;
37282bb7c22SToomas Soome if (console->vga.cursor.visible) {
37348633f18SJan Setje-Eilers vgatext_set_cursor(softc,
37482bb7c22SToomas Soome console->vga.cursor.row,
37582bb7c22SToomas Soome console->vga.cursor.col);
37648633f18SJan Setje-Eilers }
37748633f18SJan Setje-Eilers vgatext_restore_colormap(softc);
37848633f18SJan Setje-Eilers }
37948633f18SJan Setje-Eilers
38048633f18SJan Setje-Eilers static void
vgatext_kdsetgraphics(struct gfxp_fb_softc * softc)38130165b7fSToomas Soome vgatext_kdsetgraphics(struct gfxp_fb_softc *softc)
38248633f18SJan Setje-Eilers {
38382bb7c22SToomas Soome vgatext_progressbar_stop(softc);
38448633f18SJan Setje-Eilers vgatext_save_text(softc);
38582bb7c22SToomas Soome softc->console->vga.current_base = softc->console->vga.shadow;
38682bb7c22SToomas Soome vgatext_get_text(softc);
38748633f18SJan Setje-Eilers #if defined(USE_BORDERS)
38848633f18SJan Setje-Eilers vgatext_init_graphics(softc);
38948633f18SJan Setje-Eilers #endif
39048633f18SJan Setje-Eilers }
39148633f18SJan Setje-Eilers
39248633f18SJan Setje-Eilers static int
vgatext_kdsetmode(struct gfxp_fb_softc * softc,int mode)39330165b7fSToomas Soome vgatext_kdsetmode(struct gfxp_fb_softc *softc, int mode)
39448633f18SJan Setje-Eilers {
395fc1821feSrugrat switch (mode) {
396fc1821feSrugrat case KD_TEXT:
39782bb7c22SToomas Soome if (softc->blt_ops.setmode != NULL)
398ceedf124SToomas Soome if (softc->blt_ops.setmode(KD_TEXT) != 0)
399ceedf124SToomas Soome return (EIO);
400ceedf124SToomas Soome
40148633f18SJan Setje-Eilers vgatext_kdsettext(softc);
402fc1821feSrugrat break;
403fc1821feSrugrat
404fc1821feSrugrat case KD_GRAPHICS:
40548633f18SJan Setje-Eilers vgatext_kdsetgraphics(softc);
40682bb7c22SToomas Soome if (softc->blt_ops.setmode != NULL)
407ceedf124SToomas Soome if (softc->blt_ops.setmode(KD_GRAPHICS) != 0) {
408ceedf124SToomas Soome vgatext_kdsettext(softc);
409ceedf124SToomas Soome return (EIO);
410ceedf124SToomas Soome }
41148633f18SJan Setje-Eilers break;
4122df1fe9cSrandyf
41348633f18SJan Setje-Eilers case KD_RESETTEXT:
41448633f18SJan Setje-Eilers /*
41548633f18SJan Setje-Eilers * In order to avoid racing with a starting X server,
41648633f18SJan Setje-Eilers * this needs to be a test and set that is performed in
41748633f18SJan Setje-Eilers * a single (softc->lock protected) ioctl into this driver.
41848633f18SJan Setje-Eilers */
41982bb7c22SToomas Soome if (softc->mode == KD_TEXT && softc->silent == 1) {
42082bb7c22SToomas Soome vgatext_progressbar_stop(softc);
42148633f18SJan Setje-Eilers vgatext_kdsettext(softc);
422fc1821feSrugrat }
42382bb7c22SToomas Soome mode = KD_TEXT;
424fc1821feSrugrat break;
425fc1821feSrugrat
426fc1821feSrugrat default:
427fc1821feSrugrat return (EINVAL);
428fc1821feSrugrat }
42948633f18SJan Setje-Eilers
430fc1821feSrugrat softc->mode = mode;
431fc1821feSrugrat return (0);
432fc1821feSrugrat }
433fc1821feSrugrat
434fc1821feSrugrat /*ARGSUSED*/
43582bb7c22SToomas Soome static int
vgatext_devmap(dev_t dev,devmap_cookie_t dhp,offset_t off,size_t len,size_t * maplen,uint_t model,void * ptr)43682bb7c22SToomas Soome vgatext_devmap(dev_t dev, devmap_cookie_t dhp, offset_t off, size_t len,
437d1e631afSToomas Soome size_t *maplen, uint_t model, void *ptr)
438fc1821feSrugrat {
43930165b7fSToomas Soome struct gfxp_fb_softc *softc = (struct gfxp_fb_softc *)ptr;
44082bb7c22SToomas Soome union gfx_console *console;
441fc1821feSrugrat int err;
442fc1821feSrugrat size_t length;
443fc1821feSrugrat
444fc1821feSrugrat
445fc1821feSrugrat if (softc == NULL) {
446fc1821feSrugrat cmn_err(CE_WARN, "vgatext: Can't find softstate");
447fc1821feSrugrat return (-1);
448fc1821feSrugrat }
44982bb7c22SToomas Soome console = softc->console;
450fc1821feSrugrat
45182bb7c22SToomas Soome if (!(off >= VGA_MEM_ADDR &&
45282bb7c22SToomas Soome off < VGA_MEM_ADDR + console->vga.fb_size)) {
453fc1821feSrugrat cmn_err(CE_WARN, "vgatext: Can't map offset 0x%llx", off);
454fc1821feSrugrat return (-1);
455fc1821feSrugrat }
456fc1821feSrugrat
45782bb7c22SToomas Soome if (off + len > VGA_MEM_ADDR + console->vga.fb_size)
45882bb7c22SToomas Soome length = VGA_MEM_ADDR + console->vga.fb_size - off;
459fc1821feSrugrat else
460fc1821feSrugrat length = len;
461fc1821feSrugrat
4622df1fe9cSrandyf if ((err = devmap_devmem_setup(dhp, softc->devi,
46382bb7c22SToomas Soome NULL, console->vga.fb_regno, off - VGA_MEM_ADDR,
4642df1fe9cSrandyf length, PROT_ALL, 0, &dev_attr)) < 0) {
465fc1821feSrugrat return (err);
466fc1821feSrugrat }
467fc1821feSrugrat
468fc1821feSrugrat
469fc1821feSrugrat *maplen = length;
470fc1821feSrugrat return (0);
471fc1821feSrugrat }
472fc1821feSrugrat
473fc1821feSrugrat
474fc1821feSrugrat static int
vgatext_devinit(struct gfxp_fb_softc * softc,struct vis_devinit * data)47530165b7fSToomas Soome vgatext_devinit(struct gfxp_fb_softc *softc, struct vis_devinit *data)
476fc1821feSrugrat {
477fc1821feSrugrat /* initialize console instance */
478fc1821feSrugrat data->version = VIS_CONS_REV;
47982bb7c22SToomas Soome data->width = VGA_TEXT_COLS;
48082bb7c22SToomas Soome data->height = VGA_TEXT_ROWS;
48182bb7c22SToomas Soome data->linebytes = VGA_TEXT_COLS;
48282bb7c22SToomas Soome data->color_map = NULL;
483fc1821feSrugrat data->depth = 4;
484fc1821feSrugrat data->mode = VIS_TEXT;
485fc1821feSrugrat data->polledio = &softc->polledio;
486fc1821feSrugrat
4873ef9594aSToomas Soome vgatext_save_text(softc); /* save current console */
4883ef9594aSToomas Soome vgatext_hide_cursor(softc);
489fc1821feSrugrat return (0);
490fc1821feSrugrat }
491fc1821feSrugrat
492cbc8e155SToomas Soome /*
493cbc8e155SToomas Soome * Binary searchable table for Unicode to CP437 conversion.
494cbc8e155SToomas Soome */
495cbc8e155SToomas Soome struct unicp437 {
496cbc8e155SToomas Soome uint16_t unicode_base;
497cbc8e155SToomas Soome uint8_t cp437_base;
498cbc8e155SToomas Soome uint8_t length;
499cbc8e155SToomas Soome };
500cbc8e155SToomas Soome
501cbc8e155SToomas Soome static const struct unicp437 cp437table[] = {
502cbc8e155SToomas Soome { 0x0020, 0x20, 0x5e }, { 0x00a0, 0x20, 0x00 }, { 0x00a1, 0xad, 0x00 },
503cbc8e155SToomas Soome { 0x00a2, 0x9b, 0x00 }, { 0x00a3, 0x9c, 0x00 }, { 0x00a5, 0x9d, 0x00 },
504cbc8e155SToomas Soome { 0x00a7, 0x15, 0x00 }, { 0x00aa, 0xa6, 0x00 }, { 0x00ab, 0xae, 0x00 },
505cbc8e155SToomas Soome { 0x00ac, 0xaa, 0x00 }, { 0x00b0, 0xf8, 0x00 }, { 0x00b1, 0xf1, 0x00 },
506cbc8e155SToomas Soome { 0x00b2, 0xfd, 0x00 }, { 0x00b5, 0xe6, 0x00 }, { 0x00b6, 0x14, 0x00 },
507cbc8e155SToomas Soome { 0x00b7, 0xfa, 0x00 }, { 0x00ba, 0xa7, 0x00 }, { 0x00bb, 0xaf, 0x00 },
508cbc8e155SToomas Soome { 0x00bc, 0xac, 0x00 }, { 0x00bd, 0xab, 0x00 }, { 0x00bf, 0xa8, 0x00 },
509cbc8e155SToomas Soome { 0x00c4, 0x8e, 0x01 }, { 0x00c6, 0x92, 0x00 }, { 0x00c7, 0x80, 0x00 },
510cbc8e155SToomas Soome { 0x00c9, 0x90, 0x00 }, { 0x00d1, 0xa5, 0x00 }, { 0x00d6, 0x99, 0x00 },
511cbc8e155SToomas Soome { 0x00dc, 0x9a, 0x00 }, { 0x00df, 0xe1, 0x00 }, { 0x00e0, 0x85, 0x00 },
512cbc8e155SToomas Soome { 0x00e1, 0xa0, 0x00 }, { 0x00e2, 0x83, 0x00 }, { 0x00e4, 0x84, 0x00 },
513cbc8e155SToomas Soome { 0x00e5, 0x86, 0x00 }, { 0x00e6, 0x91, 0x00 }, { 0x00e7, 0x87, 0x00 },
514cbc8e155SToomas Soome { 0x00e8, 0x8a, 0x00 }, { 0x00e9, 0x82, 0x00 }, { 0x00ea, 0x88, 0x01 },
515cbc8e155SToomas Soome { 0x00ec, 0x8d, 0x00 }, { 0x00ed, 0xa1, 0x00 }, { 0x00ee, 0x8c, 0x00 },
516cbc8e155SToomas Soome { 0x00ef, 0x8b, 0x00 }, { 0x00f0, 0xeb, 0x00 }, { 0x00f1, 0xa4, 0x00 },
517cbc8e155SToomas Soome { 0x00f2, 0x95, 0x00 }, { 0x00f3, 0xa2, 0x00 }, { 0x00f4, 0x93, 0x00 },
518cbc8e155SToomas Soome { 0x00f6, 0x94, 0x00 }, { 0x00f7, 0xf6, 0x00 }, { 0x00f8, 0xed, 0x00 },
519cbc8e155SToomas Soome { 0x00f9, 0x97, 0x00 }, { 0x00fa, 0xa3, 0x00 }, { 0x00fb, 0x96, 0x00 },
520cbc8e155SToomas Soome { 0x00fc, 0x81, 0x00 }, { 0x00ff, 0x98, 0x00 }, { 0x0192, 0x9f, 0x00 },
521cbc8e155SToomas Soome { 0x0393, 0xe2, 0x00 }, { 0x0398, 0xe9, 0x00 }, { 0x03a3, 0xe4, 0x00 },
522cbc8e155SToomas Soome { 0x03a6, 0xe8, 0x00 }, { 0x03a9, 0xea, 0x00 }, { 0x03b1, 0xe0, 0x01 },
523cbc8e155SToomas Soome { 0x03b4, 0xeb, 0x00 }, { 0x03b5, 0xee, 0x00 }, { 0x03bc, 0xe6, 0x00 },
524cbc8e155SToomas Soome { 0x03c0, 0xe3, 0x00 }, { 0x03c3, 0xe5, 0x00 }, { 0x03c4, 0xe7, 0x00 },
525cbc8e155SToomas Soome { 0x03c6, 0xed, 0x00 }, { 0x03d5, 0xed, 0x00 }, { 0x2010, 0x2d, 0x00 },
526cbc8e155SToomas Soome { 0x2014, 0x2d, 0x00 }, { 0x2018, 0x60, 0x00 }, { 0x2019, 0x27, 0x00 },
527cbc8e155SToomas Soome { 0x201c, 0x22, 0x00 }, { 0x201d, 0x22, 0x00 }, { 0x2022, 0x07, 0x00 },
528cbc8e155SToomas Soome { 0x203c, 0x13, 0x00 }, { 0x207f, 0xfc, 0x00 }, { 0x20a7, 0x9e, 0x00 },
529cbc8e155SToomas Soome { 0x20ac, 0xee, 0x00 }, { 0x2126, 0xea, 0x00 }, { 0x2190, 0x1b, 0x00 },
530cbc8e155SToomas Soome { 0x2191, 0x18, 0x00 }, { 0x2192, 0x1a, 0x00 }, { 0x2193, 0x19, 0x00 },
531cbc8e155SToomas Soome { 0x2194, 0x1d, 0x00 }, { 0x2195, 0x12, 0x00 }, { 0x21a8, 0x17, 0x00 },
532cbc8e155SToomas Soome { 0x2202, 0xeb, 0x00 }, { 0x2208, 0xee, 0x00 }, { 0x2211, 0xe4, 0x00 },
533cbc8e155SToomas Soome { 0x2212, 0x2d, 0x00 }, { 0x2219, 0xf9, 0x00 }, { 0x221a, 0xfb, 0x00 },
534cbc8e155SToomas Soome { 0x221e, 0xec, 0x00 }, { 0x221f, 0x1c, 0x00 }, { 0x2229, 0xef, 0x00 },
535cbc8e155SToomas Soome { 0x2248, 0xf7, 0x00 }, { 0x2261, 0xf0, 0x00 }, { 0x2264, 0xf3, 0x00 },
536cbc8e155SToomas Soome { 0x2265, 0xf2, 0x00 }, { 0x2302, 0x7f, 0x00 }, { 0x2310, 0xa9, 0x00 },
537cbc8e155SToomas Soome { 0x2320, 0xf4, 0x00 }, { 0x2321, 0xf5, 0x00 }, { 0x2500, 0xc4, 0x00 },
538cbc8e155SToomas Soome { 0x2502, 0xb3, 0x00 }, { 0x250c, 0xda, 0x00 }, { 0x2510, 0xbf, 0x00 },
539cbc8e155SToomas Soome { 0x2514, 0xc0, 0x00 }, { 0x2518, 0xd9, 0x00 }, { 0x251c, 0xc3, 0x00 },
540cbc8e155SToomas Soome { 0x2524, 0xb4, 0x00 }, { 0x252c, 0xc2, 0x00 }, { 0x2534, 0xc1, 0x00 },
541cbc8e155SToomas Soome { 0x253c, 0xc5, 0x00 }, { 0x2550, 0xcd, 0x00 }, { 0x2551, 0xba, 0x00 },
542cbc8e155SToomas Soome { 0x2552, 0xd5, 0x00 }, { 0x2553, 0xd6, 0x00 }, { 0x2554, 0xc9, 0x00 },
543cbc8e155SToomas Soome { 0x2555, 0xb8, 0x00 }, { 0x2556, 0xb7, 0x00 }, { 0x2557, 0xbb, 0x00 },
544cbc8e155SToomas Soome { 0x2558, 0xd4, 0x00 }, { 0x2559, 0xd3, 0x00 }, { 0x255a, 0xc8, 0x00 },
545cbc8e155SToomas Soome { 0x255b, 0xbe, 0x00 }, { 0x255c, 0xbd, 0x00 }, { 0x255d, 0xbc, 0x00 },
546cbc8e155SToomas Soome { 0x255e, 0xc6, 0x01 }, { 0x2560, 0xcc, 0x00 }, { 0x2561, 0xb5, 0x00 },
547cbc8e155SToomas Soome { 0x2562, 0xb6, 0x00 }, { 0x2563, 0xb9, 0x00 }, { 0x2564, 0xd1, 0x01 },
548cbc8e155SToomas Soome { 0x2566, 0xcb, 0x00 }, { 0x2567, 0xcf, 0x00 }, { 0x2568, 0xd0, 0x00 },
549cbc8e155SToomas Soome { 0x2569, 0xca, 0x00 }, { 0x256a, 0xd8, 0x00 }, { 0x256b, 0xd7, 0x00 },
550cbc8e155SToomas Soome { 0x256c, 0xce, 0x00 }, { 0x2580, 0xdf, 0x00 }, { 0x2584, 0xdc, 0x00 },
551cbc8e155SToomas Soome { 0x2588, 0xdb, 0x00 }, { 0x258c, 0xdd, 0x00 }, { 0x2590, 0xde, 0x00 },
552cbc8e155SToomas Soome { 0x2591, 0xb0, 0x02 }, { 0x25a0, 0xfe, 0x00 }, { 0x25ac, 0x16, 0x00 },
553cbc8e155SToomas Soome { 0x25b2, 0x1e, 0x00 }, { 0x25ba, 0x10, 0x00 }, { 0x25bc, 0x1f, 0x00 },
554cbc8e155SToomas Soome { 0x25c4, 0x11, 0x00 }, { 0x25cb, 0x09, 0x00 }, { 0x25d8, 0x08, 0x00 },
555cbc8e155SToomas Soome { 0x25d9, 0x0a, 0x00 }, { 0x263a, 0x01, 0x01 }, { 0x263c, 0x0f, 0x00 },
556cbc8e155SToomas Soome { 0x2640, 0x0c, 0x00 }, { 0x2642, 0x0b, 0x00 }, { 0x2660, 0x06, 0x00 },
557cbc8e155SToomas Soome { 0x2663, 0x05, 0x00 }, { 0x2665, 0x03, 0x01 }, { 0x266a, 0x0d, 0x00 },
558cbc8e155SToomas Soome { 0x266c, 0x0e, 0x00 }
559cbc8e155SToomas Soome };
560cbc8e155SToomas Soome
561cbc8e155SToomas Soome static uint8_t
vga_get_cp437(uint32_t c)562cbc8e155SToomas Soome vga_get_cp437(uint32_t c)
563cbc8e155SToomas Soome {
564cbc8e155SToomas Soome int min, mid, max;
565cbc8e155SToomas Soome
566cbc8e155SToomas Soome min = 0;
567cbc8e155SToomas Soome max = (sizeof (cp437table) / sizeof (struct unicp437)) - 1;
568cbc8e155SToomas Soome
569cbc8e155SToomas Soome if (c < cp437table[0].unicode_base ||
570cbc8e155SToomas Soome c > cp437table[max].unicode_base + cp437table[max].length)
571cbc8e155SToomas Soome return ('?');
572cbc8e155SToomas Soome
573cbc8e155SToomas Soome while (max >= min) {
574cbc8e155SToomas Soome mid = (min + max) / 2;
575cbc8e155SToomas Soome if (c < cp437table[mid].unicode_base)
576cbc8e155SToomas Soome max = mid - 1;
577cbc8e155SToomas Soome else if (c > cp437table[mid].unicode_base +
578cbc8e155SToomas Soome cp437table[mid].length)
579cbc8e155SToomas Soome min = mid + 1;
580cbc8e155SToomas Soome else
581cbc8e155SToomas Soome return (c - cp437table[mid].unicode_base +
582cbc8e155SToomas Soome cp437table[mid].cp437_base);
583cbc8e155SToomas Soome }
584cbc8e155SToomas Soome
585cbc8e155SToomas Soome return ('?');
586cbc8e155SToomas Soome }
587cbc8e155SToomas Soome
588fc1821feSrugrat /*
589fc1821feSrugrat * display a string on the screen at (row, col)
590fc1821feSrugrat * assume it has been cropped to fit.
591fc1821feSrugrat */
592fc1821feSrugrat static void
vgatext_cons_display(struct gfxp_fb_softc * softc,struct vis_consdisplay * da)59330165b7fSToomas Soome vgatext_cons_display(struct gfxp_fb_softc *softc, struct vis_consdisplay *da)
594fc1821feSrugrat {
595cbc8e155SToomas Soome uint32_t *string;
596fc1821feSrugrat int i;
597fc1821feSrugrat unsigned char attr;
598fc1821feSrugrat struct cgatext {
599fc1821feSrugrat unsigned char ch;
600fc1821feSrugrat unsigned char attr;
601fc1821feSrugrat };
602fc1821feSrugrat struct cgatext *addr;
603fc1821feSrugrat
604fc1821feSrugrat /*
605fc1821feSrugrat * Sanity checks. This is a last-ditch effort to avoid damage
606fc1821feSrugrat * from brokenness or maliciousness above.
607fc1821feSrugrat */
60882bb7c22SToomas Soome if (da->row < 0 || da->row >= VGA_TEXT_ROWS ||
60982bb7c22SToomas Soome da->col < 0 || da->col >= VGA_TEXT_COLS ||
61082bb7c22SToomas Soome da->col + da->width > VGA_TEXT_COLS)
611fc1821feSrugrat return;
612fc1821feSrugrat
613fc1821feSrugrat /*
614fc1821feSrugrat * To be fully general, we should copyin the data. This is not
615fc1821feSrugrat * really relevant for this text-only driver, but a graphical driver
616fc1821feSrugrat * should support these ioctls from userland to enable simple
617fc1821feSrugrat * system startup graphics.
618fc1821feSrugrat */
619*fa9eb222SToomas Soome attr = (solaris_color_to_pc_color[da->bg_color.four & 0xf] << 4)
620*fa9eb222SToomas Soome | solaris_color_to_pc_color[da->fg_color.four & 0xf];
621cbc8e155SToomas Soome string = (uint32_t *)da->data;
62282bb7c22SToomas Soome addr = (struct cgatext *)softc->console->vga.current_base
62382bb7c22SToomas Soome + (da->row * VGA_TEXT_COLS + da->col);
624fc1821feSrugrat for (i = 0; i < da->width; i++) {
625cbc8e155SToomas Soome addr[i].ch = vga_get_cp437(string[i]);
626cbc8e155SToomas Soome addr[i].attr = attr;
627fc1821feSrugrat }
628fc1821feSrugrat }
629fc1821feSrugrat
630fc1821feSrugrat static void
vgatext_polled_display(struct vis_polledio_arg * arg,struct vis_consdisplay * da)631fc1821feSrugrat vgatext_polled_display(
632fc1821feSrugrat struct vis_polledio_arg *arg,
633fc1821feSrugrat struct vis_consdisplay *da)
634fc1821feSrugrat {
63530165b7fSToomas Soome vgatext_cons_display((struct gfxp_fb_softc *)arg, da);
636fc1821feSrugrat }
637fc1821feSrugrat
638fc1821feSrugrat /*
639fc1821feSrugrat * screen-to-screen copy
640fc1821feSrugrat */
641fc1821feSrugrat
642fc1821feSrugrat static void
vgatext_cons_copy(struct gfxp_fb_softc * softc,struct vis_conscopy * ma)64330165b7fSToomas Soome vgatext_cons_copy(struct gfxp_fb_softc *softc, struct vis_conscopy *ma)
644fc1821feSrugrat {
645fc1821feSrugrat unsigned short *from;
646fc1821feSrugrat unsigned short *to;
647fc1821feSrugrat int cnt;
648fc1821feSrugrat screen_size_t chars_per_row;
649fc1821feSrugrat unsigned short *to_row_start;
650fc1821feSrugrat unsigned short *from_row_start;
651fc1821feSrugrat screen_size_t rows_to_move;
652fc1821feSrugrat unsigned short *base;
653fc1821feSrugrat
654fc1821feSrugrat /*
655fc1821feSrugrat * Sanity checks. Note that this is a last-ditch effort to avoid
656fc1821feSrugrat * damage caused by broken-ness or maliciousness above.
657fc1821feSrugrat */
65882bb7c22SToomas Soome if (ma->s_col < 0 || ma->s_col >= VGA_TEXT_COLS ||
65982bb7c22SToomas Soome ma->s_row < 0 || ma->s_row >= VGA_TEXT_ROWS ||
66082bb7c22SToomas Soome ma->e_col < 0 || ma->e_col >= VGA_TEXT_COLS ||
66182bb7c22SToomas Soome ma->e_row < 0 || ma->e_row >= VGA_TEXT_ROWS ||
66282bb7c22SToomas Soome ma->t_col < 0 || ma->t_col >= VGA_TEXT_COLS ||
66382bb7c22SToomas Soome ma->t_row < 0 || ma->t_row >= VGA_TEXT_ROWS ||
664fc1821feSrugrat ma->s_col > ma->e_col ||
665fc1821feSrugrat ma->s_row > ma->e_row)
666fc1821feSrugrat return;
667fc1821feSrugrat
668fc1821feSrugrat /*
669fc1821feSrugrat * Remember we're going to copy shorts because each
670fc1821feSrugrat * character/attribute pair is 16 bits.
671fc1821feSrugrat */
672fc1821feSrugrat chars_per_row = ma->e_col - ma->s_col + 1;
673fc1821feSrugrat rows_to_move = ma->e_row - ma->s_row + 1;
674fc1821feSrugrat
675fc1821feSrugrat /* More sanity checks. */
67682bb7c22SToomas Soome if (ma->t_row + rows_to_move > VGA_TEXT_ROWS ||
67782bb7c22SToomas Soome ma->t_col + chars_per_row > VGA_TEXT_COLS)
678fc1821feSrugrat return;
679fc1821feSrugrat
68082bb7c22SToomas Soome base = (unsigned short *)softc->console->vga.current_base;
681fc1821feSrugrat
68282bb7c22SToomas Soome to_row_start = base + ((ma->t_row * VGA_TEXT_COLS) + ma->t_col);
68382bb7c22SToomas Soome from_row_start = base + ((ma->s_row * VGA_TEXT_COLS) + ma->s_col);
684fc1821feSrugrat
685fc1821feSrugrat if (to_row_start < from_row_start) {
686fc1821feSrugrat while (rows_to_move-- > 0) {
687fc1821feSrugrat to = to_row_start;
688fc1821feSrugrat from = from_row_start;
68982bb7c22SToomas Soome to_row_start += VGA_TEXT_COLS;
69082bb7c22SToomas Soome from_row_start += VGA_TEXT_COLS;
691fc1821feSrugrat for (cnt = chars_per_row; cnt-- > 0; )
692fc1821feSrugrat *to++ = *from++;
693fc1821feSrugrat }
694fc1821feSrugrat } else {
695fc1821feSrugrat /*
696fc1821feSrugrat * Offset to the end of the region and copy backwards.
697fc1821feSrugrat */
69882bb7c22SToomas Soome cnt = rows_to_move * VGA_TEXT_COLS + chars_per_row;
699fc1821feSrugrat to_row_start += cnt;
700fc1821feSrugrat from_row_start += cnt;
701fc1821feSrugrat
702fc1821feSrugrat while (rows_to_move-- > 0) {
70382bb7c22SToomas Soome to_row_start -= VGA_TEXT_COLS;
70482bb7c22SToomas Soome from_row_start -= VGA_TEXT_COLS;
705fc1821feSrugrat to = to_row_start;
706fc1821feSrugrat from = from_row_start;
707fc1821feSrugrat for (cnt = chars_per_row; cnt-- > 0; )
708fc1821feSrugrat *--to = *--from;
709fc1821feSrugrat }
710fc1821feSrugrat }
711fc1821feSrugrat }
712fc1821feSrugrat
713fc1821feSrugrat static void
vgatext_polled_copy(struct vis_polledio_arg * arg,struct vis_conscopy * ca)714fc1821feSrugrat vgatext_polled_copy(
715fc1821feSrugrat struct vis_polledio_arg *arg,
716fc1821feSrugrat struct vis_conscopy *ca)
717fc1821feSrugrat {
71830165b7fSToomas Soome vgatext_cons_copy((struct gfxp_fb_softc *)arg, ca);
719fc1821feSrugrat }
720fc1821feSrugrat
72182bb7c22SToomas Soome /*ARGSUSED*/
72282bb7c22SToomas Soome static int
vgatext_cons_clear(struct gfxp_fb_softc * softc,struct vis_consclear * ca)72382bb7c22SToomas Soome vgatext_cons_clear(struct gfxp_fb_softc *softc, struct vis_consclear *ca)
72482bb7c22SToomas Soome {
72582bb7c22SToomas Soome uint16_t val, fg, *base;
72682bb7c22SToomas Soome int i;
72782bb7c22SToomas Soome
728*fa9eb222SToomas Soome if (ca->bg_color.four == 0) /* bright white */
72982bb7c22SToomas Soome fg = 1; /* black */
73082bb7c22SToomas Soome else
73182bb7c22SToomas Soome fg = 8;
73282bb7c22SToomas Soome
733*fa9eb222SToomas Soome val = (solaris_color_to_pc_color[ca->bg_color.four & 0xf] << 4) |
73482bb7c22SToomas Soome solaris_color_to_pc_color[fg];
73582bb7c22SToomas Soome val = (val << 8) | ' ';
73682bb7c22SToomas Soome
73782bb7c22SToomas Soome base = (uint16_t *)softc->console->vga.current_base;
73882bb7c22SToomas Soome for (i = 0; i < VGA_TEXT_ROWS * VGA_TEXT_COLS; i++)
73982bb7c22SToomas Soome base[i] = val;
74082bb7c22SToomas Soome
74182bb7c22SToomas Soome return (0);
74282bb7c22SToomas Soome }
74382bb7c22SToomas Soome
744fc1821feSrugrat static void
vgatext_cons_cursor(struct gfxp_fb_softc * softc,struct vis_conscursor * ca)74530165b7fSToomas Soome vgatext_cons_cursor(struct gfxp_fb_softc *softc, struct vis_conscursor *ca)
746fc1821feSrugrat {
74782bb7c22SToomas Soome if (softc->silent)
748fc1821feSrugrat return;
749fc1821feSrugrat
750fc1821feSrugrat switch (ca->action) {
751fc1821feSrugrat case VIS_HIDE_CURSOR:
75282bb7c22SToomas Soome softc->console->vga.cursor.visible = B_FALSE;
75382bb7c22SToomas Soome if (softc->console->vga.current_base ==
75482bb7c22SToomas Soome softc->console->vga.text_base)
755fc1821feSrugrat vgatext_hide_cursor(softc);
756fc1821feSrugrat break;
757fc1821feSrugrat case VIS_DISPLAY_CURSOR:
758fc1821feSrugrat /*
759fc1821feSrugrat * Sanity check. This is a last-ditch effort to avoid
760fc1821feSrugrat * damage from brokenness or maliciousness above.
761fc1821feSrugrat */
76282bb7c22SToomas Soome if (ca->col < 0 || ca->col >= VGA_TEXT_COLS ||
76382bb7c22SToomas Soome ca->row < 0 || ca->row >= VGA_TEXT_ROWS)
764fc1821feSrugrat return;
765fc1821feSrugrat
76682bb7c22SToomas Soome softc->console->vga.cursor.visible = B_TRUE;
76782bb7c22SToomas Soome softc->console->vga.cursor.col = ca->col;
76882bb7c22SToomas Soome softc->console->vga.cursor.row = ca->row;
76982bb7c22SToomas Soome if (softc->console->vga.current_base ==
77082bb7c22SToomas Soome softc->console->vga.text_base)
771fc1821feSrugrat vgatext_set_cursor(softc, ca->row, ca->col);
772fc1821feSrugrat break;
773fc1821feSrugrat case VIS_GET_CURSOR:
77482bb7c22SToomas Soome if (softc->console->vga.current_base ==
77582bb7c22SToomas Soome softc->console->vga.text_base) {
776fc1821feSrugrat vgatext_get_cursor(softc, &ca->row, &ca->col);
777fc1821feSrugrat }
778fc1821feSrugrat break;
779fc1821feSrugrat }
780fc1821feSrugrat }
781fc1821feSrugrat
782fc1821feSrugrat static void
vgatext_polled_cursor(struct vis_polledio_arg * arg,struct vis_conscursor * ca)783fc1821feSrugrat vgatext_polled_cursor(
784fc1821feSrugrat struct vis_polledio_arg *arg,
785fc1821feSrugrat struct vis_conscursor *ca)
786fc1821feSrugrat {
78730165b7fSToomas Soome vgatext_cons_cursor((struct gfxp_fb_softc *)arg, ca);
788fc1821feSrugrat }
789fc1821feSrugrat
790fc1821feSrugrat static void
vgatext_hide_cursor(struct gfxp_fb_softc * softc)79130165b7fSToomas Soome vgatext_hide_cursor(struct gfxp_fb_softc *softc)
792fc1821feSrugrat {
79382bb7c22SToomas Soome union gfx_console *console = softc->console;
7943ef9594aSToomas Soome uint8_t msl, s;
7953ef9594aSToomas Soome
79682bb7c22SToomas Soome if (softc->silent)
7973ef9594aSToomas Soome return;
7983ef9594aSToomas Soome
79982bb7c22SToomas Soome msl = vga_get_crtc(&console->vga.regs, VGA_CRTC_MAX_S_LN) & 0x1f;
80082bb7c22SToomas Soome s = vga_get_crtc(&console->vga.regs, VGA_CRTC_CSSL) & 0xc0;
8013ef9594aSToomas Soome s |= (1 << 5);
8023ef9594aSToomas Soome
8033ef9594aSToomas Soome /* disable cursor */
80482bb7c22SToomas Soome vga_set_crtc(&console->vga.regs, VGA_CRTC_CSSL, s);
80582bb7c22SToomas Soome vga_set_crtc(&console->vga.regs, VGA_CRTC_CESL, msl);
806fc1821feSrugrat }
807fc1821feSrugrat
808fc1821feSrugrat static void
vgatext_set_cursor(struct gfxp_fb_softc * softc,int row,int col)80930165b7fSToomas Soome vgatext_set_cursor(struct gfxp_fb_softc *softc, int row, int col)
810fc1821feSrugrat {
81182bb7c22SToomas Soome union gfx_console *console = softc->console;
812fc1821feSrugrat short addr;
8133ef9594aSToomas Soome uint8_t msl, s;
814fc1821feSrugrat
81582bb7c22SToomas Soome if (softc->silent)
816fc1821feSrugrat return;
817fc1821feSrugrat
81882bb7c22SToomas Soome msl = vga_get_crtc(&console->vga.regs, VGA_CRTC_MAX_S_LN) & 0x1f;
81982bb7c22SToomas Soome s = vga_get_crtc(&console->vga.regs, VGA_CRTC_CSSL) & 0xc0;
8203ef9594aSToomas Soome
82182bb7c22SToomas Soome addr = row * VGA_TEXT_COLS + col;
822fc1821feSrugrat
82382bb7c22SToomas Soome vga_set_crtc(&console->vga.regs, VGA_CRTC_CLAH, addr >> 8);
82482bb7c22SToomas Soome vga_set_crtc(&console->vga.regs, VGA_CRTC_CLAL, addr & 0xff);
8253ef9594aSToomas Soome
8263ef9594aSToomas Soome /* enable cursor */
82782bb7c22SToomas Soome vga_set_crtc(&console->vga.regs, VGA_CRTC_CSSL, s);
82882bb7c22SToomas Soome vga_set_crtc(&console->vga.regs, VGA_CRTC_CESL, msl);
829fc1821feSrugrat }
830fc1821feSrugrat
831fc1821feSrugrat static void
vgatext_get_cursor(struct gfxp_fb_softc * softc,screen_pos_t * row,screen_pos_t * col)83230165b7fSToomas Soome vgatext_get_cursor(struct gfxp_fb_softc *softc,
833fc1821feSrugrat screen_pos_t *row, screen_pos_t *col)
834fc1821feSrugrat {
83582bb7c22SToomas Soome union gfx_console *console = softc->console;
836fc1821feSrugrat short addr;
837fc1821feSrugrat
83882bb7c22SToomas Soome addr = (vga_get_crtc(&console->vga.regs, VGA_CRTC_CLAH) << 8) +
83982bb7c22SToomas Soome vga_get_crtc(&console->vga.regs, VGA_CRTC_CLAL);
840fc1821feSrugrat
84182bb7c22SToomas Soome *row = addr / VGA_TEXT_COLS;
84282bb7c22SToomas Soome *col = addr % VGA_TEXT_COLS;
84382bb7c22SToomas Soome }
84482bb7c22SToomas Soome
84582bb7c22SToomas Soome static void
vgatext_get_text(struct gfxp_fb_softc * softc)84682bb7c22SToomas Soome vgatext_get_text(struct gfxp_fb_softc *softc)
84782bb7c22SToomas Soome {
84882bb7c22SToomas Soome union gfx_console *console = softc->console;
84982bb7c22SToomas Soome struct vgareg *vga_reg;
85082bb7c22SToomas Soome struct vgaregmap *regs;
85182bb7c22SToomas Soome int i;
85282bb7c22SToomas Soome
85382bb7c22SToomas Soome regs = &console->vga.regs;
85482bb7c22SToomas Soome vga_reg = &console->vga.vga_reg;
85582bb7c22SToomas Soome
85682bb7c22SToomas Soome vga_reg->vga_misc = vga_get_reg(regs, VGA_MISC_R);
85782bb7c22SToomas Soome
85882bb7c22SToomas Soome /* get crt controller registers */
85982bb7c22SToomas Soome for (i = 0; i < NUM_CRTC_REG; i++) {
86082bb7c22SToomas Soome vga_reg->vga_crtc[i] = vga_get_crtc(regs, i);
86182bb7c22SToomas Soome }
86282bb7c22SToomas Soome
86382bb7c22SToomas Soome /* get attribute registers */
86482bb7c22SToomas Soome for (i = 0; i < NUM_ATR_REG; i++) {
86582bb7c22SToomas Soome vga_reg->vga_atr[i] = vga_get_atr(regs, i);
86682bb7c22SToomas Soome }
86782bb7c22SToomas Soome
86882bb7c22SToomas Soome /* get graphics controller registers */
86982bb7c22SToomas Soome for (i = 0; i < NUM_GRC_REG; i++) {
87082bb7c22SToomas Soome vga_reg->vga_grc[i] = vga_get_grc(regs, i);
87182bb7c22SToomas Soome }
87282bb7c22SToomas Soome
87382bb7c22SToomas Soome /* get sequencer registers */
87482bb7c22SToomas Soome for (i = 1; i < NUM_SEQ_REG; i++) {
87582bb7c22SToomas Soome vga_reg->vga_seq[i] = vga_get_seq(regs, i);
87682bb7c22SToomas Soome }
877fc1821feSrugrat }
878fc1821feSrugrat
879fc1821feSrugrat /*
880fc1821feSrugrat * This code is experimental. It's only enabled if console is
881fc1821feSrugrat * set to graphics, a preliminary implementation of happyface boot.
882fc1821feSrugrat */
883fc1821feSrugrat static void
vgatext_set_text(struct gfxp_fb_softc * softc)88430165b7fSToomas Soome vgatext_set_text(struct gfxp_fb_softc *softc)
885fc1821feSrugrat {
88682bb7c22SToomas Soome union gfx_console *console = softc->console;
88782bb7c22SToomas Soome struct vgareg *vga_reg;
88882bb7c22SToomas Soome struct vgaregmap *regs;
889fc1821feSrugrat int i;
890fc1821feSrugrat
89182bb7c22SToomas Soome regs = &console->vga.regs;
89282bb7c22SToomas Soome vga_reg = &console->vga.vga_reg;
893fc1821feSrugrat
89482bb7c22SToomas Soome vgatext_get_text(softc);
895fc1821feSrugrat
89682bb7c22SToomas Soome /*
89782bb7c22SToomas Soome * Set output register bits for text mode.
89882bb7c22SToomas Soome * Make sure the VGA adapter is not in monochrome emulation mode.
89982bb7c22SToomas Soome */
90082bb7c22SToomas Soome vga_set_reg(regs, VGA_MISC_W, VGA_MISC_HSP | VGA_MISC_PGSL |
90182bb7c22SToomas Soome VGA_MISC_VCLK1 | VGA_MISC_ENB_RAM | VGA_MISC_IOA_SEL);
902fc1821feSrugrat
903fc1821feSrugrat /* set sequencer registers */
90482bb7c22SToomas Soome vga_set_seq(regs, VGA_SEQ_RST_SYN,
90582bb7c22SToomas Soome (vga_get_seq(regs, VGA_SEQ_RST_SYN) &
9062df1fe9cSrandyf ~VGA_SEQ_RST_SYN_NO_SYNC_RESET));
907fc1821feSrugrat for (i = 1; i < NUM_SEQ_REG; i++) {
90882bb7c22SToomas Soome vga_set_seq(regs, i, VGA_SEQ_TEXT[i]);
909fc1821feSrugrat }
91082bb7c22SToomas Soome vga_set_seq(regs, VGA_SEQ_RST_SYN,
91182bb7c22SToomas Soome (vga_get_seq(regs, VGA_SEQ_RST_SYN) |
9122df1fe9cSrandyf VGA_SEQ_RST_SYN_NO_ASYNC_RESET |
9132df1fe9cSrandyf VGA_SEQ_RST_SYN_NO_SYNC_RESET));
914fc1821feSrugrat
915fc1821feSrugrat /* set crt controller registers */
91682bb7c22SToomas Soome vga_set_crtc(regs, VGA_CRTC_VRE,
91782bb7c22SToomas Soome (vga_reg->vga_crtc[VGA_CRTC_VRE] & ~VGA_CRTC_VRE_LOCK));
918fc1821feSrugrat for (i = 0; i < NUM_CRTC_REG; i++) {
91982bb7c22SToomas Soome vga_set_crtc(regs, i, VGA_CRTC_TEXT[i]);
920fc1821feSrugrat }
921fc1821feSrugrat
922fc1821feSrugrat /* set graphics controller registers */
923fc1821feSrugrat for (i = 0; i < NUM_GRC_REG; i++) {
92482bb7c22SToomas Soome vga_set_grc(regs, i, VGA_GRC_TEXT[i]);
925fc1821feSrugrat }
926fc1821feSrugrat
927fc1821feSrugrat /* set attribute registers */
928fc1821feSrugrat for (i = 0; i < NUM_ATR_REG; i++) {
92982bb7c22SToomas Soome vga_set_atr(regs, i, VGA_ATR_TEXT[i]);
930fc1821feSrugrat }
931fc1821feSrugrat
932fc1821feSrugrat /* set palette */
933fc1821feSrugrat for (i = 0; i < VGA_TEXT_CMAP_ENTRIES; i++) {
93482bb7c22SToomas Soome vga_put_cmap(regs, i,
93582bb7c22SToomas Soome VGA_TEXT_PALETTES[i][0] << 2,
9362df1fe9cSrandyf VGA_TEXT_PALETTES[i][1] << 2,
9372df1fe9cSrandyf VGA_TEXT_PALETTES[i][2] << 2);
938fc1821feSrugrat }
939fc1821feSrugrat for (i = VGA_TEXT_CMAP_ENTRIES; i < VGA8_CMAP_ENTRIES; i++) {
94082bb7c22SToomas Soome vga_put_cmap(regs, i, 0, 0, 0);
941fc1821feSrugrat }
942fc1821feSrugrat }
943fc1821feSrugrat
944fc1821feSrugrat static void
vgatext_init(struct gfxp_fb_softc * softc)94530165b7fSToomas Soome vgatext_init(struct gfxp_fb_softc *softc)
946fc1821feSrugrat {
94782bb7c22SToomas Soome union gfx_console *console = softc->console;
948097aa9ceSToomas Soome bitmap_data_t *font_data;
949fc1821feSrugrat unsigned char atr_mode;
950097aa9ceSToomas Soome short width, height;
951097aa9ceSToomas Soome int i;
952fc1821feSrugrat
95382bb7c22SToomas Soome atr_mode = vga_get_atr(&console->vga.regs, VGA_ATR_MODE);
954fc1821feSrugrat if (atr_mode & VGA_ATR_MODE_GRAPH)
955fc1821feSrugrat vgatext_set_text(softc);
95682bb7c22SToomas Soome atr_mode = vga_get_atr(&console->vga.regs, VGA_ATR_MODE);
957fc1821feSrugrat atr_mode &= ~VGA_ATR_MODE_BLINK;
958fc1821feSrugrat atr_mode &= ~VGA_ATR_MODE_9WIDE;
95982bb7c22SToomas Soome vga_set_atr(&console->vga.regs, VGA_ATR_MODE, atr_mode);
960fc1821feSrugrat #if defined(USE_BORDERS)
96182bb7c22SToomas Soome vga_set_atr(&console->vga.regs, VGA_ATR_BDR_CLR,
96282bb7c22SToomas Soome vga_get_atr(&console->vga.regs, pc_brt_white));
963fc1821feSrugrat #else
96482bb7c22SToomas Soome vga_set_atr(&console->vga.regs, VGA_ATR_BDR_CLR,
96582bb7c22SToomas Soome vga_get_atr(&console->vga.regs, pc_black));
966fc1821feSrugrat #endif
967097aa9ceSToomas Soome
968097aa9ceSToomas Soome width = VGA_TEXT_COLS;
969097aa9ceSToomas Soome height = VGA_TEXT_ROWS;
970097aa9ceSToomas Soome font_data = set_font(&height, &width,
971097aa9ceSToomas Soome 16 * height + BORDER_PIXELS,
972097aa9ceSToomas Soome 8 * width + BORDER_PIXELS);
973097aa9ceSToomas Soome for (i = 0; i < VFNT_MAPS; i++) {
974097aa9ceSToomas Soome console->vga.font.vf_map[i] = font_data->font->vf_map[i];
975097aa9ceSToomas Soome console->vga.font.vf_map_count[i] =
976097aa9ceSToomas Soome font_data->font->vf_map_count[i];
977097aa9ceSToomas Soome }
978097aa9ceSToomas Soome console->vga.font.vf_bytes = font_data->font->vf_bytes;
979097aa9ceSToomas Soome console->vga.font.vf_width = font_data->font->vf_width;
980097aa9ceSToomas Soome console->vga.font.vf_height = font_data->font->vf_height;
981097aa9ceSToomas Soome vgatext_setfont(softc);
982fc1821feSrugrat }
983fc1821feSrugrat
984fc1821feSrugrat #if defined(USE_BORDERS)
985fc1821feSrugrat static void
vgatext_init_graphics(struct gfxp_fb_softc * softc)98630165b7fSToomas Soome vgatext_init_graphics(struct gfxp_fb_softc *softc)
987fc1821feSrugrat {
98882bb7c22SToomas Soome vga_set_atr(&softc->console->vga.regs, VGA_ATR_BDR_CLR,
989cbc8e155SToomas Soome vga_get_atr(&softc->console->vga.regs, pc_black));
990fc1821feSrugrat }
991fc1821feSrugrat #endif
992fc1821feSrugrat
993cbc8e155SToomas Soome /*
994cbc8e155SToomas Soome * Binary searchable table for CP437 to Unicode conversion.
995cbc8e155SToomas Soome */
996cbc8e155SToomas Soome struct cp437uni {
997cbc8e155SToomas Soome uint8_t cp437_base;
998cbc8e155SToomas Soome uint16_t unicode_base;
999cbc8e155SToomas Soome uint8_t length;
1000cbc8e155SToomas Soome };
1001cbc8e155SToomas Soome
1002cbc8e155SToomas Soome static const struct cp437uni cp437unitable[] = {
1003cbc8e155SToomas Soome { 0, 0x0000, 0 }, { 1, 0x263A, 1 }, { 3, 0x2665, 1 },
1004cbc8e155SToomas Soome { 5, 0x2663, 0 }, { 6, 0x2660, 0 }, { 7, 0x2022, 0 },
1005cbc8e155SToomas Soome { 8, 0x25D8, 0 }, { 9, 0x25CB, 0 }, { 10, 0x25D9, 0 },
1006cbc8e155SToomas Soome { 11, 0x2642, 0 }, { 12, 0x2640, 0 }, { 13, 0x266A, 1 },
1007cbc8e155SToomas Soome { 15, 0x263C, 0 }, { 16, 0x25BA, 0 }, { 17, 0x25C4, 0 },
1008cbc8e155SToomas Soome { 18, 0x2195, 0 }, { 19, 0x203C, 0 }, { 20, 0x00B6, 0 },
1009cbc8e155SToomas Soome { 21, 0x00A7, 0 }, { 22, 0x25AC, 0 }, { 23, 0x21A8, 0 },
1010cbc8e155SToomas Soome { 24, 0x2191, 0 }, { 25, 0x2193, 0 }, { 26, 0x2192, 0 },
1011cbc8e155SToomas Soome { 27, 0x2190, 0 }, { 28, 0x221F, 0 }, { 29, 0x2194, 0 },
1012cbc8e155SToomas Soome { 30, 0x25B2, 0 }, { 31, 0x25BC, 0 }, { 32, 0x0020, 0x5e },
1013cbc8e155SToomas Soome { 127, 0x2302, 0 }, { 128, 0x00C7, 0 }, { 129, 0x00FC, 0 },
1014cbc8e155SToomas Soome { 130, 0x00E9, 0 }, { 131, 0x00E2, 0 }, { 132, 0x00E4, 0 },
1015cbc8e155SToomas Soome { 133, 0x00E0, 0 }, { 134, 0x00E5, 0 }, { 135, 0x00E7, 0 },
1016cbc8e155SToomas Soome { 136, 0x00EA, 1 }, { 138, 0x00E8, 0 }, { 139, 0x00EF, 0 },
1017cbc8e155SToomas Soome { 140, 0x00EE, 0 }, { 141, 0x00EC, 0 }, { 142, 0x00C4, 1 },
1018cbc8e155SToomas Soome { 144, 0x00C9, 0 }, { 145, 0x00E6, 0 }, { 146, 0x00C6, 0 },
1019cbc8e155SToomas Soome { 147, 0x00F4, 0 }, { 148, 0x00F6, 0 }, { 149, 0x00F2, 0 },
1020cbc8e155SToomas Soome { 150, 0x00FB, 0 }, { 151, 0x00F9, 0 }, { 152, 0x00FF, 0 },
1021cbc8e155SToomas Soome { 153, 0x00D6, 0 }, { 154, 0x00DC, 0 }, { 155, 0x00A2, 1 },
1022cbc8e155SToomas Soome { 157, 0x00A5, 0 }, { 158, 0x20A7, 0 }, { 159, 0x0192, 0 },
1023cbc8e155SToomas Soome { 160, 0x00E1, 0 }, { 161, 0x00ED, 0 }, { 162, 0x00F3, 0 },
1024cbc8e155SToomas Soome { 163, 0x00FA, 0 }, { 164, 0x00F1, 0 }, { 165, 0x00D1, 0 },
1025cbc8e155SToomas Soome { 166, 0x00AA, 0 }, { 167, 0x00BA, 0 }, { 168, 0x00BF, 0 },
1026cbc8e155SToomas Soome { 169, 0x2310, 0 }, { 170, 0x00AC, 0 }, { 171, 0x00BD, 0 },
1027cbc8e155SToomas Soome { 172, 0x00BC, 0 }, { 173, 0x00A1, 0 }, { 174, 0x00AB, 0 },
1028cbc8e155SToomas Soome { 175, 0x00BB, 0 }, { 176, 0x2591, 2 }, { 179, 0x2502, 0 },
1029cbc8e155SToomas Soome { 180, 0x2524, 0 }, { 181, 0x2561, 1 }, { 183, 0x2556, 0 },
1030cbc8e155SToomas Soome { 184, 0x2555, 0 }, { 185, 0x2563, 0 }, { 186, 0x2551, 0 },
1031cbc8e155SToomas Soome { 187, 0x2557, 0 }, { 188, 0x255D, 0 }, { 189, 0x255C, 0 },
1032cbc8e155SToomas Soome { 190, 0x255B, 0 }, { 191, 0x2510, 0 }, { 192, 0x2514, 0 },
1033cbc8e155SToomas Soome { 193, 0x2534, 0 }, { 194, 0x252C, 0 }, { 195, 0x251C, 0 },
1034cbc8e155SToomas Soome { 196, 0x2500, 0 }, { 197, 0x253C, 0 }, { 198, 0x255E, 1 },
1035cbc8e155SToomas Soome { 200, 0x255A, 0 }, { 201, 0x2554, 0 }, { 202, 0x2569, 0 },
1036cbc8e155SToomas Soome { 203, 0x2566, 0 }, { 204, 0x2560, 0 }, { 205, 0x2550, 0 },
1037cbc8e155SToomas Soome { 206, 0x256C, 0 }, { 207, 0x2567, 1 }, { 209, 0x2564, 1 },
1038cbc8e155SToomas Soome { 211, 0x2559, 0 }, { 212, 0x2558, 0 }, { 213, 0x2552, 1 },
1039cbc8e155SToomas Soome { 215, 0x256B, 0 }, { 216, 0x256A, 0 }, { 217, 0x2518, 0 },
1040cbc8e155SToomas Soome { 218, 0x250C, 0 }, { 219, 0x2588, 0 }, { 220, 0x2584, 0 },
1041cbc8e155SToomas Soome { 221, 0x258C, 0 }, { 222, 0x2590, 0 }, { 223, 0x2580, 0 },
1042cbc8e155SToomas Soome { 224, 0x03B1, 0 }, { 225, 0x00DF, 0 }, { 226, 0x0393, 0 },
1043cbc8e155SToomas Soome { 227, 0x03C0, 0 }, { 228, 0x03A3, 0 }, { 229, 0x03C3, 0 },
1044cbc8e155SToomas Soome { 230, 0x00B5, 0 }, { 231, 0x03C4, 0 }, { 232, 0x03A6, 0 },
1045cbc8e155SToomas Soome { 233, 0x0398, 0 }, { 234, 0x03A9, 0 }, { 235, 0x03B4, 0 },
1046cbc8e155SToomas Soome { 236, 0x221E, 0 }, { 237, 0x03C6, 0 }, { 238, 0x03B5, 0 },
1047cbc8e155SToomas Soome { 239, 0x2229, 0 }, { 240, 0x2261, 0 }, { 241, 0x00B1, 0 },
1048cbc8e155SToomas Soome { 242, 0x2265, 0 }, { 243, 0x2264, 0 }, { 244, 0x2320, 1 },
1049cbc8e155SToomas Soome { 246, 0x00F7, 0 }, { 247, 0x2248, 0 }, { 248, 0x00B0, 0 },
1050cbc8e155SToomas Soome { 249, 0x2219, 0 }, { 250, 0x00B7, 0 }, { 251, 0x221A, 0 },
1051cbc8e155SToomas Soome { 252, 0x207F, 0 }, { 253, 0x00B2, 0 }, { 254, 0x25A0, 0 },
1052cbc8e155SToomas Soome { 255, 0x00A0, 0 }
1053cbc8e155SToomas Soome };
1054cbc8e155SToomas Soome
1055cbc8e155SToomas Soome static uint16_t
vga_cp437_to_uni(uint8_t c)1056cbc8e155SToomas Soome vga_cp437_to_uni(uint8_t c)
1057cbc8e155SToomas Soome {
1058cbc8e155SToomas Soome int min, mid, max;
1059cbc8e155SToomas Soome
1060cbc8e155SToomas Soome min = 0;
1061cbc8e155SToomas Soome max = (sizeof (cp437unitable) / sizeof (struct cp437uni)) - 1;
1062cbc8e155SToomas Soome
1063cbc8e155SToomas Soome while (max >= min) {
1064cbc8e155SToomas Soome mid = (min + max) / 2;
1065cbc8e155SToomas Soome if (c < cp437unitable[mid].cp437_base)
1066cbc8e155SToomas Soome max = mid - 1;
1067cbc8e155SToomas Soome else if (c > cp437unitable[mid].cp437_base +
1068cbc8e155SToomas Soome cp437unitable[mid].length)
1069cbc8e155SToomas Soome min = mid + 1;
1070cbc8e155SToomas Soome else
1071cbc8e155SToomas Soome return (c - cp437unitable[mid].cp437_base +
1072cbc8e155SToomas Soome cp437unitable[mid].unicode_base);
1073cbc8e155SToomas Soome }
1074cbc8e155SToomas Soome
1075cbc8e155SToomas Soome return ('?');
1076cbc8e155SToomas Soome }
1077cbc8e155SToomas Soome
1078fc1821feSrugrat static void
vgatext_setfont(struct gfxp_fb_softc * softc)107930165b7fSToomas Soome vgatext_setfont(struct gfxp_fb_softc *softc)
1080fc1821feSrugrat {
108182bb7c22SToomas Soome union gfx_console *console = softc->console;
108230165b7fSToomas Soome static uchar_t fsreg[8] = {0x0, 0x30, 0x5, 0x35, 0xa, 0x3a, 0xf, 0x3f};
1083fc1821feSrugrat
1084cbc8e155SToomas Soome const uchar_t *from;
108530165b7fSToomas Soome uchar_t volatile *to;
1086cbc8e155SToomas Soome uint16_t c;
108730165b7fSToomas Soome int i, j, s;
108830165b7fSToomas Soome int bpc, f_offset;
1089fc1821feSrugrat
109030165b7fSToomas Soome /* Sync-reset the sequencer registers */
109182bb7c22SToomas Soome vga_set_seq(&console->vga.regs, 0x00, 0x01);
1092fc1821feSrugrat /*
109330165b7fSToomas Soome * enable write to plane2, since fonts
109430165b7fSToomas Soome * could only be loaded into plane2
1095fc1821feSrugrat */
109682bb7c22SToomas Soome vga_set_seq(&console->vga.regs, 0x02, 0x04);
109730165b7fSToomas Soome /*
109830165b7fSToomas Soome * sequentially access data in the bit map being
109930165b7fSToomas Soome * selected by MapMask register (index 0x02)
110030165b7fSToomas Soome */
110182bb7c22SToomas Soome vga_set_seq(&console->vga.regs, 0x04, 0x07);
110230165b7fSToomas Soome /* Sync-reset ended, and allow the sequencer to operate */
110382bb7c22SToomas Soome vga_set_seq(&console->vga.regs, 0x00, 0x03);
110430165b7fSToomas Soome
110530165b7fSToomas Soome /*
110630165b7fSToomas Soome * select plane 2 on Read Mode 0
110730165b7fSToomas Soome */
110882bb7c22SToomas Soome vga_set_grc(&console->vga.regs, 0x04, 0x02);
110930165b7fSToomas Soome /*
111030165b7fSToomas Soome * system addresses sequentially access data, follow
111130165b7fSToomas Soome * Memory Mode register bit 2 in the sequencer
111230165b7fSToomas Soome */
111382bb7c22SToomas Soome vga_set_grc(&console->vga.regs, 0x05, 0x00);
111430165b7fSToomas Soome /*
111530165b7fSToomas Soome * set range of host memory addresses decoded by VGA
111630165b7fSToomas Soome * hardware -- A0000h-BFFFFh (128K region)
111730165b7fSToomas Soome */
111882bb7c22SToomas Soome vga_set_grc(&console->vga.regs, 0x06, 0x00);
1119fc1821feSrugrat
1120fc1821feSrugrat /*
1121fc1821feSrugrat * This assumes 8x16 characters, which yield the traditional 80x25
1122fc1821feSrugrat * screen. It really should support other character heights.
1123fc1821feSrugrat */
1124fc1821feSrugrat bpc = 16;
112582bb7c22SToomas Soome s = console->vga.vga_fontslot;
112630165b7fSToomas Soome f_offset = s * 8 * 1024;
1127fc1821feSrugrat for (i = 0; i < 256; i++) {
1128cbc8e155SToomas Soome c = vga_cp437_to_uni(i);
1129097aa9ceSToomas Soome from = font_lookup(&console->vga.font, c);
113082bb7c22SToomas Soome to = (unsigned char *)console->vga.fb.addr + f_offset +
113182bb7c22SToomas Soome i * 0x20;
1132fc1821feSrugrat for (j = 0; j < bpc; j++)
1133fc1821feSrugrat *to++ = *from++;
1134fc1821feSrugrat }
1135fc1821feSrugrat
113630165b7fSToomas Soome /* Sync-reset the sequencer registers */
113782bb7c22SToomas Soome vga_set_seq(&console->vga.regs, 0x00, 0x01);
113830165b7fSToomas Soome /* enable write to plane 0 and 1 */
113982bb7c22SToomas Soome vga_set_seq(&console->vga.regs, 0x02, 0x03);
114030165b7fSToomas Soome /*
114130165b7fSToomas Soome * enable character map selection
114230165b7fSToomas Soome * and odd/even addressing
114330165b7fSToomas Soome */
114482bb7c22SToomas Soome vga_set_seq(&console->vga.regs, 0x04, 0x03);
114530165b7fSToomas Soome /*
114630165b7fSToomas Soome * select font map
114730165b7fSToomas Soome */
114882bb7c22SToomas Soome vga_set_seq(&console->vga.regs, 0x03, fsreg[s]);
114930165b7fSToomas Soome /* Sync-reset ended, and allow the sequencer to operate */
115082bb7c22SToomas Soome vga_set_seq(&console->vga.regs, 0x00, 0x03);
115130165b7fSToomas Soome
115230165b7fSToomas Soome /* restore graphic registers */
115330165b7fSToomas Soome
115430165b7fSToomas Soome /* select plane 0 */
115582bb7c22SToomas Soome vga_set_grc(&console->vga.regs, 0x04, 0x00);
115630165b7fSToomas Soome /* enable odd/even addressing mode */
115782bb7c22SToomas Soome vga_set_grc(&console->vga.regs, 0x05, 0x10);
115830165b7fSToomas Soome /*
115930165b7fSToomas Soome * range of host memory addresses decoded by VGA
116030165b7fSToomas Soome * hardware -- B8000h-BFFFFh (32K region)
116130165b7fSToomas Soome */
116282bb7c22SToomas Soome vga_set_grc(&console->vga.regs, 0x06, 0x0e);
116330165b7fSToomas Soome /* enable all color plane */
116482bb7c22SToomas Soome vga_set_atr(&console->vga.regs, 0x12, 0x0f);
1165fc1821feSrugrat
1166fc1821feSrugrat }
1167fc1821feSrugrat
1168fc1821feSrugrat static void
vgatext_save_colormap(struct gfxp_fb_softc * softc)116930165b7fSToomas Soome vgatext_save_colormap(struct gfxp_fb_softc *softc)
1170fc1821feSrugrat {
117182bb7c22SToomas Soome union gfx_console *console = softc->console;
1172fc1821feSrugrat int i;
1173fc1821feSrugrat
1174fc1821feSrugrat for (i = 0; i < VGA_ATR_NUM_PLT; i++) {
117582bb7c22SToomas Soome console->vga.attrib_palette[i] =
117682bb7c22SToomas Soome vga_get_atr(&console->vga.regs, i);
1177fc1821feSrugrat }
1178fc1821feSrugrat for (i = 0; i < VGA8_CMAP_ENTRIES; i++) {
117982bb7c22SToomas Soome vga_get_cmap(&console->vga.regs, i,
118082bb7c22SToomas Soome &console->vga.colormap[i].red,
118182bb7c22SToomas Soome &console->vga.colormap[i].green,
118282bb7c22SToomas Soome &console->vga.colormap[i].blue);
1183fc1821feSrugrat }
1184fc1821feSrugrat }
1185fc1821feSrugrat
1186fc1821feSrugrat static void
vgatext_restore_colormap(struct gfxp_fb_softc * softc)118730165b7fSToomas Soome vgatext_restore_colormap(struct gfxp_fb_softc *softc)
1188fc1821feSrugrat {
118982bb7c22SToomas Soome union gfx_console *console = softc->console;
1190fc1821feSrugrat int i;
1191fc1821feSrugrat
1192fc1821feSrugrat for (i = 0; i < VGA_ATR_NUM_PLT; i++) {
119382bb7c22SToomas Soome vga_set_atr(&console->vga.regs, i,
119482bb7c22SToomas Soome console->vga.attrib_palette[i]);
1195fc1821feSrugrat }
1196fc1821feSrugrat for (i = 0; i < VGA8_CMAP_ENTRIES; i++) {
119782bb7c22SToomas Soome vga_put_cmap(&console->vga.regs, i,
119882bb7c22SToomas Soome console->vga.colormap[i].red,
119982bb7c22SToomas Soome console->vga.colormap[i].green,
120082bb7c22SToomas Soome console->vga.colormap[i].blue);
1201fc1821feSrugrat }
1202fc1821feSrugrat }
1203fc1821feSrugrat
1204fc1821feSrugrat /*
1205fc1821feSrugrat * search the entries of the "reg" property for one which has the desired
1206fc1821feSrugrat * combination of phys_hi bits and contains the desired address.
1207fc1821feSrugrat *
1208fc1821feSrugrat * This version searches a PCI-style "reg" property. It was prompted by
1209fc1821feSrugrat * issues surrounding the presence or absence of an entry for the ROM:
1210fc1821feSrugrat * (a) a transition problem with PowerPC Virtual Open Firmware
1211fc1821feSrugrat * (b) uncertainty as to whether an entry will be included on a device
1212fc1821feSrugrat * with ROM support (and so an "active" ROM base address register),
1213fc1821feSrugrat * but no ROM actually installed.
1214fc1821feSrugrat *
1215fc1821feSrugrat * See the note below on vgatext_get_isa_reg_index for the reasons for
1216fc1821feSrugrat * returning the offset.
1217fc1821feSrugrat *
1218fc1821feSrugrat * Note that this routine may not be fully general; it is intended for the
1219fc1821feSrugrat * specific purpose of finding a couple of particular VGA reg entries and
1220fc1821feSrugrat * may not be suitable for all reg-searching purposes.
1221fc1821feSrugrat */
1222fc1821feSrugrat static int
vgatext_get_pci_reg_index(dev_info_t * const devi,unsigned long himask,unsigned long hival,unsigned long addr,off_t * offset)1223fc1821feSrugrat vgatext_get_pci_reg_index(
1224fc1821feSrugrat dev_info_t *const devi,
1225fc1821feSrugrat unsigned long himask,
1226fc1821feSrugrat unsigned long hival,
1227fc1821feSrugrat unsigned long addr,
1228fc1821feSrugrat off_t *offset)
1229fc1821feSrugrat {
1230fc1821feSrugrat
1231fc1821feSrugrat int length, index;
1232fc1821feSrugrat pci_regspec_t *reg;
1233fc1821feSrugrat
1234fc1821feSrugrat if (ddi_getlongprop(DDI_DEV_T_ANY, devi, DDI_PROP_DONTPASS,
12352df1fe9cSrandyf "reg", (caddr_t)®, &length) != DDI_PROP_SUCCESS) {
1236fc1821feSrugrat return (-1);
1237fc1821feSrugrat }
1238fc1821feSrugrat
1239fc1821feSrugrat for (index = 0; index < length / sizeof (pci_regspec_t); index++) {
1240fc1821feSrugrat if ((reg[index].pci_phys_hi & himask) != hival)
1241fc1821feSrugrat continue;
1242fc1821feSrugrat if (reg[index].pci_size_hi != 0)
1243fc1821feSrugrat continue;
1244fc1821feSrugrat if (reg[index].pci_phys_mid != 0)
1245fc1821feSrugrat continue;
1246fc1821feSrugrat if (reg[index].pci_phys_low > addr)
1247fc1821feSrugrat continue;
1248fc1821feSrugrat if (reg[index].pci_phys_low + reg[index].pci_size_low <= addr)
1249fc1821feSrugrat continue;
1250fc1821feSrugrat
1251fc1821feSrugrat *offset = addr - reg[index].pci_phys_low;
1252fc1821feSrugrat kmem_free(reg, (size_t)length);
1253fc1821feSrugrat return (index);
1254fc1821feSrugrat }
1255fc1821feSrugrat kmem_free(reg, (size_t)length);
1256fc1821feSrugrat
1257fc1821feSrugrat return (-1);
1258fc1821feSrugrat }
1259fc1821feSrugrat
1260fc1821feSrugrat /*
1261fc1821feSrugrat * search the entries of the "reg" property for one which has the desired
1262fc1821feSrugrat * combination of phys_hi bits and contains the desired address.
1263fc1821feSrugrat *
1264fc1821feSrugrat * This version searches a ISA-style "reg" property. It was prompted by
1265fc1821feSrugrat * issues surrounding 8514/A support. By IEEE 1275 compatibility conventions,
1266fc1821feSrugrat * 8514/A registers should have been added after all standard VGA registers.
1267fc1821feSrugrat * Unfortunately, the Solaris/Intel device configuration framework
1268fc1821feSrugrat * (a) lists the 8514/A registers before the video memory, and then
1269fc1821feSrugrat * (b) also sorts the entries so that I/O entries come before memory
1270fc1821feSrugrat * entries.
1271fc1821feSrugrat *
1272fc1821feSrugrat * It returns the "reg" index and offset into that register set.
1273fc1821feSrugrat * The offset is needed because there exist (broken?) BIOSes that
1274fc1821feSrugrat * report larger ranges enclosing the standard ranges. One reports
1275fc1821feSrugrat * 0x3bf for 0x21 instead of 0x3c0 for 0x20, for instance. Using the
1276fc1821feSrugrat * offset adjusts for this difference in the base of the register set.
1277fc1821feSrugrat *
1278fc1821feSrugrat * Note that this routine may not be fully general; it is intended for the
1279fc1821feSrugrat * specific purpose of finding a couple of particular VGA reg entries and
1280fc1821feSrugrat * may not be suitable for all reg-searching purposes.
1281fc1821feSrugrat */
1282fc1821feSrugrat static int
vgatext_get_isa_reg_index(dev_info_t * const devi,unsigned long hival,unsigned long addr,off_t * offset)1283fc1821feSrugrat vgatext_get_isa_reg_index(
1284fc1821feSrugrat dev_info_t *const devi,
1285fc1821feSrugrat unsigned long hival,
1286fc1821feSrugrat unsigned long addr,
1287fc1821feSrugrat off_t *offset)
1288fc1821feSrugrat {
1289fc1821feSrugrat
1290fc1821feSrugrat int length, index;
1291fc1821feSrugrat struct regspec *reg;
1292fc1821feSrugrat
1293fc1821feSrugrat if (ddi_getlongprop(DDI_DEV_T_ANY, devi, DDI_PROP_DONTPASS,
12942df1fe9cSrandyf "reg", (caddr_t)®, &length) != DDI_PROP_SUCCESS) {
1295fc1821feSrugrat return (-1);
1296fc1821feSrugrat }
1297fc1821feSrugrat
1298fc1821feSrugrat for (index = 0; index < length / sizeof (struct regspec); index++) {
1299fc1821feSrugrat if (reg[index].regspec_bustype != hival)
1300fc1821feSrugrat continue;
1301fc1821feSrugrat if (reg[index].regspec_addr > addr)
1302fc1821feSrugrat continue;
1303fc1821feSrugrat if (reg[index].regspec_addr + reg[index].regspec_size <= addr)
1304fc1821feSrugrat continue;
1305fc1821feSrugrat
1306fc1821feSrugrat *offset = addr - reg[index].regspec_addr;
1307fc1821feSrugrat kmem_free(reg, (size_t)length);
1308fc1821feSrugrat return (index);
1309fc1821feSrugrat }
1310fc1821feSrugrat kmem_free(reg, (size_t)length);
1311fc1821feSrugrat
1312fc1821feSrugrat return (-1);
1313fc1821feSrugrat }
13142df1fe9cSrandyf
13152df1fe9cSrandyf /*
13162df1fe9cSrandyf * This vgatext function is used to return the fb, and reg pointers
13172df1fe9cSrandyf * and handles for peer graphics drivers.
13182df1fe9cSrandyf */
13192df1fe9cSrandyf
13202df1fe9cSrandyf void
vgatext_return_pointers(struct gfxp_fb_softc * softc,struct vgaregmap * fbs,struct vgaregmap * regss)132130165b7fSToomas Soome vgatext_return_pointers(struct gfxp_fb_softc *softc, struct vgaregmap *fbs,
1322d1e631afSToomas Soome struct vgaregmap *regss)
13232df1fe9cSrandyf {
13242df1fe9cSrandyf
132582bb7c22SToomas Soome fbs->addr = softc->console->vga.fb.addr;
132682bb7c22SToomas Soome fbs->handle = softc->console->vga.fb.handle;
132782bb7c22SToomas Soome fbs->mapped = softc->console->vga.fb.mapped;
132882bb7c22SToomas Soome regss->addr = softc->console->vga.regs.addr;
132982bb7c22SToomas Soome regss->handle = softc->console->vga.regs.handle;
133082bb7c22SToomas Soome regss->mapped = softc->console->vga.regs.mapped;
1331c4d05ea6SGordon Ross }
1332