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

📄 uvesafb.c

📁 Linux环境下视频显示卡设备的驱动程序源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
				(green << info->var.green.offset) |				(blue  << info->var.blue.offset);			break;		}	}	return err;}static int uvesafb_setcmap(struct fb_cmap *cmap, struct fb_info *info){	struct uvesafb_pal_entry *entries;	int shift = 16 - info->var.green.length;	int i, err = 0;	if (info->var.bits_per_pixel == 8) {		if (cmap->start + cmap->len > info->cmap.start +		    info->cmap.len || cmap->start < info->cmap.start)			return -EINVAL;		entries = kmalloc(sizeof(*entries) * cmap->len, GFP_KERNEL);		if (!entries)			return -ENOMEM;		for (i = 0; i < cmap->len; i++) {			entries[i].red   = cmap->red[i]   >> shift;			entries[i].green = cmap->green[i] >> shift;			entries[i].blue  = cmap->blue[i]  >> shift;			entries[i].pad   = 0;		}		err = uvesafb_setpalette(entries, cmap->len, cmap->start, info);		kfree(entries);	} else {		/*		 * For modes with bpp > 8, we only set the pseudo palette in		 * the fb_info struct. We rely on uvesafb_setcolreg to do all		 * sanity checking.		 */		for (i = 0; i < cmap->len; i++) {			err |= uvesafb_setcolreg(cmap->start + i, cmap->red[i],						cmap->green[i], cmap->blue[i],						0, info);		}	}	return err;}static int uvesafb_pan_display(struct fb_var_screeninfo *var,		struct fb_info *info){#ifdef CONFIG_X86_32	int offset;	struct uvesafb_par *par = info->par;	offset = (var->yoffset * info->fix.line_length + var->xoffset) / 4;	/*	 * It turns out it's not the best idea to do panning via vm86,	 * so we only allow it if we have a PMI.	 */	if (par->pmi_start) {		__asm__ __volatile__(			"call *(%%edi)"			: /* no return value */			: "a" (0x4f07),         /* EAX */			  "b" (0),              /* EBX */			  "c" (offset),         /* ECX */			  "d" (offset >> 16),   /* EDX */			  "D" (&par->pmi_start));    /* EDI */	}#endif	return 0;}static int uvesafb_blank(int blank, struct fb_info *info){	struct uvesafb_ktask *task;	int err = 1;#ifdef CONFIG_X86	struct uvesafb_par *par = info->par;	if (par->vbe_ib.capabilities & VBE_CAP_VGACOMPAT) {		int loop = 10000;		u8 seq = 0, crtc17 = 0;		if (blank == FB_BLANK_POWERDOWN) {			seq = 0x20;			crtc17 = 0x00;			err = 0;		} else {			seq = 0x00;			crtc17 = 0x80;			err = (blank == FB_BLANK_UNBLANK) ? 0 : -EINVAL;		}		vga_wseq(NULL, 0x00, 0x01);		seq |= vga_rseq(NULL, 0x01) & ~0x20;		vga_wseq(NULL, 0x00, seq);		crtc17 |= vga_rcrt(NULL, 0x17) & ~0x80;		while (loop--);		vga_wcrt(NULL, 0x17, crtc17);		vga_wseq(NULL, 0x00, 0x03);	} else#endif /* CONFIG_X86 */	{		task = uvesafb_prep();		if (!task)			return -ENOMEM;		task->t.regs.eax = 0x4f10;		switch (blank) {		case FB_BLANK_UNBLANK:			task->t.regs.ebx = 0x0001;			break;		case FB_BLANK_NORMAL:			task->t.regs.ebx = 0x0101;	/* standby */			break;		case FB_BLANK_POWERDOWN:			task->t.regs.ebx = 0x0401;	/* powerdown */			break;		default:			goto out;		}		err = uvesafb_exec(task);		if (err || (task->t.regs.eax & 0xffff) != 0x004f)			err = 1;out:		uvesafb_free(task);	}	return err;}static int uvesafb_open(struct fb_info *info, int user){	struct uvesafb_par *par = info->par;	int cnt = atomic_read(&par->ref_count);	if (!cnt && par->vbe_state_size)		par->vbe_state_orig = uvesafb_vbe_state_save(par);	atomic_inc(&par->ref_count);	return 0;}static int uvesafb_release(struct fb_info *info, int user){	struct uvesafb_ktask *task = NULL;	struct uvesafb_par *par = info->par;	int cnt = atomic_read(&par->ref_count);	if (!cnt)		return -EINVAL;	if (cnt != 1)		goto out;	task = uvesafb_prep();	if (!task)		goto out;	/* First, try to set the standard 80x25 text mode. */	task->t.regs.eax = 0x0003;	uvesafb_exec(task);	/*	 * Now try to restore whatever hardware state we might have	 * saved when the fb device was first opened.	 */	uvesafb_vbe_state_restore(par, par->vbe_state_orig);out:	atomic_dec(&par->ref_count);	if (task)		uvesafb_free(task);	return 0;}static int uvesafb_set_par(struct fb_info *info){	struct uvesafb_par *par = info->par;	struct uvesafb_ktask *task = NULL;	struct vbe_crtc_ib *crtc = NULL;	struct vbe_mode_ib *mode = NULL;	int i, err = 0, depth = info->var.bits_per_pixel;	if (depth > 8 && depth != 32)		depth = info->var.red.length + info->var.green.length +			info->var.blue.length;	i = uvesafb_vbe_find_mode(par, info->var.xres, info->var.yres, depth,				 UVESAFB_EXACT_RES | UVESAFB_EXACT_DEPTH);	if (i >= 0)		mode = &par->vbe_modes[i];	else		return -EINVAL;	task = uvesafb_prep();	if (!task)		return -ENOMEM;setmode:	task->t.regs.eax = 0x4f02;	task->t.regs.ebx = mode->mode_id | 0x4000;	/* use LFB */	if (par->vbe_ib.vbe_version >= 0x0300 && !par->nocrtc &&	    info->var.pixclock != 0) {		task->t.regs.ebx |= 0x0800;		/* use CRTC data */		task->t.flags = TF_BUF_ESDI;		crtc = kzalloc(sizeof(struct vbe_crtc_ib), GFP_KERNEL);		if (!crtc) {			err = -ENOMEM;			goto out;		}		crtc->horiz_start = info->var.xres + info->var.right_margin;		crtc->horiz_end	  = crtc->horiz_start + info->var.hsync_len;		crtc->horiz_total = crtc->horiz_end + info->var.left_margin;		crtc->vert_start  = info->var.yres + info->var.lower_margin;		crtc->vert_end    = crtc->vert_start + info->var.vsync_len;		crtc->vert_total  = crtc->vert_end + info->var.upper_margin;		crtc->pixel_clock = PICOS2KHZ(info->var.pixclock) * 1000;		crtc->refresh_rate = (u16)(100 * (crtc->pixel_clock /				(crtc->vert_total * crtc->horiz_total)));		if (info->var.vmode & FB_VMODE_DOUBLE)			crtc->flags |= 0x1;		if (info->var.vmode & FB_VMODE_INTERLACED)			crtc->flags |= 0x2;		if (!(info->var.sync & FB_SYNC_HOR_HIGH_ACT))			crtc->flags |= 0x4;		if (!(info->var.sync & FB_SYNC_VERT_HIGH_ACT))			crtc->flags |= 0x8;		memcpy(&par->crtc, crtc, sizeof(*crtc));	} else {		memset(&par->crtc, 0, sizeof(*crtc));	}	task->t.buf_len = sizeof(struct vbe_crtc_ib);	task->buf = &par->crtc;	err = uvesafb_exec(task);	if (err || (task->t.regs.eax & 0xffff) != 0x004f) {		/*		 * The mode switch might have failed because we tried to		 * use our own timings.  Try again with the default timings.		 */		if (crtc != NULL) {			printk(KERN_WARNING "uvesafb: mode switch failed "				"(eax=0x%x, err=%d). Trying again with "				"default timings.\n", task->t.regs.eax, err);			uvesafb_reset(task);			kfree(crtc);			crtc = NULL;			info->var.pixclock = 0;			goto setmode;		} else {			printk(KERN_ERR "uvesafb: mode switch failed (eax="				"0x%x, err=%d)\n", task->t.regs.eax, err);			err = -EINVAL;			goto out;		}	}	par->mode_idx = i;	/* For 8bpp modes, always try to set the DAC to 8 bits. */	if (par->vbe_ib.capabilities & VBE_CAP_CAN_SWITCH_DAC &&	    mode->bits_per_pixel <= 8) {		uvesafb_reset(task);		task->t.regs.eax = 0x4f08;		task->t.regs.ebx = 0x0800;		err = uvesafb_exec(task);		if (err || (task->t.regs.eax & 0xffff) != 0x004f ||		    ((task->t.regs.ebx & 0xff00) >> 8) != 8) {			/*			 * We've failed to set the DAC palette format -			 * time to correct var.			 */			info->var.red.length    = 6;			info->var.green.length  = 6;			info->var.blue.length   = 6;		}	}	info->fix.visual = (info->var.bits_per_pixel == 8) ?				FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;	info->fix.line_length = mode->bytes_per_scan_line;out:	if (crtc != NULL)		kfree(crtc);	uvesafb_free(task);	return err;}static void uvesafb_check_limits(struct fb_var_screeninfo *var,		struct fb_info *info){	const struct fb_videomode *mode;	struct uvesafb_par *par = info->par;	/*	 * If pixclock is set to 0, then we're using default BIOS timings	 * and thus don't have to perform any checks here.	 */	if (!var->pixclock)		return;	if (par->vbe_ib.vbe_version < 0x0300) {		fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON, 60, var, info);		return;	}	if (!fb_validate_mode(var, info))		return;	mode = fb_find_best_mode(var, &info->modelist);	if (mode) {		if (mode->xres == var->xres && mode->yres == var->yres &&		    !(mode->vmode & (FB_VMODE_INTERLACED | FB_VMODE_DOUBLE))) {			fb_videomode_to_var(var, mode);			return;		}	}	if (info->monspecs.gtf && !fb_get_mode(FB_MAXTIMINGS, 0, var, info))		return;	/* Use default refresh rate */	var->pixclock = 0;}static int uvesafb_check_var(struct fb_var_screeninfo *var,		struct fb_info *info){	struct uvesafb_par *par = info->par;	struct vbe_mode_ib *mode = NULL;	int match = -1;	int depth = var->red.length + var->green.length + var->blue.length;	/*	 * Various apps will use bits_per_pixel to set the color depth,	 * which is theoretically incorrect, but which we'll try to handle	 * here.	 */	if (depth == 0 || abs(depth - var->bits_per_pixel) >= 8)		depth = var->bits_per_pixel;	match = uvesafb_vbe_find_mode(par, var->xres, var->yres, depth,						UVESAFB_EXACT_RES);	if (match == -1)		return -EINVAL;	mode = &par->vbe_modes[match];	uvesafb_setup_var(var, info, mode);	/*	 * Check whether we have remapped enough memory for this mode.	 * We might be called at an early stage, when we haven't remapped	 * any memory yet, in which case we simply skip the check.	 */	if (var->yres * mode->bytes_per_scan_line > info->fix.smem_len						&& info->fix.smem_len)		return -EINVAL;	if ((var->vmode & FB_VMODE_DOUBLE) &&				!(par->vbe_modes[match].mode_attr & 0x100))		var->vmode &= ~FB_VMODE_DOUBLE;	if ((var->vmode & FB_VMODE_INTERLACED) &&				!(par->vbe_modes[match].mode_attr & 0x200))		var->vmode &= ~FB_VMODE_INTERLACED;	uvesafb_check_limits(var, info);	var->xres_virtual = var->xres;	var->yres_virtual = (par->ypan) ?				info->fix.smem_len / mode->bytes_per_scan_line :				var->yres;	return 0;}static void uvesafb_save_state(struct fb_info *info){	struct uvesafb_par *par = info->par;	if (par->vbe_state_saved)		kfree(par->vbe_state_saved);	par->vbe_state_saved = uvesafb_vbe_state_save(par);}static void uvesafb_restore_state(struct fb_info *info){	struct uvesafb_par *par = info->par;	uvesafb_vbe_state_restore(par, par->vbe_state_saved);}static struct fb_ops uvesafb_ops = {	.owner		= THIS_MODULE,	.fb_open	= uvesafb_open,	.fb_release	= uvesafb_release,	.fb_setcolreg	= uvesafb_setcolreg,	.fb_setcmap	= uvesafb_setcmap,	.fb_pan_display	= uvesafb_pan_display,	.fb_blank	= uvesafb_blank,	.fb_fillrect	= cfb_fillrect,	.fb_copyarea	= cfb_copyarea,	.fb_imageblit	= cfb_imageblit,	.fb_check_var	= uvesafb_check_var,	.fb_set_par	= uvesafb_set_par,	.fb_save_state	= uvesafb_save_state,	.fb_restore_state = uvesafb_restore_state,};static void __devinit uvesafb_init_info(struct fb_info *info,		struct vbe_mode_ib *mode){	unsigned int size_vmode;	unsigned int size_remap;	unsigned int size_total;	struct uvesafb_par *par = info->par;	int i, h;	info->pseudo_palette = ((u8 *)info->par + sizeof(struct uvesafb_par));	info->fix = uvesafb_fix;	info->fix.ypanstep = par->ypan ? 1 : 0;	info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;	/*	 * If we were unable to get the state buffer size, disable	 * functions for saving and restoring the hardware state.	 */	if (par->vbe_state_size == 0) {		info->fbops->fb_save_state = NULL;		info->fbops->fb_restore_state = NULL;	}	/* Disable blanking if the user requested so. */	if (!blank)		info->fbops->fb_blank = NULL;	/*	 * Find out how much IO memory is required for the mode with	 * the highest resolution.	 */	size_remap = 0;	for (i = 0; i < par->vbe_modes_cnt; i++) {		h = par->vbe_modes[i].bytes_per_scan_line *					par->vbe_modes[i].y_res;		if (h > size_remap)			size_remap = h;	}	size_remap *= 2;	/*	 *   size_vmode -- that is the amount of memory needed for the	 *                 used video mode, i.e. the minimum amount of	 *                 memory we need.	 */	if (mode != NULL) {		size_vmode = info->var.yres * mode->bytes_per_scan_line;	} else {		size_vmode = info->var.yres * info->var.xres *			     ((info->var.bits_per_pixel + 7) >> 3);	}	/*	 *   size_total -- all video memory we have. Used for mtrr	 *                 entries, resource allocation and bounds	 *                 checking.	 */	size_total = par->vbe_ib.total_memory * 65536;	if (vram_total)		size_total = vram_total * 1024 * 1024;	if (size_total < size_vmode)		size_total = size_vmode;	/*	 *   size_remap -- the amount of video memory we are going to	 *                 use for vesafb.  With modern cards it is no	 *                 option to simply use size_total as th	 *                 wastes plenty of kernel address space.	 */	if (vram_remap)		size_remap = vram_remap * 1024 * 1024;	if (size_remap < size_vmode)		size_remap = size_vmode;	if (size_remap > size_total)		size_remap = size_total;	info->fix.smem_len = size_remap;	info->fix.smem_start = mode->phys_base_ptr;	/*	 * We have to set yres_virtual here because when setup_var() was	 * called, smem_len wasn't defined yet.	 */	info->var.yres_virtual = info->fix.smem_len /				 mode->bytes_per_scan_line;	if (par->ypan && info->var.yres_virtual > info->var.yres) {		printk(KERN_INFO "uvesafb: scrolling: %s "			"using protected mode interface, "			"yres_virtual=%d\n",			(par->ypan > 1) ? "ywrap" : "ypan",			info->var.yres_virtual);	} else {		printk(KERN_INFO "uvesafb: scrolling: redraw\n");		info->var.yres_virtual = info->var.yres;		par->ypan = 0;	}	info->flags = FBINFO_FLAG_DEFAULT |			(par->ypan) ? FBINFO_HWACCEL_YPAN : 0;	if (!par->ypan)		info->fbops->fb_pan_display = NULL;}

⌨️ 快捷键说明

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