/*
* Copyright (C) 1999 Scott Reynolds
* All rights reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
/*
* macfb compatibility with legacy grf devices
*/
/*
* (Re-)initialize the grf_softc block so that at least the requested
* number of elements has been allocated. If this results in more
* elements than we had prior to getting here, we initialize each of
* them to avoid problems down the road.
*/
void
grf_init(int n)
{
struct grf_softc *sc;
int i;
/* Initialize per-softc structures. */
while (i < numgrf) {
grf_scinit(&grf_softc[i], "grf", i);
i++;
}
}
}
/*
* Called by main() during pseudo-device attachment. If we had a
* way to configure additional grf devices later, this would actually
* allocate enough space for them. As it stands, it's nonsensical,
* so other than a basic sanity check we do nothing.
*/
void
grfattach(int n)
{
if (n <= 0) {
#ifdef DIAGNOSTIC
panic("grfattach: count <= 0");
#endif
return;
}
#if 0 /* XXX someday, if we implement a way to attach after autoconfig */
grf_init(n);
#endif
}
/*
* Called from macfb_attach() after setting up the frame buffer. Since
* there is a 1:1 correspondence between the macfb device and the grf
* device, the only bit of information we really need is the macfb_softc.
*/
void
grf_attach(struct macfb_softc *sc, int unit)
{
grf_init(unit);
if (unit < numgrf)
grf_softc[unit].mfb_sc = sc;
}
/*
* Standard device ops
*/
int
grfopen(dev_t dev, int flag, int mode, struct lwp *l)
{
struct grf_softc *sc;
int unit = GRFUNIT(dev);
int rv = 0;
if (grf_softc == NULL || unit >= numgrf)
return ENXIO;
sc = &grf_softc[unit];
if (sc->mfb_sc == NULL)
rv = ENXIO;
return rv;
}
int
grfclose(dev_t dev, int flag, int mode, struct lwp *l)
{
struct grf_softc *sc;
int unit = GRFUNIT(dev);
int rv = 0;
if (grf_softc == NULL || unit >= numgrf)
return ENXIO;
sc = &grf_softc[unit];
if (sc->mfb_sc != NULL)
macfb_clear(sc->mfb_sc->sc_dc); /* clear the display */
else
rv = ENXIO;
return rv;
}
int
grfioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
{
struct grf_softc *sc;
struct macfb_devconfig *dc;
#if defined(GRF_COMPAT) || (NGRF > 0)
struct grfinfo *gd;
#endif /* GRF_COMPAT || (NGRF > 0) */
struct grfmode *gm;
int unit = GRFUNIT(dev);
int rv;
if (grf_softc == NULL || unit >= numgrf)
return ENXIO;
sc = &grf_softc[unit];
if (sc->mfb_sc == NULL)
return ENXIO;
case GRFIOCLISTMODES:
case GRFIOCGETMODE:
case GRFIOCSETMODE:
/* NONE of these operations are (officially) supported. */
default:
rv = EINVAL;
break;
}
return rv;
}
paddr_t
grfmmap(dev_t dev, off_t off, int prot)
{
struct grf_softc *sc;
struct macfb_devconfig *dc;
int unit = GRFUNIT(dev);
if (grf_softc == NULL || unit >= numgrf)
return ENXIO;
sc = &grf_softc[unit];
if (sc->mfb_sc == NULL)
return ENXIO;
dc = sc->mfb_sc->sc_dc;
if ((u_int)off < m68k_round_page(dc->dc_offset + dc->dc_size))
return m68k_btop(dc->dc_paddr + off);
return (-1);
}
int
grfmap(dev_t dev, struct macfb_softc *sc, void **addrp, struct proc *p)
{
size_t len;
int error;