📄 fb.c
字号:
/* * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Sony Corp. and Kazumasa Utashiro of Software Research Associates, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * from: $Hdr: fb.c,v 4.300 91/06/27 20:43:06 root Rel41 $ SONY * * @(#)fb.c 8.1 (Berkeley) 6/11/93 */#include "fb.h"#if NFB > 0/* * Frame buffer driver */#include <sys/types.h>#include <machine/pte.h>#include <machine/cpu.h>#include <sys/param.h>#include <sys/proc.h>#include <sys/user.h>#include <sys/buf.h>#include <vm/vm.h>#include <sys/systm.h>#include <sys/map.h>#include <sys/uio.h>#include <sys/kernel.h>#include <news3400/iop/framebuf.h>#include <news3400/iop/fbreg.h>#include <news3400/iodev/ioptohb.h>#ifdef CPU_SINGLE#include <news3400/hbdev/hbvar.h>#define ipc_phys(x) (caddr_t)((int)(x))#define ipc_log(x) (caddr_t)((int)(x) | 0x80000000)#define iop_driver hb_driver#define iop_device hb_deviceextern rop_xint();#else /* CPU_SINGLE */#include <news3400/iop/iopvar.h>#ifdef IPC_MRX#include "../ipc/newsipc.h"#ifdef mips#define ipc_phys(x) K0_TT0(x)#define ipc_log(x) TT0_K0(x)#else#define ipc_phys(x) (caddr_t)((int)(x) & ~0x80000000)#define ipc_log(x) (caddr_t)((int)(x) | 0x80000000)#endifstatic int port_fb, port_fb_iop;#endif /* IPC_MRX */#endif /* CPU_SINGLE */#define FB_USED 1#define VIDEO_USED 2/* * driver definition */int fbprobe(), fbattach();struct iop_device *fbinfo[NFB];struct iop_driver fbdriver =#ifdef CPU_SINGLE { fbprobe, 0, fbattach, 0, 0, "fb", fbinfo, "fbc", 0, 0 };#else { fbprobe, 0, fbattach, 0, "fb", fbinfo };#endif/* static */static struct fb_softc fb_softc[NFB];static struct fbreg fbreg[NFB];static int fbstate;static struct fbreg *last_fb;static char *devname[] = {/* 0*/ "",/* 1*/ "NWB-512",/* 2*/ "NWB-225",/* 3*/ "POP-MONO",/* 4*/ "POP-COLOR",/* 5*/ "NWB-514",/* 6*/ "NWB-251",/* 7*/ "LCD-MONO",/* 8*/ "LDC-COLOR",/* 9*/ "NWB-518",/*10*/ "NWB-252",/*11*/ "NWB-253",/*12*/ "NWB-254",/*13*/ "NWB-255",/*14*/ "SLB-101",/*15*/ "NWB-256",/*16*/ "NWB-257",};static void fblock(), fbunlock(), fbreset();static int fbinit();#ifdef CPU_DOUBLE#ifdef USE_RAW_INTR#include "../mrx/h/ipc.h"#ifdef mips# define FB_ADDR &IPC_ARG(&ipc_block, ARG_CPU, 4)#else# define FB_ADDR &IPC_ARG(&ipc_block, ARG_CPU0, 4)# define volatile#endiftypedef struct fbreg *fbregp;int fb_waiting;Xfb_intr(chan, arg) int chan; int arg;{ intrcnt[INTR_BITMAP]++; if (fb_waiting) { fb_waiting = 0; wakeup((caddr_t)&fb_waiting); }}static voidfbwait(){ int s = splfb(); while (*(volatile fbregp *)FB_ADDR) { fb_waiting = 1; sleep((caddr_t)&fb_waiting, FBPRI); } (void) splx(s);}voidfbstart(fbp, wait) struct fbreg *fbp; int wait;{ fbwait(); *(volatile fbregp *)FB_ADDR =#ifdef mips (volatile fbregp)ipc_phys(MACH_UNCACHED_TO_CACHED(fbp));#else (volatile fbregp)ipc_phys(fbp);#endif if (wait) fbwait();}#else /* USE_RAW_INTR */voidfbstart(fbp, wait) register struct fbreg *fbp; int wait;{ int s = splfb();#ifdef IPC_MRX msg_send(port_fb_iop, port_fb, fbp, sizeof(*fbp), MSG_INDIRECT);#endif last_fb = fbp; if (wait) { fbstate |= FB_WAIT; sleep((caddr_t)fbreg, FBPRI); } else { fbstate |= FB_DELAY; } splx(s);}voidfbcint(arg) int arg;{ intrcnt[INTR_BITMAP]++;#ifdef IPC_MRX msg_recv(arg, NULL, NULL, NULL, 0);#ifdef mips clean_dcache((caddr_t)last_fb, sizeof(struct fbreg));#endif#endif /* IPC_MRX */ if (fbstate & FB_WAIT) { fbstate &= ~FB_WAIT; wakeup((caddr_t)fbreg); } else if (fbstate & FB_DELAY) { fbstate &= ~FB_DELAY; } else if (fbstate & FB_DELAY2) { fbstate &= ~(FB_BUSY|FB_DELAY2); if (fbstate & FB_WANTED) { fbstate &= ~FB_WANTED; wakeup((caddr_t)&fbstate); } } return;}#endif /* USE_RAW_INTR */#endif /* CPU_DOUBLE *//* ARGSUSED */fbprobe(ii) struct iop_device *ii;{ register int unit = ii->ii_unit; register struct fb_softc *fb = &fb_softc[unit];#if defined(IPC_MRX) && defined(mips) register struct fbreg *fbp = (struct fbreg *)MACH_CACHED_TO_UNCACHED(&fbreg[unit]);#else register struct fbreg *fbp = &fbreg[unit];#endif#ifdef CPU_SINGLE if (unit == 0) register_hb_intr2(rop_xint, ii->ii_unit, ii->ii_intr);#endif#ifdef IPC_MRX if (port_fb_iop <= 0) {#ifdef USE_RAW_INTR register_ipcintr(4, Xfb_intr);#endif port_fb_iop = object_query("framebuf"); if (port_fb_iop <= 0) { return (0); }#ifndef USE_RAW_INTR port_fb = port_create("@port_fb", fbcint, -1);#endif }#endif /* IPC_MRX */ fbp->fb_command = FB_CPROBE; fbp->fb_device = 0; fbp->fb_unit = unit; fbp->fb_data = -1; fbstart(fbp, 1); if ((fb->fbs_device = fbp->fb_data) == -1) return (0); else return (-1);}/* ARGSUSED */fbattach(ii) struct iop_device *ii;{ register int unit = ii->ii_unit; register struct fb_softc *fb = &fb_softc[unit];#if defined(IPC_MRX) && defined(mips) register struct fbreg *fbp = (struct fbreg *)MACH_CACHED_TO_UNCACHED(&fbreg[unit]);#else register struct fbreg *fbp = &fbreg[unit];#endif fbp->fb_command = FB_CATTACH; fbp->fb_device = fb->fbs_device; fbstart(fbp, 1); fb->fbs_type = fbp->fb_scrtype; if (fb->fbs_type.type) { fb->fbs_state = 0; fb->fbs_flag = 0; printf("fb%d: %s", unit, (fb->fbs_type.type < sizeof(devname)/sizeof(*devname)) ? devname[fb->fbs_type.type] : "UNKNOWN"); printf(" (%d x %d %d plane)\n", fb->fbs_type.visiblerect.extent.x, fb->fbs_type.visiblerect.extent.y, fb->fbs_type.plane); }}/*ARGSUSED*/fbopen(dev, flag) dev_t dev; int flag;{ register int unit = FBUNIT(dev); register struct fb_softc *fb = &fb_softc[unit]; register struct iop_device *ii;#if defined(IPC_MRX) && defined(mips) register struct fbreg *fbp = (struct fbreg *)MACH_CACHED_TO_UNCACHED(&fbreg[unit]);#else register struct fbreg *fbp = &fbreg[unit];#endif if (unit >= NFB || (ii = fbinfo[unit]) == 0 || ii->ii_alive == 0) return (ENXIO); if (fb->fbs_flag && !FBVIDEO(dev)) return (EBUSY); if (fb->fbs_state == 0) { fbp->fb_device = fb->fbs_device; if(fbinit(fbp)) return (EBUSY); } fb->fbs_state |= FBVIDEO(dev) ? VIDEO_USED : FB_USED; return (0);}/*ARGSUSED*/fbclose(dev, flag) dev_t dev; int flag;{ register int unit = FBUNIT(dev); register struct fb_softc *fb = &fb_softc[unit];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -