⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mfb.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/*- * Copyright (c) 1992, 1993 *	The Regents of the University of California.  All rights reserved. * * This code is derived from software contributed to Berkeley by * Ralph Campbell and Rick Macklem. * * 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. * *	@(#)mfb.c	8.1 (Berkeley) 6/10/93 *//*  * Mach Operating System * Copyright (c) 1991,1990,1989 Carnegie Mellon University * All Rights Reserved. *  * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. *  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. *  * Carnegie Mellon requests users of this software to return to *  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU *  School of Computer Science *  Carnegie Mellon University *  Pittsburgh PA 15213-3890 *  * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. *//* *  devGraphics.c -- * *     	This file contains machine-dependent routines for the graphics device. * *	Copyright (C) 1989 Digital Equipment Corporation. *	Permission to use, copy, modify, and distribute this software and *	its documentation for any purpose and without fee is hereby granted, *	provided that the above copyright notice appears in all copies.   *	Digital Equipment Corporation makes no representations about the *	suitability of this software for any purpose.  It is provided "as is" *	without express or implied warranty. * * from: $Header: /sprite/src/kernel/dev/ds3100.md/RCS/devGraphics.c, *	v 9.2 90/02/13 22:16:24 shirriff Exp $ SPRITE (DECWRL)"; */#include <mfb.h>#if NMFB > 0#include <sys/param.h>#include <sys/time.h>#include <sys/kernel.h>#include <sys/ioctl.h>#include <sys/file.h>#include <sys/errno.h>#include <sys/proc.h>#include <sys/mman.h>#include <vm/vm.h>#include <machine/machConst.h>#include <machine/pmioctl.h>#include <pmax/pmax/cons.h>#include <pmax/pmax/pmaxtype.h>#include <pmax/dev/device.h>#include <pmax/dev/mfbreg.h>#include <pmax/dev/fbreg.h>#include <dc.h>#include <dtop.h>#include <scc.h>/* * These need to be mapped into user space. */struct fbuaccess mfbu;struct pmax_fb mfbfb;/* * Forward references. */static void mfbScreenInit();static void mfbLoadCursor();static void mfbRestoreCursorColor();static void mfbCursorColor();void mfbPosCursor();static void mfbInitColorMap();static void mfbLoadColorMap();static void mfbConfigMouse(), mfbDeconfigMouse();static void bt455_video_on(), bt455_video_off(), bt431_select_reg();static void bt431_write_reg(), bt431_init();static u_char bt431_read_reg();void mfbKbdEvent(), mfbMouseEvent(), mfbMouseButtons();#if NDC > 0extern void (*dcDivertXInput)();extern void (*dcMouseEvent)();extern void (*dcMouseButtons)();#endif#if NSCC > 0extern void (*sccDivertXInput)();extern void (*sccMouseEvent)();extern void (*sccMouseButtons)();#endif#if NDTOP > 0extern void (*dtopDivertXInput)();extern void (*dtopMouseEvent)();extern void (*dtopMouseButtons)();#endifextern int pmax_boardtype;extern u_short defCursor[32];extern struct consdev cn_tab;int	mfbprobe();struct	driver mfbdriver = {	"mfb", mfbprobe, 0, 0,};#define	MFB_OFFSET_VRAM		0x200000	/* from module's base */#define MFB_OFFSET_BT431	0x180000	/* Bt431 registers */#define MFB_OFFSET_BT455	0x100000	/* Bt455 registers */#define MFB_OFFSET_IREQ		0x080000	/* Interrupt req. control */#define MFB_OFFSET_ROM		0x0		/* Diagnostic ROM */#define MFB_FB_SIZE		0x200000	/* frame buffer size *//* * Test to see if device is present. * Return true if found and initialized ok. *//*ARGSUSED*/mfbprobe(cp)	register struct pmax_ctlr *cp;{	register struct pmax_fb *fp = &mfbfb;	if (!fp->initialized && !mfbinit(cp->pmax_addr))		return (0);	printf("mfb0 (mono display)\n");	return (1);}/*ARGSUSED*/mfbopen(dev, flag)	dev_t dev;	int flag;{	register struct pmax_fb *fp = &mfbfb;	int s;	if (!fp->initialized)		return (ENXIO);	if (fp->GraphicsOpen)		return (EBUSY);	fp->GraphicsOpen = 1;	mfbInitColorMap(1);	/*	 * Set up event queue for later	 */	fp->fbu->scrInfo.qe.eSize = PM_MAXEVQ;	fp->fbu->scrInfo.qe.eHead = fp->fbu->scrInfo.qe.eTail = 0;	fp->fbu->scrInfo.qe.tcSize = MOTION_BUFFER_SIZE;	fp->fbu->scrInfo.qe.tcNext = 0;	fp->fbu->scrInfo.qe.timestamp_ms = TO_MS(time);	mfbConfigMouse();	return (0);}/*ARGSUSED*/mfbclose(dev, flag)	dev_t dev;	int flag;{	register struct pmax_fb *fp = &mfbfb;	int s;	if (!fp->GraphicsOpen)		return (EBADF);	fp->GraphicsOpen = 0;	mfbInitColorMap(0);	mfbDeconfigMouse();	mfbScreenInit();	bzero((caddr_t)fp->fr_addr, 2048 * 1024);	mfbPosCursor(fp->col * 8, fp->row * 15);	return (0);}/*ARGSUSED*/mfbioctl(dev, cmd, data, flag, p)	dev_t dev;	caddr_t data;	struct proc *p;{	register struct pmax_fb *fp = &mfbfb;	int s;	switch (cmd) {	case QIOCGINFO:		return (fbmmap(fp, dev, data, p));	case QIOCPMSTATE:		/*		 * Set mouse state.		 */		fp->fbu->scrInfo.mouse = *(pmCursor *)data;		mfbPosCursor(fp->fbu->scrInfo.mouse.x, fp->fbu->scrInfo.mouse.y);		break;	case QIOCINIT:		/*		 * Initialize the screen.		 */		mfbScreenInit();		break;	case QIOCKPCMD:	    {		pmKpCmd *kpCmdPtr;		unsigned char *cp;		kpCmdPtr = (pmKpCmd *)data;		if (kpCmdPtr->nbytes == 0)			kpCmdPtr->cmd |= 0x80;		if (!fp->GraphicsOpen)			kpCmdPtr->cmd |= 1;		(*fp->KBDPutc)(fp->kbddev, (int)kpCmdPtr->cmd);		cp = &kpCmdPtr->par[0];		for (; kpCmdPtr->nbytes > 0; cp++, kpCmdPtr->nbytes--) {			if (kpCmdPtr->nbytes == 1)				*cp |= 0x80;			(*fp->KBDPutc)(fp->kbddev, (int)*cp);		}		break;	    }	case QIOCADDR:		*(PM_Info **)data = &fp->fbu->scrInfo;		break;	case QIOWCURSOR:		mfbLoadCursor((unsigned short *)data);		break;	case QIOWCURSORCOLOR:		mfbCursorColor((unsigned int *)data);		break;	case QIOSETCMAP:#ifdef notdef		mfbLoadColorMap((ColorMap *)data);#endif		break;	case QIOKERNLOOP:		mfbConfigMouse();		break;	case QIOKERNUNLOOP:		mfbDeconfigMouse();		break;	case QIOVIDEOON:		bt455_video_on();		break;	case QIOVIDEOOFF:		bt455_video_off();		break;	default:		printf("mfb0: Unknown ioctl command %x\n", cmd);		return (EINVAL);	}	return (0);}/* * Return the physical page number that corresponds to byte offset 'off'. *//*ARGSUSED*/mfbmap(dev, off, prot)	dev_t dev;{	int len;	len = pmax_round_page(((vm_offset_t)&mfbu & PGOFSET) + sizeof(mfbu));	if (off < len)		return pmax_btop(MACH_CACHED_TO_PHYS(&mfbu) + off);	off -= len;	if (off >= mfbfb.fr_size)		return (-1);	return pmax_btop(MACH_UNCACHED_TO_PHYS(mfbfb.fr_addr) + off);}mfbselect(dev, flag, p)	dev_t dev;	int flag;	struct proc *p;{	struct pmax_fb *fp = &mfbfb;	switch (flag) {	case FREAD:		if (fp->fbu->scrInfo.qe.eHead != fp->fbu->scrInfo.qe.eTail)			return (1);		selrecord(p, &fp->selp);		break;	}	return (0);}static u_char	cursor_RGB[6];	/* cursor color 2 & 3 *//* * There are actually 2 Bt431 cursor sprite chips that each generate 1 bit * of each cursor pixel for a 2bit 64x64 cursor sprite. The corresponding * registers for these two chips live in adjacent bytes of the shorts that * are defined in bt431_regmap_t. */static voidmfbLoadCursor(cursor)	u_short *cursor;{	register int i, j, k, pos;	register u_short ap, bp, out;	register bt431_regmap_t *regs;	regs = (bt431_regmap_t *)(mfbfb.fr_chipaddr +		 MFB_OFFSET_BT431);	/*	 * Fill in the cursor sprite using the A and B planes, as provided	 * for the pmax.	 * XXX This will have to change when the X server knows that this	 * is not a pmax display. (ie. Not the Xcfbpmax server.)	 */	pos = 0;	bt431_select_reg(regs, BT431_REG_CRAM_BASE);	for (k = 0; k < 16; k++) {		ap = *cursor;		bp = *(cursor + 16);		j = 0;		while (j < 2) {			out = 0;			for (i = 0; i < 8; i++) {				out = (out << 1) | ((bp & 0x1) << 8) |					(ap & 0x1);				ap >>= 1;				bp >>= 1;			}			BT431_WRITE_CMAP_AUTOI(regs, out);			pos++;			j++;		}		while (j < 8) {			BT431_WRITE_CMAP_AUTOI(regs, 0);			pos++;			j++;		}		cursor++;	}	while (pos < 512) {		BT431_WRITE_CMAP_AUTOI(regs, 0);		pos++;	}}/* * Initialization */intmfbinit(cp)	char *cp;{	register struct pmax_fb *fp = &mfbfb;	/* check for no frame buffer */	if (badaddr(cp, 4))		return (0);	fp->isMono = 0;	fp->fr_addr = cp + MFB_OFFSET_VRAM;	fp->fr_chipaddr = cp;	fp->fr_size = MFB_FB_SIZE;	/*	 * Must be in Uncached space since the fbuaccess structure is	 * mapped into the user's address space uncached.	 */	fp->fbu = (struct fbuaccess *)		MACH_PHYS_TO_UNCACHED(MACH_CACHED_TO_PHYS(&mfbu));	fp->posCursor = mfbPosCursor;	if (tb_kbdmouseconfig(fp))		return (0);	/*	 * Initialize the screen.	 */	bt431_init(fp->fr_chipaddr + MFB_OFFSET_BT431);	/*	 * Initialize screen info.	 */	fp->fbu->scrInfo.max_row = 67;	fp->fbu->scrInfo.max_col = 80;	fp->fbu->scrInfo.max_x = 1280;	fp->fbu->scrInfo.max_y = 1024;	fp->fbu->scrInfo.max_cur_x = 1279;	fp->fbu->scrInfo.max_cur_y = 1023;	fp->fbu->scrInfo.version = 11;	fp->fbu->scrInfo.mthreshold = 4;	fp->fbu->scrInfo.mscale = 2;	fp->fbu->scrInfo.min_cur_x = 0;	fp->fbu->scrInfo.min_cur_y = 0;	fp->fbu->scrInfo.qe.timestamp_ms = TO_MS(time);	fp->fbu->scrInfo.qe.eSize = PM_MAXEVQ;	fp->fbu->scrInfo.qe.eHead = fp->fbu->scrInfo.qe.eTail = 0;	fp->fbu->scrInfo.qe.tcSize = MOTION_BUFFER_SIZE;	fp->fbu->scrInfo.qe.tcNext = 0;	/*	 * Initialize the color map, the screen, and the mouse.	 */	mfbInitColorMap(0);	mfbScreenInit();	fbScroll(fp);	fp->initialized = 1;	if (cn_tab.cn_fb == (struct pmax_fb *)0)		cn_tab.cn_fb = fp;	return (1);}/* * ---------------------------------------------------------------------------- * * mfbScreenInit -- * *	Initialize the screen.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -