1997-04-03 02:37:21 +04:00
|
|
|
/* $NetBSD: grf.c,v 1.25 1997/04/02 22:37:30 scottr Exp $ */
|
1994-10-26 10:22:45 +03:00
|
|
|
|
1993-05-13 17:56:20 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1988 University of Utah.
|
1994-05-25 15:47:14 +04:00
|
|
|
* Copyright (c) 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-05-13 17:56:20 +04:00
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* the Systems Programming Group of the University of Utah Computer
|
|
|
|
* Science Department.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1994-05-25 15:47:14 +04:00
|
|
|
* from: Utah $Hdr: grf.c 1.36 93/08/13$
|
|
|
|
*
|
1994-10-26 10:22:45 +03:00
|
|
|
* @(#)grf.c 8.4 (Berkeley) 1/12/94
|
1993-05-13 17:56:20 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1994-05-25 15:47:14 +04:00
|
|
|
* Graphics display driver for HP 300/400/700/800 machines.
|
1993-05-13 17:56:20 +04:00
|
|
|
* This is the hardware-independent portion of the driver.
|
1994-05-25 15:47:14 +04:00
|
|
|
* Hardware access is through the machine dependent grf switch routines.
|
1993-05-13 17:56:20 +04:00
|
|
|
*/
|
|
|
|
|
1994-02-10 16:59:25 +03:00
|
|
|
#include <sys/param.h>
|
1997-03-31 11:32:14 +04:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/device.h>
|
1994-02-10 16:59:25 +03:00
|
|
|
#include <sys/file.h>
|
1997-03-31 11:32:14 +04:00
|
|
|
#include <sys/ioctl.h>
|
1994-02-10 16:59:25 +03:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mman.h>
|
1996-09-12 05:22:58 +04:00
|
|
|
#include <sys/poll.h>
|
1997-03-31 11:32:14 +04:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/vnode.h>
|
1993-05-13 17:56:20 +04:00
|
|
|
|
1996-02-24 03:54:53 +03:00
|
|
|
#include <machine/autoconf.h>
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
|
1994-02-10 16:59:25 +03:00
|
|
|
#include <hp300/dev/grfioctl.h>
|
1994-02-10 17:55:29 +03:00
|
|
|
#include <hp300/dev/grfvar.h>
|
1994-05-25 15:47:14 +04:00
|
|
|
#include <hp300/dev/grfreg.h>
|
1993-05-13 17:56:20 +04:00
|
|
|
|
1994-05-04 08:02:54 +04:00
|
|
|
#ifdef COMPAT_HPUX
|
1995-11-28 11:12:37 +03:00
|
|
|
#include <compat/hpux/hpux.h>
|
1995-04-23 00:24:40 +04:00
|
|
|
extern struct emul emul_hpux;
|
1993-05-13 17:56:20 +04:00
|
|
|
#endif
|
|
|
|
|
1994-02-10 16:59:25 +03:00
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_kern.h>
|
|
|
|
#include <vm/vm_page.h>
|
|
|
|
#include <vm/vm_pager.h>
|
1993-05-13 17:56:20 +04:00
|
|
|
|
1994-02-10 16:59:25 +03:00
|
|
|
#include <miscfs/specfs/specdev.h>
|
1993-05-13 17:56:20 +04:00
|
|
|
|
1995-11-20 01:32:38 +03:00
|
|
|
#include "ite.h"
|
1996-02-24 03:54:53 +03:00
|
|
|
#if NITE > 0
|
|
|
|
#include <hp300/dev/itevar.h>
|
|
|
|
#else
|
1997-01-30 12:18:33 +03:00
|
|
|
#define iteon(u,f) 0 /* noramlly returns int */
|
1993-05-13 17:56:20 +04:00
|
|
|
#define iteoff(u,f)
|
1996-02-24 03:54:53 +03:00
|
|
|
#endif /* NITE > 0 */
|
1993-05-13 17:56:20 +04:00
|
|
|
|
1996-09-12 05:22:58 +04:00
|
|
|
/* prototypes for the devsw entry points */
|
|
|
|
cdev_decl(grf);
|
|
|
|
|
1996-12-17 11:40:56 +03:00
|
|
|
int grfmatch __P((struct device *, struct cfdata *, void *));
|
|
|
|
void grfattach __P((struct device *, struct device *, void *));
|
|
|
|
|
|
|
|
struct cfattach grf_ca = {
|
|
|
|
sizeof(struct grf_softc), grfmatch, grfattach
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cfdriver grf_cd = {
|
|
|
|
NULL, "grf", DV_DULL
|
|
|
|
};
|
|
|
|
|
|
|
|
int grfprint __P((void *, const char *));
|
1993-05-13 17:56:20 +04:00
|
|
|
|
1996-02-24 03:54:53 +03:00
|
|
|
/*
|
|
|
|
* Frambuffer state information, statically allocated for benefit
|
|
|
|
* of the console.
|
|
|
|
*/
|
|
|
|
struct grf_data grf_cn;
|
|
|
|
|
1993-05-13 17:56:20 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
int grfdebug = 0;
|
|
|
|
#define GDB_DEVNO 0x01
|
|
|
|
#define GDB_MMAP 0x02
|
|
|
|
#define GDB_IOMAP 0x04
|
|
|
|
#define GDB_LOCK 0x08
|
|
|
|
#endif
|
|
|
|
|
1996-12-17 11:40:56 +03:00
|
|
|
int
|
|
|
|
grfmatch(parent, match, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *match;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
grfattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct grf_softc *sc = (struct grf_softc *)self;
|
|
|
|
struct grfdev_attach_args *ga = aux;
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
sc->sc_data = ga->ga_data;
|
|
|
|
sc->sc_scode = ga->ga_scode; /* XXX */
|
|
|
|
|
|
|
|
/* Attach an ITE. */
|
|
|
|
(void)config_found(self, aux, grfprint);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
grfprint(aux, pnp)
|
|
|
|
void *aux;
|
|
|
|
const char *pnp;
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Only ITEs can attach to GRFs, easy... */
|
|
|
|
if (pnp)
|
|
|
|
printf("ite at %s", pnp);
|
|
|
|
|
|
|
|
return (UNCONF);
|
|
|
|
}
|
|
|
|
|
1993-05-13 17:56:20 +04:00
|
|
|
/*ARGSUSED*/
|
1996-09-12 05:22:58 +04:00
|
|
|
int
|
1996-02-24 03:54:53 +03:00
|
|
|
grfopen(dev, flags, mode, p)
|
1993-05-13 17:56:20 +04:00
|
|
|
dev_t dev;
|
1996-02-24 03:54:53 +03:00
|
|
|
int flags, mode;
|
|
|
|
struct proc *p;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
|
|
|
int unit = GRFUNIT(dev);
|
1996-02-24 03:54:53 +03:00
|
|
|
struct grf_softc *sc;
|
|
|
|
struct grf_data *gp;
|
1993-05-13 17:56:20 +04:00
|
|
|
int error = 0;
|
|
|
|
|
1996-12-17 11:40:56 +03:00
|
|
|
if (unit >= grf_cd.cd_ndevs ||
|
|
|
|
(sc = grf_cd.cd_devs[unit]) == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
1996-02-24 03:54:53 +03:00
|
|
|
gp = sc->sc_data;
|
|
|
|
|
|
|
|
if ((gp->g_flags & GF_ALIVE) == 0)
|
|
|
|
return (ENXIO);
|
|
|
|
|
1993-05-13 17:56:20 +04:00
|
|
|
if ((gp->g_flags & (GF_OPEN|GF_EXCLUDE)) == (GF_OPEN|GF_EXCLUDE))
|
|
|
|
return(EBUSY);
|
1994-05-04 08:02:54 +04:00
|
|
|
#ifdef COMPAT_HPUX
|
1993-05-13 17:56:20 +04:00
|
|
|
/*
|
|
|
|
* XXX: cannot handle both HPUX and BSD processes at the same time
|
|
|
|
*/
|
1996-02-24 03:54:53 +03:00
|
|
|
if (p->p_emul == &emul_hpux)
|
1993-05-13 17:56:20 +04:00
|
|
|
if (gp->g_flags & GF_BSDOPEN)
|
|
|
|
return(EBUSY);
|
|
|
|
else
|
|
|
|
gp->g_flags |= GF_HPUXOPEN;
|
|
|
|
else
|
|
|
|
if (gp->g_flags & GF_HPUXOPEN)
|
|
|
|
return(EBUSY);
|
|
|
|
else
|
|
|
|
gp->g_flags |= GF_BSDOPEN;
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* First open.
|
|
|
|
* XXX: always put in graphics mode.
|
|
|
|
*/
|
|
|
|
error = 0;
|
|
|
|
if ((gp->g_flags & GF_OPEN) == 0) {
|
|
|
|
gp->g_flags |= GF_OPEN;
|
|
|
|
error = grfon(dev);
|
|
|
|
}
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
1996-09-12 05:22:58 +04:00
|
|
|
int
|
1996-02-24 03:54:53 +03:00
|
|
|
grfclose(dev, flags, mode, p)
|
1993-05-13 17:56:20 +04:00
|
|
|
dev_t dev;
|
1996-02-24 03:54:53 +03:00
|
|
|
int flags, mode;
|
|
|
|
struct proc *p;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1996-02-24 03:54:53 +03:00
|
|
|
int unit = GRFUNIT(dev);
|
|
|
|
struct grf_softc *sc;
|
|
|
|
struct grf_data *gp;
|
|
|
|
|
1996-12-17 11:40:56 +03:00
|
|
|
sc = grf_cd.cd_devs[unit];
|
|
|
|
|
1996-02-24 03:54:53 +03:00
|
|
|
gp = sc->sc_data;
|
|
|
|
|
|
|
|
if ((gp->g_flags & GF_ALIVE) == 0)
|
|
|
|
return (ENXIO);
|
1993-05-13 17:56:20 +04:00
|
|
|
|
|
|
|
(void) grfoff(dev);
|
1994-05-25 15:47:14 +04:00
|
|
|
#ifdef COMPAT_HPUX
|
1993-05-13 17:56:20 +04:00
|
|
|
(void) grfunlock(gp);
|
1994-05-25 15:47:14 +04:00
|
|
|
#endif
|
1993-05-13 17:56:20 +04:00
|
|
|
gp->g_flags &= GF_ALIVE;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
1996-09-12 05:22:58 +04:00
|
|
|
int
|
1993-05-13 17:56:20 +04:00
|
|
|
grfioctl(dev, cmd, data, flag, p)
|
|
|
|
dev_t dev;
|
1996-09-12 05:22:58 +04:00
|
|
|
u_long cmd;
|
|
|
|
int flag;
|
1993-05-13 17:56:20 +04:00
|
|
|
caddr_t data;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1996-02-24 03:54:53 +03:00
|
|
|
struct grf_softc *sc;
|
|
|
|
struct grf_data *gp;
|
|
|
|
int error, unit = GRFUNIT(dev);
|
|
|
|
|
1996-12-17 11:40:56 +03:00
|
|
|
sc = grf_cd.cd_devs[unit];
|
|
|
|
|
1996-02-24 03:54:53 +03:00
|
|
|
gp = sc->sc_data;
|
|
|
|
|
|
|
|
if ((gp->g_flags & GF_ALIVE) == 0)
|
|
|
|
return (ENXIO);
|
1993-05-13 17:56:20 +04:00
|
|
|
|
1994-05-04 08:02:54 +04:00
|
|
|
#ifdef COMPAT_HPUX
|
1995-04-23 00:24:40 +04:00
|
|
|
if (p->p_emul == &emul_hpux)
|
1993-05-13 17:56:20 +04:00
|
|
|
return(hpuxgrfioctl(dev, cmd, data, flag, p));
|
|
|
|
#endif
|
|
|
|
error = 0;
|
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
case GRFIOCGINFO:
|
|
|
|
bcopy((caddr_t)&gp->g_display, data, sizeof(struct grfinfo));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GRFIOCON:
|
|
|
|
error = grfon(dev);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GRFIOCOFF:
|
|
|
|
error = grfoff(dev);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GRFIOCMAP:
|
1995-04-10 04:58:10 +04:00
|
|
|
error = grfmap(dev, (caddr_t *)data, p);
|
1993-05-13 17:56:20 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GRFIOCUNMAP:
|
1995-04-10 04:58:10 +04:00
|
|
|
error = grfunmap(dev, *(caddr_t *)data, p);
|
1993-05-13 17:56:20 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
1996-09-12 05:22:58 +04:00
|
|
|
int
|
|
|
|
grfpoll(dev, events, p)
|
1993-05-13 17:56:20 +04:00
|
|
|
dev_t dev;
|
1996-09-12 05:22:58 +04:00
|
|
|
int events;
|
|
|
|
struct proc *p;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1996-09-12 05:22:58 +04:00
|
|
|
|
|
|
|
return (events & (POLLOUT | POLLWRNORM));
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
|
1994-05-25 15:47:14 +04:00
|
|
|
/*ARGSUSED*/
|
1996-09-12 05:22:58 +04:00
|
|
|
int
|
1995-04-10 04:58:10 +04:00
|
|
|
grfmmap(dev, off, prot)
|
1994-05-25 15:47:14 +04:00
|
|
|
dev_t dev;
|
|
|
|
int off, prot;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1996-12-17 11:40:56 +03:00
|
|
|
struct grf_softc *sc = grf_cd.cd_devs[GRFUNIT(dev)];
|
|
|
|
|
|
|
|
return (grfaddr(sc, off));
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
|
1996-02-24 03:54:53 +03:00
|
|
|
int
|
1994-05-25 15:47:14 +04:00
|
|
|
grfon(dev)
|
1996-02-24 03:54:53 +03:00
|
|
|
dev_t dev; /* XXX */
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1994-05-25 15:47:14 +04:00
|
|
|
int unit = GRFUNIT(dev);
|
1996-02-24 03:54:53 +03:00
|
|
|
struct grf_softc *sc;
|
|
|
|
struct grf_data *gp;
|
|
|
|
|
1996-12-17 11:40:56 +03:00
|
|
|
sc = grf_cd.cd_devs[unit];
|
1996-02-24 03:54:53 +03:00
|
|
|
gp = sc->sc_data;
|
1994-05-25 15:47:14 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: iteoff call relies on devices being in same order
|
|
|
|
* as ITEs and the fact that iteoff only uses the minor part
|
|
|
|
* of the dev arg.
|
|
|
|
*/
|
1996-02-24 03:54:53 +03:00
|
|
|
iteoff(sc->sc_ite->sc_data, 3);
|
1994-05-25 15:47:14 +04:00
|
|
|
return((*gp->g_sw->gd_mode)(gp,
|
|
|
|
(dev&GRFOVDEV) ? GM_GRFOVON : GM_GRFON,
|
|
|
|
(caddr_t)0));
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
|
1996-02-24 03:54:53 +03:00
|
|
|
int
|
1994-05-25 15:47:14 +04:00
|
|
|
grfoff(dev)
|
1996-02-24 03:54:53 +03:00
|
|
|
dev_t dev; /* XXX */
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1994-05-25 15:47:14 +04:00
|
|
|
int unit = GRFUNIT(dev);
|
1996-02-24 03:54:53 +03:00
|
|
|
struct grf_softc *sc;
|
|
|
|
struct grf_data *gp;
|
1994-05-25 15:47:14 +04:00
|
|
|
int error;
|
|
|
|
|
1996-12-17 11:40:56 +03:00
|
|
|
sc = grf_cd.cd_devs[unit];
|
1996-02-24 03:54:53 +03:00
|
|
|
gp = sc->sc_data;
|
|
|
|
|
1995-04-10 04:58:10 +04:00
|
|
|
(void) grfunmap(dev, (caddr_t)0, curproc);
|
1994-05-25 15:47:14 +04:00
|
|
|
error = (*gp->g_sw->gd_mode)(gp,
|
|
|
|
(dev&GRFOVDEV) ? GM_GRFOVOFF : GM_GRFOFF,
|
|
|
|
(caddr_t)0);
|
|
|
|
/* XXX: see comment for iteoff above */
|
1997-01-30 12:18:33 +03:00
|
|
|
(void) iteon(sc->sc_ite->sc_data, 2);
|
1994-05-25 15:47:14 +04:00
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
1996-02-24 03:54:53 +03:00
|
|
|
int
|
|
|
|
grfaddr(sc, off)
|
|
|
|
struct grf_softc *sc;
|
1997-03-31 11:32:14 +04:00
|
|
|
int off;
|
1994-05-25 15:47:14 +04:00
|
|
|
{
|
1996-02-24 03:54:53 +03:00
|
|
|
struct grf_data *gp= sc->sc_data;
|
|
|
|
struct grfinfo *gi = &gp->g_display;
|
1994-05-25 15:47:14 +04:00
|
|
|
|
|
|
|
/* control registers */
|
|
|
|
if (off >= 0 && off < gi->gd_regsize)
|
|
|
|
return(((u_int)gi->gd_regaddr + off) >> PGSHIFT);
|
|
|
|
|
|
|
|
/* frame buffer */
|
|
|
|
if (off >= gi->gd_regsize && off < gi->gd_regsize+gi->gd_fbsize) {
|
|
|
|
off -= gi->gd_regsize;
|
|
|
|
return(((u_int)gi->gd_fbaddr + off) >> PGSHIFT);
|
|
|
|
}
|
|
|
|
/* bogus */
|
|
|
|
return(-1);
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
|
1994-05-25 15:47:14 +04:00
|
|
|
/*
|
|
|
|
* HP-UX compatibility routines
|
|
|
|
*/
|
1994-05-04 08:02:54 +04:00
|
|
|
#ifdef COMPAT_HPUX
|
1993-05-13 17:56:20 +04:00
|
|
|
|
|
|
|
/*ARGSUSED*/
|
1996-09-12 05:22:58 +04:00
|
|
|
int
|
1993-05-13 17:56:20 +04:00
|
|
|
hpuxgrfioctl(dev, cmd, data, flag, p)
|
|
|
|
dev_t dev;
|
1994-05-25 15:47:14 +04:00
|
|
|
int cmd, flag;
|
1993-05-13 17:56:20 +04:00
|
|
|
caddr_t data;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1996-12-17 11:40:56 +03:00
|
|
|
struct grf_softc *sc = grf_cd.cd_devs[GRFUNIT(dev)];
|
1996-02-24 03:54:53 +03:00
|
|
|
struct grf_data *gp = sc->sc_data;
|
1993-05-13 17:56:20 +04:00
|
|
|
int error;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
case GCID:
|
|
|
|
*(int *)data = gp->g_display.gd_id;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GCON:
|
|
|
|
error = grfon(dev);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GCOFF:
|
|
|
|
error = grfoff(dev);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GCLOCK:
|
|
|
|
error = grflock(gp, 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GCUNLOCK:
|
|
|
|
error = grfunlock(gp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GCAON:
|
|
|
|
case GCAOFF:
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* GCSTATIC is implied by our implementation */
|
|
|
|
case GCSTATIC_CMAP:
|
|
|
|
case GCVARIABLE_CMAP:
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* map in control regs and frame buffer */
|
|
|
|
case GCMAP:
|
1995-04-10 04:58:10 +04:00
|
|
|
error = grfmap(dev, (caddr_t *)data, p);
|
1993-05-13 17:56:20 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GCUNMAP:
|
1995-04-10 04:58:10 +04:00
|
|
|
error = grfunmap(dev, *(caddr_t *)data, p);
|
1993-05-13 17:56:20 +04:00
|
|
|
/* XXX: HP-UX uses GCUNMAP to get rid of GCSLOT memory */
|
|
|
|
if (error)
|
|
|
|
error = grflckunmmap(dev, *(caddr_t *)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GCSLOT:
|
|
|
|
{
|
|
|
|
struct grf_slot *sp = (struct grf_slot *)data;
|
|
|
|
|
|
|
|
sp->slot = grffindpid(gp);
|
|
|
|
if (sp->slot) {
|
|
|
|
error = grflckmmap(dev, (caddr_t *)&sp->addr);
|
|
|
|
if (error && gp->g_pid) {
|
|
|
|
free((caddr_t)gp->g_pid, M_DEVBUF);
|
|
|
|
gp->g_pid = NULL;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
error = EINVAL; /* XXX */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1994-05-25 15:47:14 +04:00
|
|
|
case GCDESCRIBE:
|
|
|
|
error = (*gp->g_sw->gd_mode)(gp, GM_DESCRIBE, data);
|
|
|
|
break;
|
|
|
|
|
1993-05-13 17:56:20 +04:00
|
|
|
/*
|
|
|
|
* XXX: only used right now to map in rbox control registers
|
|
|
|
* Will be replaced in the future with a real IOMAP interface.
|
|
|
|
*/
|
|
|
|
case IOMAPMAP:
|
|
|
|
error = iommap(dev, (caddr_t *)data);
|
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* It may not be worth kludging this (using p_devtmp) to
|
|
|
|
* make this work. It was an undocumented side-effect
|
|
|
|
* in HP-UX that the mapped address was the return value
|
|
|
|
* of the ioctl. The only thing I remember that counted
|
|
|
|
* on this behavior was the rbox X10 server.
|
|
|
|
*/
|
|
|
|
if (!error)
|
|
|
|
u.u_r.r_val1 = *(int *)data; /* XXX: this sux */
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IOMAPUNMAP:
|
|
|
|
error = iounmmap(dev, *(caddr_t *)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
1996-02-24 03:54:53 +03:00
|
|
|
int
|
1994-05-25 15:47:14 +04:00
|
|
|
grflock(gp, block)
|
1996-02-24 03:54:53 +03:00
|
|
|
struct grf_data *gp;
|
1994-05-25 15:47:14 +04:00
|
|
|
int block;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1994-05-25 15:47:14 +04:00
|
|
|
struct proc *p = curproc; /* XXX */
|
1993-05-13 17:56:20 +04:00
|
|
|
int error;
|
1994-05-25 15:47:14 +04:00
|
|
|
extern char devioc[];
|
1993-05-13 17:56:20 +04:00
|
|
|
|
1994-05-25 15:47:14 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (grfdebug & GDB_LOCK)
|
1996-10-13 07:14:05 +04:00
|
|
|
printf("grflock(%d): flags %x lockpid %x\n",
|
1996-02-24 03:54:53 +03:00
|
|
|
p->p_pid, gp->g_flags,
|
1994-05-25 15:47:14 +04:00
|
|
|
gp->g_lockp ? gp->g_lockp->p_pid : -1);
|
|
|
|
#endif
|
|
|
|
if (gp->g_pid) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (grfdebug & GDB_LOCK)
|
1996-10-13 07:14:05 +04:00
|
|
|
printf(" lockpslot %d lockslot %d lock[lockslot] %d\n",
|
1994-05-25 15:47:14 +04:00
|
|
|
gp->g_lock->gl_lockslot, gp->g_lockpslot,
|
|
|
|
gp->g_lock->gl_locks[gp->g_lockpslot]);
|
|
|
|
#endif
|
|
|
|
gp->g_lock->gl_lockslot = 0;
|
|
|
|
if (gp->g_lock->gl_locks[gp->g_lockpslot] == 0) {
|
|
|
|
gp->g_lockp = NULL;
|
|
|
|
gp->g_lockpslot = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (gp->g_lockp) {
|
|
|
|
if (gp->g_lockp == p)
|
|
|
|
return(EBUSY);
|
|
|
|
if (!block)
|
|
|
|
return(OEAGAIN);
|
|
|
|
do {
|
|
|
|
gp->g_flags |= GF_WANTED;
|
1997-03-31 11:32:14 +04:00
|
|
|
if ((error = tsleep((caddr_t)&gp->g_flags,
|
|
|
|
(PZERO+1) | PCATCH, devioc, 0)))
|
1994-05-25 15:47:14 +04:00
|
|
|
return (error);
|
|
|
|
} while (gp->g_lockp);
|
|
|
|
}
|
|
|
|
gp->g_lockp = p;
|
|
|
|
if (gp->g_pid) {
|
|
|
|
int slot = grffindpid(gp);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (grfdebug & GDB_LOCK)
|
1996-10-13 07:14:05 +04:00
|
|
|
printf(" slot %d\n", slot);
|
1994-05-25 15:47:14 +04:00
|
|
|
#endif
|
|
|
|
gp->g_lockpslot = gp->g_lock->gl_lockslot = slot;
|
|
|
|
gp->g_lock->gl_locks[slot] = 1;
|
|
|
|
}
|
|
|
|
return(0);
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
|
1996-09-12 05:22:58 +04:00
|
|
|
int
|
1994-05-25 15:47:14 +04:00
|
|
|
grfunlock(gp)
|
1996-02-24 03:54:53 +03:00
|
|
|
struct grf_data *gp;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1994-05-25 15:47:14 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (grfdebug & GDB_LOCK)
|
1996-10-13 07:14:05 +04:00
|
|
|
printf("grfunlock(%d): flags %x lockpid %d\n",
|
1996-02-24 03:54:53 +03:00
|
|
|
curproc->p_pid, gp->g_flags,
|
1994-05-25 15:47:14 +04:00
|
|
|
gp->g_lockp ? gp->g_lockp->p_pid : -1);
|
|
|
|
#endif
|
|
|
|
if (gp->g_lockp != curproc)
|
|
|
|
return(EBUSY);
|
|
|
|
if (gp->g_pid) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (grfdebug & GDB_LOCK)
|
1996-10-13 07:14:05 +04:00
|
|
|
printf(" lockpslot %d lockslot %d lock[lockslot] %d\n",
|
1994-05-25 15:47:14 +04:00
|
|
|
gp->g_lock->gl_lockslot, gp->g_lockpslot,
|
|
|
|
gp->g_lock->gl_locks[gp->g_lockpslot]);
|
|
|
|
#endif
|
|
|
|
gp->g_lock->gl_locks[gp->g_lockpslot] = 0;
|
|
|
|
gp->g_lockpslot = gp->g_lock->gl_lockslot = 0;
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
1994-05-25 15:47:14 +04:00
|
|
|
if (gp->g_flags & GF_WANTED) {
|
|
|
|
wakeup((caddr_t)&gp->g_flags);
|
|
|
|
gp->g_flags &= ~GF_WANTED;
|
|
|
|
}
|
|
|
|
gp->g_lockp = NULL;
|
|
|
|
return(0);
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert a BSD style minor devno to HPUX style.
|
|
|
|
* We cannot just create HPUX style nodes as they require 24 bits
|
|
|
|
* of minor device number and we only have 8.
|
|
|
|
* XXX: This may give the wrong result for remote stats of other
|
|
|
|
* machines where device 10 exists.
|
|
|
|
*/
|
1996-09-12 05:22:58 +04:00
|
|
|
int
|
1993-05-13 17:56:20 +04:00
|
|
|
grfdevno(dev)
|
|
|
|
dev_t dev;
|
|
|
|
{
|
|
|
|
int unit = GRFUNIT(dev);
|
1996-12-17 11:40:56 +03:00
|
|
|
struct grf_softc *sc;
|
|
|
|
struct grf_data *gp;
|
1994-05-25 15:47:14 +04:00
|
|
|
int newdev;
|
1993-05-13 17:56:20 +04:00
|
|
|
|
1996-12-17 11:40:56 +03:00
|
|
|
if (unit >= grf_cd.cd_ndevs ||
|
|
|
|
(sc = grf_cd.cd_devs[unit]) == NULL)
|
|
|
|
return (bsdtohpuxdev(dev));
|
|
|
|
|
|
|
|
gp = sc->sc_data;
|
|
|
|
if ((gp->g_flags & GF_ALIVE) == 0)
|
|
|
|
return (bsdtohpuxdev(dev));
|
|
|
|
|
1993-05-13 17:56:20 +04:00
|
|
|
/* magic major number */
|
|
|
|
newdev = 12 << 24;
|
|
|
|
/* now construct minor number */
|
1996-12-17 11:40:56 +03:00
|
|
|
if (gp->g_display.gd_regaddr != (caddr_t)GRFIADDR)
|
|
|
|
newdev |= (sc->sc_scode << 16) | 0x200;
|
1993-05-13 17:56:20 +04:00
|
|
|
if (dev & GRFIMDEV)
|
|
|
|
newdev |= 0x02;
|
|
|
|
else if (dev & GRFOVDEV)
|
|
|
|
newdev |= 0x01;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (grfdebug & GDB_DEVNO)
|
1996-10-13 07:14:05 +04:00
|
|
|
printf("grfdevno: dev %x newdev %x\n", dev, newdev);
|
1993-05-13 17:56:20 +04:00
|
|
|
#endif
|
|
|
|
return(newdev);
|
|
|
|
}
|
1994-05-25 15:47:14 +04:00
|
|
|
|
|
|
|
#endif /* COMPAT_HPUX */
|
1993-05-13 17:56:20 +04:00
|
|
|
|
1996-09-12 05:22:58 +04:00
|
|
|
int
|
1995-04-10 04:58:10 +04:00
|
|
|
grfmap(dev, addrp, p)
|
1993-05-13 17:56:20 +04:00
|
|
|
dev_t dev;
|
|
|
|
caddr_t *addrp;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1996-12-17 11:40:56 +03:00
|
|
|
struct grf_softc *sc = grf_cd.cd_devs[GRFUNIT(dev)];
|
1996-02-24 03:54:53 +03:00
|
|
|
struct grf_data *gp = sc->sc_data;
|
1993-05-13 17:56:20 +04:00
|
|
|
int len, error;
|
|
|
|
struct vnode vn;
|
|
|
|
struct specinfo si;
|
|
|
|
int flags;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (grfdebug & GDB_MMAP)
|
1997-04-03 02:37:21 +04:00
|
|
|
printf("grfmap(%d): addr %p\n", p->p_pid, *addrp);
|
1993-05-13 17:56:20 +04:00
|
|
|
#endif
|
|
|
|
len = gp->g_display.gd_regsize + gp->g_display.gd_fbsize;
|
1994-04-08 10:32:26 +04:00
|
|
|
flags = MAP_SHARED;
|
1993-05-13 17:56:20 +04:00
|
|
|
if (*addrp)
|
|
|
|
flags |= MAP_FIXED;
|
|
|
|
else
|
|
|
|
*addrp = (caddr_t)0x1000000; /* XXX */
|
|
|
|
vn.v_type = VCHR; /* XXX */
|
|
|
|
vn.v_specinfo = &si; /* XXX */
|
|
|
|
vn.v_rdev = dev; /* XXX */
|
|
|
|
error = vm_mmap(&p->p_vmspace->vm_map, (vm_offset_t *)addrp,
|
1994-05-25 15:47:14 +04:00
|
|
|
(vm_size_t)len, VM_PROT_ALL, VM_PROT_ALL,
|
|
|
|
flags, (caddr_t)&vn, 0);
|
|
|
|
if (error == 0)
|
|
|
|
(void) (*gp->g_sw->gd_mode)(gp, GM_MAP, *addrp);
|
1993-05-13 17:56:20 +04:00
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
1997-03-31 11:32:14 +04:00
|
|
|
int
|
1995-04-10 04:58:10 +04:00
|
|
|
grfunmap(dev, addr, p)
|
1993-05-13 17:56:20 +04:00
|
|
|
dev_t dev;
|
|
|
|
caddr_t addr;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1996-12-17 11:40:56 +03:00
|
|
|
struct grf_softc *sc = grf_cd.cd_devs[GRFUNIT(dev)];
|
1996-02-24 03:54:53 +03:00
|
|
|
struct grf_data *gp = sc->sc_data;
|
1993-05-13 17:56:20 +04:00
|
|
|
vm_size_t size;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (grfdebug & GDB_MMAP)
|
1997-04-03 02:37:21 +04:00
|
|
|
printf("grfunmap(%d): dev %x addr %p\n", p->p_pid, dev, addr);
|
1993-05-13 17:56:20 +04:00
|
|
|
#endif
|
|
|
|
if (addr == 0)
|
|
|
|
return(EINVAL); /* XXX: how do we deal with this? */
|
1994-05-25 15:47:14 +04:00
|
|
|
(void) (*gp->g_sw->gd_mode)(gp, GM_UNMAP, 0);
|
1993-05-13 17:56:20 +04:00
|
|
|
size = round_page(gp->g_display.gd_regsize + gp->g_display.gd_fbsize);
|
1994-05-17 14:27:49 +04:00
|
|
|
rv = vm_deallocate(&p->p_vmspace->vm_map, (vm_offset_t)addr, size);
|
1993-05-13 17:56:20 +04:00
|
|
|
return(rv == KERN_SUCCESS ? 0 : EINVAL);
|
|
|
|
}
|
|
|
|
|
1994-05-04 08:02:54 +04:00
|
|
|
#ifdef COMPAT_HPUX
|
1996-09-12 05:22:58 +04:00
|
|
|
int
|
1993-05-13 17:56:20 +04:00
|
|
|
iommap(dev, addrp)
|
|
|
|
dev_t dev;
|
|
|
|
caddr_t *addrp;
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (grfdebug & (GDB_MMAP|GDB_IOMAP))
|
1997-04-03 02:37:21 +04:00
|
|
|
printf("iommap(%d): addr %p\n", curproc->p_pid, *addrp);
|
1993-05-13 17:56:20 +04:00
|
|
|
#endif
|
|
|
|
return(EINVAL);
|
|
|
|
}
|
|
|
|
|
1996-09-12 05:22:58 +04:00
|
|
|
int
|
1993-05-13 17:56:20 +04:00
|
|
|
iounmmap(dev, addr)
|
|
|
|
dev_t dev;
|
|
|
|
caddr_t addr;
|
|
|
|
{
|
1997-03-31 11:32:14 +04:00
|
|
|
#ifdef DEBUG
|
1993-05-13 17:56:20 +04:00
|
|
|
int unit = minor(dev);
|
|
|
|
|
|
|
|
if (grfdebug & (GDB_MMAP|GDB_IOMAP))
|
1997-04-03 02:37:21 +04:00
|
|
|
printf("iounmmap(%d): id %d addr %p\n",
|
1993-05-13 17:56:20 +04:00
|
|
|
curproc->p_pid, unit, addr);
|
|
|
|
#endif
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Processes involved in framebuffer mapping via GCSLOT are recorded in
|
|
|
|
* an array of pids. The first element is used to record the last slot used
|
|
|
|
* (for faster lookups). The remaining elements record up to GRFMAXLCK-1
|
|
|
|
* process ids. Returns a slot number between 1 and GRFMAXLCK or 0 if no
|
|
|
|
* slot is available.
|
|
|
|
*/
|
1997-03-31 11:32:14 +04:00
|
|
|
int
|
1993-05-13 17:56:20 +04:00
|
|
|
grffindpid(gp)
|
1996-02-24 03:54:53 +03:00
|
|
|
struct grf_data *gp;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1997-03-31 11:32:14 +04:00
|
|
|
short pid, *sp;
|
|
|
|
int i, limit;
|
1993-05-13 17:56:20 +04:00
|
|
|
int ni;
|
|
|
|
|
|
|
|
if (gp->g_pid == NULL) {
|
|
|
|
gp->g_pid = (short *)
|
|
|
|
malloc(GRFMAXLCK * sizeof(short), M_DEVBUF, M_WAITOK);
|
|
|
|
bzero((caddr_t)gp->g_pid, GRFMAXLCK * sizeof(short));
|
|
|
|
}
|
|
|
|
pid = curproc->p_pid;
|
|
|
|
ni = limit = gp->g_pid[0];
|
|
|
|
for (i = 1, sp = &gp->g_pid[1]; i <= limit; i++, sp++) {
|
|
|
|
if (*sp == pid)
|
|
|
|
goto done;
|
|
|
|
if (*sp == 0)
|
|
|
|
ni = i;
|
|
|
|
}
|
|
|
|
i = ni;
|
|
|
|
if (i < limit) {
|
|
|
|
gp->g_pid[i] = pid;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (++i == GRFMAXLCK)
|
|
|
|
return(0);
|
|
|
|
gp->g_pid[0] = i;
|
|
|
|
gp->g_pid[i] = pid;
|
|
|
|
done:
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (grfdebug & GDB_LOCK)
|
1996-10-13 07:14:05 +04:00
|
|
|
printf("grffindpid(%d): slot %d of %d\n",
|
1993-05-13 17:56:20 +04:00
|
|
|
pid, i, gp->g_pid[0]);
|
|
|
|
#endif
|
|
|
|
return(i);
|
|
|
|
}
|
|
|
|
|
1997-03-31 11:32:14 +04:00
|
|
|
void
|
1993-05-13 17:56:20 +04:00
|
|
|
grfrmpid(gp)
|
1996-02-24 03:54:53 +03:00
|
|
|
struct grf_data *gp;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1997-03-31 11:32:14 +04:00
|
|
|
short pid, *sp;
|
|
|
|
int limit, i;
|
1993-05-13 17:56:20 +04:00
|
|
|
int mi;
|
|
|
|
|
|
|
|
if (gp->g_pid == NULL || (limit = gp->g_pid[0]) == 0)
|
|
|
|
return;
|
|
|
|
pid = curproc->p_pid;
|
|
|
|
limit = gp->g_pid[0];
|
|
|
|
mi = 0;
|
|
|
|
for (i = 1, sp = &gp->g_pid[1]; i <= limit; i++, sp++) {
|
|
|
|
if (*sp == pid)
|
|
|
|
*sp = 0;
|
|
|
|
else if (*sp)
|
|
|
|
mi = i;
|
|
|
|
}
|
|
|
|
i = mi;
|
|
|
|
if (i < limit)
|
|
|
|
gp->g_pid[0] = i;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (grfdebug & GDB_LOCK)
|
1996-10-13 07:14:05 +04:00
|
|
|
printf("grfrmpid(%d): slot %d of %d\n",
|
1993-05-13 17:56:20 +04:00
|
|
|
pid, sp-gp->g_pid, gp->g_pid[0]);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1997-03-31 11:32:14 +04:00
|
|
|
int
|
1993-05-13 17:56:20 +04:00
|
|
|
grflckmmap(dev, addrp)
|
|
|
|
dev_t dev;
|
|
|
|
caddr_t *addrp;
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
struct proc *p = curproc; /* XXX */
|
|
|
|
|
|
|
|
if (grfdebug & (GDB_MMAP|GDB_LOCK))
|
1997-04-03 02:37:21 +04:00
|
|
|
printf("grflckmmap(%d): addr %p\n",
|
1993-05-13 17:56:20 +04:00
|
|
|
p->p_pid, *addrp);
|
|
|
|
#endif
|
|
|
|
return(EINVAL);
|
|
|
|
}
|
|
|
|
|
1997-03-31 11:32:14 +04:00
|
|
|
int
|
1993-05-13 17:56:20 +04:00
|
|
|
grflckunmmap(dev, addr)
|
|
|
|
dev_t dev;
|
|
|
|
caddr_t addr;
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
int unit = minor(dev);
|
|
|
|
|
|
|
|
if (grfdebug & (GDB_MMAP|GDB_LOCK))
|
1997-04-03 02:37:21 +04:00
|
|
|
printf("grflckunmmap(%d): id %d addr %p\n",
|
1993-05-13 17:56:20 +04:00
|
|
|
curproc->p_pid, unit, addr);
|
|
|
|
#endif
|
|
|
|
return(EINVAL);
|
|
|
|
}
|
1994-05-04 08:02:54 +04:00
|
|
|
#endif /* COMPAT_HPUX */
|