Add wscons/vcons support for cg3.

This commit is contained in:
jdc 2008-11-28 07:57:04 +00:00
parent 0fa0158c37
commit b75399d6f2
3 changed files with 290 additions and 9 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: cgthree.c,v 1.16 2008/06/11 21:25:31 drochner Exp $ */
/* $NetBSD: cgthree.c,v 1.17 2008/11/28 07:57:04 jdc Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: cgthree.c,v 1.16 2008/06/11 21:25:31 drochner Exp $");
__KERNEL_RCSID(0, "$NetBSD: cgthree.c,v 1.17 2008/11/28 07:57:04 jdc Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -56,6 +56,16 @@ __KERNEL_RCSID(0, "$NetBSD: cgthree.c,v 1.16 2008/06/11 21:25:31 drochner Exp $"
#include <dev/sun/fbio.h>
#include <dev/sun/fbvar.h>
#include "wsdisplay.h"
#if NWSDISPLAY > 0
#include <dev/wscons/wsconsio.h>
#include <dev/wsfont/wsfont.h>
#include <dev/rasops/rasops.h>
#include <dev/wscons/wsdisplay_vconsvar.h>
#include "opt_wsemul.h"
#endif
#include <dev/sun/btreg.h>
#include <dev/sun/btvar.h>
#include <dev/sun/cgthreereg.h>
@ -97,6 +107,54 @@ struct cg3_videoctrl {
}
};
#if NWSDISPLAY > 0
#ifdef RASTERCONSOLE
#error RASTERCONSOLE and wsdisplay are mutually exclusive
#endif
static void cg3_setup_palette(struct cgthree_softc *);
struct wsscreen_descr cgthree_defaultscreen = {
"std",
0, 0, /* will be filled in -- XXX shouldn't, it's global */
NULL, /* textops */
8, 16, /* font width/height */
WSSCREEN_WSCOLORS, /* capabilities */
NULL /* modecookie */
};
static int cgthree_ioctl(void *, void *, u_long, void *, int, struct lwp *);
static paddr_t cgthree_mmap(void *, void *, off_t, int);
static void cgthree_init_screen(void *, struct vcons_screen *, int, long *);
int cgthree_putcmap(struct cgthree_softc *, struct wsdisplay_cmap *);
int cgthree_getcmap(struct cgthree_softc *, struct wsdisplay_cmap *);
struct wsdisplay_accessops cgthree_accessops = {
cgthree_ioctl,
cgthree_mmap,
NULL, /* alloc_screen */
NULL, /* free_screen */
NULL, /* show_screen */
NULL, /* load_font */
NULL, /* pollc */
NULL /* scroll */
};
const struct wsscreen_descr *_cgthree_scrlist[] = {
&cgthree_defaultscreen
};
struct wsscreen_list cgthree_screenlist = {
sizeof(_cgthree_scrlist) / sizeof(struct wsscreen_descr *),
_cgthree_scrlist
};
extern const u_char rasops_cmap[768];
static struct vcons_screen cg3_console_screen;
#endif /* NWSDISPLAY > 0 */
void
cgthreeattach(sc, name, isconsole)
@ -106,6 +164,11 @@ cgthreeattach(sc, name, isconsole)
{
int i;
struct fbdevice *fb = &sc->sc_fb;
#if NWSDISPLAY > 0
struct wsemuldisplaydev_attach_args aa;
struct rasops_info *ri = &cg3_console_screen.scr_ri;
unsigned long defattr;
#endif
volatile struct fbcontrol *fbc = sc->sc_fbc;
volatile struct bt_regs *bt = &fbc->fbc_dac;
@ -134,10 +197,6 @@ cgthreeattach(sc, name, isconsole)
}
}
/* Initialize the default color map. */
bt_initcmap(&sc->sc_cmap, 256);
cgthreeloadcmap(sc, 0, 256);
/* make sure we are not blanked */
cgthree_set_video(sc, 1);
BT_INIT(bt, 0);
@ -151,6 +210,65 @@ cgthreeattach(sc, name, isconsole)
printf("\n");
fb_attach(fb, isconsole);
#if NWSDISPLAY > 0
sc->sc_width = fb->fb_type.fb_width;
sc->sc_stride = fb->fb_type.fb_width;
sc->sc_height = fb->fb_type.fb_height;
/* setup rasops and so on for wsdisplay */
sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
vcons_init(&sc->vd, sc, &cgthree_defaultscreen, &cgthree_accessops);
sc->vd.init_screen = cgthree_init_screen;
if(isconsole) {
/* we mess with cg3_console_screen only once */
vcons_init_screen(&sc->vd, &cg3_console_screen, 1,
&defattr);
cg3_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
cgthree_defaultscreen.textops = &ri->ri_ops;
cgthree_defaultscreen.capabilities = ri->ri_caps;
cgthree_defaultscreen.nrows = ri->ri_rows;
cgthree_defaultscreen.ncols = ri->ri_cols;
sc->vd.active = &cg3_console_screen;
wsdisplay_cnattach(&cgthree_defaultscreen, ri, 0, 0, defattr);
} else {
/*
* we're not the console so we just clear the screen and don't
* set up any sort of text display
*/
if (cgthree_defaultscreen.textops == NULL) {
/*
* ugly, but...
* we want the console settings to win, so we only
* touch anything when we find an untouched screen
* definition. In this case we fill it from fb to
* avoid problems in case no cgthree is the console
*/
ri = &sc->sc_fb.fb_rinfo;
cgthree_defaultscreen.textops = &ri->ri_ops;
cgthree_defaultscreen.capabilities = ri->ri_caps;
cgthree_defaultscreen.nrows = ri->ri_rows;
cgthree_defaultscreen.ncols = ri->ri_cols;
}
}
/* Initialize the default color map. */
cg3_setup_palette(sc);
aa.scrdata = &cgthree_screenlist;
aa.console = isconsole;
aa.accessops = &cgthree_accessops;
aa.accesscookie = &sc->vd;
config_found(&sc->sc_dev, &aa, wsemuldisplaydevprint);
#else
/* Initialize the default color map. */
bt_initcmap(&sc->sc_cmap, 256);
cgthreeloadcmap(sc, 0, 256);
#endif
}
@ -322,3 +440,159 @@ cgthreemmap(dev, off, prot)
sc->sc_paddr, CG3REG_MEM + off,
prot, BUS_SPACE_MAP_LINEAR));
}
#if NWSDISPLAY > 0
static void
cg3_setup_palette(struct cgthree_softc *sc)
{
int i, j;
j = 0;
for (i = 0; i < 256; i++) {
sc->sc_cmap.cm_map[i][0] = rasops_cmap[j];
j++;
sc->sc_cmap.cm_map[i][1] = rasops_cmap[j];
j++;
sc->sc_cmap.cm_map[i][2] = rasops_cmap[j];
j++;
}
cgthreeloadcmap(sc, 0, 256);
}
int
cgthree_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
struct lwp *l)
{
/* we'll probably need to add more stuff here */
struct vcons_data *vd = v;
struct cgthree_softc *sc = vd->cookie;
struct wsdisplay_fbinfo *wdf;
struct rasops_info *ri = &sc->sc_fb.fb_rinfo;
struct vcons_screen *ms = sc->vd.active;
switch (cmd) {
case WSDISPLAYIO_GTYPE:
*(u_int *)data = WSDISPLAY_TYPE_SUNTCX;
return 0;
case WSDISPLAYIO_GINFO:
wdf = (void *)data;
wdf->height = ri->ri_height;
wdf->width = ri->ri_width;
wdf->depth = ri->ri_depth;
wdf->cmsize = 256;
return 0;
case WSDISPLAYIO_GETCMAP:
return cgthree_getcmap(sc,
(struct wsdisplay_cmap *)data);
case WSDISPLAYIO_PUTCMAP:
return cgthree_putcmap(sc,
(struct wsdisplay_cmap *)data);
case WSDISPLAYIO_SMODE:
{
int new_mode = *(int*)data;
if (new_mode != sc->sc_mode)
{
sc->sc_mode = new_mode;
if(new_mode == WSDISPLAYIO_MODE_EMUL)
{
cg3_setup_palette(sc);
vcons_redraw_screen(ms);
}
}
}
}
return EPASSTHROUGH;
}
paddr_t
cgthree_mmap(void *v, void *vs, off_t offset, int prot)
{
/* I'm not at all sure this is the right thing to do */
return cgthreemmap(0, offset, prot); /* assume minor dev 0 for now */
}
int
cgthree_putcmap(struct cgthree_softc *sc, struct wsdisplay_cmap *cm)
{
u_int index = cm->index;
u_int count = cm->count;
int error,i;
if (index >= 256 || count > 256 || index + count > 256)
return EINVAL;
for (i = 0; i < count; i++)
{
error = copyin(&cm->red[i],
&sc->sc_cmap.cm_map[index + i][0], 1);
if (error)
return error;
error = copyin(&cm->green[i],
&sc->sc_cmap.cm_map[index + i][1],
1);
if (error)
return error;
error = copyin(&cm->blue[i],
&sc->sc_cmap.cm_map[index + i][2], 1);
if (error)
return error;
}
cgthreeloadcmap(sc, index, count);
return 0;
}
int
cgthree_getcmap(struct cgthree_softc *sc, struct wsdisplay_cmap *cm)
{
u_int index = cm->index;
u_int count = cm->count;
int error,i;
if (index >= 256 || count > 256 || index + count > 256)
return EINVAL;
for (i = 0; i < count; i++)
{
error = copyout(&sc->sc_cmap.cm_map[index + i][0],
&cm->red[i], 1);
if (error)
return error;
error = copyout(&sc->sc_cmap.cm_map[index + i][1],
&cm->green[i], 1);
if (error)
return error;
error = copyout(&sc->sc_cmap.cm_map[index + i][2],
&cm->blue[i], 1);
if (error)
return error;
}
return 0;
}
void
cgthree_init_screen(void *cookie, struct vcons_screen *scr,
int existing, long *defattr)
{
struct cgthree_softc *sc = cookie;
struct rasops_info *ri = &scr->scr_ri;
ri->ri_depth = 8;
ri->ri_width = sc->sc_width;
ri->ri_height = sc->sc_height;
ri->ri_stride = sc->sc_stride;
ri->ri_flg = RI_CENTER;
ri->ri_bits = sc->sc_fb.fb_pixels;
rasops_init(ri, sc->sc_height/8, sc->sc_width/8);
ri->ri_caps = WSSCREEN_WSCOLORS | WSSCREEN_REVERSE;
rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
sc->sc_width / ri->ri_font->fontwidth);
ri->ri_hw = scr;
}
#endif /* NWSDISPLAY > 0 */

View File

@ -1,4 +1,4 @@
/* $NetBSD: cgthreevar.h,v 1.5 2008/04/28 20:23:58 martin Exp $ */
/* $NetBSD: cgthreevar.h,v 1.6 2008/11/28 07:57:04 jdc Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -41,6 +41,13 @@ struct cgthree_softc {
bus_addr_t sc_paddr; /* phys address for device mmap() */
volatile struct fbcontrol *sc_fbc; /* Brooktree registers */
#if NWSDISPLAY > 0
uint32_t sc_width;
uint32_t sc_height; /* display width / height */
uint32_t sc_stride;
int sc_mode;
struct vcons_data vd;
#endif
union bt_cmap sc_cmap; /* Brooktree color map */
};

View File

@ -1,4 +1,4 @@
# $NetBSD: files.sun,v 1.14 2008/02/21 13:44:17 martin Exp $
# $NetBSD: files.sun,v 1.15 2008/11/28 07:57:04 jdc Exp $
#
# Configuration file for devices found on Sun machines.
#
@ -72,7 +72,7 @@ file dev/sun/pfour_subr.c pfour needs-flag
device bwtwo: fb, rasops1, pfour
file dev/sun/bwtwo.c bwtwo needs-flag
device cgthree: bt_dac, fb, rasops8
device cgthree: bt_dac, fb, rasops8, wsemuldisplaydev, vcons
file dev/sun/cgthree.c cgthree needs-flag
device cgsix: bt_dac, fb, rasops8, pfour, wsemuldisplaydev, vcons