[BACK]Return to rfx.c CVS log [TXT][DIR] Up to [local] / sys / arch / sparc / dev

Annotation of sys/arch/sparc/dev/rfx.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: rfx.c,v 1.12 2007/02/18 18:40:35 miod Exp $   */
                      2:
                      3: /*
                      4:  * Copyright (c) 2004, Miodrag Vallat.
                      5:  * All rights reserved.
                      6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
                     15:  *
                     16:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     17:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
                     18:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
                     19:  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
                     20:  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
                     21:  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
                     22:  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     23:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
                     24:  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
                     25:  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     26:  * POSSIBILITY OF SUCH DAMAGE.
                     27:  *
                     28:  */
                     29:
                     30: /*
                     31:  * Driver for the Vitec RasterFlex family of frame buffers.
                     32:  * It should support RasterFlex-24, RasterFlex-32 and RasterFlex-HR.
                     33:  */
                     34:
                     35: #include <sys/param.h>
                     36: #include <sys/systm.h>
                     37: #include <sys/buf.h>
                     38: #include <sys/device.h>
                     39: #include <sys/ioctl.h>
                     40: #include <sys/malloc.h>
                     41: #include <sys/mman.h>
                     42: #include <sys/tty.h>
                     43: #include <sys/conf.h>
                     44:
                     45: #include <uvm/uvm_extern.h>
                     46:
                     47: #include <machine/autoconf.h>
                     48: #include <machine/pmap.h>
                     49: #include <machine/cpu.h>
                     50: #include <machine/conf.h>
                     51:
                     52: #include <dev/wscons/wsconsio.h>
                     53: #include <dev/wscons/wsdisplayvar.h>
                     54: #include <dev/rasops/rasops.h>
                     55: #include <machine/fbvar.h>
                     56:
                     57: #include <sparc/dev/sbusvar.h>
                     58:
                     59: #include <dev/ic/bt463reg.h>
                     60:
                     61: /*
                     62:  * Configuration structure
                     63:  */
                     64: struct rfx_config {
                     65:        u_int16_t       unknown;
                     66:        u_int16_t       version;
                     67:        u_int32_t       scanline;
                     68:        u_int32_t       maxwidth;       /* unsure */
                     69:        u_int32_t       maxheight;      /* unsure */
                     70:        u_int32_t       width;
                     71:        u_int32_t       height;
                     72: };
                     73:
                     74: /*
                     75:  * In-memory offsets
                     76:  */
                     77:
                     78: #define        RFX_RAMDAC_ADDR         0x00020000
                     79: #define        RFX_RAMDAC_SIZE         0x00000004
                     80:
                     81: #define        RFX_CONTROL_ADDR        0x00040000
                     82: #define        RFX_CONTROL_SIZE        0x000000e0
                     83:
                     84: #define        RFX_INIT_ADDR           0x00018000
                     85: #define        RFX_INIT_OFFSET         0x0000001c
                     86: #define        RFX_INIT_SIZE           0x00008000
                     87:
                     88: #define        RFX_VRAM_ADDR           0x00100000
                     89:
                     90: /*
                     91:  * Control registers
                     92:  */
                     93:
                     94: #define        RFX_VIDCTRL_REG         0x10
                     95: #define        RFX_VSYNC_ENABLE        0x00000001
                     96: #define        RFX_VIDEO_DISABLE       0x00000002
                     97:
                     98: /*
                     99:  * Shadow colormap
                    100:  */
                    101: struct rfx_cmap {
                    102:        u_int8_t        red[256];
                    103:        u_int8_t        green[256];
                    104:        u_int8_t        blue[256];
                    105: };
                    106:
                    107: struct rfx_softc {
                    108:        struct  sunfb            sc_sunfb;
                    109:        struct  rom_reg          sc_phys;
                    110:        struct  intrhand         sc_ih;
                    111:
                    112:        struct rfx_cmap          sc_cmap;
                    113:        volatile u_int8_t       *sc_ramdac;
                    114:        volatile u_int32_t      *sc_ctrl;
                    115: };
                    116:
                    117: void   rfx_burner(void *, u_int, u_int);
                    118: int    rfx_ioctl(void *, u_long, caddr_t, int, struct proc *);
                    119: paddr_t        rfx_mmap(void *, off_t, int);
                    120:
                    121: int    rfx_getcmap(struct rfx_cmap *, struct wsdisplay_cmap *);
                    122: void   rfx_initialize(struct rfx_softc *, struct rfx_config *);
                    123: int    rfx_intr(void *);
                    124: void   rfx_loadcmap(struct rfx_softc *, int, int);
                    125: int    rfx_putcmap(struct rfx_cmap *, struct wsdisplay_cmap *);
                    126: void   rfx_setcolor(void *, u_int, u_int8_t, u_int8_t, u_int8_t);
                    127:
                    128: struct wsdisplay_accessops rfx_accessops = {
                    129:        rfx_ioctl,
                    130:        rfx_mmap,
                    131:        NULL,   /* alloc_screen */
                    132:        NULL,   /* free_screen */
                    133:        NULL,   /* show_screen */
                    134:        NULL,   /* load_font */
                    135:        NULL,   /* scrollback */
                    136:        NULL,   /* getchar */
                    137:        rfx_burner,
                    138:        NULL    /* pollc */
                    139: };
                    140:
                    141: int    rfxmatch(struct device *, void *, void *);
                    142: void   rfxattach(struct device *, struct device *, void *);
                    143:
                    144: #if defined(OpenBSD)
                    145:
                    146: struct cfattach rfx_ca = {
                    147:        sizeof (struct rfx_softc), rfxmatch, rfxattach
                    148: };
                    149:
                    150: struct cfdriver rfx_cd = {
                    151:        NULL, "rfx", DV_DULL
                    152: };
                    153:
                    154: #else
                    155:
                    156: CFATTACH_DECL(rfx, sizeof (struct rfx_softc), rfxmatch, rfxattach, NULL, NULL);
                    157:
                    158: #endif
                    159:
                    160: /*
                    161:  * Match a supported RasterFlex card.
                    162:  */
                    163: int
                    164: rfxmatch(struct device *parent, void *vcf, void *aux)
                    165: {
                    166:        struct confargs *ca = aux;
                    167:        struct romaux *ra = &ca->ca_ra;
                    168:        const char *device = ra->ra_name;
                    169:
                    170:        /* skip vendor name (could be CWARE, VITec, ...) */
                    171:        while (*device != ',' && *device != '\0')
                    172:                device++;
                    173:        if (*device == '\0')
                    174:                device = ra->ra_name;
                    175:        else
                    176:                device++;
                    177:
                    178:        if (strncmp(device, "RasterFLEX", strlen("RasterFLEX")) != 0)
                    179:                return (0);
                    180:
                    181:        /* RasterVideo and RasterFlex-TV are frame grabbers */
                    182:        if (strcmp(device, "RasterFLEX-TV") == 0)
                    183:                return (0);
                    184:
                    185:        return (1);
                    186: }
                    187:
                    188: /*
                    189:  * Attach and initialize a rfx display, as well as a child wsdisplay.
                    190:  */
                    191: void
                    192: rfxattach(struct device *parent, struct device *self, void *args)
                    193: {
                    194:        struct rfx_softc *sc = (struct rfx_softc *)self;
                    195:        struct confargs *ca = args;
                    196:        const char *device = ca->ca_ra.ra_name;
                    197:        struct rfx_config cf;
                    198:        int node, cflen, isconsole;
                    199: #if 0
                    200:        int pri;
                    201: #endif
                    202:
                    203: #if 0
                    204:        pri = ca->ca_ra.ra_intr[0].int_pri;
                    205:        printf(" pri %d", pri);
                    206: #endif
                    207:
                    208:        /* skip vendor name (could be CWARE, VITec, ...) */
                    209:        while (*device != ',' && *device != '\0')
                    210:                device++;
                    211:        if (*device == '\0')
                    212:                device = ca->ca_ra.ra_name;
                    213:        else
                    214:                device++;
                    215:        printf(": %s", device);
                    216:
                    217:        if (ca->ca_ra.ra_nreg == 0) {
                    218:                printf("\n%s: no SBus registers!\n",
                    219:                    self->dv_xname);
                    220:                return;
                    221:        }
                    222:
                    223:        node = ca->ca_ra.ra_node;
                    224:        isconsole = node == fbnode;
                    225:
                    226:        /*
                    227:         * Parse configuration structure
                    228:         */
                    229:        cflen = getproplen(node, "configuration");
                    230:        if (cflen != sizeof cf) {
                    231:                printf(", unknown %d bytes conf. structure", cflen);
                    232:                /* fill in default values */
                    233:                cf.version = 0;
                    234:                cf.scanline = 2048;
                    235:                cf.width = 1152;
                    236:                cf.height = 900;
                    237:        } else {
                    238:                getprop(node, "configuration", &cf, cflen);
                    239:                printf(", revision %d", cf.version);
                    240:        }
                    241:
                    242:        /*
                    243:         * Map registers
                    244:         */
                    245:        sc->sc_ramdac = (u_int8_t *)
                    246:            mapiodev(ca->ca_ra.ra_reg, RFX_RAMDAC_ADDR, RFX_RAMDAC_SIZE);
                    247:        sc->sc_ctrl = (u_int32_t *)
                    248:            mapiodev(ca->ca_ra.ra_reg, RFX_CONTROL_ADDR, RFX_CONTROL_SIZE);
                    249:        sc->sc_phys = ca->ca_ra.ra_reg[0];
                    250:
                    251: #if 0  /* not yet */
                    252:        sc->sc_ih.ih_fun = rfx_intr;
                    253:        sc->sc_ih.ih_arg = sc;
                    254:        intr_establish(pri, &sc->sc_ih, IPL_FB, self->dv_xname);
                    255: #endif
                    256:
                    257:        /*
                    258:         * The following is an equivalent for
                    259:         *   fb_setsize(&sc->sc_sunfb, 8, cf.width, cf.height,
                    260:         *     node, ca->ca_bustype);
                    261:         * forcing the correct scan line value. Since the usual frame buffer
                    262:         * properties are missing on this card, no need to go through
                    263:         * fb_setsize()...
                    264:         */
                    265:        sc->sc_sunfb.sf_depth = 8;
                    266:        sc->sc_sunfb.sf_width = cf.width;
                    267:        sc->sc_sunfb.sf_height = cf.height;
                    268:        sc->sc_sunfb.sf_linebytes = cf.scanline;
                    269:        sc->sc_sunfb.sf_fbsize = cf.height * cf.scanline;
                    270:
                    271:        printf(", %dx%d\n", sc->sc_sunfb.sf_width, sc->sc_sunfb.sf_height);
                    272:
                    273:        sc->sc_sunfb.sf_ro.ri_bits = mapiodev(ca->ca_ra.ra_reg,
                    274:            RFX_VRAM_ADDR, round_page(sc->sc_sunfb.sf_fbsize));
                    275:        sc->sc_sunfb.sf_ro.ri_hw = sc;
                    276:
                    277:        /*
                    278:         * If we are not the console, the frame buffer has not been
                    279:         * initalized by the PROM - do this ourselves.
                    280:         */
                    281:        if (!isconsole)
                    282:                rfx_initialize(sc, &cf);
                    283:
                    284:        fbwscons_init(&sc->sc_sunfb, isconsole ? 0 : RI_CLEAR);
                    285:
                    286:        bzero(&sc->sc_cmap, sizeof(sc->sc_cmap));
                    287:        fbwscons_setcolormap(&sc->sc_sunfb, rfx_setcolor);
                    288:
                    289:        if (isconsole) {
                    290:                fbwscons_console_init(&sc->sc_sunfb, -1);
                    291:        }
                    292:
                    293:        /* enable video */
                    294:        rfx_burner(sc, 1, 0);
                    295:
                    296:        fbwscons_attach(&sc->sc_sunfb, &rfx_accessops, isconsole);
                    297: }
                    298:
                    299: /*
                    300:  * Common wsdisplay operations
                    301:  */
                    302:
                    303: int
                    304: rfx_ioctl(void *v, u_long cmd, caddr_t data, int flags, struct proc *p)
                    305: {
                    306:        struct rfx_softc *sc = v;
                    307:        struct wsdisplay_cmap *cm;
                    308:        struct wsdisplay_fbinfo *wdf;
                    309:        int error;
                    310:
                    311:        switch (cmd) {
                    312:        case WSDISPLAYIO_GTYPE:
                    313:                *(u_int *)data = WSDISPLAY_TYPE_RFLEX;
                    314:                break;
                    315:        case WSDISPLAYIO_GINFO:
                    316:                wdf = (struct wsdisplay_fbinfo *)data;
                    317:                wdf->height = sc->sc_sunfb.sf_height;
                    318:                wdf->width  = sc->sc_sunfb.sf_width;
                    319:                wdf->depth  = sc->sc_sunfb.sf_depth;
                    320:                wdf->cmsize = 256;
                    321:                break;
                    322:        case WSDISPLAYIO_LINEBYTES:
                    323:                *(u_int *)data = sc->sc_sunfb.sf_linebytes;
                    324:                break;
                    325:
                    326:        case WSDISPLAYIO_GETCMAP:
                    327:                cm = (struct wsdisplay_cmap *)data;
                    328:                error = rfx_getcmap(&sc->sc_cmap, cm);
                    329:                if (error != 0)
                    330:                        return (error);
                    331:                break;
                    332:        case WSDISPLAYIO_PUTCMAP:
                    333:                cm = (struct wsdisplay_cmap *)data;
                    334:                error = rfx_putcmap(&sc->sc_cmap, cm);
                    335:                if (error != 0)
                    336:                        return (error);
                    337:                rfx_loadcmap(sc, cm->index, cm->count);
                    338:                break;
                    339:
                    340:        case WSDISPLAYIO_SVIDEO:
                    341:        case WSDISPLAYIO_GVIDEO:
                    342:                break;
                    343:
                    344:        default:
                    345:                return (-1);
                    346:         }
                    347:
                    348:        return (0);
                    349: }
                    350:
                    351: paddr_t
                    352: rfx_mmap(void *v, off_t offset, int prot)
                    353: {
                    354:        struct rfx_softc *sc = v;
                    355:
                    356:        if (offset & PGOFSET)
                    357:                return (-1);
                    358:
                    359:        if (offset >= 0 && offset < sc->sc_sunfb.sf_fbsize) {
                    360:                return (REG2PHYS(&sc->sc_phys, RFX_VRAM_ADDR + offset) |
                    361:                    PMAP_NC);
                    362:        }
                    363:
                    364:        return (-1);
                    365: }
                    366:
                    367: void
                    368: rfx_burner(void *v, u_int on, u_int flags)
                    369: {
                    370:        struct rfx_softc *sc = v;
                    371:
                    372:        if (on) {
                    373:                sc->sc_ctrl[RFX_VIDCTRL_REG] &= ~RFX_VIDEO_DISABLE;
                    374:                sc->sc_ctrl[RFX_VIDCTRL_REG] |= RFX_VSYNC_ENABLE;
                    375:        } else {
                    376:                sc->sc_ctrl[RFX_VIDCTRL_REG] |= RFX_VIDEO_DISABLE;
                    377:                if (flags & WSDISPLAY_BURN_VBLANK)
                    378:                        sc->sc_ctrl[RFX_VIDCTRL_REG] &= ~RFX_VSYNC_ENABLE;
                    379:        }
                    380: }
                    381:
                    382: /*
                    383:  * Colormap helper functions
                    384:  */
                    385:
                    386: void
                    387: rfx_setcolor(void *v, u_int index, u_int8_t r, u_int8_t g, u_int8_t b)
                    388: {
                    389:        struct rfx_softc *sc = v;
                    390:
                    391:        sc->sc_cmap.red[index] = r;
                    392:        sc->sc_cmap.green[index] = g;
                    393:        sc->sc_cmap.blue[index] = b;
                    394:
                    395:        rfx_loadcmap(sc, index, 1);
                    396: }
                    397:
                    398: int
                    399: rfx_getcmap(struct rfx_cmap *cm, struct wsdisplay_cmap *rcm)
                    400: {
                    401:        u_int index = rcm->index, count = rcm->count;
                    402:        int error;
                    403:
                    404:        if (index >= 256 || count > 256 - index)
                    405:                return (EINVAL);
                    406:
                    407:        if ((error = copyout(cm->red + index, rcm->red, count)) != 0)
                    408:                return (error);
                    409:        if ((error = copyout(cm->green + index, rcm->green, count)) != 0)
                    410:                return (error);
                    411:        if ((error = copyout(cm->blue + index, rcm->blue, count)) != 0)
                    412:                return (error);
                    413:
                    414:        return (0);
                    415: }
                    416:
                    417: int
                    418: rfx_putcmap(struct rfx_cmap *cm, struct wsdisplay_cmap *rcm)
                    419: {
                    420:        u_int index = rcm->index, count = rcm->count;
                    421:        u_int8_t red[256], green[256], blue[256];
                    422:        int error;
                    423:
                    424:        if (index >= 256 || count > 256 - index)
                    425:                return (EINVAL);
                    426:
                    427:        if ((error = copyin(rcm->red, red, count)) != 0)
                    428:                return (error);
                    429:        if ((error = copyin(rcm->green, green, count)) != 0)
                    430:                return (error);
                    431:        if ((error = copyin(rcm->blue, blue, count)) != 0)
                    432:                return (error);
                    433:
                    434:        bcopy(red, cm->red + index, count);
                    435:        bcopy(green, cm->green + index, count);
                    436:        bcopy(blue, cm->blue + index, count);
                    437:
                    438:        return (0);
                    439: }
                    440:
                    441: void
                    442: rfx_loadcmap(struct rfx_softc *sc, int start, int ncolors)
                    443: {
                    444:        u_int8_t *r, *g, *b;
                    445:
                    446:        r = sc->sc_cmap.red + start;
                    447:        g = sc->sc_cmap.green + start;
                    448:        b = sc->sc_cmap.blue + start;
                    449:
                    450:        start += BT463_IREG_CPALETTE_RAM;
                    451:        sc->sc_ramdac[BT463_REG_ADDR_LOW] = start & 0xff;
                    452:        sc->sc_ramdac[BT463_REG_ADDR_HIGH] = (start >> 8) & 0xff;
                    453:
                    454:        while (ncolors-- != 0) {
                    455:                sc->sc_ramdac[BT463_REG_CMAP_DATA] = *r++;
                    456:                sc->sc_ramdac[BT463_REG_CMAP_DATA] = *g++;
                    457:                sc->sc_ramdac[BT463_REG_CMAP_DATA] = *b++;
                    458:        }
                    459: }
                    460:
                    461: /*
                    462:  * Initialization code parser
                    463:  */
                    464:
                    465: void
                    466: rfx_initialize(struct rfx_softc *sc, struct rfx_config *cf)
                    467: {
                    468:        u_int32_t *data, offset, value;
                    469:        size_t cnt;
                    470:
                    471:        /*
                    472:         * Map the initialization data - this is a waste as we won't be
                    473:         * able to reclaim this mapping...
                    474:         */
                    475:        data = (u_int32_t *)
                    476:            mapiodev(&sc->sc_phys, RFX_INIT_ADDR, RFX_INIT_SIZE);
                    477:
                    478:        /*
                    479:         * Skip copyright notice
                    480:         */
                    481:        data += RFX_INIT_OFFSET / sizeof(u_int32_t);
                    482:        cnt = (RFX_INIT_SIZE - RFX_INIT_OFFSET) / sizeof(u_int32_t);
                    483:        cnt >>= 1;
                    484:
                    485:        /*
                    486:         * Parse and apply settings
                    487:         */
                    488:        while (cnt != 0) {
                    489:                offset = *data++;
                    490:                value = *data++;
                    491:
                    492:                if (offset == (u_int32_t)-1 && value == (u_int32_t)-1)
                    493:                        break;
                    494:
                    495:                /* Old PROM are little-endian */
                    496:                if (cf->version <= 1) {
                    497:                        offset = letoh32(offset);
                    498:                        value = letoh32(offset);
                    499:                }
                    500:
                    501:                if (offset & (1 << 31)) {
                    502:                        offset = (offset & ~(1 << 31)) - RFX_RAMDAC_ADDR;
                    503:                        if (offset < RFX_RAMDAC_SIZE)
                    504:                                sc->sc_ramdac[offset] = value >> 24;
                    505:                } else {
                    506:                        offset -= RFX_CONTROL_ADDR;
                    507:                        if (offset < RFX_CONTROL_SIZE)
                    508:                                sc->sc_ctrl[offset >> 2] = value;
                    509:                }
                    510:
                    511:                cnt--;
                    512:        }
                    513: }

CVSweb