免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 821 | 回复: 0
打印 上一主题 下一主题

framebuffer驱动相关结构详解(转载) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-12-10 11:47 |只看该作者 |倒序浏览
[color="#02368d"]framebuffer驱动相关结构详解(转载)
转载地址:http://www.91linux.com/html/article/kernel/20071204/8805.html
Framebuffer对应的源文件在linux/drivers/video/目录下。总的抽象设备文件为fbcon.c,在这个目录下还有与各种显卡驱动相关的源文件。   [color="#ff0000"]//这个文件要好好看看
(一)、分析Framebuffer设备驱动
   
需要特别提出的是在INTEL平台上,老式的VESA 1.2
卡,如CGA/EGA卡,是不能支持Framebuffer的,因为Framebuffer要求显卡支持线性帧缓冲,即CPU可以访问显缓冲中的每一位,
但是VESA 1.2 卡只能允许CPU一次访问64K的地址空间。
FrameBuffer设备驱动基于如下两个文件:
1) linux/include/linux/fb.h
2) linux/drivers/video/fbmem.c
下面分析这两个文件。
1、fb.h
   几乎主要的结构都是在这个中文件定义的。这些结构包括:
1)fb_var_screeninfo
   这个结构描述了显示卡的特性:
[color="#ff0000"]NOTE::::   [color="#009900"]__u32 是表示 unsigned 不带符号的 32 bits 的数据类型,其余类推。这是 Linux 内核中所用到的数据类型,如果是开发用户空间(user-space)的程序,可以根据具体计算机平台的情况,用 unsigned long 等等来代替
struct fb_var_screeninfo
{
__u32 xres; /* visible resolution */   [color="#ff0000"]//可视区域
__u32 yres;
__u32 xres_virtual; /* virtual resolution */  [color="#ff0000"]//可视区域
__u32 yres_virtual;
__u32 xoffset; /* offset from virtual to visible resolution */ [color="#ff0000"]//可视区域的偏移
__u32 yoffset;
__u32 bits_per_pixel; /* guess what */  [color="#ff0000"]//每一象素的bit数
__u32 grayscale; /* != 0 Gray levels instead of colors */[color="#ff0000"]//等于零就成黑白
struct fb_bitfield red; /* bitfield in fb mem if true color, */[color="#ff0000"]真彩的bit机构
struct fb_bitfield green; /* else only length is significant */
struct fb_bitfield blue;   
struct fb_bitfield transp; /* transparency */  [color="#ff0000"]透明
__u32 nonstd; /* != 0 Non standard pixel format */ [color="#ff0000"]不是标准格式
__u32 activate; /* see FB_ACTIVATE_* */
__u32 height; /* height of picture in mm */ [color="#ff0000"]内存中的图像高度
__u32 width; /* width of picture in mm */ [color="#ff0000"]内存中的图像宽度
__u32 accel_flags; /* acceleration flags (hints) */ [color="#ff0000"]加速标志
/* Timing: All values in pixclocks, except pixclock (of course) */
[color="#ff0000"]时序-_-这些部分就是显示器的显示方法了,可以找相关的资料看看
__u32 pixclock; /* pixel clock in ps (pico seconds) */
__u32 left_margin; /* time from sync to picture */
__u32 right_margin; /* time from picture to sync */
__u32 upper_margin; /* time from sync to picture */
__u32 lower_margin;
__u32 hsync_len; /* length of horizontal sync */  [color="#ff0000"]水平可视区域
__u32 vsync_len; /* length of vertical sync */   [color="#ff0000"]垂直可视区域
__u32 sync; /* see FB_SYNC_* */
__u32 vmode; /* see FB_VMODE_* */
__u32 reserved[6]; /* Reserved for future compatibility */[color="#ff0000"] 备用-以后开发
};
2) fb_fix_screeninfon
这个[color="#0000ff"]结构在显卡被设定模式后创建,它描述显示卡的属性,并且系统运行时不能被修改;比如FrameBuffer内存的起始地址。它依赖于被设定的模式,当一个模式被设定后,内存信息由显示卡硬件给出,内存的位置等信息就不可以修改。
struct fb_fix_screeninfo {
char id[16]; /* identification string eg "TT Builtin" */[color="#ff0000"]ID
unsigned long smem_start; /* Start of frame buffer mem */ [color="#ff0000"]内存起始
/* (physical address) */ [color="#ff0000"]物理地址
__u32 smem_len; /* Length of frame buffer mem */ [color="#ff0000"]内存大小
__u32 type; /* see FB_TYPE_* */
__u32 type_aux; /* Interleave for interleaved Planes */[color="#ff0000"]插入区域?
__u32 visual; /* see FB_VISUAL_* */
__u16 xpanstep; /* zero if no hardware panning */[color="#ff0000"]没有硬件设备就为零
__u16 ypanstep; /* zero if no hardware panning */
__u16 ywrapstep; /* zero if no hardware ywrap */
__u32 line_length; /* length of a line in bytes */ [color="#ff0000"]一行的字节表示
unsigned long mmio_start; /* Start of Memory Mapped I/O */[color="#ff0000"]内存映射的I/O起始
/* (physical address) */
__u32 mmio_len; /* Length of Memory Mapped I/O */ [color="#ff0000"]I/O的大小
__u32 accel; /* Type of acceleration available */ [color="#ff0000"]可用的加速类型
__u16 reserved[3]; /* Reserved for future compatibility */
};
3) fb_cmap
描述设备无关的颜色映射信息。可以通过[color="#0000ff"]FBIOGETCMAP 和 FBIOPUTCMAP 对应的ioctl操作设定或获取颜色映射信息.
struct fb_cmap {
__u32 start; /* First entry */ [color="#ff0000"]第一个入口
__u32 len; /* Number of entries */ [color="#ff0000"]入口的数字
__u16 *red; /* Red values */ [color="#ff0000"]红
__u16 *green;
__u16 *blue;
__u16 *transp; /* transparency, can be NULL */[color="#ff0000"] 透明,可以为零
};
4) fb_info
[color="#009900"]定义当显卡的当前状态;fb_info结构仅在内核中可见,在这个结构中有一个fb_ops指针, 指向驱动设备工作所需的函数集。
struct fb_info {
char modename[40]; /* default video mode */ [color="#ff0000"]默认的视频卡类型
kdev_t node;
int flags;
int open; /* Has this been open already ? */ [color="#ff0000"]被打开过么?
#define FBINFO_FLAG_MODULE 1 /* Low-level driver is a module */
struct fb_var_screeninfo var; /* Current var */ [color="#ff0000"]现在的视频信息
struct fb_fix_screeninfo fix; /* Current fix */ [color="#ff0000"]修正的信息
struct fb_monspecs monspecs; /* Current Monitor specs */ [color="#ff0000"]现在的显示器模式
struct fb_cmap cmap; /* Current cmap */ [color="#ff0000"]当前优先级
struct fb_ops *fbops;
char *screen_base; /* Virtual address */ [color="#ff0000"]物理基址
struct display *disp; /* initial display variable */[color="#ff0000"]初始化
struct vc_data *display_fg; /* Console visible on this display */
char fontname[40]; /* default font name */[color="#ff0000"]默认的字体
devfs_handle_t devfs_handle; /* Devfs handle for new name */
devfs_handle_t devfs_lhandle; /* Devfs handle for compat. symlink */[color="#ff0000"]兼容
int (*changevar)(int); /* tell console var has changed */ [color="#ff0000"]告诉console变量修改了
int (*switch_con)(int, struct fb_info*);
/* tell fb to switch consoles */ [color="#ff0000"]告诉fb选择consoles
int (*updatevar)(int, struct fb_info*);
/* tell fb to update the vars */ [color="#ff0000"]告诉fb更新变量
void (*blank)(int, struct fb_info*); /* tell fb to (un)blank the screen */[color="#ff0000"]告诉fb使用黑白模式(或者不黑)
/* arg = 0: unblank */[color="#ff0000"]arg=0的时候黑白模式
/* arg > 0: VESA level (arg-1) */ [color="#ff0000"]arg>0时候选择VESA模式
void *pseudo_palette; /* Fake palette of 16 colors and
the cursor's color for non
palette mode */  [color="#ff0000"]修正调色板
/* From here on everything is device dependent */ [color="#ff0000"]现在就可以使用了
void *par;
};
5) struct fb_ops
用户应用可以使用ioctl()系统调用来操作设备,这个结构就是用一支持ioctl()的这些操作的。
struct fb_ops {
/* open/release and usage marking */
struct module *owner;
int (*fb_open)(struct fb_info *info, int user);
int (*fb_release)(struct fb_info *info, int user);
/* get non settable parameters */
int (*fb_get_fix)(struct fb_fix_screeninfo *fix, int con,
struct fb_info *info);
/* get settable parameters */
int (*fb_get_var)(struct fb_var_screeninfo *var, int con,
struct fb_info *info);
/* set settable parameters */
int (*fb_set_var)(struct fb_var_screeninfo *var, int con,
struct fb_info *info);
/* get colormap */
int (*fb_get_cmap)(struct fb_cmap *cmap, int kspc, int con,
struct fb_info *info);
/* set colormap */
int (*fb_set_cmap)(struct fb_cmap *cmap, int kspc, int con,
struct fb_info *info);
/* pan display (optional) */
int (*fb_pan_display)(struct fb_var_screeninfo *var, int con,
struct fb_info *info);
/* perform fb specific ioctl (optional) */
int (*fb_ioctl)(struct inode *inode, struct file *file, unsigned int cmd,
unsigned long arg, int con, struct fb_info *info);
/* perform fb specific mmap */
int (*fb_mmap)(struct fb_info *info, struct file *file, struct vm_area_struct *vma);
/* switch to/from raster image mode */
int (*fb_rasterimg)(struct fb_info *info, int start);
};
6) structure map
struct fb_info_gen | struct fb_info | fb_var_screeninfo
                   |                | fb_fix_screeninfo
                   |                | fb_cmap
                   |                | modename[40]
                   |                | fb_ops ---|--->ops on var
                   |                | ...       | fb_open
                   |                |           | fb_release
                   |                |           | fb_ioctl
                   |                |           | fb_mmap
                   | struct fbgen_hwswitch  
                              \-----|-> detect
                                    | encode_fix
                                    | encode_var
                                    | decode_fix
                                    | decode_var
                                    | get_var
                                    | set_var
                                    | getcolreg
                                    | setcolreg
                                    | pan_display
                                    | blank
                                    | set_disp
[编排有点困难,第一行的第一条竖线和下面的第一列竖线对齐,第一行的第二条竖线和下面的第二列竖线对齐就可以了]
这个结构 fbgen_hwswitch抽象了硬件的操作.虽然它不是必需的,但有时候很有用.
91linux
               
               
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/50916/showart_1712130.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP