1995-04-21 07:44:13 +04:00
|
|
|
/* $NetBSD: grf.c,v 1.20 1995/04/21 03:44:13 briggs Exp $ */
|
1994-10-26 11:45:48 +03:00
|
|
|
|
1993-09-29 09:08:37 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1988 University of Utah.
|
|
|
|
* Copyright (c) 1990 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* from: Utah $Hdr: grf.c 1.31 91/01/21$
|
|
|
|
*
|
1994-10-26 11:45:48 +03:00
|
|
|
* @(#)grf.c 7.8 (Berkeley) 5/7/91
|
1993-09-29 09:08:37 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1994-07-31 12:32:47 +04:00
|
|
|
* Graphics display driver for the Macintosh.
|
1993-09-29 09:08:37 +03:00
|
|
|
* This is the hardware-independent portion of the driver.
|
|
|
|
* Hardware access is through the grfdev routines below.
|
|
|
|
*/
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
#include <sys/param.h>
|
1993-09-29 09:08:37 +03:00
|
|
|
|
1994-01-30 04:15:31 +03:00
|
|
|
#include <sys/device.h>
|
1995-04-21 06:47:35 +04:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/vnode.h>
|
1993-09-29 09:08:37 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
#include <machine/grfioctl.h>
|
1994-01-30 04:15:31 +03:00
|
|
|
#include <machine/cpu.h>
|
1993-09-29 09:08:37 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
#include <miscfs/specfs/specdev.h>
|
|
|
|
|
1994-01-30 04:15:31 +03:00
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_kern.h>
|
|
|
|
#include <vm/vm_page.h>
|
|
|
|
#include <vm/vm_pager.h>
|
1993-09-29 09:08:37 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
#include "nubus.h"
|
|
|
|
#include "grfvar.h"
|
1993-09-29 09:08:37 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
#include "grf.h"
|
1993-09-29 09:08:37 +03:00
|
|
|
#include "ite.h"
|
1995-04-21 06:47:35 +04:00
|
|
|
|
1995-03-26 19:52:21 +04:00
|
|
|
#if NITE == 0
|
1993-09-29 09:08:37 +03:00
|
|
|
#define iteon(u,f)
|
|
|
|
#define iteoff(u,f)
|
1995-03-26 19:52:21 +04:00
|
|
|
#endif
|
1993-09-29 09:08:37 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
static int matchvideocard __P((/*struct device *parent, struct device *dev,
|
|
|
|
void *aux*/));
|
|
|
|
static void grf_attach __P((struct device *parent, struct device *dev,
|
|
|
|
void *aux));
|
1993-09-29 09:08:37 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
static void fake_internal __P((void));
|
|
|
|
static int grfprobe __P((struct nubus_hw *nu, int unit));
|
|
|
|
static int macvideo_init __P((struct grf_softc *gp, struct nubus_hw *nu));
|
|
|
|
static int macvideo_mode __P((struct grf_softc *gp, int cmd, void *arg));
|
|
|
|
|
|
|
|
struct cfdriver grfcd = {
|
|
|
|
NULL, "grf", matchvideocard, grf_attach, DV_DULL,
|
1995-04-21 07:44:13 +04:00
|
|
|
sizeof(struct grf_softc)
|
1993-09-29 09:08:37 +03:00
|
|
|
};
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
struct grfdev grfdev[] = {
|
|
|
|
GID_MAC, GRFMAC, macvideo_init, macvideo_mode, "MacVideo",
|
|
|
|
};
|
1993-09-29 09:08:37 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
static int ngrfdev=(sizeof(grfdev) / sizeof(grfdev[0]));
|
1995-04-21 07:44:13 +04:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
static int gNumGrfDev=0;
|
1993-09-29 09:08:37 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
1995-04-21 06:47:35 +04:00
|
|
|
static int grfdebug = 0xff;
|
1993-09-29 09:08:37 +03:00
|
|
|
#define GDB_DEVNO 0x01
|
|
|
|
#define GDB_MMAP 0x02
|
|
|
|
#define GDB_IOMAP 0x04
|
|
|
|
#define GDB_LOCK 0x08
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Normal init routine called by configure() code
|
|
|
|
*/
|
1993-11-29 03:32:22 +03:00
|
|
|
grfprobe(nu, unit)
|
|
|
|
struct nubus_hw *nu;
|
1995-04-21 06:47:35 +04:00
|
|
|
int unit;
|
1993-09-29 09:08:37 +03:00
|
|
|
{
|
1995-04-21 07:44:13 +04:00
|
|
|
struct grf_softc *gp;
|
|
|
|
|
|
|
|
gp = grfcd.cd_devs[unit];
|
1993-09-29 09:08:37 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
if ((gp->g_flags & GF_ALIVE) == 0 && !grfinit(nu, unit)) {
|
1993-11-29 03:32:22 +03:00
|
|
|
printf("\n");
|
1995-04-21 06:47:35 +04:00
|
|
|
return (0);
|
1993-11-29 03:32:22 +03:00
|
|
|
}
|
|
|
|
printf(": %d x %d ",
|
1995-04-21 06:47:35 +04:00
|
|
|
gp->g_display.gd_dwidth, gp->g_display.gd_dheight);
|
|
|
|
|
1993-09-29 09:08:37 +03:00
|
|
|
if (gp->g_display.gd_colors == 2)
|
|
|
|
printf("monochrome");
|
|
|
|
else
|
|
|
|
printf("%d color", gp->g_display.gd_colors);
|
1995-04-21 06:47:35 +04:00
|
|
|
|
|
|
|
printf(" %s (%s) display\n",
|
|
|
|
grfdev[gp->g_type].gd_desc, nu->slot.name);
|
|
|
|
|
|
|
|
gp->g_data = (void *) &nu->slot;
|
|
|
|
|
|
|
|
return (1);
|
1993-09-29 09:08:37 +03:00
|
|
|
}
|
|
|
|
|
1993-11-29 03:32:22 +03:00
|
|
|
static int
|
|
|
|
matchvideocard(parent, cf, aux)
|
1995-04-21 06:47:35 +04:00
|
|
|
struct device *parent;
|
|
|
|
struct device *cf;
|
|
|
|
void *aux;
|
1993-11-29 03:32:22 +03:00
|
|
|
{
|
1995-04-21 06:47:35 +04:00
|
|
|
struct nubus_hw *nu = (struct nubus_hw *) aux;
|
1993-11-29 03:32:22 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
return (nu->slot.type == NUBUS_VIDEO);
|
1993-11-29 03:32:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
grf_attach(parent, dev, aux)
|
1995-04-21 06:47:35 +04:00
|
|
|
struct device *parent, *dev;
|
|
|
|
void *aux;
|
1993-11-29 03:32:22 +03:00
|
|
|
{
|
1995-04-21 06:47:35 +04:00
|
|
|
struct nubus_hw *nu = (struct nubus_hw *) aux;
|
1993-11-29 03:32:22 +03:00
|
|
|
|
|
|
|
grfprobe(nu, dev->dv_unit);
|
|
|
|
}
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
int
|
1993-11-29 03:32:22 +03:00
|
|
|
grfinit(nu, unit)
|
|
|
|
struct nubus_hw *nu;
|
1995-04-21 06:47:35 +04:00
|
|
|
int unit;
|
1993-09-29 09:08:37 +03:00
|
|
|
{
|
1995-04-21 07:44:13 +04:00
|
|
|
struct grf_softc *gp;
|
1993-09-29 09:08:37 +03:00
|
|
|
struct grfreg *gr;
|
|
|
|
register struct grfdev *gd;
|
|
|
|
|
1995-04-21 07:44:13 +04:00
|
|
|
gp = grfcd.cd_devs[unit];
|
|
|
|
|
1993-09-29 09:08:37 +03:00
|
|
|
for (gd = grfdev; gd < &grfdev[ngrfdev]; gd++)
|
|
|
|
/* if (gd->gd_hardid == gr->gr_id2) */
|
1995-04-21 06:47:35 +04:00
|
|
|
break;
|
|
|
|
if (gd < &grfdev[ngrfdev] && (*gd->gd_init) (gp, nu)) {
|
1993-09-29 09:08:37 +03:00
|
|
|
gp->g_display.gd_id = gd->gd_softid;
|
|
|
|
gp->g_type = gd - grfdev;
|
|
|
|
gp->g_flags = GF_ALIVE;
|
1995-04-21 06:47:35 +04:00
|
|
|
return (1);
|
1993-09-29 09:08:37 +03:00
|
|
|
}
|
1995-04-21 06:47:35 +04:00
|
|
|
return (0);
|
1993-09-29 09:08:37 +03:00
|
|
|
}
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
static void
|
|
|
|
fake_internal()
|
1994-07-31 12:32:47 +04:00
|
|
|
{
|
1995-04-21 06:47:35 +04:00
|
|
|
extern unsigned long int_video_start;
|
|
|
|
struct grf_softc *gp;
|
|
|
|
struct grfinfo *gi;
|
|
|
|
struct grfterm *gt;
|
|
|
|
struct grfmouse *gm;
|
|
|
|
int i, j;
|
1994-07-31 12:32:47 +04:00
|
|
|
|
|
|
|
if (int_video_start == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (i = 0; i < NGRF; i++) {
|
1995-04-21 07:44:13 +04:00
|
|
|
gp = grfcd.cd_devs[i];
|
1994-07-31 12:32:47 +04:00
|
|
|
if ((gp->g_flags & GF_ALIVE) == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == NGRF) {
|
1995-04-21 06:47:35 +04:00
|
|
|
printf("grf: not enough grf's to map internal video.\n");
|
1994-07-31 12:32:47 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
gp->g_type = 0;
|
|
|
|
gp->g_flags = GF_ALIVE;
|
|
|
|
|
|
|
|
gi = &(gp->g_display);
|
|
|
|
gi->gd_id = GRFMAC;
|
|
|
|
gi->gd_regsize = 0;
|
|
|
|
gi->gd_colors = 1;
|
|
|
|
gi->gd_planes = 1;
|
1995-04-21 06:47:35 +04:00
|
|
|
gi->gd_dwidth = gi->gd_fbwidth = 640; /* XXX */
|
|
|
|
gi->gd_dheight = gi->gd_fbheight = 480; /* XXX */
|
1994-07-31 12:32:47 +04:00
|
|
|
gi->gd_fbsize = gi->gd_dwidth * gi->gd_dheight;
|
1995-04-21 06:47:35 +04:00
|
|
|
gi->gd_fbrowbytes = 80; /* XXX Hack */
|
|
|
|
gi->gd_fbaddr = (caddr_t) 0;
|
1994-07-31 12:32:47 +04:00
|
|
|
gp->g_fbkva = gi->gd_fbaddr;
|
|
|
|
}
|
|
|
|
|
1993-09-29 09:08:37 +03:00
|
|
|
/*ARGSUSED*/
|
1995-04-21 06:47:35 +04:00
|
|
|
int
|
|
|
|
grfopen(dev, flag, mode, p)
|
1993-09-29 09:08:37 +03:00
|
|
|
dev_t dev;
|
1995-04-21 06:47:35 +04:00
|
|
|
int flag;
|
|
|
|
int mode;
|
|
|
|
struct proc *p;
|
1993-09-29 09:08:37 +03:00
|
|
|
{
|
1995-04-21 06:47:35 +04:00
|
|
|
static int faked; /* Whether we've faked internal video yet */
|
|
|
|
register struct grf_softc *gp;
|
|
|
|
int unit;
|
|
|
|
int error;
|
1994-07-31 12:32:47 +04:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
unit = GRFUNIT(dev);
|
1995-04-21 07:44:13 +04:00
|
|
|
gp = grfcd.cd_devs[unit];
|
1994-07-31 12:32:47 +04:00
|
|
|
if (!faked) {
|
1995-04-21 06:47:35 +04:00
|
|
|
fake_internal();
|
1994-07-31 12:32:47 +04:00
|
|
|
faked = 1;
|
|
|
|
}
|
1993-09-29 09:08:37 +03:00
|
|
|
|
|
|
|
if (unit >= NGRF || (gp->g_flags & GF_ALIVE) == 0)
|
1995-04-21 06:47:35 +04:00
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
if ((gp->g_flags & (GF_OPEN | GF_EXCLUDE)) == (GF_OPEN | GF_EXCLUDE))
|
|
|
|
return (EBUSY);
|
|
|
|
|
1993-09-29 09:08:37 +03:00
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
}
|
1995-04-21 06:47:35 +04:00
|
|
|
return (error);
|
1993-09-29 09:08:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
1995-04-21 06:47:35 +04:00
|
|
|
grfclose(dev, flag, mode, p)
|
1993-09-29 09:08:37 +03:00
|
|
|
dev_t dev;
|
1995-04-21 06:47:35 +04:00
|
|
|
int flag;
|
|
|
|
int mode;
|
|
|
|
struct proc *p;
|
1993-09-29 09:08:37 +03:00
|
|
|
{
|
1995-04-21 06:47:35 +04:00
|
|
|
register struct grf_softc *gp;
|
|
|
|
|
1995-04-21 07:44:13 +04:00
|
|
|
gp = grfcd.cd_devs[GRFUNIT(dev)];
|
1993-09-29 09:08:37 +03:00
|
|
|
|
|
|
|
(void) grfoff(dev);
|
|
|
|
(void) grfunlock(gp);
|
|
|
|
gp->g_flags &= GF_ALIVE;
|
1995-04-21 06:47:35 +04:00
|
|
|
|
|
|
|
return (0);
|
1993-09-29 09:08:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
grfioctl(dev, cmd, data, flag, p)
|
|
|
|
dev_t dev;
|
1995-04-21 06:47:35 +04:00
|
|
|
int cmd;
|
1993-09-29 09:08:37 +03:00
|
|
|
caddr_t data;
|
1995-04-21 06:47:35 +04:00
|
|
|
int flag;
|
1993-09-29 09:08:37 +03:00
|
|
|
struct proc *p;
|
|
|
|
{
|
1995-04-21 06:47:35 +04:00
|
|
|
register struct grf_softc *gp;
|
|
|
|
int error;
|
1993-09-29 09:08:37 +03:00
|
|
|
|
1995-04-21 07:44:13 +04:00
|
|
|
gp = grfcd.cd_devs[GRFUNIT(dev)];
|
1993-09-29 09:08:37 +03:00
|
|
|
error = 0;
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
switch (cmd) {
|
1993-09-29 09:08:37 +03:00
|
|
|
case OGRFIOCGINFO:
|
1995-04-21 06:47:35 +04:00
|
|
|
bcopy((caddr_t) & gp->g_display, data, sizeof(struct ogrfinfo));
|
1993-09-29 09:08:37 +03:00
|
|
|
break;
|
|
|
|
case GRFIOCGINFO:
|
1995-04-21 06:47:35 +04:00
|
|
|
bcopy((caddr_t) & gp->g_display, data, sizeof(struct grfinfo));
|
1993-09-29 09:08:37 +03:00
|
|
|
break;
|
|
|
|
case GRFIOCON:
|
|
|
|
error = grfon(dev);
|
|
|
|
break;
|
|
|
|
case GRFIOCOFF:
|
|
|
|
error = grfoff(dev);
|
|
|
|
break;
|
|
|
|
case GRFIOCMAP:
|
1995-04-21 06:47:35 +04:00
|
|
|
error = grfmap(dev, (caddr_t *) data, p);
|
1993-09-29 09:08:37 +03:00
|
|
|
break;
|
|
|
|
case GRFIOCUNMAP:
|
1995-04-21 06:47:35 +04:00
|
|
|
error = grfunmap(dev, *(caddr_t *) data, p);
|
1993-09-29 09:08:37 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
1995-04-21 06:47:35 +04:00
|
|
|
return (error);
|
1993-09-29 09:08:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
1995-04-21 06:47:35 +04:00
|
|
|
grfselect(dev, rw, p)
|
1993-09-29 09:08:37 +03:00
|
|
|
dev_t dev;
|
1995-04-21 06:47:35 +04:00
|
|
|
int rw;
|
|
|
|
struct proc *p;
|
1993-09-29 09:08:37 +03:00
|
|
|
{
|
|
|
|
if (rw == FREAD)
|
1995-04-21 06:47:35 +04:00
|
|
|
return (0);
|
|
|
|
return (1);
|
1993-09-29 09:08:37 +03:00
|
|
|
}
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
int
|
1993-09-29 09:08:37 +03:00
|
|
|
grflock(gp, block)
|
|
|
|
register struct grf_softc *gp;
|
|
|
|
int block;
|
|
|
|
{
|
|
|
|
extern char devioc[];
|
1995-04-21 06:47:35 +04:00
|
|
|
struct proc *p = curproc; /* XXX */
|
|
|
|
int error;
|
1993-09-29 09:08:37 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (grfdebug & GDB_LOCK)
|
|
|
|
printf("grflock(%d): dev %x flags %x lockpid %x\n",
|
1995-04-21 07:44:13 +04:00
|
|
|
p->p_pid, gp->sc_dev.dv_unit, gp->g_flags,
|
1995-04-21 06:47:35 +04:00
|
|
|
gp->g_lockp ? gp->g_lockp->p_pid : -1);
|
1993-09-29 09:08:37 +03:00
|
|
|
#endif
|
|
|
|
if (gp->g_lockp) {
|
|
|
|
if (gp->g_lockp == p)
|
1995-04-21 06:47:35 +04:00
|
|
|
return (EBUSY);
|
1993-09-29 09:08:37 +03:00
|
|
|
if (!block)
|
1995-04-21 06:47:35 +04:00
|
|
|
return (EAGAIN);
|
1993-09-29 09:08:37 +03:00
|
|
|
do {
|
|
|
|
gp->g_flags |= GF_WANTED;
|
1995-04-21 06:47:35 +04:00
|
|
|
if (error = tsleep((caddr_t) & gp->g_flags,
|
|
|
|
(PZERO + 1) | PCATCH, devioc, 0))
|
1993-09-29 09:08:37 +03:00
|
|
|
return (error);
|
|
|
|
} while (gp->g_lockp);
|
|
|
|
}
|
|
|
|
gp->g_lockp = p;
|
1995-04-21 06:47:35 +04:00
|
|
|
return (0);
|
1993-09-29 09:08:37 +03:00
|
|
|
}
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
int
|
1993-09-29 09:08:37 +03:00
|
|
|
grfunlock(gp)
|
|
|
|
register struct grf_softc *gp;
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (grfdebug & GDB_LOCK)
|
|
|
|
printf("grfunlock(%d): dev %x flags %x lockpid %d\n",
|
1995-04-21 07:44:13 +04:00
|
|
|
curproc->p_pid, gp->sc_dev.dv_unit, gp->g_flags,
|
1995-04-21 06:47:35 +04:00
|
|
|
gp->g_lockp ? gp->g_lockp->p_pid : -1);
|
1993-09-29 09:08:37 +03:00
|
|
|
#endif
|
|
|
|
if (gp->g_lockp != curproc)
|
1995-04-21 06:47:35 +04:00
|
|
|
return (EBUSY);
|
|
|
|
|
1993-09-29 09:08:37 +03:00
|
|
|
if (gp->g_flags & GF_WANTED) {
|
1995-04-21 06:47:35 +04:00
|
|
|
wakeup((caddr_t) & gp->g_flags);
|
1993-09-29 09:08:37 +03:00
|
|
|
gp->g_flags &= ~GF_WANTED;
|
|
|
|
}
|
|
|
|
gp->g_lockp = NULL;
|
1995-04-21 06:47:35 +04:00
|
|
|
|
|
|
|
return (0);
|
1993-09-29 09:08:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
1995-04-10 11:56:46 +04:00
|
|
|
grfmmap(dev, off, prot)
|
1993-09-29 09:08:37 +03:00
|
|
|
dev_t dev;
|
1995-04-21 06:47:35 +04:00
|
|
|
int off;
|
|
|
|
int prot;
|
1993-09-29 09:08:37 +03:00
|
|
|
{
|
1995-04-21 07:44:13 +04:00
|
|
|
return (grfaddr(grfcd.cd_devs[GRFUNIT(dev)], off));
|
1993-09-29 09:08:37 +03:00
|
|
|
}
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
int
|
1993-09-29 09:08:37 +03:00
|
|
|
grfon(dev)
|
1995-04-21 06:47:35 +04:00
|
|
|
dev_t dev;
|
1993-09-29 09:08:37 +03:00
|
|
|
{
|
1995-04-21 06:47:35 +04:00
|
|
|
int unit = GRFUNIT(dev);
|
1995-04-21 07:44:13 +04:00
|
|
|
struct grf_softc *gp;
|
1993-09-29 09:08:37 +03:00
|
|
|
|
1995-04-21 07:44:13 +04:00
|
|
|
gp = grfcd.cd_devs[unit];
|
1993-09-29 09:08:37 +03: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.
|
|
|
|
*/
|
|
|
|
iteoff(unit, 3);
|
1995-04-21 06:47:35 +04:00
|
|
|
return ((*grfdev[gp->g_type].gd_mode)
|
|
|
|
(gp, (dev & GRFOVDEV) ? GM_GRFOVON : GM_GRFON));
|
1993-09-29 09:08:37 +03:00
|
|
|
}
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
int
|
1993-09-29 09:08:37 +03:00
|
|
|
grfoff(dev)
|
1995-04-21 06:47:35 +04:00
|
|
|
dev_t dev;
|
1993-09-29 09:08:37 +03:00
|
|
|
{
|
1995-04-21 06:47:35 +04:00
|
|
|
int unit = GRFUNIT(dev);
|
1995-04-21 07:44:13 +04:00
|
|
|
struct grf_softc *gp;
|
1995-04-21 06:47:35 +04:00
|
|
|
int error;
|
1993-09-29 09:08:37 +03:00
|
|
|
|
1995-04-21 07:44:13 +04:00
|
|
|
gp = grfcd.cd_devs[unit];
|
1995-04-21 06:47:35 +04:00
|
|
|
(void) grfunmap(dev, (caddr_t) 0, curproc);
|
1993-09-29 09:08:37 +03:00
|
|
|
error = (*grfdev[gp->g_type].gd_mode)
|
1995-04-21 06:47:35 +04:00
|
|
|
(gp, (dev & GRFOVDEV) ? GM_GRFOVOFF : GM_GRFOFF);
|
1993-09-29 09:08:37 +03:00
|
|
|
/* XXX: see comment for iteoff above */
|
|
|
|
iteon(unit, 2);
|
1995-04-21 06:47:35 +04:00
|
|
|
return (error);
|
1993-09-29 09:08:37 +03:00
|
|
|
}
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
int
|
1993-09-29 09:08:37 +03:00
|
|
|
grfaddr(gp, off)
|
|
|
|
struct grf_softc *gp;
|
|
|
|
register int off;
|
|
|
|
{
|
|
|
|
register struct grfinfo *gi = &gp->g_display;
|
|
|
|
|
|
|
|
/* control registers */
|
|
|
|
if (off >= 0 && off < gi->gd_regsize)
|
1995-04-21 06:47:35 +04:00
|
|
|
return (((u_int) gi->gd_regaddr + off) >> PGSHIFT);
|
1993-09-29 09:08:37 +03:00
|
|
|
|
|
|
|
/* frame buffer */
|
1995-04-21 06:47:35 +04:00
|
|
|
if (off >= gi->gd_regsize && off < gi->gd_regsize + gi->gd_fbsize) {
|
1993-09-29 09:08:37 +03:00
|
|
|
off -= gi->gd_regsize;
|
1995-04-21 06:47:35 +04:00
|
|
|
return (((u_int) gi->gd_fbaddr + off) >> PGSHIFT);
|
1993-09-29 09:08:37 +03:00
|
|
|
}
|
|
|
|
/* bogus */
|
1995-04-21 06:47:35 +04:00
|
|
|
return (-1);
|
1993-09-29 09:08:37 +03:00
|
|
|
}
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
int
|
1995-04-10 11:56:46 +04:00
|
|
|
grfmap(dev, addrp, p)
|
1993-09-29 09:08:37 +03:00
|
|
|
dev_t dev;
|
|
|
|
caddr_t *addrp;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1995-04-21 07:44:13 +04:00
|
|
|
struct grf_softc *gp;
|
1995-04-21 06:47:35 +04:00
|
|
|
int len, error;
|
1993-09-29 09:08:37 +03:00
|
|
|
struct vnode vn;
|
|
|
|
struct specinfo si;
|
1995-04-21 06:47:35 +04:00
|
|
|
int flags;
|
1993-09-29 09:08:37 +03:00
|
|
|
|
1995-04-21 07:44:13 +04:00
|
|
|
gp = grfcd.cd_devs[GRFUNIT(dev)];
|
1993-09-29 09:08:37 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (grfdebug & GDB_MMAP)
|
1995-04-10 11:56:46 +04:00
|
|
|
printf("grfmap(%d): addr %x\n", p->p_pid, *addrp);
|
1993-09-29 09:08:37 +03:00
|
|
|
#endif
|
|
|
|
len = gp->g_display.gd_regsize + gp->g_display.gd_fbsize;
|
1994-04-05 05:30:28 +04:00
|
|
|
flags = MAP_SHARED;
|
1993-09-29 09:08:37 +03:00
|
|
|
if (*addrp)
|
|
|
|
flags |= MAP_FIXED;
|
1995-04-21 06:47:35 +04:00
|
|
|
else {
|
1993-09-29 09:08:37 +03:00
|
|
|
return 12;
|
1995-04-21 06:47:35 +04:00
|
|
|
*addrp = (caddr_t) 0x1000000; /* XXX */
|
1993-09-29 09:08:37 +03:00
|
|
|
}
|
1995-04-21 06:47:35 +04:00
|
|
|
vn.v_type = VCHR; /* XXX */
|
|
|
|
vn.v_specinfo = &si; /* XXX */
|
|
|
|
vn.v_rdev = dev; /* XXX */
|
1993-09-29 09:08:37 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
error = vm_mmap(&p->p_vmspace->vm_map, (vm_offset_t *) addrp,
|
|
|
|
(vm_size_t) len, VM_PROT_ALL, VM_PROT_ALL, flags, (caddr_t) & vn,
|
|
|
|
0);
|
1994-07-31 12:32:47 +04:00
|
|
|
|
|
|
|
/* Offset into page: */
|
1995-04-21 06:47:35 +04:00
|
|
|
*addrp += (unsigned long) gp->g_display.gd_fbaddr & 0xfff;
|
1994-04-05 05:30:28 +04:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
return (error);
|
1993-09-29 09:08:37 +03:00
|
|
|
}
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
int
|
1995-04-10 11:56:46 +04:00
|
|
|
grfunmap(dev, addr, p)
|
1995-04-21 06:47:35 +04:00
|
|
|
dev_t dev;
|
1993-09-29 09:08:37 +03:00
|
|
|
caddr_t addr;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1995-04-21 07:44:13 +04:00
|
|
|
struct grf_softc *gp;
|
1993-09-29 09:08:37 +03:00
|
|
|
vm_size_t size;
|
1995-04-21 06:47:35 +04:00
|
|
|
int rv;
|
1993-09-29 09:08:37 +03:00
|
|
|
|
1995-04-21 07:44:13 +04:00
|
|
|
gp = grfcd.cd_devs[GRFUNIT(dev)];
|
1993-09-29 09:08:37 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (grfdebug & GDB_MMAP)
|
1995-04-10 11:56:46 +04:00
|
|
|
printf("grfunmap(%d): dev %x addr %x\n", p->p_pid, dev, addr);
|
1993-09-29 09:08:37 +03:00
|
|
|
#endif
|
|
|
|
if (addr == 0)
|
1995-04-21 06:47:35 +04:00
|
|
|
return (EINVAL);/* XXX: how do we deal with this? */
|
1993-09-29 09:08:37 +03:00
|
|
|
size = round_page(gp->g_display.gd_regsize + gp->g_display.gd_fbsize);
|
1995-04-21 06:47:35 +04:00
|
|
|
rv = vm_deallocate(&p->p_vmspace->vm_map, (vm_offset_t) addr, size);
|
|
|
|
return (rv == KERN_SUCCESS ? 0 : EINVAL);
|
1993-09-29 09:08:37 +03:00
|
|
|
}
|
|
|
|
|
1995-03-23 16:45:07 +03:00
|
|
|
static char zero = 0;
|
1993-09-29 09:08:37 +03:00
|
|
|
|
1995-04-13 08:04:58 +04:00
|
|
|
static void
|
1995-04-21 06:47:35 +04:00
|
|
|
macvideo_intr(unit, slot)
|
|
|
|
int unit, slot;
|
1995-03-23 16:45:07 +03:00
|
|
|
{
|
1995-04-21 06:47:35 +04:00
|
|
|
struct grf_softc *gp;
|
1995-03-23 16:45:07 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
((char *) (0xf0000000 | ((long) slot << 24)))[0xa0000] = zero;
|
1995-03-23 16:45:07 +03:00
|
|
|
}
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
static int
|
|
|
|
macvideo_init(gp, nu)
|
|
|
|
struct grf_softc *gp;
|
|
|
|
struct nubus_hw *nu;
|
1993-09-29 09:08:37 +03:00
|
|
|
{
|
|
|
|
struct grfinfo *gi;
|
|
|
|
struct imagedata *image;
|
|
|
|
struct imagedata imageSpace;
|
1995-04-21 06:47:35 +04:00
|
|
|
int i = 0;
|
1993-09-29 09:08:37 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
/*
|
|
|
|
* find out which nubus slot this guy is in, then get the video params
|
|
|
|
*/
|
|
|
|
image = (struct imagedata *) NUBUS_GetImageData(&(nu->slot), &imageSpace);
|
1993-09-29 09:08:37 +03:00
|
|
|
|
|
|
|
gi = &(gp->g_display);
|
1995-04-21 06:47:35 +04:00
|
|
|
gi->gd_regsize = 0;
|
|
|
|
gi->gd_colors = 1;
|
|
|
|
gi->gd_planes = 1;
|
|
|
|
gi->gd_dwidth = gi->gd_fbwidth = image->right;
|
|
|
|
gi->gd_dheight = gi->gd_fbheight = image->bottom;
|
|
|
|
gi->gd_fbsize = image->rowbytes * image->bottom;
|
|
|
|
gi->gd_fbrowbytes = image->rowbytes;
|
|
|
|
gi->gd_fbaddr = (caddr_t) ((u_long) image->offset + (u_long) nu->addr);
|
|
|
|
gp->g_fbkva = gi->gd_fbaddr;
|
|
|
|
|
|
|
|
add_nubus_intr((unsigned int) nu->addr & 0xFF000000, macvideo_intr,
|
1995-04-21 07:44:13 +04:00
|
|
|
(gp->sc_dev.dv_unit));
|
1995-03-23 16:45:07 +03:00
|
|
|
|
1994-01-11 02:52:01 +03:00
|
|
|
gNumGrfDev++;
|
1995-04-21 06:47:35 +04:00
|
|
|
|
1993-09-29 09:08:37 +03:00
|
|
|
return 1;
|
|
|
|
}
|
1995-03-23 16:45:07 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
static int
|
|
|
|
macvideo_mode(gp, cmd, arg)
|
|
|
|
struct grf_softc *gp;
|
|
|
|
int cmd;
|
|
|
|
void *arg;
|
1993-09-29 09:08:37 +03:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|