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

📄 vfb.c

📁 SigmDesign SMP8634 media decode chip development SDK
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  linux/drivers/video/vfb.c -- Virtual frame buffer device * *	Copyright (C) 1997 Geert Uytterhoeven * *  This file is subject to the terms and conditions of the GNU General Public *  License. See the file COPYING in the main directory of this archive for *  more details. */#define ALLOW_OS_CODE 1#include "kernelcalls.h"#include "gbus.h"#include "mambolfb.h"#include <linux/module.h>#include <linux/vmalloc.h>#include <asm/uaccess.h>#include <linux/fb.h>#include <video/fbcon.h>#include <video/fbcon-mfb.h>#include <video/fbcon-cfb2.h>#include <video/fbcon-cfb4.h>#include <video/fbcon-cfb8.h>#include <video/fbcon-cfb16.h>#include <video/fbcon-cfb24.h>#include <video/fbcon-cfb32.h>#if 0#define DEB(f) (f)#else#define DEB(f)#endif#define RM_OSDBUFWIDTH 640#define RM_OSDBUFHEIGHT 480#define RM_OSDBUFDEPTH 32static u_long videomemory=0, videomemorysize=0, palette=0;static char bound=0;static char *mode;MODULE_PARM(videomemorysize, "l");MODULE_PARM_DESC(videomemorysize, "Size of the OSD buffer.\n");MODULE_PARM(videomemory, "l");MODULE_PARM_DESC(videomemory, "Address of the OSD buffer (DRAM address).\n");MODULE_PARM(palette, "l");MODULE_PARM_DESC(palette, "Address of the OSD palette (DRAM address).\n");MODULE_PARM(mode, "s");MODULE_PARM_DESC(mode, "Video mode : with:height:bpp.\n");#ifdef MODULE_LICENSEMODULE_LICENSE("GPL");#endif#define CHECK_BOUND()									\if (!bound){										\	printk(KERN_INFO "%s : Mambo/Tango frame buffer not bound yet.\n", __func__);	\	return -EAGAIN;									\}static int currcon = 0;static struct display disp;static struct fb_info fb_info;#if defined(FBCON_HAS_CFB16) || defined(FBCON_HAS_CFB24) || defined(FBCON_HAS_CFB32)static union {#ifdef FBCON_HAS_CFB16	u16 cfb16[16];#endif#ifdef FBCON_HAS_CFB24	u32 cfb24[16];#endif#ifdef FBCON_HAS_CFB32	u32 cfb32[16];#endif} fbcon_cmap;#endif /* FBCON_HAS_CFB16 || FBCON_HAS_CFB24 || FBCON_HAS_CFB32 */static char mambolfb_name[32] = "Mambo/Tango Linux Frame Buffer";/* Those values arr changed during init */static struct fb_var_screeninfo mambolfb_default = {	RM_OSDBUFWIDTH, RM_OSDBUFHEIGHT, RM_OSDBUFWIDTH, RM_OSDBUFHEIGHT, 0, 0, RM_OSDBUFDEPTH, 0,	{16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {24, 8, 0},	0, 0, -1, -1, 0, 20000, 64, 64, 32, 32, 64, 2,	0, FB_VMODE_NONINTERLACED};static struct osd_descriptor{	RMuint32 region_index;          //First region used to map the OSD buffer	RMuint32 region_count;          //How many regions for the OSD buffer	RMuint32 offset;                //offset from the base address of the first region} osd;static struct llad *p_llad;static struct gbus *p_gbus;/* Some RedHat systems have CONFIG_HIGHPTE, so pte_offset is renamed */#ifndef pte_offset#define pte_offset pte_offset_kernel#endif/* This is used to get the physical address or cookie associated to an iomapped area  *  See http://www.xml.com/ldd/chapter/book/ch13.html */#if (RMARCHID==RMARCHID_MIPS)#define io_virt_to_phys(v) kc_virt_to_phys(v)#else#define io_virt_to_phys(v) (pte_val(*(pte_t *)pte_offset(pmd_offset(pgd_offset_k((v)), (v)), (v))) & PAGE_MASK) + ((v) & ~PAGE_MASK)#endifstatic int mambolfb_mmap(struct fb_info *info, struct file *file, struct vm_area_struct *vma){	unsigned long phys;	/* physical address to map */	CHECK_BOUND();#if (RMPLATFORM==RMPLATFORMID_AOE6_SH4)	phys = videomemory;#elif (RMPLATFORM==RMPLATFORMID_JASPERMAMBO)	phys = videomemory;#elif (RMPLATFORM==RMPLATFORMID_IXDP425)	phys = videomemory;#else	phys = io_virt_to_phys(videomemory);#endif	printk("mambolfb_mmap: OSD videomemory asked:0x%08lx\n",phys);	/* This should really be kc_io_remap_range, but as long as we don't	 * port on alpha or sparc, it's enough */	if (kc_remap_page_range((struct kc_vm_area_struct *) vma,	                        vma->vm_start, phys,	                        vma->vm_end-vma->vm_start,	                        (struct kc_pgprot_t *) &vma->vm_page_prot)) 		return -EAGAIN;	printk("mambolfb_mmap remapped %ld bytes in userland of process %d at address vma_start0x%08lx to phys=0x%08lx\n",	       vma->vm_end-vma->vm_start,current->pid,vma->vm_start, phys); 	return 0;}static u_long get_line_length(int xres_virtual, int bpp){	u_long length;    	length = xres_virtual*bpp;	length = (length+31)&-32;	length >>= 3;	return(length);}static void mambolfb_encode_fix(struct fb_fix_screeninfo *fix,                             struct fb_var_screeninfo *var){	memset(fix, 0, sizeof(struct fb_fix_screeninfo));	strcpy(fix->id, mambolfb_name);	fix->smem_start = videomemory;	fix->smem_len = videomemorysize;	fix->type = FB_TYPE_PACKED_PIXELS;	fix->type_aux = 0;	switch (var->bits_per_pixel) {		case 1:			fix->visual = FB_VISUAL_MONO01;			break;		case 2:		case 4:		case 8:			fix->visual = FB_VISUAL_PSEUDOCOLOR;			break;		case 16:		case 24:		case 32:			fix->visual = FB_VISUAL_TRUECOLOR;			break;	}	fix->ywrapstep = 1;	fix->xpanstep = 1;	fix->ypanstep = 1;	fix->line_length = get_line_length(var->xres_virtual, var->bits_per_pixel);}/* *  Get the Fixed Part of the Display */static int mambolfb_get_fix(struct fb_fix_screeninfo *fix, int con,                         struct fb_info *info){	struct fb_var_screeninfo *var;	CHECK_BOUND();	DEB(printk("mambolfb_get_fix, con = %d\n",con));	if (con == -1)		var = &mambolfb_default;	else		var = &fb_display[con].var;	mambolfb_encode_fix(fix, var);	return 0;}static void set_color_bitfields(struct fb_var_screeninfo *var){	switch (var->bits_per_pixel) {		case 1:		case 8:			var->red.offset = 0;			var->red.length = 8;			var->green.offset = 0;			var->green.length = 8;			var->blue.offset = 0;			var->blue.length = 8;			var->transp.offset = 0;			var->transp.length = 0;			break;		case 16:	/* RGB 565 */			var->red.offset = 11;			var->red.length = 5;			var->green.offset = 5;			var->green.length = 6;			var->blue.offset = 0;			var->blue.length = 5;			var->transp.offset = 0;			var->transp.length = 0;			break;		case 24:	/* RGB 888 */			var->red.offset = 16;			var->red.length = 8;			var->green.offset = 8;			var->green.length = 8;			var->blue.offset = 0;			var->blue.length = 8;			var->transp.offset = 0;			var->transp.length = 0;			break;		case 32:	/* ARGB 8888 */			var->red.offset = 16;			var->red.length = 8;			var->green.offset = 8;			var->green.length = 8;			var->blue.offset = 0;			var->blue.length = 8;			var->transp.offset = 24;			var->transp.length = 8;			break;	}	var->red.msb_right = 0;	var->green.msb_right = 0;	var->blue.msb_right = 0;	var->transp.msb_right = 0;}/* *  Get the User Defined Part of the Display */static int mambolfb_get_var(struct fb_var_screeninfo *var, int con,                         struct fb_info *info){	CHECK_BOUND();	if (con == -1)		*var = mambolfb_default;	else		*var = fb_display[con].var;	set_color_bitfields(var);	return 0;}/* *  Read a single color register and split it into *  colors/transparent. Return != 0 for invalid regno. *  # on 84XX */static int mambolfb_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,                           u_int *transp, struct fb_info *info){	RMuint32 color ;		if (regno > 255)		return 1;	DEB(printk("getcolreg %d\n",regno));	color = gbus_read_uint32(p_gbus,palette+regno*4);	*red = color >> 16 & 0xFF;	*green = color >> 8 & 0xFF;	*blue = color & 0xFF;	*transp = 0xFF;	return 0;}/* *  Set a single color register. The values supplied are already *  rounded down to the hardware's capabilities (according to the *  entries in the var structure). Return != 0 for invalid regno. */static int mambolfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,                           u_int transp, struct fb_info *info){	RMuint32 color;	CHECK_BOUND();		if (regno > 255)		return 1;	DEB(printk("setcolreg reg %d, (%lx,%lx,%lx,%lx)\n",regno,red,green,blue,transp));	red >>= 8;	green >>= 8;	blue >>= 8;		color = 0xFF << 24 | red << 16 | green << 8 | blue;	gbus_write_uint32(p_gbus,palette+regno*4,color);	/* Set colors for fb console */	if (regno < 16){		switch(fb_display[currcon].var.bits_per_pixel){			case 16:#ifdef FBCON_HAS_CFB16				red >>= 3;				green >>= 2;				blue >>= 3;				fbcon_cmap.cfb16[regno] = (u16) red << 11 | (u16) green << 5 | (u16) blue ;#endif				break;			case 24:#ifdef FBCON_HAS_CFB24				fbcon_cmap.cfb24[regno] = 0xFF << 24 | red << 16 | green << 8 | blue ;#endif				break;			case 32:#ifdef FBCON_HAS_CFB32				fbcon_cmap.cfb32[regno] = 0xFF << 24 | red << 16 | green << 8 | blue ;#endif				break;			default:				printk(KERN_WARNING "Warning, mambolfb_setcolreg, unsupported resolution : %d\n",				       info->var.bits_per_pixel);		}	}	return 0;}static void do_install_cmap(int con, struct fb_info *info){	if (con != currcon)		return;	if (fb_display[con].cmap.len)		fb_set_cmap(&fb_display[con].cmap, 1, mambolfb_setcolreg, info);	else		fb_set_cmap(fb_default_cmap(1<<fb_display[con].var.bits_per_pixel), 1,		            mambolfb_setcolreg, info);}/* *  Set the User Defined Part of the Display (different en 84XX) */static int mambolfb_set_var(struct fb_var_screeninfo *var, int con,		         struct fb_info *info){	int err, activate = var->activate;	int oldxres, oldyres, oldvxres, oldvyres, oldbpp;	u_long line_length;	struct display *display;	CHECK_BOUND();	DEB(printk("mambolfb_set_var, con = %d\n",con));	if (con >= 0)		display = &fb_display[con];	else		display = &disp;	/* used during initialization */	/*	 *  FB_VMODE_CONUPDATE and FB_VMODE_SMOOTH_XPAN are equal!	 *  as FB_VMODE_SMOOTH_XPAN is only used internally	 */	if (var->vmode & FB_VMODE_CONUPDATE) {		var->vmode |= FB_VMODE_YWRAP;		var->xoffset = display->var.xoffset;		var->yoffset = display->var.yoffset;	}	/*	 *  Some very basic checks	 */	if (!var->xres)		var->xres = 1;	if (!var->yres)		var->yres = 1;	if (var->xres > var->xres_virtual)		var->xres_virtual = var->xres;	if (var->yres > var->yres_virtual)		var->yres_virtual = var->yres;	if (var->bits_per_pixel <= 1)		var->bits_per_pixel = 1;	else if (var->bits_per_pixel <= 8)		var->bits_per_pixel = 8;	else if (var->bits_per_pixel <= 16)		var->bits_per_pixel = 16;	/* fbcon doesn't support this (yet) */	else if (var->bits_per_pixel <= 24)		var->bits_per_pixel = 24;	else if (var->bits_per_pixel <= 32)		var->bits_per_pixel = 32;	else		return -EINVAL;	/*	 *  Memory limit	 */	line_length = get_line_length(var->xres_virtual, var->bits_per_pixel);	DEB(printk("Line length = %d (%dx%d)\n",line_length,var->xres_virtual,var->bits_per_pixel));	if (line_length*var->yres_virtual > videomemorysize){		printk("Error, frame buffer doesn't have enough memory\n");		return -ENOMEM;	}	set_color_bitfields(var);	if ((activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {

⌨️ 快捷键说明

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