1945Srugrat /*
2945Srugrat * CDDL HEADER START
3945Srugrat *
4945Srugrat * The contents of this file are subject to the terms of the
51106Smrj * Common Development and Distribution License (the "License").
61106Smrj * You may not use this file except in compliance with the License.
7945Srugrat *
8945Srugrat * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9945Srugrat * or http://www.opensolaris.org/os/licensing.
10945Srugrat * See the License for the specific language governing permissions
11945Srugrat * and limitations under the License.
12945Srugrat *
13945Srugrat * When distributing Covered Code, include this CDDL HEADER in each
14945Srugrat * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15945Srugrat * If applicable, add the following below this CDDL HEADER, with the
16945Srugrat * fields enclosed by brackets "[]" replaced with your own identifying
17945Srugrat * information: Portions Copyright [yyyy] [name of copyright owner]
18945Srugrat *
19945Srugrat * CDDL HEADER END
20945Srugrat */
211106Smrj
22945Srugrat /*
23*11762SEnrico.Perla@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24945Srugrat * Use is subject to license terms.
25945Srugrat */
26945Srugrat
272845Srugrat /* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
282845Srugrat /* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T */
292845Srugrat /* All Rights Reserved */
302845Srugrat
31945Srugrat #include <sys/errno.h>
32945Srugrat #include <sys/types.h>
33945Srugrat #include <sys/conf.h>
34945Srugrat #include <sys/kmem.h>
35945Srugrat #include <sys/visual_io.h>
36945Srugrat #include <sys/font.h>
37945Srugrat #include <sys/fbio.h>
38945Srugrat #include <sys/ddi.h>
39945Srugrat #include <sys/stat.h>
40945Srugrat #include <sys/sunddi.h>
41945Srugrat #include <sys/file.h>
42945Srugrat #include <sys/open.h>
43945Srugrat #include <sys/modctl.h>
44945Srugrat #include <sys/vgareg.h>
45945Srugrat #include <sys/vgasubr.h>
46945Srugrat #include <sys/pci.h>
47945Srugrat #include <sys/kd.h>
48945Srugrat #include <sys/ddi_impldefs.h>
492820Skz151634
50945Srugrat #include "gfx_private.h"
51945Srugrat
52945Srugrat #define MYNAME "gfxp_vgatext"
53945Srugrat
54945Srugrat #define TEXT_ROWS 25
55945Srugrat #define TEXT_COLS 80
56945Srugrat
57945Srugrat #define VGA_BRIGHT_WHITE 0x0f
58945Srugrat #define VGA_BLACK 0x00
59945Srugrat
60945Srugrat #define VGA_REG_ADDR 0x3c0
61945Srugrat #define VGA_REG_SIZE 0x20
62945Srugrat
63945Srugrat #define VGA_MEM_ADDR 0xa0000
64945Srugrat #define VGA_MEM_SIZE 0x20000
65945Srugrat
66945Srugrat #define VGA_MMAP_FB_BASE VGA_MEM_ADDR
67945Srugrat
68945Srugrat struct vgatext_softc {
69945Srugrat struct vgaregmap regs;
70945Srugrat struct vgaregmap fb;
71945Srugrat off_t fb_size;
72945Srugrat int fb_regno;
73945Srugrat dev_info_t *devi;
74945Srugrat int mode; /* KD_TEXT or KD_GRAPHICS */
75945Srugrat caddr_t text_base; /* hardware text base */
76945Srugrat char shadow[TEXT_ROWS*TEXT_COLS*2];
77945Srugrat caddr_t current_base; /* hardware or shadow */
78945Srugrat struct {
79945Srugrat boolean_t visible;
80945Srugrat int row;
81945Srugrat int col;
82945Srugrat } cursor;
83945Srugrat struct vis_polledio polledio;
84945Srugrat struct {
85945Srugrat unsigned char red;
86945Srugrat unsigned char green;
87945Srugrat unsigned char blue;
88945Srugrat } colormap[VGA8_CMAP_ENTRIES];
89945Srugrat unsigned char attrib_palette[VGA_ATR_NUM_PLT];
903499Srugrat unsigned int flags;
918960SJan.Setje-Eilers@Sun.COM kmutex_t lock;
92945Srugrat };
93945Srugrat
94945Srugrat typedef enum pc_colors {
95945Srugrat pc_black = 0,
96945Srugrat pc_blue = 1,
97945Srugrat pc_green = 2,
98945Srugrat pc_cyan = 3,
99945Srugrat pc_red = 4,
100945Srugrat pc_magenta = 5,
101945Srugrat pc_brown = 6,
102945Srugrat pc_white = 7,
103945Srugrat pc_grey = 8,
104945Srugrat pc_brt_blue = 9,
105945Srugrat pc_brt_green = 10,
106945Srugrat pc_brt_cyan = 11,
107945Srugrat pc_brt_red = 12,
108945Srugrat pc_brt_magenta = 13,
109945Srugrat pc_yellow = 14,
110945Srugrat pc_brt_white = 15
111945Srugrat } pc_colors_t;
112945Srugrat
113945Srugrat static const unsigned char solaris_color_to_pc_color[16] = {
114945Srugrat pc_brt_white, /* 0 - brt_white */
115945Srugrat pc_black, /* 1 - black */
116945Srugrat pc_blue, /* 2 - blue */
117945Srugrat pc_green, /* 3 - green */
118945Srugrat pc_cyan, /* 4 - cyan */
119945Srugrat pc_red, /* 5 - red */
120945Srugrat pc_magenta, /* 6 - magenta */
121945Srugrat pc_brown, /* 7 - brown */
122945Srugrat pc_white, /* 8 - white */
123945Srugrat pc_grey, /* 9 - gery */
124945Srugrat pc_brt_blue, /* 10 - brt_blue */
125945Srugrat pc_brt_green, /* 11 - brt_green */
126945Srugrat pc_brt_cyan, /* 12 - brt_cyan */
127945Srugrat pc_brt_red, /* 13 - brt_red */
128945Srugrat pc_brt_magenta, /* 14 - brt_magenta */
129945Srugrat pc_yellow /* 15 - yellow */
130945Srugrat };
131945Srugrat
132945Srugrat static ddi_device_acc_attr_t dev_attr = {
133945Srugrat DDI_DEVICE_ATTR_V0,
134945Srugrat DDI_NEVERSWAP_ACC,
135945Srugrat DDI_STRICTORDER_ACC,
136945Srugrat };
137945Srugrat
138945Srugrat /* default structure for FBIOGATTR ioctl */
139945Srugrat static struct fbgattr vgatext_attr = {
140945Srugrat /* real_type owner */
141945Srugrat FBTYPE_SUNFAST_COLOR, 0,
142945Srugrat /* fbtype: type h w depth cms size */
143945Srugrat { FBTYPE_SUNFAST_COLOR, TEXT_ROWS, TEXT_COLS, 1, 256, 0 },
144945Srugrat /* fbsattr: flags emu_type dev_specific */
145945Srugrat { 0, FBTYPE_SUN4COLOR, { 0 } },
146945Srugrat /* emu_types */
147945Srugrat { -1 }
148945Srugrat };
149945Srugrat
1503499Srugrat #define GFXP_FLAG_CONSOLE 0x00000001
1513499Srugrat #define GFXP_IS_CONSOLE(softc) ((softc)->flags & GFXP_FLAG_CONSOLE)
1523499Srugrat
1535295Srandyf /*
1545295Srandyf * Global name used to write the softc pointer in, for the
1555295Srandyf * data wrapper vgatext_return_pointers()
1565295Srandyf */
1575295Srandyf
1585295Srandyf
1592820Skz151634 int gfxp_vgatext_detach(dev_info_t *devi, ddi_detach_cmd_t cmd,
1602820Skz151634 gfxp_vgatext_softc_ptr_t ptr);
1612820Skz151634 static int vgatext_devinit(struct vgatext_softc *, struct vis_devinit *data);
1622820Skz151634 static void vgatext_cons_copy(struct vgatext_softc *,
1632820Skz151634 struct vis_conscopy *);
1642820Skz151634 static void vgatext_cons_display(struct vgatext_softc *,
1652820Skz151634 struct vis_consdisplay *);
1662820Skz151634 static void vgatext_cons_cursor(struct vgatext_softc *,
1672820Skz151634 struct vis_conscursor *);
1682820Skz151634 static void vgatext_polled_copy(struct vis_polledio_arg *,
1692820Skz151634 struct vis_conscopy *);
1702820Skz151634 static void vgatext_polled_display(struct vis_polledio_arg *,
1712820Skz151634 struct vis_consdisplay *);
1722820Skz151634 static void vgatext_polled_cursor(struct vis_polledio_arg *,
1732820Skz151634 struct vis_conscursor *);
1742820Skz151634 static void vgatext_init(struct vgatext_softc *);
1752820Skz151634 static void vgatext_set_text(struct vgatext_softc *);
1765295Srandyf
1775295Srandyf static void vgatext_save_text(struct vgatext_softc *softc);
1785295Srandyf static void vgatext_restore_textmode(struct vgatext_softc *softc);
1795295Srandyf static int vgatext_suspend(struct vgatext_softc *softc);
1805295Srandyf static void vgatext_resume(struct vgatext_softc *softc);
1815295Srandyf
1822820Skz151634 #if defined(USE_BORDERS)
1832820Skz151634 static void vgatext_init_graphics(struct vgatext_softc *);
1842820Skz151634 #endif
1855295Srandyf
1862820Skz151634 static int vgatext_kdsetmode(struct vgatext_softc *softc, int mode);
1872820Skz151634 static void vgatext_setfont(struct vgatext_softc *softc);
1882820Skz151634 static void vgatext_get_cursor(struct vgatext_softc *softc,
1892820Skz151634 screen_pos_t *row, screen_pos_t *col);
1902820Skz151634 static void vgatext_set_cursor(struct vgatext_softc *softc, int row, int col);
1912820Skz151634 static void vgatext_hide_cursor(struct vgatext_softc *softc);
1922820Skz151634 static void vgatext_save_colormap(struct vgatext_softc *softc);
1932820Skz151634 static void vgatext_restore_colormap(struct vgatext_softc *softc);
1942820Skz151634 static int vgatext_get_pci_reg_index(dev_info_t *const devi,
1952820Skz151634 unsigned long himask, unsigned long hival, unsigned long addr,
1962820Skz151634 off_t *offset);
1972820Skz151634 static int vgatext_get_isa_reg_index(dev_info_t *const devi,
1982820Skz151634 unsigned long hival, unsigned long addr, off_t *offset);
1992820Skz151634
2002820Skz151634 static char vgatext_silent;
2012820Skz151634 static char happyface_boot;
2022820Skz151634
203945Srugrat gfxp_vgatext_softc_ptr_t
gfxp_vgatext_softc_alloc(void)204945Srugrat gfxp_vgatext_softc_alloc(void)
205945Srugrat {
206945Srugrat return (kmem_zalloc(sizeof (struct vgatext_softc), KM_SLEEP));
207945Srugrat }
208945Srugrat
209945Srugrat void
gfxp_vgatext_softc_free(gfxp_vgatext_softc_ptr_t ptr)210945Srugrat gfxp_vgatext_softc_free(gfxp_vgatext_softc_ptr_t ptr)
211945Srugrat {
212945Srugrat kmem_free(ptr, sizeof (struct vgatext_softc));
213945Srugrat }
214945Srugrat
215*11762SEnrico.Perla@Sun.COM /*
216*11762SEnrico.Perla@Sun.COM * NOTE: this function is duplicated here and in consplat/vgatext while
217*11762SEnrico.Perla@Sun.COM * we work on a set of commitable interfaces to sunpci.c.
218*11762SEnrico.Perla@Sun.COM *
219*11762SEnrico.Perla@Sun.COM * Use the class code to determine if the device is a PCI-to-PCI bridge.
220*11762SEnrico.Perla@Sun.COM * Returns: B_TRUE if the device is a bridge.
221*11762SEnrico.Perla@Sun.COM * B_FALSE if the device is not a bridge or the property cannot be
222*11762SEnrico.Perla@Sun.COM * retrieved.
223*11762SEnrico.Perla@Sun.COM */
224*11762SEnrico.Perla@Sun.COM static boolean_t
is_pci_bridge(dev_info_t * dip)225*11762SEnrico.Perla@Sun.COM is_pci_bridge(dev_info_t *dip)
226*11762SEnrico.Perla@Sun.COM {
227*11762SEnrico.Perla@Sun.COM uint32_t class_code;
228*11762SEnrico.Perla@Sun.COM
229*11762SEnrico.Perla@Sun.COM class_code = (uint32_t)ddi_prop_get_int(DDI_DEV_T_ANY, dip,
230*11762SEnrico.Perla@Sun.COM DDI_PROP_DONTPASS, "class-code", 0xffffffff);
231*11762SEnrico.Perla@Sun.COM
232*11762SEnrico.Perla@Sun.COM if (class_code == 0xffffffff || class_code == DDI_PROP_NOT_FOUND)
233*11762SEnrico.Perla@Sun.COM return (B_FALSE);
234*11762SEnrico.Perla@Sun.COM
235*11762SEnrico.Perla@Sun.COM class_code &= 0x00ffff00;
236*11762SEnrico.Perla@Sun.COM if (class_code == ((PCI_CLASS_BRIDGE << 16) | (PCI_BRIDGE_PCI << 8)))
237*11762SEnrico.Perla@Sun.COM return (B_TRUE);
238*11762SEnrico.Perla@Sun.COM
239*11762SEnrico.Perla@Sun.COM return (B_FALSE);
240*11762SEnrico.Perla@Sun.COM }
241*11762SEnrico.Perla@Sun.COM
2423499Srugrat #define STREQ(a, b) (strcmp((a), (b)) == 0)
2433499Srugrat
2443499Srugrat static void
gfxp_check_for_console(dev_info_t * devi,struct vgatext_softc * softc,int pci_pcie_bus)2453499Srugrat gfxp_check_for_console(dev_info_t *devi, struct vgatext_softc *softc,
2463499Srugrat int pci_pcie_bus)
2473499Srugrat {
2483499Srugrat ddi_acc_handle_t pci_conf;
2493499Srugrat dev_info_t *pdevi;
2503499Srugrat uint16_t data16;
2513499Srugrat
2523499Srugrat /*
2533499Srugrat * Based on Section 11.3, "PCI Display Subsystem Initialization",
2543499Srugrat * of the 1.1 PCI-to-PCI Bridge Architecture Specification
2553499Srugrat * determine if this is the boot console device. First, see
2563499Srugrat * if the SBIOS has turned on PCI I/O for this device. Then if
2573499Srugrat * this is PCI/PCI-E, verify the parent bridge has VGAEnable set.
2583499Srugrat */
2593499Srugrat
2603499Srugrat if (pci_config_setup(devi, &pci_conf) != DDI_SUCCESS) {
2613499Srugrat cmn_err(CE_WARN,
2625295Srandyf MYNAME
2635295Srandyf ": can't get PCI conf handle");
2643499Srugrat return;
2653499Srugrat }
2663499Srugrat
2673499Srugrat data16 = pci_config_get16(pci_conf, PCI_CONF_COMM);
2683499Srugrat if (data16 & PCI_COMM_IO)
2693499Srugrat softc->flags |= GFXP_FLAG_CONSOLE;
2703499Srugrat
2713499Srugrat pci_config_teardown(&pci_conf);
2723499Srugrat
2733499Srugrat /* If IO not enabled or ISA/EISA, just return */
2743499Srugrat if (!(softc->flags & GFXP_FLAG_CONSOLE) || !pci_pcie_bus)
2753499Srugrat return;
2763499Srugrat
2773499Srugrat /*
2783499Srugrat * Check for VGA Enable in the Bridge Control register for all
2793499Srugrat * PCI/PCIEX parents. If not set all the way up the chain,
2803499Srugrat * this cannot be the boot console.
2813499Srugrat */
2823499Srugrat
283*11762SEnrico.Perla@Sun.COM pdevi = devi;
284*11762SEnrico.Perla@Sun.COM while (pdevi = ddi_get_parent(pdevi)) {
2853499Srugrat int error;
2863499Srugrat ddi_acc_handle_t ppci_conf;
2873499Srugrat char *parent_type = NULL;
2883499Srugrat
2893499Srugrat error = ddi_prop_lookup_string(DDI_DEV_T_ANY, pdevi,
2903499Srugrat DDI_PROP_DONTPASS, "device_type", &parent_type);
2913499Srugrat if (error != DDI_SUCCESS) {
2923499Srugrat return;
2933499Srugrat }
2943499Srugrat
2953499Srugrat /* Verify still on the PCI/PCIEX parent tree */
2963499Srugrat if (!STREQ(parent_type, "pci") &&
2973499Srugrat !STREQ(parent_type, "pciex")) {
2983499Srugrat ddi_prop_free(parent_type);
2993499Srugrat return;
3003499Srugrat }
3013499Srugrat
3023499Srugrat ddi_prop_free(parent_type);
3033499Srugrat parent_type = NULL;
3043499Srugrat
305*11762SEnrico.Perla@Sun.COM /* VGAEnable is set only for PCI-to-PCI bridges. */
306*11762SEnrico.Perla@Sun.COM if (is_pci_bridge(pdevi) == B_FALSE)
307*11762SEnrico.Perla@Sun.COM continue;
308*11762SEnrico.Perla@Sun.COM
309*11762SEnrico.Perla@Sun.COM if (pci_config_setup(pdevi, &ppci_conf) != DDI_SUCCESS)
310*11762SEnrico.Perla@Sun.COM continue;
3113499Srugrat
3123499Srugrat data16 = pci_config_get16(ppci_conf, PCI_BCNF_BCNTRL);
3133499Srugrat pci_config_teardown(&ppci_conf);
3143499Srugrat
3153499Srugrat if (!(data16 & PCI_BCNF_BCNTRL_VGA_ENABLE)) {
3163499Srugrat softc->flags &= ~GFXP_FLAG_CONSOLE;
3173499Srugrat return;
3183499Srugrat }
3193499Srugrat }
3203499Srugrat }
3213499Srugrat
322945Srugrat int
gfxp_vgatext_attach(dev_info_t * devi,ddi_attach_cmd_t cmd,gfxp_vgatext_softc_ptr_t ptr)323945Srugrat gfxp_vgatext_attach(dev_info_t *devi, ddi_attach_cmd_t cmd,
324945Srugrat gfxp_vgatext_softc_ptr_t ptr)
325945Srugrat {
326945Srugrat struct vgatext_softc *softc = (struct vgatext_softc *)ptr;
327945Srugrat int unit = ddi_get_instance(devi);
328945Srugrat int error;
329945Srugrat char *parent_type = NULL;
330945Srugrat int reg_rnumber;
331945Srugrat off_t reg_offset;
332945Srugrat off_t mem_offset;
333945Srugrat char *cons;
3343499Srugrat int pci_pcie_bus = 0;
33511046SEdward.Shu@Sun.COM int value;
336945Srugrat
337945Srugrat switch (cmd) {
338945Srugrat case DDI_ATTACH:
3395295Srandyf break;
340945Srugrat
341945Srugrat case DDI_RESUME:
3425295Srandyf vgatext_resume(softc);
3435295Srandyf return (DDI_SUCCESS);
3445295Srandyf
345945Srugrat default:
3465295Srandyf return (DDI_FAILURE);
347945Srugrat }
348945Srugrat
349945Srugrat /* DDI_ATTACH */
350945Srugrat
3515295Srandyf softc->devi = devi; /* Copy and init DEVI */
3525295Srandyf
353945Srugrat softc->polledio.arg = (struct vis_polledio_arg *)softc;
354945Srugrat softc->polledio.display = vgatext_polled_display;
355945Srugrat softc->polledio.copy = vgatext_polled_copy;
356945Srugrat softc->polledio.cursor = vgatext_polled_cursor;
357945Srugrat
3588960SJan.Setje-Eilers@Sun.COM mutex_init(&(softc->lock), NULL, MUTEX_DRIVER, NULL);
3598960SJan.Setje-Eilers@Sun.COM
360945Srugrat error = ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_get_parent(devi),
3615295Srandyf DDI_PROP_DONTPASS, "device_type", &parent_type);
362945Srugrat if (error != DDI_SUCCESS) {
363945Srugrat cmn_err(CE_WARN, MYNAME ": can't determine parent type.");
364945Srugrat goto fail;
365945Srugrat }
366945Srugrat
3672820Skz151634 /* Not enable AGP and DRM by default */
368945Srugrat if (STREQ(parent_type, "isa") || STREQ(parent_type, "eisa")) {
369945Srugrat reg_rnumber = vgatext_get_isa_reg_index(devi, 1, VGA_REG_ADDR,
3705295Srandyf ®_offset);
371945Srugrat if (reg_rnumber < 0) {
372945Srugrat cmn_err(CE_WARN,
3735295Srandyf MYNAME
3745295Srandyf ": can't find reg entry for registers");
3752297Sms148562 error = DDI_FAILURE;
376945Srugrat goto fail;
377945Srugrat }
378945Srugrat softc->fb_regno = vgatext_get_isa_reg_index(devi, 0,
3795295Srandyf VGA_MEM_ADDR, &mem_offset);
380945Srugrat if (softc->fb_regno < 0) {
381945Srugrat cmn_err(CE_WARN,
3825295Srandyf MYNAME
3835295Srandyf ": can't find reg entry for memory");
3842297Sms148562 error = DDI_FAILURE;
385945Srugrat goto fail;
386945Srugrat }
3871041Srugrat } else if (STREQ(parent_type, "pci") || STREQ(parent_type, "pciex")) {
3883499Srugrat pci_pcie_bus = 1;
389945Srugrat reg_rnumber = vgatext_get_pci_reg_index(devi,
3905295Srandyf PCI_REG_ADDR_M|PCI_REG_REL_M,
3915295Srandyf PCI_ADDR_IO|PCI_RELOCAT_B, VGA_REG_ADDR,
3925295Srandyf ®_offset);
393945Srugrat if (reg_rnumber < 0) {
394945Srugrat cmn_err(CE_WARN,
3955295Srandyf MYNAME
3965295Srandyf ": can't find reg entry for registers");
3972297Sms148562 error = DDI_FAILURE;
398945Srugrat goto fail;
399945Srugrat }
400945Srugrat softc->fb_regno = vgatext_get_pci_reg_index(devi,
4015295Srandyf PCI_REG_ADDR_M|PCI_REG_REL_M,
4025295Srandyf PCI_ADDR_MEM32|PCI_RELOCAT_B, VGA_MEM_ADDR,
4035295Srandyf &mem_offset);
404945Srugrat if (softc->fb_regno < 0) {
405945Srugrat cmn_err(CE_WARN,
4065295Srandyf MYNAME
4075295Srandyf ": can't find reg entry for memory");
4082297Sms148562 error = DDI_FAILURE;
409945Srugrat goto fail;
410945Srugrat }
411945Srugrat } else {
412945Srugrat cmn_err(CE_WARN, MYNAME ": unknown parent type \"%s\".",
4135295Srandyf parent_type);
4142297Sms148562 error = DDI_FAILURE;
415945Srugrat goto fail;
416945Srugrat }
417945Srugrat ddi_prop_free(parent_type);
418945Srugrat parent_type = NULL;
419945Srugrat
420945Srugrat error = ddi_regs_map_setup(devi, reg_rnumber,
4215295Srandyf (caddr_t *)&softc->regs.addr, reg_offset, VGA_REG_SIZE,
4225295Srandyf &dev_attr, &softc->regs.handle);
423945Srugrat if (error != DDI_SUCCESS)
424945Srugrat goto fail;
425945Srugrat softc->regs.mapped = B_TRUE;
426945Srugrat
427945Srugrat softc->fb_size = VGA_MEM_SIZE;
428945Srugrat
429945Srugrat error = ddi_regs_map_setup(devi, softc->fb_regno,
4305295Srandyf (caddr_t *)&softc->fb.addr,
4315295Srandyf mem_offset, softc->fb_size,
4325295Srandyf &dev_attr, &softc->fb.handle);
433945Srugrat if (error != DDI_SUCCESS)
434945Srugrat goto fail;
435945Srugrat softc->fb.mapped = B_TRUE;
436945Srugrat
4371106Smrj if (ddi_get8(softc->regs.handle,
438945Srugrat softc->regs.addr + VGA_MISC_R) & VGA_MISC_IOA_SEL)
439945Srugrat softc->text_base = (caddr_t)softc->fb.addr + VGA_COLOR_BASE;
440945Srugrat else
441945Srugrat softc->text_base = (caddr_t)softc->fb.addr + VGA_MONO_BASE;
442945Srugrat
443945Srugrat if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(),
4445295Srandyf DDI_PROP_DONTPASS, "console", &cons) == DDI_SUCCESS) {
445945Srugrat if (strcmp(cons, "graphics") == 0) {
446945Srugrat happyface_boot = 1;
447945Srugrat vgatext_silent = 1;
4488960SJan.Setje-Eilers@Sun.COM softc->current_base = softc->shadow;
4498960SJan.Setje-Eilers@Sun.COM } else {
4508960SJan.Setje-Eilers@Sun.COM softc->current_base = softc->text_base;
451945Srugrat }
452945Srugrat ddi_prop_free(cons);
4538960SJan.Setje-Eilers@Sun.COM } else {
4548960SJan.Setje-Eilers@Sun.COM softc->current_base = softc->text_base;
455945Srugrat }
456945Srugrat
4578960SJan.Setje-Eilers@Sun.COM error = ddi_prop_create(makedevice(DDI_MAJOR_T_UNKNOWN, unit),
4588960SJan.Setje-Eilers@Sun.COM devi, DDI_PROP_CANSLEEP, DDI_KERNEL_IOCTL, NULL, 0);
4598960SJan.Setje-Eilers@Sun.COM if (error != DDI_SUCCESS)
4608960SJan.Setje-Eilers@Sun.COM goto fail;
4618960SJan.Setje-Eilers@Sun.COM
4623499Srugrat gfxp_check_for_console(devi, softc, pci_pcie_bus);
4633499Srugrat
46411046SEdward.Shu@Sun.COM value = GFXP_IS_CONSOLE(softc) ? 1 : 0;
46511046SEdward.Shu@Sun.COM if (ddi_prop_update_int(DDI_DEV_T_NONE, devi,
46611046SEdward.Shu@Sun.COM "primary-controller", value) != DDI_SUCCESS) {
46711046SEdward.Shu@Sun.COM cmn_err(CE_WARN,
46811046SEdward.Shu@Sun.COM "Can not %s primary-controller "
46911046SEdward.Shu@Sun.COM "property for driver", value ? "set" : "clear");
47011046SEdward.Shu@Sun.COM }
47111046SEdward.Shu@Sun.COM
472945Srugrat /* only do this if not in graphics mode */
4733499Srugrat if ((vgatext_silent == 0) && (GFXP_IS_CONSOLE(softc))) {
474945Srugrat vgatext_init(softc);
475945Srugrat vgatext_save_colormap(softc);
476945Srugrat }
477945Srugrat
478945Srugrat return (DDI_SUCCESS);
479945Srugrat
480945Srugrat fail:
481945Srugrat if (parent_type != NULL)
482945Srugrat ddi_prop_free(parent_type);
483945Srugrat (void) gfxp_vgatext_detach(devi, DDI_DETACH, (void *)softc);
484945Srugrat return (error);
485945Srugrat }
486945Srugrat
487945Srugrat /*ARGSUSED*/
488945Srugrat int
gfxp_vgatext_detach(dev_info_t * devi,ddi_detach_cmd_t cmd,gfxp_vgatext_softc_ptr_t ptr)489945Srugrat gfxp_vgatext_detach(dev_info_t *devi, ddi_detach_cmd_t cmd,
490945Srugrat gfxp_vgatext_softc_ptr_t ptr)
491945Srugrat {
492945Srugrat struct vgatext_softc *softc = (struct vgatext_softc *)ptr;
493945Srugrat
49411046SEdward.Shu@Sun.COM (void) ddi_prop_remove(DDI_DEV_T_ANY, devi, "primary-controller");
49511046SEdward.Shu@Sun.COM
496945Srugrat switch (cmd) {
4975295Srandyf
4985295Srandyf case DDI_SUSPEND:
4995295Srandyf return (vgatext_suspend(softc));
5005295Srandyf /* break; */
501945Srugrat case DDI_DETACH:
502945Srugrat if (softc->fb.mapped)
503945Srugrat ddi_regs_map_free(&softc->fb.handle);
504945Srugrat if (softc->regs.mapped)
505945Srugrat ddi_regs_map_free(&softc->regs.handle);
5068960SJan.Setje-Eilers@Sun.COM mutex_destroy(&(softc->lock));
507945Srugrat return (DDI_SUCCESS);
508945Srugrat
509945Srugrat default:
510945Srugrat cmn_err(CE_WARN, "gfxp_vgatext_detach: unknown cmd 0x%x\n",
5115295Srandyf cmd);
512945Srugrat return (DDI_FAILURE);
513945Srugrat }
514945Srugrat }
515945Srugrat
516945Srugrat /*ARGSUSED*/
517945Srugrat int
gfxp_vgatext_open(dev_t * devp,int flag,int otyp,cred_t * cred,gfxp_vgatext_softc_ptr_t ptr)518945Srugrat gfxp_vgatext_open(dev_t *devp, int flag, int otyp, cred_t *cred,
519945Srugrat gfxp_vgatext_softc_ptr_t ptr)
520945Srugrat {
521945Srugrat struct vgatext_softc *softc = (struct vgatext_softc *)ptr;
522945Srugrat
523945Srugrat if (softc == NULL || otyp == OTYP_BLK)
524945Srugrat return (ENXIO);
525945Srugrat
526945Srugrat return (0);
527945Srugrat }
528945Srugrat
529945Srugrat /*ARGSUSED*/
530945Srugrat int
gfxp_vgatext_close(dev_t devp,int flag,int otyp,cred_t * cred,gfxp_vgatext_softc_ptr_t ptr)531945Srugrat gfxp_vgatext_close(dev_t devp, int flag, int otyp, cred_t *cred,
532945Srugrat gfxp_vgatext_softc_ptr_t ptr)
533945Srugrat {
534945Srugrat return (0);
535945Srugrat }
536945Srugrat
5378960SJan.Setje-Eilers@Sun.COM static int
do_gfx_ioctl(int cmd,intptr_t data,int mode,struct vgatext_softc * softc)5388960SJan.Setje-Eilers@Sun.COM do_gfx_ioctl(int cmd, intptr_t data, int mode, struct vgatext_softc *softc)
539945Srugrat {
540945Srugrat static char kernel_only[] =
5415295Srandyf "gfxp_vgatext_ioctl: %s is a kernel only ioctl";
542945Srugrat int err;
543945Srugrat int kd_mode;
544945Srugrat
545945Srugrat switch (cmd) {
546945Srugrat case KDSETMODE:
547945Srugrat return (vgatext_kdsetmode(softc, (int)data));
548945Srugrat
549945Srugrat case KDGETMODE:
550945Srugrat kd_mode = softc->mode;
551945Srugrat if (ddi_copyout(&kd_mode, (void *)data, sizeof (int), mode))
552945Srugrat return (EFAULT);
553945Srugrat break;
554945Srugrat
555945Srugrat case VIS_DEVINIT:
556945Srugrat
5575295Srandyf if (!(mode & FKIOCTL)) {
5585295Srandyf cmn_err(CE_CONT, kernel_only, "VIS_DEVINIT");
5595295Srandyf return (ENXIO);
5605295Srandyf }
561945Srugrat
5625295Srandyf err = vgatext_devinit(softc, (struct vis_devinit *)data);
5635295Srandyf if (err != 0) {
5645295Srandyf cmn_err(CE_WARN,
5655295Srandyf "gfxp_vgatext_ioctl: could not"
5665295Srandyf " initialize console");
5675295Srandyf return (err);
5685295Srandyf }
5695295Srandyf break;
570945Srugrat
571945Srugrat case VIS_CONSCOPY: /* move */
572945Srugrat {
5735295Srandyf struct vis_conscopy pma;
574945Srugrat
5755295Srandyf if (ddi_copyin((void *)data, &pma,
5765295Srandyf sizeof (struct vis_conscopy), mode))
5775295Srandyf return (EFAULT);
578945Srugrat
5795295Srandyf vgatext_cons_copy(softc, &pma);
5805295Srandyf break;
581945Srugrat }
582945Srugrat
583945Srugrat case VIS_CONSDISPLAY: /* display */
584945Srugrat {
5855295Srandyf struct vis_consdisplay display_request;
586945Srugrat
5875295Srandyf if (ddi_copyin((void *)data, &display_request,
5885295Srandyf sizeof (display_request), mode))
5895295Srandyf return (EFAULT);
590945Srugrat
5915295Srandyf vgatext_cons_display(softc, &display_request);
5925295Srandyf break;
593945Srugrat }
594945Srugrat
595945Srugrat case VIS_CONSCURSOR:
596945Srugrat {
5975295Srandyf struct vis_conscursor cursor_request;
598945Srugrat
5995295Srandyf if (ddi_copyin((void *)data, &cursor_request,
6005295Srandyf sizeof (cursor_request), mode))
6015295Srandyf return (EFAULT);
602945Srugrat
6035295Srandyf vgatext_cons_cursor(softc, &cursor_request);
604945Srugrat
6055295Srandyf if (cursor_request.action == VIS_GET_CURSOR &&
6065295Srandyf ddi_copyout(&cursor_request, (void *)data,
6075295Srandyf sizeof (cursor_request), mode))
6085295Srandyf return (EFAULT);
6095295Srandyf break;
610945Srugrat }
611945Srugrat
612945Srugrat case VIS_GETCMAP:
613945Srugrat case VIS_PUTCMAP:
614945Srugrat case FBIOPUTCMAP:
615945Srugrat case FBIOGETCMAP:
616945Srugrat /*
617945Srugrat * At the moment, text mode is not considered to have
618945Srugrat * a color map.
619945Srugrat */
620945Srugrat return (EINVAL);
621945Srugrat
622945Srugrat case FBIOGATTR:
623945Srugrat if (copyout(&vgatext_attr, (void *)data,
624945Srugrat sizeof (struct fbgattr)))
625945Srugrat return (EFAULT);
626945Srugrat break;
627945Srugrat
628945Srugrat case FBIOGTYPE:
629945Srugrat if (copyout(&vgatext_attr.fbtype, (void *)data,
630945Srugrat sizeof (struct fbtype)))
631945Srugrat return (EFAULT);
632945Srugrat break;
633945Srugrat
634945Srugrat default:
635945Srugrat return (ENXIO);
636945Srugrat }
637945Srugrat return (0);
638945Srugrat }
639945Srugrat
6408960SJan.Setje-Eilers@Sun.COM /*ARGSUSED*/
6418960SJan.Setje-Eilers@Sun.COM int
gfxp_vgatext_ioctl(dev_t dev,int cmd,intptr_t data,int mode,cred_t * cred,int * rval,gfxp_vgatext_softc_ptr_t ptr)6428960SJan.Setje-Eilers@Sun.COM gfxp_vgatext_ioctl(
6438960SJan.Setje-Eilers@Sun.COM dev_t dev,
6448960SJan.Setje-Eilers@Sun.COM int cmd,
6458960SJan.Setje-Eilers@Sun.COM intptr_t data,
6468960SJan.Setje-Eilers@Sun.COM int mode,
6478960SJan.Setje-Eilers@Sun.COM cred_t *cred,
6488960SJan.Setje-Eilers@Sun.COM int *rval,
6498960SJan.Setje-Eilers@Sun.COM gfxp_vgatext_softc_ptr_t ptr)
6508960SJan.Setje-Eilers@Sun.COM {
6518960SJan.Setje-Eilers@Sun.COM int err;
6528960SJan.Setje-Eilers@Sun.COM
6538960SJan.Setje-Eilers@Sun.COM struct vgatext_softc *softc = (struct vgatext_softc *)ptr;
6548960SJan.Setje-Eilers@Sun.COM
6558960SJan.Setje-Eilers@Sun.COM mutex_enter(&(softc->lock));
6568960SJan.Setje-Eilers@Sun.COM err = do_gfx_ioctl(cmd, data, mode, softc);
6578960SJan.Setje-Eilers@Sun.COM mutex_exit(&(softc->lock));
6588960SJan.Setje-Eilers@Sun.COM
6598960SJan.Setje-Eilers@Sun.COM return (err);
6608960SJan.Setje-Eilers@Sun.COM }
6618960SJan.Setje-Eilers@Sun.COM
6625295Srandyf /*
6635295Srandyf * vgatext_save_text
6645295Srandyf * vgatext_restore_textmode
6655295Srandyf * vgatext_suspend
6665295Srandyf * vgatext_resume
6675295Srandyf *
6685295Srandyf * Routines to save and restore contents of the VGA text area
6695295Srandyf * Mostly, this is to support Suspend/Resume operation for graphics
6705295Srandyf * device drivers. Here in the VGAtext common code, we simply squirrel
6715295Srandyf * away the contents of the hardware's text area during Suspend and then
6725295Srandyf * put it back during Resume
6735295Srandyf */
6745295Srandyf static void
vgatext_save_text(struct vgatext_softc * softc)6755295Srandyf vgatext_save_text(struct vgatext_softc *softc)
6765295Srandyf {
6775295Srandyf unsigned i;
6785295Srandyf
6795295Srandyf for (i = 0; i < sizeof (softc->shadow); i++)
6808960SJan.Setje-Eilers@Sun.COM softc->shadow[i] = softc->current_base[i];
6815295Srandyf }
6825295Srandyf
6835295Srandyf static void
vgatext_restore_textmode(struct vgatext_softc * softc)6845295Srandyf vgatext_restore_textmode(struct vgatext_softc *softc)
6855295Srandyf {
6865295Srandyf unsigned i;
6875295Srandyf
6885295Srandyf vgatext_init(softc);
6895295Srandyf for (i = 0; i < sizeof (softc->shadow); i++) {
6905295Srandyf softc->text_base[i] = softc->shadow[i];
6915295Srandyf }
6925295Srandyf if (softc->cursor.visible) {
6935295Srandyf vgatext_set_cursor(softc,
6945295Srandyf softc->cursor.row, softc->cursor.col);
6955295Srandyf }
6965295Srandyf vgatext_restore_colormap(softc);
6975295Srandyf }
6985295Srandyf
6995295Srandyf static int
vgatext_suspend(struct vgatext_softc * softc)7005295Srandyf vgatext_suspend(struct vgatext_softc *softc)
7015295Srandyf {
7025295Srandyf switch (softc->mode) {
7035295Srandyf case KD_TEXT:
7045295Srandyf vgatext_save_text(softc);
7055295Srandyf break;
7065295Srandyf
7075295Srandyf case KD_GRAPHICS:
7085295Srandyf break;
7095295Srandyf
7105295Srandyf default:
7115295Srandyf cmn_err(CE_WARN, MYNAME ": unknown mode in vgatext_suspend.");
7125295Srandyf return (DDI_FAILURE);
7135295Srandyf }
7145295Srandyf return (DDI_SUCCESS);
7155295Srandyf }
7165295Srandyf
7175295Srandyf static void
vgatext_resume(struct vgatext_softc * softc)7185295Srandyf vgatext_resume(struct vgatext_softc *softc)
7195295Srandyf {
7205295Srandyf
7215295Srandyf switch (softc->mode) {
7225295Srandyf case KD_TEXT:
7235295Srandyf vgatext_restore_textmode(softc);
7245295Srandyf break;
7255295Srandyf
7265295Srandyf case KD_GRAPHICS:
7275295Srandyf
7285295Srandyf /*
7295295Srandyf * Upon RESUME, the graphics device will always actually
7305295Srandyf * be in TEXT mode even though the Xorg server did not
7315295Srandyf * make that mode change itself (the suspend code did).
7325295Srandyf * We want first, therefore, to restore textmode
7335295Srandyf * operation fully, and then the Xorg server will
7345295Srandyf * do the rest to restore the device to its
7355295Srandyf * (hi resolution) graphics mode
7365295Srandyf */
7375295Srandyf vgatext_restore_textmode(softc);
7385295Srandyf #if defined(USE_BORDERS)
7395295Srandyf vgatext_init_graphics(softc);
7405295Srandyf #endif
7415295Srandyf break;
7425295Srandyf default:
7435295Srandyf cmn_err(CE_WARN, MYNAME ": unknown mode in vgatext_resume.");
7445295Srandyf break;
7455295Srandyf }
7465295Srandyf }
7475295Srandyf
7488960SJan.Setje-Eilers@Sun.COM static void
vgatext_progressbar_stop()7498960SJan.Setje-Eilers@Sun.COM vgatext_progressbar_stop()
7508960SJan.Setje-Eilers@Sun.COM {
7518960SJan.Setje-Eilers@Sun.COM extern void progressbar_stop(void);
7528960SJan.Setje-Eilers@Sun.COM
7538960SJan.Setje-Eilers@Sun.COM if (vgatext_silent == 1) {
7548960SJan.Setje-Eilers@Sun.COM vgatext_silent = 0;
7558960SJan.Setje-Eilers@Sun.COM progressbar_stop();
7568960SJan.Setje-Eilers@Sun.COM }
7578960SJan.Setje-Eilers@Sun.COM }
7588960SJan.Setje-Eilers@Sun.COM
7598960SJan.Setje-Eilers@Sun.COM static void
vgatext_kdsettext(struct vgatext_softc * softc)7608960SJan.Setje-Eilers@Sun.COM vgatext_kdsettext(struct vgatext_softc *softc)
7618960SJan.Setje-Eilers@Sun.COM {
7628960SJan.Setje-Eilers@Sun.COM int i;
7638960SJan.Setje-Eilers@Sun.COM
7648960SJan.Setje-Eilers@Sun.COM vgatext_init(softc);
7658960SJan.Setje-Eilers@Sun.COM for (i = 0; i < sizeof (softc->shadow); i++) {
7668960SJan.Setje-Eilers@Sun.COM softc->text_base[i] = softc->shadow[i];
7678960SJan.Setje-Eilers@Sun.COM }
7688960SJan.Setje-Eilers@Sun.COM softc->current_base = softc->text_base;
7698960SJan.Setje-Eilers@Sun.COM if (softc->cursor.visible) {
7708960SJan.Setje-Eilers@Sun.COM vgatext_set_cursor(softc,
7718960SJan.Setje-Eilers@Sun.COM softc->cursor.row, softc->cursor.col);
7728960SJan.Setje-Eilers@Sun.COM }
7738960SJan.Setje-Eilers@Sun.COM vgatext_restore_colormap(softc);
7748960SJan.Setje-Eilers@Sun.COM }
7758960SJan.Setje-Eilers@Sun.COM
7768960SJan.Setje-Eilers@Sun.COM static void
vgatext_kdsetgraphics(struct vgatext_softc * softc)7778960SJan.Setje-Eilers@Sun.COM vgatext_kdsetgraphics(struct vgatext_softc *softc)
7788960SJan.Setje-Eilers@Sun.COM {
7798960SJan.Setje-Eilers@Sun.COM vgatext_progressbar_stop();
7808960SJan.Setje-Eilers@Sun.COM vgatext_save_text(softc);
7818960SJan.Setje-Eilers@Sun.COM softc->current_base = softc->shadow;
7828960SJan.Setje-Eilers@Sun.COM #if defined(USE_BORDERS)
7838960SJan.Setje-Eilers@Sun.COM vgatext_init_graphics(softc);
7848960SJan.Setje-Eilers@Sun.COM #endif
7858960SJan.Setje-Eilers@Sun.COM }
7868960SJan.Setje-Eilers@Sun.COM
787945Srugrat static int
vgatext_kdsetmode(struct vgatext_softc * softc,int mode)788945Srugrat vgatext_kdsetmode(struct vgatext_softc *softc, int mode)
789945Srugrat {
7903499Srugrat if ((mode == softc->mode) || (!GFXP_IS_CONSOLE(softc)))
791945Srugrat return (0);
792945Srugrat
793945Srugrat switch (mode) {
794945Srugrat case KD_TEXT:
7958960SJan.Setje-Eilers@Sun.COM vgatext_kdsettext(softc);
796945Srugrat break;
797945Srugrat
798945Srugrat case KD_GRAPHICS:
7998960SJan.Setje-Eilers@Sun.COM vgatext_kdsetgraphics(softc);
8008960SJan.Setje-Eilers@Sun.COM break;
8015295Srandyf
8028960SJan.Setje-Eilers@Sun.COM case KD_RESETTEXT:
8038960SJan.Setje-Eilers@Sun.COM /*
8048960SJan.Setje-Eilers@Sun.COM * In order to avoid racing with a starting X server,
8058960SJan.Setje-Eilers@Sun.COM * this needs to be a test and set that is performed in
8068960SJan.Setje-Eilers@Sun.COM * a single (softc->lock protected) ioctl into this driver.
8078960SJan.Setje-Eilers@Sun.COM */
8088960SJan.Setje-Eilers@Sun.COM if (softc->mode == KD_TEXT && vgatext_silent == 1) {
8098960SJan.Setje-Eilers@Sun.COM vgatext_progressbar_stop();
8108960SJan.Setje-Eilers@Sun.COM vgatext_kdsettext(softc);
811945Srugrat }
812945Srugrat break;
813945Srugrat
814945Srugrat default:
815945Srugrat return (EINVAL);
816945Srugrat }
8178960SJan.Setje-Eilers@Sun.COM
818945Srugrat softc->mode = mode;
819945Srugrat return (0);
820945Srugrat }
821945Srugrat
822945Srugrat /*ARGSUSED*/
8232820Skz151634 int
gfxp_vgatext_devmap(dev_t dev,devmap_cookie_t dhp,offset_t off,size_t len,size_t * maplen,uint_t model,void * ptr)824945Srugrat gfxp_vgatext_devmap(dev_t dev, devmap_cookie_t dhp, offset_t off, size_t len,
825945Srugrat size_t *maplen, uint_t model, void *ptr)
826945Srugrat {
827945Srugrat struct vgatext_softc *softc = (struct vgatext_softc *)ptr;
828945Srugrat int err;
829945Srugrat size_t length;
830945Srugrat
831945Srugrat
832945Srugrat if (softc == NULL) {
833945Srugrat cmn_err(CE_WARN, "vgatext: Can't find softstate");
834945Srugrat return (-1);
835945Srugrat }
836945Srugrat
837945Srugrat if (!(off >= VGA_MMAP_FB_BASE &&
8385295Srandyf off < VGA_MMAP_FB_BASE + softc->fb_size)) {
839945Srugrat cmn_err(CE_WARN, "vgatext: Can't map offset 0x%llx", off);
840945Srugrat return (-1);
841945Srugrat }
842945Srugrat
843945Srugrat if (off + len > VGA_MMAP_FB_BASE + softc->fb_size)
844945Srugrat length = VGA_MMAP_FB_BASE + softc->fb_size - off;
845945Srugrat else
846945Srugrat length = len;
847945Srugrat
8485295Srandyf if ((err = devmap_devmem_setup(dhp, softc->devi,
8495295Srandyf NULL, softc->fb_regno, off - VGA_MMAP_FB_BASE,
8505295Srandyf length, PROT_ALL, 0, &dev_attr)) < 0) {
851945Srugrat return (err);
852945Srugrat }
853945Srugrat
854945Srugrat
855945Srugrat *maplen = length;
856945Srugrat return (0);
857945Srugrat }
858945Srugrat
859945Srugrat
860945Srugrat static int
vgatext_devinit(struct vgatext_softc * softc,struct vis_devinit * data)861945Srugrat vgatext_devinit(struct vgatext_softc *softc, struct vis_devinit *data)
862945Srugrat {
863945Srugrat /* initialize console instance */
864945Srugrat data->version = VIS_CONS_REV;
865945Srugrat data->width = TEXT_COLS;
866945Srugrat data->height = TEXT_ROWS;
867945Srugrat data->linebytes = TEXT_COLS;
868945Srugrat data->depth = 4;
869945Srugrat data->mode = VIS_TEXT;
870945Srugrat data->polledio = &softc->polledio;
871945Srugrat
872945Srugrat return (0);
873945Srugrat }
874945Srugrat
875945Srugrat /*
876945Srugrat * display a string on the screen at (row, col)
877945Srugrat * assume it has been cropped to fit.
878945Srugrat */
879945Srugrat
880945Srugrat static void
vgatext_cons_display(struct vgatext_softc * softc,struct vis_consdisplay * da)881945Srugrat vgatext_cons_display(struct vgatext_softc *softc, struct vis_consdisplay *da)
882945Srugrat {
883945Srugrat unsigned char *string;
884945Srugrat int i;
885945Srugrat unsigned char attr;
886945Srugrat struct cgatext {
887945Srugrat unsigned char ch;
888945Srugrat unsigned char attr;
889945Srugrat };
890945Srugrat struct cgatext *addr;
891945Srugrat
892945Srugrat /*
893945Srugrat * Sanity checks. This is a last-ditch effort to avoid damage
894945Srugrat * from brokenness or maliciousness above.
895945Srugrat */
896945Srugrat if (da->row < 0 || da->row >= TEXT_ROWS ||
897945Srugrat da->col < 0 || da->col >= TEXT_COLS ||
898945Srugrat da->col + da->width > TEXT_COLS)
899945Srugrat return;
900945Srugrat
901945Srugrat /*
902945Srugrat * To be fully general, we should copyin the data. This is not
903945Srugrat * really relevant for this text-only driver, but a graphical driver
904945Srugrat * should support these ioctls from userland to enable simple
905945Srugrat * system startup graphics.
906945Srugrat */
907945Srugrat attr = (solaris_color_to_pc_color[da->bg_color & 0xf] << 4)
9085295Srandyf | solaris_color_to_pc_color[da->fg_color & 0xf];
909945Srugrat string = da->data;
910945Srugrat addr = (struct cgatext *)softc->current_base
9115295Srandyf + (da->row * TEXT_COLS + da->col);
912945Srugrat for (i = 0; i < da->width; i++) {
913945Srugrat addr->ch = string[i];
914945Srugrat addr->attr = attr;
915945Srugrat addr++;
916945Srugrat }
917945Srugrat }
918945Srugrat
919945Srugrat static void
vgatext_polled_display(struct vis_polledio_arg * arg,struct vis_consdisplay * da)920945Srugrat vgatext_polled_display(
921945Srugrat struct vis_polledio_arg *arg,
922945Srugrat struct vis_consdisplay *da)
923945Srugrat {
924945Srugrat vgatext_cons_display((struct vgatext_softc *)arg, da);
925945Srugrat }
926945Srugrat
927945Srugrat /*
928945Srugrat * screen-to-screen copy
929945Srugrat */
930945Srugrat
931945Srugrat static void
vgatext_cons_copy(struct vgatext_softc * softc,struct vis_conscopy * ma)932945Srugrat vgatext_cons_copy(struct vgatext_softc *softc, struct vis_conscopy *ma)
933945Srugrat {
934945Srugrat unsigned short *from;
935945Srugrat unsigned short *to;
936945Srugrat int cnt;
937945Srugrat screen_size_t chars_per_row;
938945Srugrat unsigned short *to_row_start;
939945Srugrat unsigned short *from_row_start;
940945Srugrat screen_size_t rows_to_move;
941945Srugrat unsigned short *base;
942945Srugrat
943945Srugrat /*
944945Srugrat * Sanity checks. Note that this is a last-ditch effort to avoid
945945Srugrat * damage caused by broken-ness or maliciousness above.
946945Srugrat */
947945Srugrat if (ma->s_col < 0 || ma->s_col >= TEXT_COLS ||
948945Srugrat ma->s_row < 0 || ma->s_row >= TEXT_ROWS ||
949945Srugrat ma->e_col < 0 || ma->e_col >= TEXT_COLS ||
950945Srugrat ma->e_row < 0 || ma->e_row >= TEXT_ROWS ||
951945Srugrat ma->t_col < 0 || ma->t_col >= TEXT_COLS ||
952945Srugrat ma->t_row < 0 || ma->t_row >= TEXT_ROWS ||
953945Srugrat ma->s_col > ma->e_col ||
954945Srugrat ma->s_row > ma->e_row)
955945Srugrat return;
956945Srugrat
957945Srugrat /*
958945Srugrat * Remember we're going to copy shorts because each
959945Srugrat * character/attribute pair is 16 bits.
960945Srugrat */
961945Srugrat chars_per_row = ma->e_col - ma->s_col + 1;
962945Srugrat rows_to_move = ma->e_row - ma->s_row + 1;
963945Srugrat
964945Srugrat /* More sanity checks. */
965945Srugrat if (ma->t_row + rows_to_move > TEXT_ROWS ||
966945Srugrat ma->t_col + chars_per_row > TEXT_COLS)
967945Srugrat return;
968945Srugrat
969945Srugrat base = (unsigned short *)softc->current_base;
970945Srugrat
971945Srugrat to_row_start = base + ((ma->t_row * TEXT_COLS) + ma->t_col);
972945Srugrat from_row_start = base + ((ma->s_row * TEXT_COLS) + ma->s_col);
973945Srugrat
974945Srugrat if (to_row_start < from_row_start) {
975945Srugrat while (rows_to_move-- > 0) {
976945Srugrat to = to_row_start;
977945Srugrat from = from_row_start;
978945Srugrat to_row_start += TEXT_COLS;
979945Srugrat from_row_start += TEXT_COLS;
980945Srugrat for (cnt = chars_per_row; cnt-- > 0; )
981945Srugrat *to++ = *from++;
982945Srugrat }
983945Srugrat } else {
984945Srugrat /*
985945Srugrat * Offset to the end of the region and copy backwards.
986945Srugrat */
987945Srugrat cnt = rows_to_move * TEXT_COLS + chars_per_row;
988945Srugrat to_row_start += cnt;
989945Srugrat from_row_start += cnt;
990945Srugrat
991945Srugrat while (rows_to_move-- > 0) {
992945Srugrat to_row_start -= TEXT_COLS;
993945Srugrat from_row_start -= TEXT_COLS;
994945Srugrat to = to_row_start;
995945Srugrat from = from_row_start;
996945Srugrat for (cnt = chars_per_row; cnt-- > 0; )
997945Srugrat *--to = *--from;
998945Srugrat }
999945Srugrat }
1000945Srugrat }
1001945Srugrat
1002945Srugrat static void
vgatext_polled_copy(struct vis_polledio_arg * arg,struct vis_conscopy * ca)1003945Srugrat vgatext_polled_copy(
1004945Srugrat struct vis_polledio_arg *arg,
1005945Srugrat struct vis_conscopy *ca)
1006945Srugrat {
1007945Srugrat vgatext_cons_copy((struct vgatext_softc *)arg, ca);
1008945Srugrat }
1009945Srugrat
1010945Srugrat
1011945Srugrat static void
vgatext_cons_cursor(struct vgatext_softc * softc,struct vis_conscursor * ca)1012945Srugrat vgatext_cons_cursor(struct vgatext_softc *softc, struct vis_conscursor *ca)
1013945Srugrat {
1014945Srugrat if (vgatext_silent)
1015945Srugrat return;
1016945Srugrat
1017945Srugrat switch (ca->action) {
1018945Srugrat case VIS_HIDE_CURSOR:
1019945Srugrat softc->cursor.visible = B_FALSE;
1020945Srugrat if (softc->current_base == softc->text_base)
1021945Srugrat vgatext_hide_cursor(softc);
1022945Srugrat break;
1023945Srugrat case VIS_DISPLAY_CURSOR:
1024945Srugrat /*
1025945Srugrat * Sanity check. This is a last-ditch effort to avoid
1026945Srugrat * damage from brokenness or maliciousness above.
1027945Srugrat */
1028945Srugrat if (ca->col < 0 || ca->col >= TEXT_COLS ||
1029945Srugrat ca->row < 0 || ca->row >= TEXT_ROWS)
1030945Srugrat return;
1031945Srugrat
1032945Srugrat softc->cursor.visible = B_TRUE;
1033945Srugrat softc->cursor.col = ca->col;
1034945Srugrat softc->cursor.row = ca->row;
1035945Srugrat if (softc->current_base == softc->text_base)
1036945Srugrat vgatext_set_cursor(softc, ca->row, ca->col);
1037945Srugrat break;
1038945Srugrat case VIS_GET_CURSOR:
1039945Srugrat if (softc->current_base == softc->text_base) {
1040945Srugrat vgatext_get_cursor(softc, &ca->row, &ca->col);
1041945Srugrat }
1042945Srugrat break;
1043945Srugrat }
1044945Srugrat }
1045945Srugrat
1046945Srugrat static void
vgatext_polled_cursor(struct vis_polledio_arg * arg,struct vis_conscursor * ca)1047945Srugrat vgatext_polled_cursor(
1048945Srugrat struct vis_polledio_arg *arg,
1049945Srugrat struct vis_conscursor *ca)
1050945Srugrat {
1051945Srugrat vgatext_cons_cursor((struct vgatext_softc *)arg, ca);
1052945Srugrat }
1053945Srugrat
1054945Srugrat
1055945Srugrat
1056945Srugrat /*ARGSUSED*/
1057945Srugrat static void
vgatext_hide_cursor(struct vgatext_softc * softc)1058945Srugrat vgatext_hide_cursor(struct vgatext_softc *softc)
1059945Srugrat {
1060945Srugrat /* Nothing at present */
1061945Srugrat }
1062945Srugrat
1063945Srugrat static void
vgatext_set_cursor(struct vgatext_softc * softc,int row,int col)1064945Srugrat vgatext_set_cursor(struct vgatext_softc *softc, int row, int col)
1065945Srugrat {
1066945Srugrat short addr;
1067945Srugrat
1068945Srugrat if (vgatext_silent)
1069945Srugrat return;
1070945Srugrat
1071945Srugrat addr = row * TEXT_COLS + col;
1072945Srugrat
1073945Srugrat vga_set_crtc(&softc->regs, VGA_CRTC_CLAH, addr >> 8);
1074945Srugrat vga_set_crtc(&softc->regs, VGA_CRTC_CLAL, addr & 0xff);
1075945Srugrat }
1076945Srugrat
1077945Srugrat static int vga_row, vga_col;
1078945Srugrat
1079945Srugrat static void
vgatext_get_cursor(struct vgatext_softc * softc,screen_pos_t * row,screen_pos_t * col)1080945Srugrat vgatext_get_cursor(struct vgatext_softc *softc,
1081945Srugrat screen_pos_t *row, screen_pos_t *col)
1082945Srugrat {
1083945Srugrat short addr;
1084945Srugrat
1085945Srugrat addr = (vga_get_crtc(&softc->regs, VGA_CRTC_CLAH) << 8) +
1086945Srugrat vga_get_crtc(&softc->regs, VGA_CRTC_CLAL);
1087945Srugrat
1088945Srugrat vga_row = *row = addr / TEXT_COLS;
1089945Srugrat vga_col = *col = addr % TEXT_COLS;
1090945Srugrat }
1091945Srugrat
1092945Srugrat /*
1093945Srugrat * This code is experimental. It's only enabled if console is
1094945Srugrat * set to graphics, a preliminary implementation of happyface boot.
1095945Srugrat */
1096945Srugrat static void
vgatext_set_text(struct vgatext_softc * softc)1097945Srugrat vgatext_set_text(struct vgatext_softc *softc)
1098945Srugrat {
1099945Srugrat int i;
1100945Srugrat
1101945Srugrat if (happyface_boot == 0)
1102945Srugrat return;
1103945Srugrat
1104945Srugrat /* we are in graphics mode, set to text 80X25 mode */
1105945Srugrat
1106945Srugrat /* set misc registers */
1107945Srugrat vga_set_reg(&softc->regs, VGA_MISC_W, VGA_MISC_TEXT);
1108945Srugrat
1109945Srugrat /* set sequencer registers */
1110945Srugrat vga_set_seq(&softc->regs, VGA_SEQ_RST_SYN,
11115295Srandyf (vga_get_seq(&softc->regs, VGA_SEQ_RST_SYN) &
11125295Srandyf ~VGA_SEQ_RST_SYN_NO_SYNC_RESET));
1113945Srugrat for (i = 1; i < NUM_SEQ_REG; i++) {
1114945Srugrat vga_set_seq(&softc->regs, i, VGA_SEQ_TEXT[i]);
1115945Srugrat }
1116945Srugrat vga_set_seq(&softc->regs, VGA_SEQ_RST_SYN,
11175295Srandyf (vga_get_seq(&softc->regs, VGA_SEQ_RST_SYN) |
11185295Srandyf VGA_SEQ_RST_SYN_NO_ASYNC_RESET |
11195295Srandyf VGA_SEQ_RST_SYN_NO_SYNC_RESET));
1120945Srugrat
1121945Srugrat /* set crt controller registers */
1122945Srugrat vga_set_crtc(&softc->regs, VGA_CRTC_VRE,
11235295Srandyf (vga_get_crtc(&softc->regs, VGA_CRTC_VRE) &
11245295Srandyf ~VGA_CRTC_VRE_LOCK));
1125945Srugrat for (i = 0; i < NUM_CRTC_REG; i++) {
1126945Srugrat vga_set_crtc(&softc->regs, i, VGA_CRTC_TEXT[i]);
1127945Srugrat }
1128945Srugrat
1129945Srugrat /* set graphics controller registers */
1130945Srugrat for (i = 0; i < NUM_GRC_REG; i++) {
1131945Srugrat vga_set_grc(&softc->regs, i, VGA_GRC_TEXT[i]);
1132945Srugrat }
1133945Srugrat
1134945Srugrat /* set attribute registers */
1135945Srugrat for (i = 0; i < NUM_ATR_REG; i++) {
1136945Srugrat vga_set_atr(&softc->regs, i, VGA_ATR_TEXT[i]);
1137945Srugrat }
1138945Srugrat
1139945Srugrat /* set palette */
1140945Srugrat for (i = 0; i < VGA_TEXT_CMAP_ENTRIES; i++) {
1141945Srugrat vga_put_cmap(&softc->regs, i, VGA_TEXT_PALETTES[i][0] << 2,
11425295Srandyf VGA_TEXT_PALETTES[i][1] << 2,
11435295Srandyf VGA_TEXT_PALETTES[i][2] << 2);
1144945Srugrat }
1145945Srugrat for (i = VGA_TEXT_CMAP_ENTRIES; i < VGA8_CMAP_ENTRIES; i++) {
1146945Srugrat vga_put_cmap(&softc->regs, i, 0, 0, 0);
1147945Srugrat }
1148945Srugrat
1149945Srugrat vgatext_save_colormap(softc);
1150945Srugrat }
1151945Srugrat
1152945Srugrat static void
vgatext_init(struct vgatext_softc * softc)1153945Srugrat vgatext_init(struct vgatext_softc *softc)
1154945Srugrat {
1155945Srugrat unsigned char atr_mode;
1156945Srugrat
1157945Srugrat atr_mode = vga_get_atr(&softc->regs, VGA_ATR_MODE);
1158945Srugrat if (atr_mode & VGA_ATR_MODE_GRAPH)
1159945Srugrat vgatext_set_text(softc);
1160945Srugrat atr_mode = vga_get_atr(&softc->regs, VGA_ATR_MODE);
1161945Srugrat atr_mode &= ~VGA_ATR_MODE_BLINK;
1162945Srugrat atr_mode &= ~VGA_ATR_MODE_9WIDE;
1163945Srugrat vga_set_atr(&softc->regs, VGA_ATR_MODE, atr_mode);
1164945Srugrat #if defined(USE_BORDERS)
1165945Srugrat vga_set_atr(&softc->regs, VGA_ATR_BDR_CLR,
11665295Srandyf vga_get_atr(&softc->regs, VGA_BRIGHT_WHITE));
1167945Srugrat #else
1168945Srugrat vga_set_atr(&softc->regs, VGA_ATR_BDR_CLR,
11695295Srandyf vga_get_atr(&softc->regs, VGA_BLACK));
1170945Srugrat #endif
1171945Srugrat vgatext_setfont(softc); /* need selectable font? */
1172945Srugrat }
1173945Srugrat
1174945Srugrat #if defined(USE_BORDERS)
1175945Srugrat static void
vgatext_init_graphics(struct vgatext_softc * softc)1176945Srugrat vgatext_init_graphics(struct vgatext_softc *softc)
1177945Srugrat {
1178945Srugrat vga_set_atr(&softc->regs, VGA_ATR_BDR_CLR,
11795295Srandyf vga_get_atr(&softc->regs, VGA_BLACK));
1180945Srugrat }
1181945Srugrat #endif
1182945Srugrat
1183945Srugrat static void
vgatext_setfont(struct vgatext_softc * softc)1184945Srugrat vgatext_setfont(struct vgatext_softc *softc)
1185945Srugrat {
1186945Srugrat extern unsigned char *ENCODINGS[];
1187945Srugrat unsigned char *from;
1188945Srugrat unsigned char *to;
1189945Srugrat int i;
1190945Srugrat int j;
1191945Srugrat int bpc;
1192945Srugrat
1193945Srugrat /*
1194945Srugrat * The newboot code to use font plane 2 breaks NVIDIA
1195945Srugrat * (and some ATI) behavior. Revert back to the S10
1196945Srugrat * code.
1197945Srugrat */
1198945Srugrat
1199945Srugrat /*
1200945Srugrat * I'm embarassed to say that I don't know what these magic
1201945Srugrat * sequences do, other than at the high level of "set the
1202945Srugrat * memory window to allow font setup". I stole them straight
1203945Srugrat * from "kd"...
1204945Srugrat */
1205945Srugrat vga_set_seq(&softc->regs, 0x02, 0x04);
1206945Srugrat vga_set_seq(&softc->regs, 0x04, 0x06);
1207945Srugrat vga_set_grc(&softc->regs, 0x05, 0x00);
1208945Srugrat vga_set_grc(&softc->regs, 0x06, 0x04);
1209945Srugrat
1210945Srugrat /*
1211945Srugrat * This assumes 8x16 characters, which yield the traditional 80x25
1212945Srugrat * screen. It really should support other character heights.
1213945Srugrat */
1214945Srugrat bpc = 16;
1215945Srugrat for (i = 0; i < 256; i++) {
1216945Srugrat from = ENCODINGS[i];
1217945Srugrat to = (unsigned char *)softc->fb.addr + i * 0x20;
1218945Srugrat for (j = 0; j < bpc; j++)
1219945Srugrat *to++ = *from++;
1220945Srugrat }
1221945Srugrat
1222945Srugrat vga_set_seq(&softc->regs, 0x02, 0x03);
1223945Srugrat vga_set_seq(&softc->regs, 0x04, 0x02);
1224945Srugrat vga_set_grc(&softc->regs, 0x04, 0x00);
1225945Srugrat vga_set_grc(&softc->regs, 0x05, 0x10);
1226945Srugrat vga_set_grc(&softc->regs, 0x06, 0x0e);
1227945Srugrat
1228945Srugrat }
1229945Srugrat
1230945Srugrat static void
vgatext_save_colormap(struct vgatext_softc * softc)1231945Srugrat vgatext_save_colormap(struct vgatext_softc *softc)
1232945Srugrat {
1233945Srugrat int i;
1234945Srugrat
1235945Srugrat for (i = 0; i < VGA_ATR_NUM_PLT; i++) {
1236945Srugrat softc->attrib_palette[i] = vga_get_atr(&softc->regs, i);
1237945Srugrat }
1238945Srugrat for (i = 0; i < VGA8_CMAP_ENTRIES; i++) {
1239945Srugrat vga_get_cmap(&softc->regs, i,
12405295Srandyf &softc->colormap[i].red,
12415295Srandyf &softc->colormap[i].green,
12425295Srandyf &softc->colormap[i].blue);
1243945Srugrat }
1244945Srugrat }
1245945Srugrat
1246945Srugrat static void
vgatext_restore_colormap(struct vgatext_softc * softc)1247945Srugrat vgatext_restore_colormap(struct vgatext_softc *softc)
1248945Srugrat {
1249945Srugrat int i;
1250945Srugrat
1251945Srugrat for (i = 0; i < VGA_ATR_NUM_PLT; i++) {
1252945Srugrat vga_set_atr(&softc->regs, i, softc->attrib_palette[i]);
1253945Srugrat }
1254945Srugrat for (i = 0; i < VGA8_CMAP_ENTRIES; i++) {
1255945Srugrat vga_put_cmap(&softc->regs, i,
12565295Srandyf softc->colormap[i].red,
12575295Srandyf softc->colormap[i].green,
12585295Srandyf softc->colormap[i].blue);
1259945Srugrat }
1260945Srugrat }
1261945Srugrat
1262945Srugrat /*
1263945Srugrat * search the entries of the "reg" property for one which has the desired
1264945Srugrat * combination of phys_hi bits and contains the desired address.
1265945Srugrat *
1266945Srugrat * This version searches a PCI-style "reg" property. It was prompted by
1267945Srugrat * issues surrounding the presence or absence of an entry for the ROM:
1268945Srugrat * (a) a transition problem with PowerPC Virtual Open Firmware
1269945Srugrat * (b) uncertainty as to whether an entry will be included on a device
1270945Srugrat * with ROM support (and so an "active" ROM base address register),
1271945Srugrat * but no ROM actually installed.
1272945Srugrat *
1273945Srugrat * See the note below on vgatext_get_isa_reg_index for the reasons for
1274945Srugrat * returning the offset.
1275945Srugrat *
1276945Srugrat * Note that this routine may not be fully general; it is intended for the
1277945Srugrat * specific purpose of finding a couple of particular VGA reg entries and
1278945Srugrat * may not be suitable for all reg-searching purposes.
1279945Srugrat */
1280945Srugrat static int
vgatext_get_pci_reg_index(dev_info_t * const devi,unsigned long himask,unsigned long hival,unsigned long addr,off_t * offset)1281945Srugrat vgatext_get_pci_reg_index(
1282945Srugrat dev_info_t *const devi,
1283945Srugrat unsigned long himask,
1284945Srugrat unsigned long hival,
1285945Srugrat unsigned long addr,
1286945Srugrat off_t *offset)
1287945Srugrat {
1288945Srugrat
1289945Srugrat int length, index;
1290945Srugrat pci_regspec_t *reg;
1291945Srugrat
1292945Srugrat if (ddi_getlongprop(DDI_DEV_T_ANY, devi, DDI_PROP_DONTPASS,
12935295Srandyf "reg", (caddr_t)®, &length) != DDI_PROP_SUCCESS) {
1294945Srugrat return (-1);
1295945Srugrat }
1296945Srugrat
1297945Srugrat for (index = 0; index < length / sizeof (pci_regspec_t); index++) {
1298945Srugrat if ((reg[index].pci_phys_hi & himask) != hival)
1299945Srugrat continue;
1300945Srugrat if (reg[index].pci_size_hi != 0)
1301945Srugrat continue;
1302945Srugrat if (reg[index].pci_phys_mid != 0)
1303945Srugrat continue;
1304945Srugrat if (reg[index].pci_phys_low > addr)
1305945Srugrat continue;
1306945Srugrat if (reg[index].pci_phys_low + reg[index].pci_size_low <= addr)
1307945Srugrat continue;
1308945Srugrat
1309945Srugrat *offset = addr - reg[index].pci_phys_low;
1310945Srugrat kmem_free(reg, (size_t)length);
1311945Srugrat return (index);
1312945Srugrat }
1313945Srugrat kmem_free(reg, (size_t)length);
1314945Srugrat
1315945Srugrat return (-1);
1316945Srugrat }
1317945Srugrat
1318945Srugrat /*
1319945Srugrat * search the entries of the "reg" property for one which has the desired
1320945Srugrat * combination of phys_hi bits and contains the desired address.
1321945Srugrat *
1322945Srugrat * This version searches a ISA-style "reg" property. It was prompted by
1323945Srugrat * issues surrounding 8514/A support. By IEEE 1275 compatibility conventions,
1324945Srugrat * 8514/A registers should have been added after all standard VGA registers.
1325945Srugrat * Unfortunately, the Solaris/Intel device configuration framework
1326945Srugrat * (a) lists the 8514/A registers before the video memory, and then
1327945Srugrat * (b) also sorts the entries so that I/O entries come before memory
1328945Srugrat * entries.
1329945Srugrat *
1330945Srugrat * It returns the "reg" index and offset into that register set.
1331945Srugrat * The offset is needed because there exist (broken?) BIOSes that
1332945Srugrat * report larger ranges enclosing the standard ranges. One reports
1333945Srugrat * 0x3bf for 0x21 instead of 0x3c0 for 0x20, for instance. Using the
1334945Srugrat * offset adjusts for this difference in the base of the register set.
1335945Srugrat *
1336945Srugrat * Note that this routine may not be fully general; it is intended for the
1337945Srugrat * specific purpose of finding a couple of particular VGA reg entries and
1338945Srugrat * may not be suitable for all reg-searching purposes.
1339945Srugrat */
1340945Srugrat static int
vgatext_get_isa_reg_index(dev_info_t * const devi,unsigned long hival,unsigned long addr,off_t * offset)1341945Srugrat vgatext_get_isa_reg_index(
1342945Srugrat dev_info_t *const devi,
1343945Srugrat unsigned long hival,
1344945Srugrat unsigned long addr,
1345945Srugrat off_t *offset)
1346945Srugrat {
1347945Srugrat
1348945Srugrat int length, index;
1349945Srugrat struct regspec *reg;
1350945Srugrat
1351945Srugrat if (ddi_getlongprop(DDI_DEV_T_ANY, devi, DDI_PROP_DONTPASS,
13525295Srandyf "reg", (caddr_t)®, &length) != DDI_PROP_SUCCESS) {
1353945Srugrat return (-1);
1354945Srugrat }
1355945Srugrat
1356945Srugrat for (index = 0; index < length / sizeof (struct regspec); index++) {
1357945Srugrat if (reg[index].regspec_bustype != hival)
1358945Srugrat continue;
1359945Srugrat if (reg[index].regspec_addr > addr)
1360945Srugrat continue;
1361945Srugrat if (reg[index].regspec_addr + reg[index].regspec_size <= addr)
1362945Srugrat continue;
1363945Srugrat
1364945Srugrat *offset = addr - reg[index].regspec_addr;
1365945Srugrat kmem_free(reg, (size_t)length);
1366945Srugrat return (index);
1367945Srugrat }
1368945Srugrat kmem_free(reg, (size_t)length);
1369945Srugrat
1370945Srugrat return (-1);
1371945Srugrat }
13725295Srandyf
13735295Srandyf /*
13745295Srandyf * This vgatext function is used to return the fb, and reg pointers
13755295Srandyf * and handles for peer graphics drivers.
13765295Srandyf */
13775295Srandyf
13785295Srandyf void
vgatext_return_pointers(struct vgatext_softc * softc,struct vgaregmap * fbs,struct vgaregmap * regss)13795295Srandyf vgatext_return_pointers(struct vgatext_softc *softc,
13805295Srandyf struct vgaregmap *fbs,
13815295Srandyf struct vgaregmap *regss)
13825295Srandyf {
13835295Srandyf
13845295Srandyf fbs->addr = softc->fb.addr;
13855295Srandyf fbs->handle = softc->fb.handle;
13865295Srandyf fbs->mapped = softc->fb.mapped;
13875295Srandyf regss->addr = softc->regs.addr;
13885295Srandyf regss->handle = softc->regs.handle;
13895295Srandyf regss->mapped = softc->regs.mapped;
13905295Srandyf }
1391