1*1dc652efSthorpej /* $NetBSD: gfb.c,v 1.12 2023/12/20 05:33:58 thorpej Exp $ */
25f7d9241Smacallan
35f7d9241Smacallan /*
45f7d9241Smacallan * Copyright (c) 2009 Michael Lorenz
55f7d9241Smacallan * All rights reserved.
65f7d9241Smacallan *
75f7d9241Smacallan * Redistribution and use in source and binary forms, with or without
85f7d9241Smacallan * modification, are permitted provided that the following conditions
95f7d9241Smacallan * are met:
105f7d9241Smacallan * 1. Redistributions of source code must retain the above copyright
115f7d9241Smacallan * notice, this list of conditions and the following disclaimer.
125f7d9241Smacallan * 2. Redistributions in binary form must reproduce the above copyright
135f7d9241Smacallan * notice, this list of conditions and the following disclaimer in the
145f7d9241Smacallan * documentation and/or other materials provided with the distribution.
155f7d9241Smacallan *
165f7d9241Smacallan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
175f7d9241Smacallan * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
185f7d9241Smacallan * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
195f7d9241Smacallan * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
205f7d9241Smacallan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
215f7d9241Smacallan * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
225f7d9241Smacallan * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
235f7d9241Smacallan * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
245f7d9241Smacallan * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
255f7d9241Smacallan * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
265f7d9241Smacallan */
275f7d9241Smacallan
285f7d9241Smacallan /*
295f7d9241Smacallan * A console driver for Sun XVR-1000 graphics cards
305f7d9241Smacallan */
315f7d9241Smacallan
325f7d9241Smacallan #include <sys/cdefs.h>
33*1dc652efSthorpej __KERNEL_RCSID(0, "$NetBSD: gfb.c,v 1.12 2023/12/20 05:33:58 thorpej Exp $");
345f7d9241Smacallan
355f7d9241Smacallan #include <sys/param.h>
365f7d9241Smacallan #include <sys/systm.h>
375f7d9241Smacallan #include <sys/kernel.h>
385f7d9241Smacallan #include <sys/device.h>
395f7d9241Smacallan #include <sys/lwp.h>
405f7d9241Smacallan #include <sys/kauth.h>
415f7d9241Smacallan #include <sys/kmem.h>
425f7d9241Smacallan
435f7d9241Smacallan #include <uvm/uvm_extern.h>
445f7d9241Smacallan
455f7d9241Smacallan #include <dev/videomode/videomode.h>
465f7d9241Smacallan
47b6584574Sdyoung #include <sys/bus.h>
485f7d9241Smacallan #include <machine/autoconf.h>
495f7d9241Smacallan #include <machine/openfirm.h>
505f7d9241Smacallan
515f7d9241Smacallan #include <dev/wscons/wsdisplayvar.h>
525f7d9241Smacallan #include <dev/wscons/wsconsio.h>
535f7d9241Smacallan #include <dev/wsfont/wsfont.h>
545f7d9241Smacallan #include <dev/rasops/rasops.h>
555f7d9241Smacallan #include <dev/wscons/wsdisplay_vconsvar.h>
565f7d9241Smacallan
575f7d9241Smacallan
585f7d9241Smacallan struct gfb_softc {
595f7d9241Smacallan device_t sc_dev;
605f7d9241Smacallan
615f7d9241Smacallan bus_space_tag_t sc_memt;
625f7d9241Smacallan
635f7d9241Smacallan bus_space_handle_t sc_fbh;
645f7d9241Smacallan bus_addr_t sc_fb_paddr;
655f7d9241Smacallan
665f7d9241Smacallan int sc_width, sc_height, sc_depth, sc_stride, sc_fblen;
675f7d9241Smacallan int sc_locked;
6860cbfd8fSmacallan void *sc_fbaddr;
695f7d9241Smacallan struct vcons_screen sc_console_screen;
705f7d9241Smacallan struct wsscreen_descr sc_defaultscreen_descr;
715f7d9241Smacallan const struct wsscreen_descr *sc_screens[1];
725f7d9241Smacallan struct wsscreen_list sc_screenlist;
735f7d9241Smacallan struct vcons_data vd;
745f7d9241Smacallan int sc_mode;
755f7d9241Smacallan int sc_node;
765f7d9241Smacallan u_char sc_cmap_red[256];
775f7d9241Smacallan u_char sc_cmap_green[256];
785f7d9241Smacallan u_char sc_cmap_blue[256];
795f7d9241Smacallan };
805f7d9241Smacallan
815f7d9241Smacallan static int gfb_match(device_t, cfdata_t, void *);
825f7d9241Smacallan static void gfb_attach(device_t, device_t, void *);
835f7d9241Smacallan
845f7d9241Smacallan CFATTACH_DECL_NEW(gfb, sizeof(struct gfb_softc),
855f7d9241Smacallan gfb_match, gfb_attach, NULL, NULL);
865f7d9241Smacallan
875f7d9241Smacallan extern const u_char rasops_cmap[768];
885f7d9241Smacallan
895f7d9241Smacallan static int gfb_ioctl(void *, void *, u_long, void *, int,
905f7d9241Smacallan struct lwp *);
915f7d9241Smacallan static paddr_t gfb_mmap(void *, void *, off_t, int);
925f7d9241Smacallan static void gfb_init_screen(void *, struct vcons_screen *, int, long *);
935f7d9241Smacallan
945f7d9241Smacallan static int gfb_putcmap(struct gfb_softc *, struct wsdisplay_cmap *);
955f7d9241Smacallan static int gfb_getcmap(struct gfb_softc *, struct wsdisplay_cmap *);
965f7d9241Smacallan static void gfb_restore_palette(struct gfb_softc *);
975f7d9241Smacallan static int gfb_putpalreg(struct gfb_softc *, uint8_t, uint8_t,
985f7d9241Smacallan uint8_t, uint8_t);
995f7d9241Smacallan
1005f7d9241Smacallan struct wsdisplay_accessops gfb_accessops = {
1015f7d9241Smacallan gfb_ioctl,
1025f7d9241Smacallan gfb_mmap,
1035f7d9241Smacallan NULL, /* alloc_screen */
1045f7d9241Smacallan NULL, /* free_screen */
1055f7d9241Smacallan NULL, /* show_screen */
1065f7d9241Smacallan NULL, /* load_font */
1075f7d9241Smacallan NULL, /* pollc */
1085f7d9241Smacallan NULL /* scroll */
1095f7d9241Smacallan };
1105f7d9241Smacallan
1115f7d9241Smacallan extern int prom_stdout_node;
1125f7d9241Smacallan
1135f7d9241Smacallan static int
gfb_match(device_t parent,cfdata_t match,void * aux)1145f7d9241Smacallan gfb_match(device_t parent, cfdata_t match, void *aux)
1155f7d9241Smacallan {
1165f7d9241Smacallan struct mainbus_attach_args *ma = aux;
1175f7d9241Smacallan
1185f7d9241Smacallan if (strcmp(ma->ma_name, "SUNW,gfb") == 0 )
1195f7d9241Smacallan return 100;
1205f7d9241Smacallan return 0;
1215f7d9241Smacallan }
1225f7d9241Smacallan
1235f7d9241Smacallan static void
gfb_attach(device_t parent,device_t self,void * aux)1245f7d9241Smacallan gfb_attach(device_t parent, device_t self, void *aux)
1255f7d9241Smacallan {
1265f7d9241Smacallan struct gfb_softc *sc = device_private(self);
1275f7d9241Smacallan struct mainbus_attach_args *ma = aux;
1285f7d9241Smacallan struct rasops_info *ri;
1295f7d9241Smacallan struct wsemuldisplaydev_attach_args aa;
1305f7d9241Smacallan unsigned long defattr;
1315f7d9241Smacallan bool is_console;
1325f7d9241Smacallan int i, j;
1335f7d9241Smacallan
1345f7d9241Smacallan sc->sc_memt = ma->ma_bustag;
1355f7d9241Smacallan sc->sc_dev = self;
1365f7d9241Smacallan sc->sc_node = ma->ma_node;
1375f7d9241Smacallan
1385f7d9241Smacallan if (ma->ma_nreg < 7) {
1395f7d9241Smacallan aprint_error("%s: can't find the fb range\n",
1405f7d9241Smacallan device_xname(self));
1415f7d9241Smacallan return;
1425f7d9241Smacallan }
1435f7d9241Smacallan
1445f7d9241Smacallan is_console = (prom_stdout_node == ma->ma_node);
1455f7d9241Smacallan
1465f7d9241Smacallan aprint_normal(": Sun XVR-1000%s\n", is_console ? " (console)" : "");
1475f7d9241Smacallan
1485f7d9241Smacallan sc->sc_depth = 32;
1495f7d9241Smacallan sc->sc_stride = 0x4000;
1505f7d9241Smacallan sc->sc_height = prom_getpropint(sc->sc_node, "height", 0);
1515f7d9241Smacallan sc->sc_width = prom_getpropint(sc->sc_node, "width", 0);
1525f7d9241Smacallan sc->sc_fblen = sc->sc_stride * sc->sc_height;
1535f7d9241Smacallan
1545f7d9241Smacallan if (sc->sc_fblen == 0) {
1555f7d9241Smacallan aprint_error("%s: not set up by firmware, can't continue.\n",
1565f7d9241Smacallan device_xname(self));
1575f7d9241Smacallan return;
1585f7d9241Smacallan }
1595f7d9241Smacallan
1605f7d9241Smacallan sc->sc_locked = 0;
1615f7d9241Smacallan sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
1625f7d9241Smacallan
1635f7d9241Smacallan if (bus_space_map(sc->sc_memt, ma->ma_reg[6].ur_paddr,
1648947b542Smacallan sc->sc_fblen, BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_PREFETCHABLE,
1658947b542Smacallan &sc->sc_fbh)) {
1665f7d9241Smacallan printf(": failed to map the framebuffer\n");
1675f7d9241Smacallan return;
1685f7d9241Smacallan }
1695f7d9241Smacallan sc->sc_fbaddr = bus_space_vaddr(sc->sc_memt, sc->sc_fbh);
1705f7d9241Smacallan sc->sc_fb_paddr = ma->ma_reg[6].ur_paddr;
1715f7d9241Smacallan
1725f7d9241Smacallan sc->sc_defaultscreen_descr = (struct wsscreen_descr){
1735f7d9241Smacallan "default",
1745f7d9241Smacallan 0, 0,
1755f7d9241Smacallan NULL,
1765f7d9241Smacallan 8, 16,
1775f7d9241Smacallan WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
1785f7d9241Smacallan NULL
1795f7d9241Smacallan };
1805f7d9241Smacallan sc->sc_screens[0] = &sc->sc_defaultscreen_descr;
1815f7d9241Smacallan sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens};
1825f7d9241Smacallan sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
1835f7d9241Smacallan sc->sc_locked = 0;
1845f7d9241Smacallan
1855f7d9241Smacallan vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr,
1865f7d9241Smacallan &gfb_accessops);
1875f7d9241Smacallan sc->vd.init_screen = gfb_init_screen;
1885f7d9241Smacallan
1895f7d9241Smacallan ri = &sc->sc_console_screen.scr_ri;
1905f7d9241Smacallan
1915f7d9241Smacallan j = 0;
1927111124bSmacallan for (i = 0; i < 256; i++) {
1935f7d9241Smacallan
1945f7d9241Smacallan sc->sc_cmap_red[i] = rasops_cmap[j];
1955f7d9241Smacallan sc->sc_cmap_green[i] = rasops_cmap[j + 1];
1965f7d9241Smacallan sc->sc_cmap_blue[i] = rasops_cmap[j + 2];
1975f7d9241Smacallan gfb_putpalreg(sc, i, rasops_cmap[j], rasops_cmap[j + 1],
1985f7d9241Smacallan rasops_cmap[j + 2]);
1995f7d9241Smacallan j += 3;
2005f7d9241Smacallan }
2015f7d9241Smacallan
2025f7d9241Smacallan if (is_console) {
2035f7d9241Smacallan vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1,
2045f7d9241Smacallan &defattr);
2055f7d9241Smacallan sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
2065f7d9241Smacallan
2075f7d9241Smacallan #if notyet
2085f7d9241Smacallan gfb_rectfill(sc, 0, 0, sc->sc_width, sc->sc_height,
2095f7d9241Smacallan ri->ri_devcmap[(defattr >> 16) & 0xff]);
2105f7d9241Smacallan #endif
2115f7d9241Smacallan sc->sc_defaultscreen_descr.textops = &ri->ri_ops;
2125f7d9241Smacallan sc->sc_defaultscreen_descr.capabilities = ri->ri_caps;
2135f7d9241Smacallan sc->sc_defaultscreen_descr.nrows = ri->ri_rows;
2145f7d9241Smacallan sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
2155f7d9241Smacallan wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0,
2165f7d9241Smacallan defattr);
2175f7d9241Smacallan vcons_replay_msgbuf(&sc->sc_console_screen);
2185f7d9241Smacallan } else {
2195f7d9241Smacallan /*
2205f7d9241Smacallan * since we're not the console we can postpone the rest
2215f7d9241Smacallan * until someone actually allocates a screen for us
2225f7d9241Smacallan */
2235f7d9241Smacallan (*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
2245f7d9241Smacallan }
2255f7d9241Smacallan
2265f7d9241Smacallan aa.console = is_console;
2275f7d9241Smacallan aa.scrdata = &sc->sc_screenlist;
2285f7d9241Smacallan aa.accessops = &gfb_accessops;
2295f7d9241Smacallan aa.accesscookie = &sc->vd;
2305f7d9241Smacallan
231c7fb772bSthorpej config_found(sc->sc_dev, &aa, wsemuldisplaydevprint, CFARGS_NONE);
23260cbfd8fSmacallan
23360cbfd8fSmacallan #ifdef GFB_DEBUG
23460cbfd8fSmacallan /*
23560cbfd8fSmacallan * now dump a register range
23660cbfd8fSmacallan * try 1, 2 and 4 since they're only 0x2000 each
23760cbfd8fSmacallan */
23860cbfd8fSmacallan bus_space_handle_t regh;
23960cbfd8fSmacallan
24060cbfd8fSmacallan if (bus_space_map(sc->sc_memt, ma->ma_reg[3].ur_paddr,
24160cbfd8fSmacallan 0x2000, BUS_SPACE_MAP_LINEAR, ®h) == 0) {
24260cbfd8fSmacallan for (i = 0; i < 0x200; i += 32) {
24360cbfd8fSmacallan printf("%04x", i);
24460cbfd8fSmacallan for (j = 0; j < 32; j += 4) {
24560cbfd8fSmacallan printf(" %08x", bus_space_read_4(sc->sc_memt,
24660cbfd8fSmacallan regh, i + j));
24760cbfd8fSmacallan }
24860cbfd8fSmacallan printf("\n");
24960cbfd8fSmacallan }
25060cbfd8fSmacallan bus_space_unmap(sc->sc_memt, regh, 0x2000);
25160cbfd8fSmacallan }
25260cbfd8fSmacallan #endif
2535f7d9241Smacallan }
2545f7d9241Smacallan
2555f7d9241Smacallan static int
gfb_ioctl(void * v,void * vs,u_long cmd,void * data,int flag,struct lwp * l)2565f7d9241Smacallan gfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
2575f7d9241Smacallan struct lwp *l)
2585f7d9241Smacallan {
2595f7d9241Smacallan struct vcons_data *vd = v;
2605f7d9241Smacallan struct gfb_softc *sc = vd->cookie;
2615f7d9241Smacallan struct wsdisplay_fbinfo *wdf;
2625f7d9241Smacallan struct vcons_screen *ms = vd->active;
2635f7d9241Smacallan
2645f7d9241Smacallan switch (cmd) {
2655f7d9241Smacallan
2665f7d9241Smacallan case WSDISPLAYIO_GTYPE:
267608f7f55Smacallan *(u_int *)data = WSDISPLAY_TYPE_XVR1000;
2685f7d9241Smacallan return 0;
2695f7d9241Smacallan
2705f7d9241Smacallan case WSDISPLAYIO_GINFO:
2715f7d9241Smacallan if (ms == NULL)
2725f7d9241Smacallan return ENODEV;
2735f7d9241Smacallan wdf = (void *)data;
2745f7d9241Smacallan wdf->height = ms->scr_ri.ri_height;
2755f7d9241Smacallan wdf->width = ms->scr_ri.ri_width;
2765f7d9241Smacallan wdf->depth = ms->scr_ri.ri_depth;
2775f7d9241Smacallan wdf->cmsize = 256;
2785f7d9241Smacallan return 0;
2795f7d9241Smacallan
2805f7d9241Smacallan case WSDISPLAYIO_GETCMAP:
2815f7d9241Smacallan return gfb_getcmap(sc,
2825f7d9241Smacallan (struct wsdisplay_cmap *)data);
2835f7d9241Smacallan
2845f7d9241Smacallan case WSDISPLAYIO_PUTCMAP:
2855f7d9241Smacallan return gfb_putcmap(sc,
2865f7d9241Smacallan (struct wsdisplay_cmap *)data);
2875f7d9241Smacallan
2885f7d9241Smacallan case WSDISPLAYIO_LINEBYTES:
2895f7d9241Smacallan *(u_int *)data = sc->sc_stride;
2905f7d9241Smacallan return 0;
2915f7d9241Smacallan
2925f7d9241Smacallan case WSDISPLAYIO_SMODE:
2935f7d9241Smacallan {
2945f7d9241Smacallan int new_mode = *(int*)data;
2955f7d9241Smacallan
2965f7d9241Smacallan /* notify the bus backend */
2975f7d9241Smacallan if (new_mode != sc->sc_mode) {
2985f7d9241Smacallan sc->sc_mode = new_mode;
2995f7d9241Smacallan if(new_mode == WSDISPLAYIO_MODE_EMUL) {
3005f7d9241Smacallan gfb_restore_palette(sc);
3015f7d9241Smacallan vcons_redraw_screen(ms);
3025f7d9241Smacallan }
3035f7d9241Smacallan }
3045f7d9241Smacallan }
3055f7d9241Smacallan return 0;
3068947b542Smacallan case WSDISPLAYIO_GET_FBINFO:
3078947b542Smacallan {
3088947b542Smacallan struct wsdisplayio_fbinfo *fbi = data;
3098947b542Smacallan return wsdisplayio_get_fbinfo(&ms->scr_ri, fbi);
3108947b542Smacallan }
3115f7d9241Smacallan }
3125f7d9241Smacallan return EPASSTHROUGH;
3135f7d9241Smacallan }
3145f7d9241Smacallan
3155f7d9241Smacallan static paddr_t
gfb_mmap(void * v,void * vs,off_t offset,int prot)3165f7d9241Smacallan gfb_mmap(void *v, void *vs, off_t offset, int prot)
3175f7d9241Smacallan {
3185f7d9241Smacallan struct vcons_data *vd = v;
3195f7d9241Smacallan struct gfb_softc *sc = vd->cookie;
3205f7d9241Smacallan paddr_t pa;
3215f7d9241Smacallan
3225f7d9241Smacallan /* 'regular' framebuffer mmap()ing */
3235f7d9241Smacallan if (offset < sc->sc_fblen) {
3248947b542Smacallan /*
3258947b542Smacallan * XXX
3268947b542Smacallan * BUS_SPACE_MAP_PREFETCHABLE produces artifacts with X, but
3278947b542Smacallan * not with the console code, so don't set it here
3288947b542Smacallan */
3295f7d9241Smacallan pa = bus_space_mmap(sc->sc_memt, sc->sc_fb_paddr + offset, 0,
3305f7d9241Smacallan prot, BUS_SPACE_MAP_LINEAR);
3315f7d9241Smacallan return pa;
3325f7d9241Smacallan }
3335f7d9241Smacallan
3345f7d9241Smacallan /*
3355f7d9241Smacallan * restrict all other mappings to processes with superuser privileges
3365f7d9241Smacallan * or the kernel itself
3375f7d9241Smacallan */
3380c9d8d15Selad if (kauth_authorize_machdep(kauth_cred_get(), KAUTH_MACHDEP_UNMANAGEDMEM,
3390c9d8d15Selad NULL, NULL, NULL, NULL) != 0) {
3405f7d9241Smacallan aprint_normal("%s: mmap() rejected.\n",
3415f7d9241Smacallan device_xname(sc->sc_dev));
3425f7d9241Smacallan return -1;
3435f7d9241Smacallan }
3445f7d9241Smacallan
3455f7d9241Smacallan /* let userland map other ranges */
3465f7d9241Smacallan
3475f7d9241Smacallan return -1;
3485f7d9241Smacallan }
3495f7d9241Smacallan
3505f7d9241Smacallan static void
gfb_init_screen(void * cookie,struct vcons_screen * scr,int existing,long * defattr)3515f7d9241Smacallan gfb_init_screen(void *cookie, struct vcons_screen *scr,
3525f7d9241Smacallan int existing, long *defattr)
3535f7d9241Smacallan {
3545f7d9241Smacallan struct gfb_softc *sc = cookie;
3555f7d9241Smacallan struct rasops_info *ri = &scr->scr_ri;
3565f7d9241Smacallan
3575f7d9241Smacallan ri->ri_depth = sc->sc_depth;
3585f7d9241Smacallan ri->ri_width = sc->sc_width;
3595f7d9241Smacallan ri->ri_height = sc->sc_height;
3605f7d9241Smacallan ri->ri_stride = sc->sc_stride;
3617111124bSmacallan ri->ri_flg = RI_CENTER | RI_FULLCLEAR | RI_ENABLE_ALPHA;
3625f7d9241Smacallan
36360cbfd8fSmacallan ri->ri_bits = (char *)sc->sc_fbaddr;
36460cbfd8fSmacallan scr->scr_flags |= VCONS_DONT_READ;
3655f7d9241Smacallan
3665f7d9241Smacallan if (existing) {
3675f7d9241Smacallan ri->ri_flg |= RI_CLEAR;
3685f7d9241Smacallan }
3695f7d9241Smacallan
3707111124bSmacallan /* explicitly request BGR in case the default changes */
3717111124bSmacallan ri->ri_rnum = 8;
3727111124bSmacallan ri->ri_gnum = 8;
3737111124bSmacallan ri->ri_bnum = 8;
3747111124bSmacallan ri->ri_rpos = 0;
3757111124bSmacallan ri->ri_gpos = 8;
3767111124bSmacallan ri->ri_bpos = 16;
3777111124bSmacallan
3781fa79ac8Smacallan rasops_init(ri, 0, 0);
3795f7d9241Smacallan ri->ri_caps = WSSCREEN_WSCOLORS;
3805f7d9241Smacallan
3815f7d9241Smacallan rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
3825f7d9241Smacallan sc->sc_width / ri->ri_font->fontwidth);
3835f7d9241Smacallan
3845f7d9241Smacallan ri->ri_hw = scr;
3855f7d9241Smacallan #if 0
3865f7d9241Smacallan ri->ri_ops.copyrows = gfb_copyrows;
3875f7d9241Smacallan ri->ri_ops.copycols = gfb_copycols;
3885f7d9241Smacallan ri->ri_ops.cursor = gfb_cursor;
3895f7d9241Smacallan ri->ri_ops.eraserows = gfb_eraserows;
3905f7d9241Smacallan ri->ri_ops.erasecols = gfb_erasecols;
3915f7d9241Smacallan ri->ri_ops.putchar = gfb_putchar;
3925f7d9241Smacallan #endif
3935f7d9241Smacallan }
3945f7d9241Smacallan
3955f7d9241Smacallan static int
gfb_putcmap(struct gfb_softc * sc,struct wsdisplay_cmap * cm)3965f7d9241Smacallan gfb_putcmap(struct gfb_softc *sc, struct wsdisplay_cmap *cm)
3975f7d9241Smacallan {
3985f7d9241Smacallan u_char *r, *g, *b;
3995f7d9241Smacallan u_int index = cm->index;
4005f7d9241Smacallan u_int count = cm->count;
4015f7d9241Smacallan int i, error;
4025f7d9241Smacallan u_char rbuf[256], gbuf[256], bbuf[256];
4035f7d9241Smacallan
4045f7d9241Smacallan #ifdef GFB_DEBUG
4055f7d9241Smacallan aprint_debug("putcmap: %d %d\n",index, count);
4065f7d9241Smacallan #endif
4075f7d9241Smacallan if (cm->index >= 256 || cm->count > 256 ||
4085f7d9241Smacallan (cm->index + cm->count) > 256)
4095f7d9241Smacallan return EINVAL;
4105f7d9241Smacallan error = copyin(cm->red, &rbuf[index], count);
4115f7d9241Smacallan if (error)
4125f7d9241Smacallan return error;
4135f7d9241Smacallan error = copyin(cm->green, &gbuf[index], count);
4145f7d9241Smacallan if (error)
4155f7d9241Smacallan return error;
4165f7d9241Smacallan error = copyin(cm->blue, &bbuf[index], count);
4175f7d9241Smacallan if (error)
4185f7d9241Smacallan return error;
4195f7d9241Smacallan
4205f7d9241Smacallan memcpy(&sc->sc_cmap_red[index], &rbuf[index], count);
4215f7d9241Smacallan memcpy(&sc->sc_cmap_green[index], &gbuf[index], count);
4225f7d9241Smacallan memcpy(&sc->sc_cmap_blue[index], &bbuf[index], count);
4235f7d9241Smacallan
4245f7d9241Smacallan r = &sc->sc_cmap_red[index];
4255f7d9241Smacallan g = &sc->sc_cmap_green[index];
4265f7d9241Smacallan b = &sc->sc_cmap_blue[index];
4275f7d9241Smacallan
4285f7d9241Smacallan for (i = 0; i < count; i++) {
4295f7d9241Smacallan gfb_putpalreg(sc, index, *r, *g, *b);
4305f7d9241Smacallan index++;
4315f7d9241Smacallan r++, g++, b++;
4325f7d9241Smacallan }
4335f7d9241Smacallan return 0;
4345f7d9241Smacallan }
4355f7d9241Smacallan
4365f7d9241Smacallan static int
gfb_getcmap(struct gfb_softc * sc,struct wsdisplay_cmap * cm)4375f7d9241Smacallan gfb_getcmap(struct gfb_softc *sc, struct wsdisplay_cmap *cm)
4385f7d9241Smacallan {
4395f7d9241Smacallan u_int index = cm->index;
4405f7d9241Smacallan u_int count = cm->count;
4415f7d9241Smacallan int error;
4425f7d9241Smacallan
4435f7d9241Smacallan if (index >= 255 || count > 256 || index + count > 256)
4445f7d9241Smacallan return EINVAL;
4455f7d9241Smacallan
4465f7d9241Smacallan error = copyout(&sc->sc_cmap_red[index], cm->red, count);
4475f7d9241Smacallan if (error)
4485f7d9241Smacallan return error;
4495f7d9241Smacallan error = copyout(&sc->sc_cmap_green[index], cm->green, count);
4505f7d9241Smacallan if (error)
4515f7d9241Smacallan return error;
4525f7d9241Smacallan error = copyout(&sc->sc_cmap_blue[index], cm->blue, count);
4535f7d9241Smacallan if (error)
4545f7d9241Smacallan return error;
4555f7d9241Smacallan
4565f7d9241Smacallan return 0;
4575f7d9241Smacallan }
4585f7d9241Smacallan
4595f7d9241Smacallan static void
gfb_restore_palette(struct gfb_softc * sc)4605f7d9241Smacallan gfb_restore_palette(struct gfb_softc *sc)
4615f7d9241Smacallan {
4625f7d9241Smacallan int i;
4635f7d9241Smacallan
4645f7d9241Smacallan for (i = 0; i < (1 << sc->sc_depth); i++) {
4655f7d9241Smacallan gfb_putpalreg(sc, i, sc->sc_cmap_red[i],
4665f7d9241Smacallan sc->sc_cmap_green[i], sc->sc_cmap_blue[i]);
4675f7d9241Smacallan }
4685f7d9241Smacallan }
4695f7d9241Smacallan
4705f7d9241Smacallan static int
gfb_putpalreg(struct gfb_softc * sc,uint8_t idx,uint8_t r,uint8_t g,uint8_t b)4715f7d9241Smacallan gfb_putpalreg(struct gfb_softc *sc, uint8_t idx, uint8_t r, uint8_t g,
4725f7d9241Smacallan uint8_t b)
4735f7d9241Smacallan {
4745f7d9241Smacallan return 0;
4755f7d9241Smacallan }
476