/*
* 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 Amiga
* This is the hardware-independent portion of the driver.
* Hardware access is through the grf_softc->g_mode routine.
*/
/*
* match if the unit of grf matches its perspective
* low level board driver.
*/
int
grfmatch(device_t parent, cfdata_t cf, void *aux)
{
struct grf_softc *psc;
/*
* Attach.. plug pointer in and print some info.
* Then try and attach a wsdisplay or ite to us.
* Note: self is NULL during console init.
*/
void
grfattach(device_t parent, device_t self, void *aux)
{
#if NWSDISPLAY > 0
struct wsemuldisplaydev_attach_args wa;
long defattr;
#endif
struct grf_softc *gp;
int maj;
gp = device_private(parent);
gp->g_device = self;
grfsp[gp->g_unit] = gp;
/*
* find our major device number, make device
*/
maj = cdevsw_lookup_major(&grf_cdevsw);
gp->g_grfdev = makedev(maj, gp->g_unit);
if ((gp->g_flags & (GF_OPEN|GF_EXCLUDE)) == (GF_OPEN|GF_EXCLUDE))
return(EBUSY);
return(0);
}
/*ARGSUSED*/
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*/
int
grfioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
{
struct grf_softc *gp;
int error;
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 && !(gp->g_flags & GF_GRFON))
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:
case GRFIOCBITBLT:
case GRFIOCSETMON:
case GRFTOGGLE: /* Toggles between Cirrus boards and native ECS on
Amiga. 15/11/94 ill */
/*
* We need the minor dev number to get the overlay/image
* information for grf_ul.
*/
return(gp->g_mode(gp, GM_GRFIOCTL, data, cmd, dev));
case GRFIOCBLANK: /* blank ioctl, IOCON/OFF will turn ite on */
case FBIOSVIDEO:
error = gp->g_mode(gp, GM_GRFIOCTL, data, GRFIOCBLANK, dev);
if (!error)
gp->g_blank = *(int *)data;
return (error);
case FBIOGVIDEO:
*(int *)data = gp->g_blank;
return (0);
default:
#if NVIEW > 0
/*
* check to see whether it's a command recognized by the
* view code if the unit is 0
* XXX
*/
if (GRFUNIT(dev) == 0) {
extern const struct cdevsw view_cdevsw;
/*
* Find the first working grf device for being console.
* Ignore unit 0 (grfcc), which should use amidisplaycc instead.
*/
for (unit = 1; unit < NGRF; unit++) {
gp = grfsp[unit];
if (gp != NULL && (gp->g_flags & GF_ALIVE)) {
cd->cn_pri = CN_INTERNAL;
cd->cn_dev = NODEV; /* initialized later by wscons */
return;
}
}
/* no grf console alive */
cd->cn_pri = CN_DEAD;
}
void
grfcninit(struct consdev *cd)
{
struct grf_softc *gp;
struct rasops_info *ri;
long defattr;
int unit;
/* find console grf and set up wsdisplay for it */
for (unit = 1; unit < NGRF; unit++) {
gp = grfsp[unit];
if (gp != NULL && (gp->g_flags & GF_ALIVE)) {
gp->g_flags |= GF_CONSOLE; /* we are console! */
/* multiplication table for row-offsets */
for (i = 0; i < ri->ri_rows; i++)
gp->g_rowoffset[i] = i * ri->ri_cols;
return ri;
}
/*
* Called as fallback for ioctls which are not handled by the specific
* grf driver.
*/
int
grf_wsioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
{
struct wsdisplayio_fbinfo *iofbi;
struct wsdisplay_fbinfo *fbinfo;
struct vcons_data *vd;
struct grf_softc *gp;
struct vcons_screen *scr;
struct grfinfo *gi;
vd = v;
gp = vd->cookie;
scr = vd->active;
switch (cmd) {
case WSDISPLAYIO_GET_FBINFO:
if (scr != NULL) {
iofbi = data;
return wsdisplayio_get_fbinfo(&scr->scr_ri, iofbi);
}
return ENODEV;
case WSDISPLAYIO_GINFO:
if (scr != NULL) {
fbinfo = (struct wsdisplay_fbinfo *)data;
gi = &gp->g_display;
/*
* We should return truth about the current mode here,
* because X11 wsfb driver depends on this!
*/
fbinfo->height = gi->gd_fbheight;
fbinfo->width = gi->gd_fbwidth;
fbinfo->depth = gi->gd_planes;
fbinfo->cmsize = gi->gd_colors;
return 0;
}
return ENODEV;
case WSDISPLAYIO_GTYPE:
*(u_int *)data = WSDISPLAY_TYPE_GRF;
return 0;
case WSDISPLAYIO_SMODE:
if ((*(int *)data) != gp->g_wsmode) {
gp->g_wsmode = *(int *)data;
if (gp->g_wsmode == WSDISPLAYIO_MODE_EMUL &&
scr != NULL)
vcons_redraw_screen(scr);
}
return 0;
}
/* Normal fb mapping */
if (off < gi->gd_fbsize)
return MD_BTOP(((paddr_t)gi->gd_fbaddr) + off);
/*
* restrict all other mappings to processes with superuser privileges
* or the kernel itself
*/
if (kauth_authorize_machdep(kauth_cred_get(), KAUTH_MACHDEP_UNMANAGEDMEM,
NULL, NULL, NULL, NULL) != 0) {
aprint_normal("%s: permission to mmap denied.\n",
device_xname(gp->g_device));
return -1;
}