xref: /illumos-gate/usr/src/uts/intel/io/vgatext/vgatext.c (revision 8704b322)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * 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.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
214ab75253Smrj 
227c478bd9Sstevel@tonic-gate /*
2393a18d6dSEnrico Perla - Sun Microsystems  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
27f67ca41aSrugrat /*	Copyright (c) 1990, 1991 UNIX System Laboratories, Inc.	*/
28f67ca41aSrugrat /*	Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T	*/
29*8704b322SToomas Soome /*	All Rights Reserved	*/
30f67ca41aSrugrat 
317c478bd9Sstevel@tonic-gate #include <sys/errno.h>
327c478bd9Sstevel@tonic-gate #include <sys/types.h>
337c478bd9Sstevel@tonic-gate #include <sys/conf.h>
347c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
357c478bd9Sstevel@tonic-gate #include <sys/visual_io.h>
367c478bd9Sstevel@tonic-gate #include <sys/font.h>
377c478bd9Sstevel@tonic-gate #include <sys/fbio.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
407c478bd9Sstevel@tonic-gate #include <sys/stat.h>
417c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
427c478bd9Sstevel@tonic-gate #include <sys/file.h>
437c478bd9Sstevel@tonic-gate #include <sys/open.h>
447c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
457c478bd9Sstevel@tonic-gate #include <sys/vgareg.h>
467c478bd9Sstevel@tonic-gate #include <sys/vgasubr.h>
477c478bd9Sstevel@tonic-gate #include <sys/pci.h>
487c478bd9Sstevel@tonic-gate #include <sys/kd.h>
497c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
507c478bd9Sstevel@tonic-gate #include <sys/sunldi.h>
5130165b7fSToomas Soome #include <sys/gfx_private.h>
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate #define	MYNAME	"vgatext"
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /*
5660405de4Skz  * Each instance of this driver has 2 minor nodes:
5760405de4Skz  * 0: for common graphics operations
5860405de4Skz  * 1: for agpmaster operations
597c478bd9Sstevel@tonic-gate  */
6060405de4Skz #define	GFX_MINOR		0
6160405de4Skz #define	AGPMASTER_MINOR		1
62d6bb6a84Sms 
6360405de4Skz #define	MY_NBITSMINOR		1
6460405de4Skz #define	DEV2INST(dev)		(getminor(dev) >> MY_NBITSMINOR)
6560405de4Skz #define	DEV2MINOR(dev)		(getminor(dev) & ((1 << MY_NBITSMINOR) - 1))
6630165b7fSToomas Soome #define	INST2NODE1(inst)	(((inst) << MY_NBITSMINOR) + GFX_MINOR)
6760405de4Skz #define	INST2NODE2(inst)	(((inst) << MY_NBITSMINOR) + AGPMASTER_MINOR)
687c478bd9Sstevel@tonic-gate 
692df1fe9cSrandyf /*
702df1fe9cSrandyf  * This variable allows for this driver to suspend even if it
712df1fe9cSrandyf  * shouldn't.  Note that by setting it, the framebuffer will probably
722df1fe9cSrandyf  * not come back.  So use it with a serial console, or with serial
732df1fe9cSrandyf  * line debugging (say, for example, if this driver is being modified
742df1fe9cSrandyf  * to support _some_ hardware doing suspend and resume).
752df1fe9cSrandyf  */
762df1fe9cSrandyf int vgatext_force_suspend = 0;
772df1fe9cSrandyf 
787c478bd9Sstevel@tonic-gate static int vgatext_open(dev_t *, int, int, cred_t *);
797c478bd9Sstevel@tonic-gate static int vgatext_close(dev_t, int, int, cred_t *);
807c478bd9Sstevel@tonic-gate static int vgatext_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
817c478bd9Sstevel@tonic-gate static int vgatext_devmap(dev_t, devmap_cookie_t, offset_t, size_t,
827c478bd9Sstevel@tonic-gate 			    size_t *, uint_t);
837c478bd9Sstevel@tonic-gate 
84*8704b322SToomas Soome static struct cb_ops cb_vgatext_ops = {
857c478bd9Sstevel@tonic-gate 	vgatext_open,		/* cb_open */
867c478bd9Sstevel@tonic-gate 	vgatext_close,		/* cb_close */
877c478bd9Sstevel@tonic-gate 	nodev,			/* cb_strategy */
887c478bd9Sstevel@tonic-gate 	nodev,			/* cb_print */
897c478bd9Sstevel@tonic-gate 	nodev,			/* cb_dump */
907c478bd9Sstevel@tonic-gate 	nodev,			/* cb_read */
917c478bd9Sstevel@tonic-gate 	nodev,			/* cb_write */
927c478bd9Sstevel@tonic-gate 	vgatext_ioctl,		/* cb_ioctl */
937c478bd9Sstevel@tonic-gate 	vgatext_devmap,		/* cb_devmap */
947c478bd9Sstevel@tonic-gate 	nodev,			/* cb_mmap */
957c478bd9Sstevel@tonic-gate 	ddi_devmap_segmap,	/* cb_segmap */
967c478bd9Sstevel@tonic-gate 	nochpoll,		/* cb_chpoll */
977c478bd9Sstevel@tonic-gate 	ddi_prop_op,		/* cb_prop_op */
987c478bd9Sstevel@tonic-gate 	0,			/* cb_stream */
997c478bd9Sstevel@tonic-gate 	D_NEW | D_MTSAFE	/* cb_flag */
1007c478bd9Sstevel@tonic-gate };
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate static int vgatext_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg,
1037c478bd9Sstevel@tonic-gate 		void **result);
1047c478bd9Sstevel@tonic-gate static int vgatext_attach(dev_info_t *, ddi_attach_cmd_t);
1057c478bd9Sstevel@tonic-gate static int vgatext_detach(dev_info_t *, ddi_detach_cmd_t);
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate static struct dev_ops vgatext_ops = {
1087c478bd9Sstevel@tonic-gate 	DEVO_REV,		/* devo_rev */
1097c478bd9Sstevel@tonic-gate 	0,			/* devo_refcnt */
1107c478bd9Sstevel@tonic-gate 	vgatext_info,		/* devo_getinfo */
1117c478bd9Sstevel@tonic-gate 	nulldev,		/* devo_identify */
1127c478bd9Sstevel@tonic-gate 	nulldev,		/* devo_probe */
1137c478bd9Sstevel@tonic-gate 	vgatext_attach,		/* devo_attach */
1147c478bd9Sstevel@tonic-gate 	vgatext_detach,		/* devo_detach */
1157c478bd9Sstevel@tonic-gate 	nodev,			/* devo_reset */
1167c478bd9Sstevel@tonic-gate 	&cb_vgatext_ops,	/* devo_cb_ops */
1177c478bd9Sstevel@tonic-gate 	(struct bus_ops *)NULL,	/* devo_bus_ops */
11819397407SSherry Moore 	NULL,			/* power */
11919397407SSherry Moore 	ddi_quiesce_not_needed,	/* quiesce */
1207c478bd9Sstevel@tonic-gate };
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate struct vgatext_softc {
12330165b7fSToomas Soome 	gfxp_fb_softc_ptr_t gfxp_state;
1247c478bd9Sstevel@tonic-gate 	dev_info_t		*devi;
1257c478bd9Sstevel@tonic-gate };
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate static void	*vgatext_softc_head;
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate /* Loadable Driver stuff */
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate static struct modldrv modldrv = {
1327c478bd9Sstevel@tonic-gate 	&mod_driverops,		/* Type of module.  This one is a driver */
133613b2871SRichard Bean 	"VGA text driver",	/* Name of the module. */
1347c478bd9Sstevel@tonic-gate 	&vgatext_ops,		/* driver ops */
1357c478bd9Sstevel@tonic-gate };
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
1387c478bd9Sstevel@tonic-gate 	MODREV_1, (void *) &modldrv, NULL
1397c478bd9Sstevel@tonic-gate };
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate int
_init(void)1427c478bd9Sstevel@tonic-gate _init(void)
1437c478bd9Sstevel@tonic-gate {
1447c478bd9Sstevel@tonic-gate 	int e;
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 	if ((e = ddi_soft_state_init(&vgatext_softc_head,
1477c478bd9Sstevel@tonic-gate 		    sizeof (struct vgatext_softc), 1)) != 0) {
1487c478bd9Sstevel@tonic-gate 	    return (e);
1497c478bd9Sstevel@tonic-gate 	}
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate 	e = mod_install(&modlinkage);
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate 	if (e) {
1542df1fe9cSrandyf 		ddi_soft_state_fini(&vgatext_softc_head);
1557c478bd9Sstevel@tonic-gate 	}
1567c478bd9Sstevel@tonic-gate 	return (e);
1577c478bd9Sstevel@tonic-gate }
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate int
_fini(void)1607c478bd9Sstevel@tonic-gate _fini(void)
1617c478bd9Sstevel@tonic-gate {
1627c478bd9Sstevel@tonic-gate 	int e;
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 	if ((e = mod_remove(&modlinkage)) != 0)
1652df1fe9cSrandyf 		return (e);
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 	ddi_soft_state_fini(&vgatext_softc_head);
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate 	return (0);
1707c478bd9Sstevel@tonic-gate }
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1737c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
1747c478bd9Sstevel@tonic-gate {
1757c478bd9Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
1767c478bd9Sstevel@tonic-gate }
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate /*
1797c478bd9Sstevel@tonic-gate  * handy macros
1807c478bd9Sstevel@tonic-gate  */
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate #define	getsoftc(instance) ((struct vgatext_softc *)	\
1837c478bd9Sstevel@tonic-gate 			ddi_get_soft_state(vgatext_softc_head, (instance)))
1847c478bd9Sstevel@tonic-gate 
1854e93fb0fSrugrat #define	STREQ(a, b)	(strcmp((a), (b)) == 0)
1864e93fb0fSrugrat 
1877c478bd9Sstevel@tonic-gate static int
vgatext_attach(dev_info_t * devi,ddi_attach_cmd_t cmd)1887c478bd9Sstevel@tonic-gate vgatext_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
1897c478bd9Sstevel@tonic-gate {
1907c478bd9Sstevel@tonic-gate 	struct vgatext_softc *softc;
1917c478bd9Sstevel@tonic-gate 	int	unit = ddi_get_instance(devi);
1927c478bd9Sstevel@tonic-gate 	int	error;
19330165b7fSToomas Soome 	char	name[80];
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate 	switch (cmd) {
1977c478bd9Sstevel@tonic-gate 	case DDI_ATTACH:
1982df1fe9cSrandyf 		break;
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate 	case DDI_RESUME:
2012df1fe9cSrandyf 		/*
2022df1fe9cSrandyf 		 * Though vgatext doesn't really know how to resume
2032df1fe9cSrandyf 		 * on a generic framebuffer, we should succeed, as
2042df1fe9cSrandyf 		 * it is far better to have no console, than potentiall
2052df1fe9cSrandyf 		 * have no machine.
2062df1fe9cSrandyf 		 */
20730165b7fSToomas Soome 		softc = getsoftc(unit);
20830165b7fSToomas Soome 		return (gfxp_fb_attach(devi, cmd, softc->gfxp_state));
2097c478bd9Sstevel@tonic-gate 	default:
2102df1fe9cSrandyf 		return (DDI_FAILURE);
2117c478bd9Sstevel@tonic-gate 	}
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate 	/* DDI_ATTACH */
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 	/* Allocate softc struct */
2167c478bd9Sstevel@tonic-gate 	if (ddi_soft_state_zalloc(vgatext_softc_head, unit) != DDI_SUCCESS) {
2177c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
2187c478bd9Sstevel@tonic-gate 	}
2197c478bd9Sstevel@tonic-gate 	softc = getsoftc(unit);
22030165b7fSToomas Soome 	softc->gfxp_state = gfxp_fb_softc_alloc();
22130165b7fSToomas Soome 	if (softc->gfxp_state == NULL) {
22230165b7fSToomas Soome 		(void) ddi_soft_state_free(vgatext_softc_head, unit);
22330165b7fSToomas Soome 		return (DDI_FAILURE);
2247c478bd9Sstevel@tonic-gate 	}
2257c478bd9Sstevel@tonic-gate 
22630165b7fSToomas Soome 	if (gfxp_fb_attach(devi, cmd, softc->gfxp_state) != DDI_SUCCESS) {
22730165b7fSToomas Soome 		gfxp_fb_softc_free(softc->gfxp_state);
22830165b7fSToomas Soome 		(void) ddi_soft_state_free(vgatext_softc_head, unit);
22930165b7fSToomas Soome 		return (DDI_FAILURE);
2307c478bd9Sstevel@tonic-gate 	}
2317c478bd9Sstevel@tonic-gate 
23230165b7fSToomas Soome 	/* link it in */
23330165b7fSToomas Soome 	softc->devi = devi;
23430165b7fSToomas Soome 	ddi_set_driver_private(devi, softc);
2357c478bd9Sstevel@tonic-gate 
23630165b7fSToomas Soome 	(void) snprintf(name, sizeof (name), "text-%d", unit);
23730165b7fSToomas Soome 	error = ddi_create_minor_node(devi, name, S_IFCHR,
238*8704b322SToomas Soome 	    INST2NODE1(unit), DDI_NT_DISPLAY, 0);
23930165b7fSToomas Soome 	if (error == DDI_SUCCESS)
24030165b7fSToomas Soome 		return (DDI_SUCCESS);
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate 	(void) vgatext_detach(devi, DDI_DETACH);
2437c478bd9Sstevel@tonic-gate 	return (error);
2447c478bd9Sstevel@tonic-gate }
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate static int
vgatext_detach(dev_info_t * devi,ddi_detach_cmd_t cmd)2477c478bd9Sstevel@tonic-gate vgatext_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
2487c478bd9Sstevel@tonic-gate {
2497c478bd9Sstevel@tonic-gate 	int instance = ddi_get_instance(devi);
2507c478bd9Sstevel@tonic-gate 	struct vgatext_softc *softc = getsoftc(instance);
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate 	switch (cmd) {
2547c478bd9Sstevel@tonic-gate 	case DDI_DETACH:
25530165b7fSToomas Soome 		(void) gfxp_fb_detach(devi, cmd, softc->gfxp_state);
25630165b7fSToomas Soome 
25730165b7fSToomas Soome 		if (softc->gfxp_state != NULL)
25830165b7fSToomas Soome 			gfxp_fb_softc_free(softc->gfxp_state);
2597c478bd9Sstevel@tonic-gate 		ddi_remove_minor_node(devi, NULL);
2607c478bd9Sstevel@tonic-gate 		(void) ddi_soft_state_free(vgatext_softc_head, instance);
2617c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
2627c478bd9Sstevel@tonic-gate 
2632df1fe9cSrandyf 	case DDI_SUSPEND:
2642df1fe9cSrandyf 		/*
2652df1fe9cSrandyf 		 * This is a generic VGA file, and therefore, cannot
2662df1fe9cSrandyf 		 * understand how to deal with suspend and resume on
2672df1fe9cSrandyf 		 * a generic interface.  So we fail any attempt to
2682df1fe9cSrandyf 		 * suspend.  At some point in the future, we might use
2692df1fe9cSrandyf 		 * this as an entrypoint for display drivers and this
2702df1fe9cSrandyf 		 * assumption may change.
2712df1fe9cSrandyf 		 *
2722df1fe9cSrandyf 		 * However, from a platform development perspective,
2732df1fe9cSrandyf 		 * it is important that this driver suspend if a
2742df1fe9cSrandyf 		 * developer is using a serial console and/or working
2752df1fe9cSrandyf 		 * on a framebuffer driver that will support suspend
2762df1fe9cSrandyf 		 * and resume.  Therefore, we have this module tunable
2772df1fe9cSrandyf 		 * (purposely using a long name) that will allow for
2782df1fe9cSrandyf 		 * suspend it it is set.  Otherwise we fail.
2792df1fe9cSrandyf 		 */
2802df1fe9cSrandyf 		if (vgatext_force_suspend != 0)
28130165b7fSToomas Soome 			return (gfxp_fb_detach(devi, cmd, softc->gfxp_state));
2822df1fe9cSrandyf 		else
2832df1fe9cSrandyf 			return (DDI_FAILURE);
2842df1fe9cSrandyf 
2857c478bd9Sstevel@tonic-gate 	default:
2867c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "vgatext_detach: unknown cmd 0x%x\n", cmd);
2877c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
2887c478bd9Sstevel@tonic-gate 	}
2897c478bd9Sstevel@tonic-gate }
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2927c478bd9Sstevel@tonic-gate static int
vgatext_info(dev_info_t * dip,ddi_info_cmd_t infocmd,void * arg,void ** result)2937c478bd9Sstevel@tonic-gate vgatext_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
2947c478bd9Sstevel@tonic-gate {
2957c478bd9Sstevel@tonic-gate 	dev_t dev;
2967c478bd9Sstevel@tonic-gate 	int error;
2977c478bd9Sstevel@tonic-gate 	int instance;
2987c478bd9Sstevel@tonic-gate 	struct vgatext_softc *softc;
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate 	error = DDI_SUCCESS;
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate 	dev = (dev_t)arg;
3037c478bd9Sstevel@tonic-gate 	instance = DEV2INST(dev);
3047c478bd9Sstevel@tonic-gate 	softc = getsoftc(instance);
3057c478bd9Sstevel@tonic-gate 
3067c478bd9Sstevel@tonic-gate 	switch (infocmd) {
3077c478bd9Sstevel@tonic-gate 	case DDI_INFO_DEVT2DEVINFO:
3087c478bd9Sstevel@tonic-gate 		if (softc == NULL || softc->devi == NULL) {
3097c478bd9Sstevel@tonic-gate 			error = DDI_FAILURE;
3107c478bd9Sstevel@tonic-gate 		} else {
3117c478bd9Sstevel@tonic-gate 			*result = (void *) softc->devi;
3127c478bd9Sstevel@tonic-gate 			error = DDI_SUCCESS;
3137c478bd9Sstevel@tonic-gate 		}
3147c478bd9Sstevel@tonic-gate 		break;
3157c478bd9Sstevel@tonic-gate 	case DDI_INFO_DEVT2INSTANCE:
3167c478bd9Sstevel@tonic-gate 		*result = (void *)(uintptr_t)instance;
3177c478bd9Sstevel@tonic-gate 		error = DDI_SUCCESS;
3187c478bd9Sstevel@tonic-gate 		break;
3197c478bd9Sstevel@tonic-gate 	default:
3207c478bd9Sstevel@tonic-gate 		error = DDI_FAILURE;
3217c478bd9Sstevel@tonic-gate 		break;
3227c478bd9Sstevel@tonic-gate 	}
3237c478bd9Sstevel@tonic-gate 	return (error);
3247c478bd9Sstevel@tonic-gate }
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate static int
vgatext_open(dev_t * devp,int flag,int otyp,cred_t * cred)3287c478bd9Sstevel@tonic-gate vgatext_open(dev_t *devp, int flag, int otyp, cred_t *cred)
3297c478bd9Sstevel@tonic-gate {
3307c478bd9Sstevel@tonic-gate 	struct vgatext_softc *softc = getsoftc(DEV2INST(*devp));
3317c478bd9Sstevel@tonic-gate 
33230165b7fSToomas Soome 	if (softc == NULL)
3337c478bd9Sstevel@tonic-gate 		return (ENXIO);
3347c478bd9Sstevel@tonic-gate 
33530165b7fSToomas Soome 	return (gfxp_fb_open(devp, flag, otyp, cred, softc->gfxp_state));
3367c478bd9Sstevel@tonic-gate }
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate static int
vgatext_close(dev_t devp,int flag,int otyp,cred_t * cred)3397c478bd9Sstevel@tonic-gate vgatext_close(dev_t devp, int flag, int otyp, cred_t *cred)
3407c478bd9Sstevel@tonic-gate {
34130165b7fSToomas Soome 	struct vgatext_softc *softc = getsoftc(DEV2INST(devp));
3427c478bd9Sstevel@tonic-gate 
34330165b7fSToomas Soome 	if (softc == NULL)
34460405de4Skz 		return (ENXIO);
3457c478bd9Sstevel@tonic-gate 
34630165b7fSToomas Soome 	return (gfxp_fb_close(devp, flag, otyp, cred, softc->gfxp_state));
34730165b7fSToomas Soome }
3487c478bd9Sstevel@tonic-gate 
34960405de4Skz static int
vgatext_ioctl(dev_t dev,int cmd,intptr_t data,int mode,cred_t * cred,int * rval)35060405de4Skz vgatext_ioctl(
35160405de4Skz     dev_t dev,
35260405de4Skz     int cmd,
35360405de4Skz     intptr_t data,
35460405de4Skz     int mode,
35560405de4Skz     cred_t *cred,
35660405de4Skz     int *rval)
35760405de4Skz {
35860405de4Skz 	struct vgatext_softc *softc = getsoftc(DEV2INST(dev));
35960405de4Skz 	int err;
3607c478bd9Sstevel@tonic-gate 
36160405de4Skz 	switch (DEV2MINOR(dev)) {
36260405de4Skz 	case GFX_MINOR:
36330165b7fSToomas Soome 		err = gfxp_fb_ioctl(dev, cmd, data, mode, cred, rval,
36430165b7fSToomas Soome 		    softc->gfxp_state);
3657c478bd9Sstevel@tonic-gate 		break;
3667c478bd9Sstevel@tonic-gate 
36760405de4Skz 	case AGPMASTER_MINOR:
368d1aea6f1SGordon Ross 		/*
369d1aea6f1SGordon Ross 		 * This is apparently not used anymore.  Let's log a
370d1aea6f1SGordon Ross 		 * message so we'll know if some consumer shows up.
371d1aea6f1SGordon Ross 		 * If it turns out that we actually do need to keep
372d1aea6f1SGordon Ross 		 * support for this pass-through to agpmaster, it
373d1aea6f1SGordon Ross 		 * would probably be better to use "layered" access
374d1aea6f1SGordon Ross 		 * to the AGP device (ldi_open, ldi_ioctl, ldi_close)
375d1aea6f1SGordon Ross 		 */
376d1aea6f1SGordon Ross 		cmn_err(CE_NOTE, "!vgatext wants agpmaster");
377d1aea6f1SGordon Ross 		return (EBADF);
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate 	default:
38060405de4Skz 		/* not a valid minor node */
38160405de4Skz 		return (EBADF);
3827c478bd9Sstevel@tonic-gate 	}
38360405de4Skz 	return (err);
38448633f18SJan Setje-Eilers }
38560405de4Skz 
3867c478bd9Sstevel@tonic-gate static int
vgatext_devmap(dev_t dev,devmap_cookie_t dhp,offset_t off,size_t len,size_t * maplen,uint_t model)3877c478bd9Sstevel@tonic-gate vgatext_devmap(dev_t dev, devmap_cookie_t dhp, offset_t off, size_t len,
388d1e631afSToomas Soome     size_t *maplen, uint_t model)
3897c478bd9Sstevel@tonic-gate {
3907c478bd9Sstevel@tonic-gate 	struct vgatext_softc *softc;
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate 	softc = getsoftc(DEV2INST(dev));
3937c478bd9Sstevel@tonic-gate 	if (softc == NULL) {
3947c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "vgatext: Can't find softstate");
3957c478bd9Sstevel@tonic-gate 		return (-1);
3967c478bd9Sstevel@tonic-gate 	}
3977c478bd9Sstevel@tonic-gate 
39830165b7fSToomas Soome 	return (gfxp_fb_devmap(dev, dhp, off, len, maplen, model,
39930165b7fSToomas Soome 	    softc->gfxp_state));
4007c478bd9Sstevel@tonic-gate }
401