Home | History | Annotate | Line # | Download | only in dev
fb.c revision 1.1
      1  1.1  tsubai /*
      2  1.1  tsubai  * Copyright (c) 1992, 1993
      3  1.1  tsubai  *	The Regents of the University of California.  All rights reserved.
      4  1.1  tsubai  *
      5  1.1  tsubai  * This code is derived from software contributed to Berkeley by
      6  1.1  tsubai  * Sony Corp. and Kazumasa Utashiro of Software Research Associates, Inc.
      7  1.1  tsubai  *
      8  1.1  tsubai  * Redistribution and use in source and binary forms, with or without
      9  1.1  tsubai  * modification, are permitted provided that the following conditions
     10  1.1  tsubai  * are met:
     11  1.1  tsubai  * 1. Redistributions of source code must retain the above copyright
     12  1.1  tsubai  *    notice, this list of conditions and the following disclaimer.
     13  1.1  tsubai  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1  tsubai  *    notice, this list of conditions and the following disclaimer in the
     15  1.1  tsubai  *    documentation and/or other materials provided with the distribution.
     16  1.1  tsubai  * 3. All advertising materials mentioning features or use of this software
     17  1.1  tsubai  *    must display the following acknowledgement:
     18  1.1  tsubai  *	This product includes software developed by the University of
     19  1.1  tsubai  *	California, Berkeley and its contributors.
     20  1.1  tsubai  * 4. Neither the name of the University nor the names of its contributors
     21  1.1  tsubai  *    may be used to endorse or promote products derived from this software
     22  1.1  tsubai  *    without specific prior written permission.
     23  1.1  tsubai  *
     24  1.1  tsubai  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  1.1  tsubai  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  1.1  tsubai  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  1.1  tsubai  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  1.1  tsubai  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  1.1  tsubai  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  1.1  tsubai  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  1.1  tsubai  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  1.1  tsubai  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  1.1  tsubai  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  1.1  tsubai  * SUCH DAMAGE.
     35  1.1  tsubai  *
     36  1.1  tsubai  * from: $Hdr: fb.c,v 4.300 91/06/27 20:43:06 root Rel41 $ SONY
     37  1.1  tsubai  *
     38  1.1  tsubai  *	@(#)fb.c	8.1 (Berkeley) 6/11/93
     39  1.1  tsubai  */
     40  1.1  tsubai 
     41  1.1  tsubai #include "fb.h"
     42  1.1  tsubai #if NFB > 0
     43  1.1  tsubai /*
     44  1.1  tsubai  * Frame buffer driver
     45  1.1  tsubai  */
     46  1.1  tsubai 
     47  1.1  tsubai #include <sys/param.h>
     48  1.1  tsubai #include <sys/types.h>
     49  1.1  tsubai #include <sys/device.h>
     50  1.1  tsubai #include <sys/systm.h>
     51  1.1  tsubai #include <sys/proc.h>
     52  1.1  tsubai 
     53  1.1  tsubai #include <machine/cpu.h>
     54  1.1  tsubai #include <machine/autoconf.h>
     55  1.1  tsubai #include <machine/framebuf.h>
     56  1.1  tsubai 
     57  1.1  tsubai #include <news/dev/fbreg.h>
     58  1.1  tsubai 
     59  1.1  tsubai #define FB_USED		1
     60  1.1  tsubai #define VIDEO_USED	2
     61  1.1  tsubai 
     62  1.1  tsubai struct fb_softc {
     63  1.1  tsubai 	struct device sc_dev;
     64  1.1  tsubai 	int fbs_state;
     65  1.1  tsubai 	int fbs_device;
     66  1.1  tsubai 	lScrType fbs_type;
     67  1.1  tsubai 	int fbs_flag;
     68  1.1  tsubai 	struct fbreg fbreg;
     69  1.1  tsubai };
     70  1.1  tsubai 
     71  1.1  tsubai static int	fbmatch __P((struct device *, struct cfdata *, void *));
     72  1.1  tsubai static void	fbattach __P((struct device *, struct device *, void *));
     73  1.1  tsubai static void	fblock __P((void));
     74  1.1  tsubai static void	fbunlock __P((int));
     75  1.1  tsubai static int	fbinit __P((struct fbreg *));
     76  1.1  tsubai static void	fbreset __P((struct fbreg *));
     77  1.1  tsubai 
     78  1.1  tsubai struct cfattach fb_ca = {
     79  1.1  tsubai 	sizeof(struct fb_softc), fbmatch, fbattach
     80  1.1  tsubai };
     81  1.1  tsubai 
     82  1.1  tsubai extern struct cfdriver fb_cd;
     83  1.1  tsubai 
     84  1.1  tsubai static char *devname[] = {
     85  1.1  tsubai /* 0*/	"",
     86  1.1  tsubai /* 1*/	"NWB-512",
     87  1.1  tsubai /* 2*/	"NWB-225",
     88  1.1  tsubai /* 3*/	"POP-MONO",
     89  1.1  tsubai /* 4*/	"POP-COLOR",
     90  1.1  tsubai /* 5*/	"NWB-514",
     91  1.1  tsubai /* 6*/	"NWB-251",
     92  1.1  tsubai /* 7*/	"LCD-MONO",
     93  1.1  tsubai /* 8*/	"LDC-COLOR",
     94  1.1  tsubai /* 9*/	"NWB-518",
     95  1.1  tsubai /*10*/	"NWB-252",
     96  1.1  tsubai /*11*/	"NWB-253",
     97  1.1  tsubai /*12*/	"NWB-254",
     98  1.1  tsubai /*13*/	"NWB-255",
     99  1.1  tsubai /*14*/	"SLB-101",
    100  1.1  tsubai /*15*/	"NWB-256",
    101  1.1  tsubai /*16*/	"NWB-257",
    102  1.1  tsubai };
    103  1.1  tsubai 
    104  1.1  tsubai static int fbstate = 0;
    105  1.1  tsubai 
    106  1.1  tsubai extern int fb253_probe();
    107  1.1  tsubai extern void bmcnattach();
    108  1.1  tsubai extern int fbstart __P((struct fbreg *, int));
    109  1.1  tsubai extern int search_fbdev __P((int, int));
    110  1.1  tsubai extern int fbgetscrtype();
    111  1.1  tsubai extern int fbsetpalette();
    112  1.1  tsubai extern int fbgetpalette();
    113  1.1  tsubai extern int fbsetcursor();
    114  1.1  tsubai extern int fbnsetcursor();
    115  1.1  tsubai extern int fbsetxy();
    116  1.1  tsubai 
    117  1.1  tsubai static int
    118  1.1  tsubai fbmatch(parent, cf, aux)
    119  1.1  tsubai 	struct device *parent;
    120  1.1  tsubai 	struct cfdata *cf;
    121  1.1  tsubai 	void *aux;
    122  1.1  tsubai {
    123  1.1  tsubai 	struct confargs *ca = aux;
    124  1.1  tsubai 	struct fbreg fbreg;
    125  1.1  tsubai 	struct fbreg *fbp = &fbreg;
    126  1.1  tsubai 	int unit = cf->cf_unit;
    127  1.1  tsubai 
    128  1.1  tsubai 	if (strcmp(ca->ca_name, "fb"))
    129  1.1  tsubai 		return 0;
    130  1.1  tsubai 
    131  1.1  tsubai 	fbp->fb_command = FB_CPROBE;
    132  1.1  tsubai 	fbp->fb_device = 0;
    133  1.1  tsubai 	fbp->fb_unit = unit;
    134  1.1  tsubai 	fbp->fb_data = -1;
    135  1.1  tsubai 	fbstart(fbp, 1);
    136  1.1  tsubai 
    137  1.1  tsubai 	if (fbp->fb_result != FB_ROK)
    138  1.1  tsubai 		return 0;
    139  1.1  tsubai 
    140  1.1  tsubai 	return 1;
    141  1.1  tsubai }
    142  1.1  tsubai 
    143  1.1  tsubai static void
    144  1.1  tsubai fbattach(parent, self, aux)
    145  1.1  tsubai 	struct device *parent;
    146  1.1  tsubai 	struct device *self;
    147  1.1  tsubai 	void *aux;
    148  1.1  tsubai {
    149  1.1  tsubai 	struct fb_softc *fb = (struct fb_softc *)self;
    150  1.1  tsubai 	struct fbreg *fbp = &fb->fbreg;
    151  1.1  tsubai 	int unit = fb->sc_dev.dv_cfdata->cf_unit;
    152  1.1  tsubai 	extern int tty00_is_console;
    153  1.1  tsubai 
    154  1.1  tsubai 	fb->fbs_device = unit;
    155  1.1  tsubai 
    156  1.1  tsubai 	fbp->fb_command = FB_CATTACH;
    157  1.1  tsubai 	fbp->fb_device = fb->fbs_device;
    158  1.1  tsubai 	fbstart(fbp, 1);
    159  1.1  tsubai 	fb->fbs_type = fbp->fb_scrtype;
    160  1.1  tsubai 
    161  1.1  tsubai 	if (fb->fbs_type.type) {
    162  1.1  tsubai 		fb->fbs_state = 0;
    163  1.1  tsubai 		fb->fbs_flag = 0;
    164  1.1  tsubai 		printf(": %s",
    165  1.1  tsubai 			(fb->fbs_type.type < sizeof(devname)/sizeof(*devname))
    166  1.1  tsubai 				? devname[(int)fb->fbs_type.type] : "UNKNOWN");
    167  1.1  tsubai 		printf(" (%d x %d %d plane)",
    168  1.1  tsubai 				fb->fbs_type.visiblerect.extent.x,
    169  1.1  tsubai 				fb->fbs_type.visiblerect.extent.y,
    170  1.1  tsubai 				fb->fbs_type.plane);
    171  1.1  tsubai 	}
    172  1.1  tsubai 
    173  1.1  tsubai 	if (! tty00_is_console) {	/* XXX */
    174  1.1  tsubai 		printf(" (console)");
    175  1.1  tsubai 		bmcnattach();
    176  1.1  tsubai 	}
    177  1.1  tsubai 	printf("\n");
    178  1.1  tsubai }
    179  1.1  tsubai 
    180  1.1  tsubai int
    181  1.1  tsubai fbopen(dev, flags, mode, p)
    182  1.1  tsubai 	dev_t dev;
    183  1.1  tsubai 	int flags, mode;
    184  1.1  tsubai 	struct proc *p;
    185  1.1  tsubai {
    186  1.1  tsubai 	register int unit = FBUNIT(dev);
    187  1.1  tsubai 	register struct fb_softc *fb = fb_cd.cd_devs[unit];
    188  1.1  tsubai 	register struct fbreg *fbp = &fb->fbreg;
    189  1.1  tsubai 
    190  1.1  tsubai 	if (unit >= NFB)
    191  1.1  tsubai 		return ENXIO;
    192  1.1  tsubai 	if (fb->fbs_flag && !FBVIDEO(dev))
    193  1.1  tsubai 		return EBUSY;
    194  1.1  tsubai 
    195  1.1  tsubai 	if (fb->fbs_state == 0) {
    196  1.1  tsubai 		fbp->fb_device = fb->fbs_device;
    197  1.1  tsubai 		if (fbinit(fbp))
    198  1.1  tsubai 			return EBUSY;
    199  1.1  tsubai 	}
    200  1.1  tsubai 
    201  1.1  tsubai         fb->fbs_state |= FBVIDEO(dev) ? VIDEO_USED : FB_USED;
    202  1.1  tsubai 
    203  1.1  tsubai 	return 0;
    204  1.1  tsubai }
    205  1.1  tsubai 
    206  1.1  tsubai int
    207  1.1  tsubai fbclose(dev, flags, mode, p)
    208  1.1  tsubai 	dev_t dev;
    209  1.1  tsubai 	int flags, mode;
    210  1.1  tsubai 	struct proc *p;
    211  1.1  tsubai {
    212  1.1  tsubai 	register int unit = FBUNIT(dev);
    213  1.1  tsubai 	register struct fb_softc *fb = fb_cd.cd_devs[unit];
    214  1.1  tsubai 	register struct fbreg *fbp = &fb->fbreg;
    215  1.1  tsubai 
    216  1.1  tsubai 	if (unit >= NFB)
    217  1.1  tsubai 		return ENXIO;
    218  1.1  tsubai 
    219  1.1  tsubai 	if (fb->fbs_state == 0)
    220  1.1  tsubai 		return 0;
    221  1.1  tsubai 
    222  1.1  tsubai 	if (!FBVIDEO(dev))
    223  1.1  tsubai 		fb->fbs_flag = 0;
    224  1.1  tsubai 
    225  1.1  tsubai 	fb->fbs_state &= ~(FBVIDEO(dev) ? VIDEO_USED : FB_USED);
    226  1.1  tsubai 
    227  1.1  tsubai 	if (fb->fbs_state == 0) {
    228  1.1  tsubai 		fbp->fb_device = fb->fbs_device;
    229  1.1  tsubai 		fbreset(fbp);
    230  1.1  tsubai 	}
    231  1.1  tsubai 
    232  1.1  tsubai 	return 0;
    233  1.1  tsubai }
    234  1.1  tsubai 
    235  1.1  tsubai int
    236  1.1  tsubai fbioctl(dev, cmd, data, flags, p)
    237  1.1  tsubai 	dev_t dev;
    238  1.1  tsubai 	u_long cmd;
    239  1.1  tsubai 	caddr_t data;
    240  1.1  tsubai 	int flags;
    241  1.1  tsubai 	struct proc *p;
    242  1.1  tsubai {
    243  1.1  tsubai 	register int unit = FBUNIT(dev);
    244  1.1  tsubai 	register struct fb_softc *fb = fb_cd.cd_devs[unit];
    245  1.1  tsubai 	register struct fbreg *fbp = &fb->fbreg;
    246  1.1  tsubai 	register int error = 0;
    247  1.1  tsubai 
    248  1.1  tsubai 	if (unit >= NFB)
    249  1.1  tsubai 		return ENXIO;
    250  1.1  tsubai 
    251  1.1  tsubai 	fblock();
    252  1.1  tsubai 
    253  1.1  tsubai 	fbp->fb_device = fb->fbs_device;
    254  1.1  tsubai 
    255  1.1  tsubai 	switch (cmd) {
    256  1.1  tsubai 	case FBIOCENABLE:
    257  1.1  tsubai 		fb->fbs_flag = 0;
    258  1.1  tsubai 		break;
    259  1.1  tsubai 	case FBIOCDISABLE:
    260  1.1  tsubai 		fb->fbs_flag = 1;
    261  1.1  tsubai 		break;
    262  1.1  tsubai 	case FBIOCAUTODIM:
    263  1.1  tsubai 		fbp->fb_command = FB_CAUTODIM;
    264  1.1  tsubai 		fbp->fb_data = *((int *)data);
    265  1.1  tsubai 		fbstart(fbp, 0);
    266  1.1  tsubai 		break;
    267  1.1  tsubai 	case FBIOCSETDIM:
    268  1.1  tsubai 		fbp->fb_command = FB_CSETDIM;
    269  1.1  tsubai 		fbp->fb_data = *((int*)data);
    270  1.1  tsubai 		fbstart(fbp, 0);
    271  1.1  tsubai 		break;
    272  1.1  tsubai 	case FBIOCGETDIM:
    273  1.1  tsubai 		fbp->fb_command = FB_CGETDIM;
    274  1.1  tsubai 		fbstart(fbp, 1);
    275  1.1  tsubai 		*((int*)data) = fbp->fb_data;
    276  1.1  tsubai 		break;
    277  1.1  tsubai #ifdef notyet
    278  1.1  tsubai 	case FBIOCBITBLT:
    279  1.1  tsubai 		error = fbbitblt(fbp, (sBitblt *)data);
    280  1.1  tsubai 		break;
    281  1.1  tsubai 	case FBIOCNBITBLT:
    282  1.1  tsubai 		error = fbnbitblt(fbp, (lBitblt *)data, UIO_USERSPACE);
    283  1.1  tsubai 		break;
    284  1.1  tsubai 	case FBIOCBATCHBITBLT:
    285  1.1  tsubai 		error = fbbatchbitblt(fbp, (sBatchBitblt*)data, UIO_USERSPACE);
    286  1.1  tsubai 		break;
    287  1.1  tsubai 	case FBIOCNBATCHBITBLT:
    288  1.1  tsubai 		error = fbnbatchbitblt(fbp, (lBatchBitblt*)data, UIO_USERSPACE);
    289  1.1  tsubai 		break;
    290  1.1  tsubai 	case FBIOCTILEBITBLT:
    291  1.1  tsubai 		error = fbtilebitblt(fbp, (sTileBitblt *)data);
    292  1.1  tsubai 		break;
    293  1.1  tsubai 	case FBIOCNTILEBITBLT:
    294  1.1  tsubai 		error = fbntilebitblt(fbp, (lTileBitblt *)data);
    295  1.1  tsubai 		break;
    296  1.1  tsubai 	case FBIOCBITBLT3:
    297  1.1  tsubai 		error = fbbitblt3(fbp, (sBitblt3 *)data);
    298  1.1  tsubai 		break;
    299  1.1  tsubai 	case FBIOCNBITBLT3:
    300  1.1  tsubai 		error = fbnbitblt3(fbp, (lBitblt3 *)data);
    301  1.1  tsubai 		break;
    302  1.1  tsubai 	case FBIOCPOLYLINE:
    303  1.1  tsubai 		error = fbpolyline(fbp, (sPrimLine *)data, 0);
    304  1.1  tsubai 		break;
    305  1.1  tsubai 	case FBIOCNPOLYLINE:
    306  1.1  tsubai 		error = fbnpolyline(fbp, (lPrimLine *)data, 0, UIO_USERSPACE);
    307  1.1  tsubai 		break;
    308  1.1  tsubai 	case FBIOCDJPOLYLINE:
    309  1.1  tsubai 		error = fbpolyline(fbp, (sPrimLine *)data, 1);
    310  1.1  tsubai 		break;
    311  1.1  tsubai 	case FBIOCNDJPOLYLINE:
    312  1.1  tsubai 		error = fbnpolyline(fbp, (lPrimLine *)data, 1, UIO_USERSPACE);
    313  1.1  tsubai 		break;
    314  1.1  tsubai 	case FBIOCPOLYMARKER:
    315  1.1  tsubai 		error = fbpolymarker(fbp, (sPrimMarker *)data);
    316  1.1  tsubai 		break;
    317  1.1  tsubai 	case FBIOCNPOLYMARKER:
    318  1.1  tsubai 		error = fbnpolymarker(fbp, (lPrimMarker *)data, UIO_USERSPACE);
    319  1.1  tsubai 		break;
    320  1.1  tsubai 	case FBIOCRECTANGLE:
    321  1.1  tsubai 		error = fbrectangle(fbp, (sPrimRect *)data);
    322  1.1  tsubai 		break;
    323  1.1  tsubai 	case FBIOCNRECTANGLE:
    324  1.1  tsubai 		error = fbnrectangle(fbp, (lPrimRect *)data);
    325  1.1  tsubai 		break;
    326  1.1  tsubai 	case FBIOCFILLSCAN:
    327  1.1  tsubai 		error = fbfillscan(fbp, (sPrimFill *)data);
    328  1.1  tsubai 		break;
    329  1.1  tsubai 	case FBIOCNFILLSCAN:
    330  1.1  tsubai 		error = fbnfillscan(fbp, (lPrimFill *)data, UIO_USERSPACE);
    331  1.1  tsubai 		break;
    332  1.1  tsubai 	case FBIOCTEXT:
    333  1.1  tsubai 		error = fbtext(fbp, (sPrimText *)data);
    334  1.1  tsubai 		break;
    335  1.1  tsubai 	case FBIOCNTEXT:
    336  1.1  tsubai 		error = fbntext(fbp, (lPrimText *)data);
    337  1.1  tsubai 		break;
    338  1.1  tsubai 	case FBIOCPOLYDOT:
    339  1.1  tsubai 		error = fbpolydot(fbp, (sPrimDot *)data);
    340  1.1  tsubai 		break;
    341  1.1  tsubai 	case FBIOCNPOLYDOT:
    342  1.1  tsubai 		error = fbnpolydot(fbp, (lPrimDot *)data, UIO_USERSPACE);
    343  1.1  tsubai 		break;
    344  1.1  tsubai #endif
    345  1.1  tsubai 
    346  1.1  tsubai 	case FBIOCGETSCRTYPE:
    347  1.1  tsubai 		fbgetscrtype(fbp, (sScrType *)data);
    348  1.1  tsubai 		break;
    349  1.1  tsubai 	case FBIOCNGETSCRTYPE:
    350  1.1  tsubai 		fbp->fb_command = FB_CGETSCRTYPE;
    351  1.1  tsubai 		fbstart(fbp, 1);
    352  1.1  tsubai 		*((lScrType*)data) = fbp->fb_scrtype;
    353  1.1  tsubai 		break;
    354  1.1  tsubai 	case FBIOCSETPALETTE:
    355  1.1  tsubai 		fbsetpalette(fbp, (sPalette *)data);
    356  1.1  tsubai 		break;
    357  1.1  tsubai #ifdef notyet
    358  1.1  tsubai 	case FBIOCNSETPALETTE:
    359  1.1  tsubai 		error = fbnsetpalette(fbp, (lPalette *)data);
    360  1.1  tsubai 		break;
    361  1.1  tsubai #endif
    362  1.1  tsubai 	case FBIOCGETPALETTE:
    363  1.1  tsubai 		fbgetpalette(fbp, (sPalette *)data);
    364  1.1  tsubai 		break;
    365  1.1  tsubai #ifdef notyet
    366  1.1  tsubai 	case FBIOCNGETPALETTE:
    367  1.1  tsubai 		error = fbngetpalette(fbp, (lPalette *)data);
    368  1.1  tsubai 		break;
    369  1.1  tsubai #endif
    370  1.1  tsubai 	case FBIOCSETCURSOR:
    371  1.1  tsubai 		fbsetcursor(fbp, (sCursor *)data);
    372  1.1  tsubai 		break;
    373  1.1  tsubai 	case FBIOCNSETCURSOR:
    374  1.1  tsubai 		fbnsetcursor(fbp, (lCursor *)data);
    375  1.1  tsubai 		break;
    376  1.1  tsubai 	case FBIOCNSETCURSOR2:
    377  1.1  tsubai 		fbp->fb_command = FB_CSETCURSOR;
    378  1.1  tsubai 		fbp->fb_cursor = *((lCursor2 *)data);
    379  1.1  tsubai 		fbstart(fbp, 0);
    380  1.1  tsubai 		break;
    381  1.1  tsubai 	case FBIOCUNSETCURSOR:
    382  1.1  tsubai 		fbp->fb_command = FB_CUNSETCURSOR;
    383  1.1  tsubai 		fbstart(fbp, 0);
    384  1.1  tsubai 		break;
    385  1.1  tsubai 	case FBIOCNUNSETCURSOR:
    386  1.1  tsubai 		fbp->fb_command = FB_CUNSETCURSOR;
    387  1.1  tsubai 		fbstart(fbp, 0);
    388  1.1  tsubai 		break;
    389  1.1  tsubai 	case FBIOCSHOWCURSOR:
    390  1.1  tsubai 		fbp->fb_command = FB_CSHOWCURSOR;
    391  1.1  tsubai 		fbstart(fbp, 0);
    392  1.1  tsubai 		break;
    393  1.1  tsubai 	case FBIOCNSHOWCURSOR:
    394  1.1  tsubai 		fbp->fb_command = FB_CSHOWCURSOR;
    395  1.1  tsubai 		fbstart(fbp, 0);
    396  1.1  tsubai 		break;
    397  1.1  tsubai 	case FBIOCHIDECURSOR:
    398  1.1  tsubai 		fbp->fb_command = FB_CHIDECURSOR;
    399  1.1  tsubai 		fbstart(fbp, 0);
    400  1.1  tsubai 		break;
    401  1.1  tsubai 	case FBIOCNHIDECURSOR:
    402  1.1  tsubai 		fbp->fb_command = FB_CHIDECURSOR;
    403  1.1  tsubai 		fbstart(fbp, 0);
    404  1.1  tsubai 		break;
    405  1.1  tsubai 	case FBIOCSETXY:
    406  1.1  tsubai 		fbsetxy(fbp, (sPoint *)data);
    407  1.1  tsubai 		break;
    408  1.1  tsubai 	case FBIOCNSETXY:
    409  1.1  tsubai 		fbp->fb_command = FB_CSETXY;
    410  1.1  tsubai 		fbp->fb_point = *((lPoint *)data);
    411  1.1  tsubai 		fbstart(fbp, 0);
    412  1.1  tsubai 		break;
    413  1.1  tsubai 	case FBIOCNSETPALETTEMODE:
    414  1.1  tsubai 		fbp->fb_command = FB_CSETPMODE;
    415  1.1  tsubai 		fbp->fb_data = *((int*)data);
    416  1.1  tsubai 		fbstart(fbp, 0);
    417  1.1  tsubai 		break;
    418  1.1  tsubai 	case FBIOCNGETPALETTEMODE:
    419  1.1  tsubai 		fbp->fb_command = FB_CGETPMODE;
    420  1.1  tsubai 		fbstart(fbp, 1);
    421  1.1  tsubai 		*((int*)data) = fbp->fb_data;
    422  1.1  tsubai 		break;
    423  1.1  tsubai 	case FBIOCNSETVIDEO:
    424  1.1  tsubai 		fbp->fb_command = FB_CSETVIDEO;
    425  1.1  tsubai 		fbp->fb_videoctl = *((lVideoCtl*)data);
    426  1.1  tsubai 		fbstart(fbp, 0);
    427  1.1  tsubai 		break;
    428  1.1  tsubai 	case FBIOCNGETVIDEO:
    429  1.1  tsubai 		fbp->fb_command = FB_CGETVIDEO;
    430  1.1  tsubai 		fbp->fb_videostatus.request = VIDEO_STATUS;
    431  1.1  tsubai 		fbstart(fbp, 1);
    432  1.1  tsubai 		*((lVideoStatus*)data) = fbp->fb_videostatus;
    433  1.1  tsubai 		error = fbp->fb_result;
    434  1.1  tsubai 		break;
    435  1.1  tsubai 	case FBIOCNIOCTL:
    436  1.1  tsubai 		fbp->fb_command = FB_CIOCTL;
    437  1.1  tsubai 		fbp->fb_fbioctl = *((lFbIoctl*)data);
    438  1.1  tsubai 		fbstart(fbp, 1);
    439  1.1  tsubai 		*((lFbIoctl*)data) = fbp->fb_fbioctl;
    440  1.1  tsubai 		if (fbp->fb_result == FB_RERROR)
    441  1.1  tsubai 			error = EINVAL;
    442  1.1  tsubai 		break;
    443  1.1  tsubai 
    444  1.1  tsubai 	default:
    445  1.1  tsubai 		error = ENXIO;
    446  1.1  tsubai 		break;
    447  1.1  tsubai 	}
    448  1.1  tsubai 
    449  1.1  tsubai 	fbunlock(error);
    450  1.1  tsubai 
    451  1.1  tsubai 	return error;
    452  1.1  tsubai }
    453  1.1  tsubai 
    454  1.1  tsubai int
    455  1.1  tsubai fbmmap(dev, off, prot)
    456  1.1  tsubai 	dev_t dev;
    457  1.1  tsubai 	int off, prot;
    458  1.1  tsubai {
    459  1.1  tsubai 	register int unit = FBUNIT(dev);
    460  1.1  tsubai 	register struct fb_softc *fb = fb_cd.cd_devs[unit];
    461  1.1  tsubai 	register struct fbreg *fbp = &fb->fbreg;
    462  1.1  tsubai 	register int page;
    463  1.1  tsubai 
    464  1.1  tsubai 	if (unit >= NFB)
    465  1.1  tsubai 		return -1;
    466  1.1  tsubai 
    467  1.1  tsubai         if (off & PGOFSET)
    468  1.1  tsubai                 return -1;
    469  1.1  tsubai 
    470  1.1  tsubai 	if (off < 0)
    471  1.1  tsubai 		return -1;
    472  1.1  tsubai 
    473  1.1  tsubai 	fblock();
    474  1.1  tsubai 	fbp->fb_device = fb->fbs_device;
    475  1.1  tsubai 	fbp->fb_command = FB_CGETPAGE;
    476  1.1  tsubai 	fbp->fb_data = off;
    477  1.1  tsubai 	fbstart(fbp, 1);
    478  1.1  tsubai 	page = fbp->fb_data;
    479  1.1  tsubai 	if (fbp->fb_result == FB_RERROR)
    480  1.1  tsubai 		page = -1;
    481  1.1  tsubai 	else
    482  1.1  tsubai 		fb->fbs_flag = 1;
    483  1.1  tsubai 	fbunlock(fbp->fb_result);
    484  1.1  tsubai 
    485  1.1  tsubai 	return page;
    486  1.1  tsubai }
    487  1.1  tsubai 
    488  1.1  tsubai #if 0	/* not needed? */
    489  1.1  tsubai int
    490  1.1  tsubai fbpoll(dev, events, p)
    491  1.1  tsubai 	dev_t dev;
    492  1.1  tsubai 	int events;
    493  1.1  tsubai 	struct proc *p;
    494  1.1  tsubai {
    495  1.1  tsubai 	return -1;
    496  1.1  tsubai }
    497  1.1  tsubai #endif
    498  1.1  tsubai 
    499  1.1  tsubai static void
    500  1.1  tsubai fblock()
    501  1.1  tsubai {
    502  1.1  tsubai 	int s;
    503  1.1  tsubai 
    504  1.1  tsubai #ifdef USE_RAW_INTR
    505  1.1  tsubai 	fbwait();
    506  1.1  tsubai #endif
    507  1.1  tsubai 	s = splfb();
    508  1.1  tsubai 	while (fbstate & FB_BUSY) {
    509  1.1  tsubai 		fbstate |= FB_WANTED;
    510  1.1  tsubai 		tsleep(&fbstate, FBPRI | PCATCH, "fblock", 0);
    511  1.1  tsubai 	}
    512  1.1  tsubai 	fbstate |= FB_BUSY;
    513  1.1  tsubai 	splx(s);
    514  1.1  tsubai }
    515  1.1  tsubai 
    516  1.1  tsubai static void
    517  1.1  tsubai fbunlock(error)
    518  1.1  tsubai 	int error;
    519  1.1  tsubai {
    520  1.1  tsubai 	int s = splfb();
    521  1.1  tsubai 
    522  1.1  tsubai #ifdef CPU_SINGLE
    523  1.1  tsubai 	fbstate &= ~FB_BUSY;
    524  1.1  tsubai 	if (fbstate & FB_WANTED) {
    525  1.1  tsubai 		fbstate &= ~FB_WANTED;
    526  1.1  tsubai 		wakeup(&fbstate);
    527  1.1  tsubai 	}
    528  1.1  tsubai #else
    529  1.1  tsubai #ifdef USE_RAW_INTR
    530  1.1  tsubai 	fbstate &= ~FB_BUSY;
    531  1.1  tsubai 	if (fbstate & FB_WANTED) {
    532  1.1  tsubai 		fbstate &= ~FB_WANTED;
    533  1.1  tsubai 		wakeup(&fbstate);
    534  1.1  tsubai 	}
    535  1.1  tsubai #else
    536  1.1  tsubai 	if (error || (fbstate & FB_DELAY) == 0) {
    537  1.1  tsubai 		fbstate &= ~(FB_BUSY | FB_WAIT | FB_DELAY);
    538  1.1  tsubai 		if (fbstate & FB_WANTED) {
    539  1.1  tsubai 			fbstate &= ~FB_WANTED;
    540  1.1  tsubai 			wakeup(&fbstate);
    541  1.1  tsubai 		}
    542  1.1  tsubai 	}
    543  1.1  tsubai 	if (fbstate & FB_DELAY) {
    544  1.1  tsubai 		fbstate &= ~FB_DELAY;
    545  1.1  tsubai 		fbstate |= FB_DELAY2;
    546  1.1  tsubai 	}
    547  1.1  tsubai #endif
    548  1.1  tsubai #endif /* CPU_SINGLE */
    549  1.1  tsubai 	splx(s);
    550  1.1  tsubai }
    551  1.1  tsubai 
    552  1.1  tsubai static int
    553  1.1  tsubai fbinit(fbp)
    554  1.1  tsubai 	struct fbreg *fbp;
    555  1.1  tsubai {
    556  1.1  tsubai 	fblock();
    557  1.1  tsubai 
    558  1.1  tsubai 	fbp->fb_command = FB_COPEN;
    559  1.1  tsubai 	fbstart(fbp, 1);
    560  1.1  tsubai 	if (fbp->fb_result != FB_ROK) {
    561  1.1  tsubai 		fbunlock(0);
    562  1.1  tsubai 		return FB_RERROR;
    563  1.1  tsubai 	}
    564  1.1  tsubai 
    565  1.1  tsubai 	fbp->fb_command = FB_CUNSETCURSOR;
    566  1.1  tsubai 	fbstart(fbp, 0);
    567  1.1  tsubai 
    568  1.1  tsubai 	fbunlock(0);
    569  1.1  tsubai 
    570  1.1  tsubai 	return FB_ROK;
    571  1.1  tsubai }
    572  1.1  tsubai 
    573  1.1  tsubai static void
    574  1.1  tsubai fbreset(fbp)
    575  1.1  tsubai 	struct fbreg *fbp;
    576  1.1  tsubai {
    577  1.1  tsubai 	fblock();
    578  1.1  tsubai 
    579  1.1  tsubai 	fbp->fb_command = FB_CUNSETCURSOR;
    580  1.1  tsubai 	fbstart(fbp, 1);
    581  1.1  tsubai 
    582  1.1  tsubai 	fbp->fb_command = FB_CCLOSE;
    583  1.1  tsubai 	fbstart(fbp, 0);
    584  1.1  tsubai 
    585  1.1  tsubai 	fbunlock(0);
    586  1.1  tsubai }
    587  1.1  tsubai #endif /* NFB > 0 */
    588