Home | History | Annotate | Line # | Download | only in dev
fb.c revision 1.4
      1 /*	$NetBSD: fb.c,v 1.4 1996/12/17 21:10:41 gwr Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1992, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This software was developed by the Computer Systems Engineering group
      8  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9  * contributed to Berkeley.
     10  *
     11  * All advertising materials mentioning features or use of this software
     12  * must display the following acknowledgement:
     13  *	This product includes software developed by the University of
     14  *	California, Lawrence Berkeley Laboratory.
     15  *
     16  * Redistribution and use in source and binary forms, with or without
     17  * modification, are permitted provided that the following conditions
     18  * are met:
     19  * 1. Redistributions of source code must retain the above copyright
     20  *    notice, this list of conditions and the following disclaimer.
     21  * 2. Redistributions in binary form must reproduce the above copyright
     22  *    notice, this list of conditions and the following disclaimer in the
     23  *    documentation and/or other materials provided with the distribution.
     24  * 3. All advertising materials mentioning features or use of this software
     25  *    must display the following acknowledgement:
     26  *	This product includes software developed by the University of
     27  *	California, Berkeley and its contributors.
     28  * 4. Neither the name of the University nor the names of its contributors
     29  *    may be used to endorse or promote products derived from this software
     30  *    without specific prior written permission.
     31  *
     32  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     33  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     34  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     35  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     36  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     40  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     41  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     42  * SUCH DAMAGE.
     43  *
     44  *	@(#)fb.c	8.1 (Berkeley) 6/11/93
     45  */
     46 
     47 /*
     48  * /dev/fb (indirect frame buffer driver).
     49  */
     50 
     51 #include <sys/param.h>
     52 #include <sys/systm.h>
     53 #include <sys/conf.h>
     54 #include <sys/device.h>
     55 #include <sys/ioctl.h>
     56 #include <sys/proc.h>
     57 
     58 #include <machine/fbio.h>
     59 
     60 #include "fbvar.h"
     61 
     62 cdev_decl(fb);
     63 
     64 static struct fbdevice *devfb;
     65 static int fbpriority;
     66 
     67 /*
     68  * This is called by the real driver (i.e. bw2, cg3, ...)
     69  * to declare itself as a potential default frame buffer.
     70  */
     71 void
     72 fb_attach(fb, newpri)
     73 	struct fbdevice *fb;
     74 	int newpri;
     75 {
     76 	if (fbpriority < newpri) {
     77 		fbpriority = newpri;
     78 		devfb = fb;
     79 	}
     80 }
     81 
     82 int
     83 fbopen(dev, flags, mode, p)
     84 	dev_t dev;
     85 	int flags, mode;
     86 	struct proc *p;
     87 {
     88 
     89 	if (devfb == NULL)
     90 		return (ENXIO);
     91 	return ((*devfb->fb_driver->fbd_open)(dev, flags, mode, p));
     92 }
     93 
     94 int
     95 fbclose(dev, flags, mode, p)
     96 	dev_t dev;
     97 	int flags, mode;
     98 	struct proc *p;
     99 {
    100 
    101 	return ((*devfb->fb_driver->fbd_close)(dev, flags, mode, p));
    102 }
    103 
    104 int
    105 fbioctl(dev, cmd, data, flags, p)
    106 	dev_t dev;
    107 	u_long cmd;
    108 	caddr_t data;
    109 	int flags;
    110 	struct proc *p;
    111 {
    112 	return (fbioctlfb(devfb, cmd, data));
    113 }
    114 
    115 int
    116 fbmmap(dev, off, prot)
    117 	dev_t dev;
    118 	int off, prot;
    119 {
    120 	return ((*devfb->fb_driver->fbd_mmap)(dev, off, prot));
    121 }
    122 
    123 /*
    124  * Common fb ioctl function
    125  */
    126 int
    127 fbioctlfb(fb, cmd, data)
    128 	struct fbdevice *fb;
    129 	u_long cmd;
    130 	caddr_t data;
    131 {
    132 	struct fbdriver *fbd = fb->fb_driver;
    133 	void *vp = (void *)data;
    134 	int error;
    135 
    136 	switch (cmd) {
    137 
    138 	case FBIOGTYPE:
    139 		*(struct fbtype *)vp = fb->fb_fbtype;
    140 		error = 0;
    141 		break;
    142 
    143 	case FBIOGATTR:
    144 		error = (*fbd->fbd_gattr)(fb, vp);
    145 		break;
    146 
    147 	case FBIOGVIDEO:
    148 		error = (*fbd->fbd_gvideo)(fb, vp);
    149 		break;
    150 
    151 	case FBIOSVIDEO:
    152 		error = (*fbd->fbd_svideo)(fb, vp);
    153 		break;
    154 
    155 	case FBIOGETCMAP:
    156 		error = (*fbd->fbd_getcmap)(fb, vp);
    157 		break;
    158 
    159 	case FBIOPUTCMAP:
    160 		error = (*fbd->fbd_putcmap)(fb, vp);
    161 		break;
    162 
    163 	default:
    164 		error = ENOTTY;
    165 	}
    166 	return (error);
    167 }
    168 
    169 void
    170 fb_unblank()
    171 {
    172 	int on = 1;
    173 
    174 	if (devfb == NULL)
    175 		return;
    176 
    177 	(*devfb->fb_driver->fbd_svideo)(devfb, (void *)&on);
    178 }
    179 
    180 /*
    181  * Default ioctl function to put in struct fbdriver
    182  * for functions that are not supported.
    183  */
    184 int
    185 fb_noioctl(fbd, vp)
    186 	struct fbdevice *fbd;
    187 	void *vp;
    188 {
    189 	return ENOTTY;
    190 }
    191 
    192