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

📄 pm2fb.c

📁 Linux环境下视频显示卡设备的驱动程序源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
		u32 v;		if (regno >= 16)			return -EINVAL;		v = (red << info->var.red.offset) |			(green << info->var.green.offset) |			(blue << info->var.blue.offset) |			(transp << info->var.transp.offset);		switch (info->var.bits_per_pixel) {		case 8:			break;		case 16:		case 24:		case 32:			par->palette[regno] = v;			break;		}		return 0;	} else if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR)		set_color(par, regno, red, green, blue);	return 0;}/** *	pm2fb_pan_display - Pans the display. *	@var: frame buffer variable screen structure *	@info: frame buffer structure that represents a single frame buffer * *	Pan (or wrap, depending on the `vmode' field) the display using the *	`xoffset' and `yoffset' fields of the `var' structure. *	If the values don't fit, return -EINVAL. * *	Returns negative errno on error, or zero on success. * */static int pm2fb_pan_display(struct fb_var_screeninfo *var,			     struct fb_info *info){	struct pm2fb_par *p = info->par;	u32 base;	u32 depth = (var->bits_per_pixel + 7) & ~7;	u32 xres = (var->xres + 31) & ~31;	depth = (depth > 32) ? 32 : depth;	base = to3264(var->yoffset * xres + var->xoffset, depth, 1);	WAIT_FIFO(p, 1);	pm2_WR(p, PM2R_SCREEN_BASE, base);	return 0;}/** *	pm2fb_blank - Blanks the display. *	@blank_mode: the blank mode we want. *	@info: frame buffer structure that represents a single frame buffer * *	Blank the screen if blank_mode != 0, else unblank. Return 0 if *	blanking succeeded, != 0 if un-/blanking failed due to e.g. a *	video mode which doesn't support it. Implements VESA suspend *	and powerdown modes on hardware that supports disabling hsync/vsync: *	blank_mode == 2: suspend vsync *	blank_mode == 3: suspend hsync *	blank_mode == 4: powerdown * *	Returns negative errno on error, or zero on success. * */static int pm2fb_blank(int blank_mode, struct fb_info *info){	struct pm2fb_par *par = info->par;	u32 video = par->video;	DPRINTK("blank_mode %d\n", blank_mode);	switch (blank_mode) {	case FB_BLANK_UNBLANK:		/* Screen: On */		video |= PM2F_VIDEO_ENABLE;		break;	case FB_BLANK_NORMAL:		/* Screen: Off */		video &= ~PM2F_VIDEO_ENABLE;		break;	case FB_BLANK_VSYNC_SUSPEND:		/* VSync: Off */		video &= ~(PM2F_VSYNC_MASK | PM2F_BLANK_LOW);		break;	case FB_BLANK_HSYNC_SUSPEND:		/* HSync: Off */		video &= ~(PM2F_HSYNC_MASK | PM2F_BLANK_LOW);		break;	case FB_BLANK_POWERDOWN:		/* HSync: Off, VSync: Off */		video &= ~(PM2F_VSYNC_MASK | PM2F_HSYNC_MASK | PM2F_BLANK_LOW);		break;	}	set_video(par, video);	return 0;}static int pm2fb_sync(struct fb_info *info){	struct pm2fb_par *par = info->par;	WAIT_FIFO(par, 1);	pm2_WR(par, PM2R_SYNC, 0);	mb();	do {		while (pm2_RD(par, PM2R_OUT_FIFO_WORDS) == 0)			cpu_relax();	} while (pm2_RD(par, PM2R_OUT_FIFO) != PM2TAG(PM2R_SYNC));	return 0;}static void pm2fb_fillrect(struct fb_info *info,				const struct fb_fillrect *region){	struct pm2fb_par *par = info->par;	struct fb_fillrect modded;	int vxres, vyres;	u32 color = (info->fix.visual == FB_VISUAL_TRUECOLOR) ?		((u32 *)info->pseudo_palette)[region->color] : region->color;	if (info->state != FBINFO_STATE_RUNNING)		return;	if ((info->flags & FBINFO_HWACCEL_DISABLED) ||		region->rop != ROP_COPY ) {		cfb_fillrect(info, region);		return;	}	vxres = info->var.xres_virtual;	vyres = info->var.yres_virtual;	memcpy(&modded, region, sizeof(struct fb_fillrect));	if (!modded.width || !modded.height ||	    modded.dx >= vxres || modded.dy >= vyres)		return;	if (modded.dx + modded.width  > vxres)		modded.width  = vxres - modded.dx;	if (modded.dy + modded.height > vyres)		modded.height = vyres - modded.dy;	if (info->var.bits_per_pixel == 8)		color |= color << 8;	if (info->var.bits_per_pixel <= 16)		color |= color << 16;	WAIT_FIFO(par, 3);	pm2_WR(par, PM2R_CONFIG, PM2F_CONFIG_FB_WRITE_ENABLE);	pm2_WR(par, PM2R_RECTANGLE_ORIGIN, (modded.dy << 16) | modded.dx);	pm2_WR(par, PM2R_RECTANGLE_SIZE, (modded.height << 16) | modded.width);	if (info->var.bits_per_pixel != 24) {		WAIT_FIFO(par, 2);		pm2_WR(par, PM2R_FB_BLOCK_COLOR, color);		wmb();		pm2_WR(par, PM2R_RENDER,				PM2F_RENDER_RECTANGLE | PM2F_RENDER_FASTFILL);	} else {		WAIT_FIFO(par, 4);		pm2_WR(par, PM2R_COLOR_DDA_MODE, 1);		pm2_WR(par, PM2R_CONSTANT_COLOR, color);		wmb();		pm2_WR(par, PM2R_RENDER,				PM2F_RENDER_RECTANGLE |				PM2F_INCREASE_X | PM2F_INCREASE_Y );		pm2_WR(par, PM2R_COLOR_DDA_MODE, 0);	}}static void pm2fb_copyarea(struct fb_info *info,				const struct fb_copyarea *area){	struct pm2fb_par *par = info->par;	struct fb_copyarea modded;	u32 vxres, vyres;	if (info->state != FBINFO_STATE_RUNNING)		return;	if (info->flags & FBINFO_HWACCEL_DISABLED) {		cfb_copyarea(info, area);		return;	}	memcpy(&modded, area, sizeof(struct fb_copyarea));	vxres = info->var.xres_virtual;	vyres = info->var.yres_virtual;	if (!modded.width || !modded.height ||	    modded.sx >= vxres || modded.sy >= vyres ||	    modded.dx >= vxres || modded.dy >= vyres)		return;	if (modded.sx + modded.width > vxres)		modded.width = vxres - modded.sx;	if (modded.dx + modded.width > vxres)		modded.width = vxres - modded.dx;	if (modded.sy + modded.height > vyres)		modded.height = vyres - modded.sy;	if (modded.dy + modded.height > vyres)		modded.height = vyres - modded.dy;	WAIT_FIFO(par, 5);	pm2_WR(par, PM2R_CONFIG, PM2F_CONFIG_FB_WRITE_ENABLE |		PM2F_CONFIG_FB_READ_SOURCE_ENABLE);	pm2_WR(par, PM2R_FB_SOURCE_DELTA,			((modded.sy - modded.dy) & 0xfff) << 16 |			((modded.sx - modded.dx) & 0xfff));	pm2_WR(par, PM2R_RECTANGLE_ORIGIN, (modded.dy << 16) | modded.dx);	pm2_WR(par, PM2R_RECTANGLE_SIZE, (modded.height << 16) | modded.width);	wmb();	pm2_WR(par, PM2R_RENDER, PM2F_RENDER_RECTANGLE |				(modded.dx < modded.sx ? PM2F_INCREASE_X : 0) |				(modded.dy < modded.sy ? PM2F_INCREASE_Y : 0));}static void pm2fb_imageblit(struct fb_info *info, const struct fb_image *image){	struct pm2fb_par *par = info->par;	u32 height = image->height;	u32 fgx, bgx;	const u32 *src = (const u32 *)image->data;	u32 xres = (info->var.xres + 31) & ~31;	int raster_mode = 1; /* invert bits */#ifdef __LITTLE_ENDIAN	raster_mode |= 3 << 7; /* reverse byte order */#endif	if (info->state != FBINFO_STATE_RUNNING)		return;	if (info->flags & FBINFO_HWACCEL_DISABLED || image->depth != 1) {		cfb_imageblit(info, image);		return;	}	switch (info->fix.visual) {	case FB_VISUAL_PSEUDOCOLOR:		fgx = image->fg_color;		bgx = image->bg_color;		break;	case FB_VISUAL_TRUECOLOR:	default:		fgx = par->palette[image->fg_color];		bgx = par->palette[image->bg_color];		break;	}	if (info->var.bits_per_pixel == 8) {		fgx |= fgx << 8;		bgx |= bgx << 8;	}	if (info->var.bits_per_pixel <= 16) {		fgx |= fgx << 16;		bgx |= bgx << 16;	}	WAIT_FIFO(par, 13);	pm2_WR(par, PM2R_FB_READ_MODE, partprod(xres));	pm2_WR(par, PM2R_SCISSOR_MIN_XY,			((image->dy & 0xfff) << 16) | (image->dx & 0x0fff));	pm2_WR(par, PM2R_SCISSOR_MAX_XY,			(((image->dy + image->height) & 0x0fff) << 16) |			((image->dx + image->width) & 0x0fff));	pm2_WR(par, PM2R_SCISSOR_MODE, 1);	/* GXcopy & UNIT_ENABLE */	pm2_WR(par, PM2R_LOGICAL_OP_MODE, (0x3 << 1) | 1);	pm2_WR(par, PM2R_RECTANGLE_ORIGIN,			((image->dy & 0xfff) << 16) | (image->dx & 0x0fff));	pm2_WR(par, PM2R_RECTANGLE_SIZE,			((image->height & 0x0fff) << 16) |			((image->width) & 0x0fff));	if (info->var.bits_per_pixel == 24) {		pm2_WR(par, PM2R_COLOR_DDA_MODE, 1);		/* clear area */		pm2_WR(par, PM2R_CONSTANT_COLOR, bgx);		pm2_WR(par, PM2R_RENDER,			PM2F_RENDER_RECTANGLE |			PM2F_INCREASE_X | PM2F_INCREASE_Y);		/* BitMapPackEachScanline */		pm2_WR(par, PM2R_RASTERIZER_MODE, raster_mode | (1 << 9));		pm2_WR(par, PM2R_CONSTANT_COLOR, fgx);		pm2_WR(par, PM2R_RENDER,			PM2F_RENDER_RECTANGLE |			PM2F_INCREASE_X | PM2F_INCREASE_Y |			PM2F_RENDER_SYNC_ON_BIT_MASK);	} else {		pm2_WR(par, PM2R_COLOR_DDA_MODE, 0);		/* clear area */		pm2_WR(par, PM2R_FB_BLOCK_COLOR, bgx);		pm2_WR(par, PM2R_RENDER,			PM2F_RENDER_RECTANGLE |			PM2F_RENDER_FASTFILL |			PM2F_INCREASE_X | PM2F_INCREASE_Y);		pm2_WR(par, PM2R_RASTERIZER_MODE, raster_mode);		pm2_WR(par, PM2R_FB_BLOCK_COLOR, fgx);		pm2_WR(par, PM2R_RENDER,			PM2F_RENDER_RECTANGLE |			PM2F_INCREASE_X | PM2F_INCREASE_Y |			PM2F_RENDER_FASTFILL |			PM2F_RENDER_SYNC_ON_BIT_MASK);	}	while (height--) {		int width = ((image->width + 7) >> 3)				+ info->pixmap.scan_align - 1;		width >>= 2;		WAIT_FIFO(par, width);		while (width--) {			pm2_WR(par, PM2R_BIT_MASK_PATTERN, *src);			src++;		}	}	WAIT_FIFO(par, 3);	pm2_WR(par, PM2R_RASTERIZER_MODE, 0);	pm2_WR(par, PM2R_COLOR_DDA_MODE, 0);	pm2_WR(par, PM2R_SCISSOR_MODE, 0);}/* *	Hardware cursor support. */static const u8 cursor_bits_lookup[16] = {	0x00, 0x40, 0x10, 0x50, 0x04, 0x44, 0x14, 0x54,	0x01, 0x41, 0x11, 0x51, 0x05, 0x45, 0x15, 0x55};static int pm2vfb_cursor(struct fb_info *info, struct fb_cursor *cursor){	struct pm2fb_par *par = info->par;	u8 mode = PM2F_CURSORMODE_TYPE_X;	int x = cursor->image.dx - info->var.xoffset;	int y = cursor->image.dy - info->var.yoffset;	if (cursor->enable)		mode |= PM2F_CURSORMODE_CURSOR_ENABLE;	pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_MODE, mode);	if (!cursor->enable)		x = 2047;	/* push it outside display */	pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_X_LOW, x & 0xff);	pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_X_HIGH, (x >> 8) & 0xf);	pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_Y_LOW, y & 0xff);	pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_Y_HIGH, (y >> 8) & 0xf);	/*	 * If the cursor is not be changed this means either we want the	 * current cursor state (if enable is set) or we want to query what	 * we can do with the cursor (if enable is not set)	 */	if (!cursor->set)		return 0;	if (cursor->set & FB_CUR_SETHOT) {		pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_X_HOT,			     cursor->hot.x & 0x3f);		pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_Y_HOT,			     cursor->hot.y & 0x3f);	}	if (cursor->set & FB_CUR_SETCMAP) {		u32 fg_idx = cursor->image.fg_color;		u32 bg_idx = cursor->image.bg_color;		struct fb_cmap cmap = info->cmap;		/* the X11 driver says one should use these color registers */		pm2_WR(par, PM2VR_RD_INDEX_HIGH, PM2VI_RD_CURSOR_PALETTE >> 8);		pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 0,			     cmap.red[bg_idx] >> 8 );		pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 1,			     cmap.green[bg_idx] >> 8 );		pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 2,			     cmap.blue[bg_idx] >> 8 );		pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 3,			     cmap.red[fg_idx] >> 8 );		pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 4,			     cmap.green[fg_idx] >> 8 );		pm2v_RDAC_WR(par, PM2VI_RD_CURSOR_PALETTE + 5,			     cmap.blue[fg_idx] >> 8 );		pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0);	}	if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) {		u8 *bitmap = (u8 *)cursor->image.data;		u8 *mask = (u8 *)cursor->mask;		int i;		int pos = PM2VI_RD_CURSOR_PATTERN;		for (i = 0; i < cursor->image.height; i++) {			int j = (cursor->image.width + 7) >> 3;			int k = 8 - j;			pm2_WR(par, PM2VR_RD_INDEX_HIGH, pos >> 8);			for (; j > 0; j--) {				u8 data = *bitmap ^ *mask;				if (cursor->rop == ROP_COPY)					data = *mask & *bitmap;				/* Upper 4 bits of bitmap data */				pm2v_RDAC_WR(par, pos++,					cursor_bits_lookup[data >> 4] |					(cursor_bits_lookup[*mask >> 4] << 1));				/* Lower 4 bits of bitmap */				pm2v_RDAC_WR(par, pos++,					cursor_bits_lookup[data & 0xf] |					(cursor_bits_lookup[*mask & 0xf] << 1));				bitmap++;				mask++;			}			for (; k > 0; k--) {				pm2v_RDAC_WR(par, pos++, 0);				pm2v_RDAC_WR(par, pos++, 0);			}		}		while (pos < (1024 + PM2VI_RD_CURSOR_PATTERN)) {			pm2_WR(par, PM2VR_RD_INDEX_HIGH, pos >> 8);			pm2v_RDAC_WR(par, pos++, 0);		}		pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0);	}	return 0;}static int pm2fb_cursor(struct fb_info *info, struct fb_cursor *cursor){	struct pm2fb_par *par = info->par;	u8 mode;	if (!hwcursor)		return -EINVAL;	/* just to force soft_cursor() call */	/* Too large of a cursor or wrong bpp :-( */	if (cursor->image.width > 64 ||	    cursor->image.height > 64 ||	    cursor->image.depth > 1)		return -EINVAL;	if (par->type == PM2_TYPE_PERMEDIA2V)		return pm2vfb_cursor(info, cursor);	mode = 0x40;	if (cursor->enable)		 mode = 0x43;	pm2_RDAC_WR(par, PM2I_RD_CURSOR_CONTROL, mode);	/*	 * If the cursor is not be changed this means either we want the	 * current cursor state (if enable is set) or we want to query what	 * we can do with the cursor (if enable is not set)	 */	if (!cursor->set)		return 0;	if (cursor->set & FB_CUR_SETPOS) {		int x = cursor->image.dx - info->var.xoffset + 63;		int y = cursor->image.dy - info->var.yoffset + 63;

⌨️ 快捷键说明

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