/*
* Copyright (c) 1995 Leo Weppelman
* 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. 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$
*
* @(#)grf.c 7.8 (Berkeley) 5/7/91
*/
/*
* Graphics display driver for the Atari
* This is the hardware-independent portion of the driver.
* Hardware access is through the grf_softc->g_mode routine.
*/
static int
grfbusprint(void *aux, const char *name)
{
if (name == NULL)
return UNCONF;
return QUIET;
}
/*ARGSUSED*/
static int
grfopen(dev_t dev, int flags, int devtype, struct lwp *l)
{
struct grf_softc *gp;
if (GRFUNIT(dev) >= NGRF)
return ENXIO;
gp = grfsp[GRFUNIT(dev)];
if (gp == NULL)
return ENXIO;
if ((gp->g_flags & GF_ALIVE) == 0)
return ENXIO;
if ((gp->g_flags & (GF_OPEN|GF_EXCLUDE)) == (GF_OPEN|GF_EXCLUDE))
return EBUSY;
grf_viewsync(gp);
return 0;
}
/*ARGSUSED*/
static int
grfclose(dev_t dev, int flags, int mode, struct lwp *l)
{
struct grf_softc *gp;
gp = grfsp[GRFUNIT(dev)];
(void)grfoff(dev);
gp->g_flags &= GF_ALIVE;
return 0;
}
/*ARGSUSED*/
static int
grfioctl(dev_t dev, u_long cmd, void * data, int flag, struct lwp *l)
{
struct grf_softc *gp;
int error;
extern const struct cdevsw view_cdevsw;
gp = grfsp[GRFUNIT(dev)];
error = 0;
switch (cmd) {
case OGRFIOCGINFO:
/* argl.. no bank-member.. */
memcpy(data, (void *)&gp->g_display, sizeof(struct grfinfo)-4);
break;
case GRFIOCGINFO:
memcpy(data, (void *)&gp->g_display, sizeof(struct grfinfo));
break;
case GRFIOCON:
error = grfon(dev);
break;
case GRFIOCOFF:
error = grfoff(dev);
break;
case GRFIOCSINFO:
error = grfsinfo(dev, (struct grfdyninfo *) data);
break;
case GRFGETVMODE:
return gp->g_mode(gp, GM_GRFGETVMODE, data, 0, 0);
case GRFSETVMODE:
error = gp->g_mode(gp, GM_GRFSETVMODE, data, 0, 0);
if (error == 0 && gp->g_itedev)
ite_reinit(gp->g_itedev);
break;
case GRFGETNUMVM:
return gp->g_mode(gp, GM_GRFGETNUMVM, data, 0, 0);
/*
* these are all hardware dependent, and have to be resolved
* in the respective driver.
*/
case GRFIOCPUTCMAP:
case GRFIOCGETCMAP:
case GRFIOCSSPRITEPOS:
case GRFIOCGSPRITEPOS:
case GRFIOCSSPRITEINF:
case GRFIOCGSPRITEINF:
case GRFIOCGSPRITEMAX:
default:
/*
* check to see whether it's a command recognized by the
* view code.
*/
return (*view_cdevsw.d_ioctl)(gp->g_viewdev,
cmd, data, flag, l);
error = EINVAL;
break;
}
return error;
}
/*
* map the contents of a graphics display card into process'
* memory space.
*/
static paddr_t
grfmmap(dev_t dev, off_t off, int prot)
{
struct grf_softc *gp;
struct grfinfo *gi;
u_int vgabase, linbase;
/*
* Change the mode of the display.
* Right now all we can do is grfon/grfoff.
* Return a UNIX error number or 0 for success.
*/
/*ARGSUSED*/
int
grf_mode(struct grf_softc *gp, int cmd, void *arg, int a2, int a3)
{
extern const struct cdevsw view_cdevsw;
switch (cmd) {
case GM_GRFON:
/*
* Get in sync with view, ite might have changed it.
*/
grf_viewsync(gp);
(*view_cdevsw.d_ioctl)(gp->g_viewdev, VIOCDISPLAY,
NULL, 0, NOLWP);
return 0;
case GM_GRFOFF:
(*view_cdevsw.d_ioctl)(gp->g_viewdev, VIOCREMOVE,
NULL, 0, NOLWP);
return 0;
case GM_GRFCONFIG:
default:
break;
}
return EPASSTHROUGH;
}
#endif /* NGRF > 0 */