Linux驱动修炼之道-framebuffer(上)

努力成为linux kernel hacker的人李万鹏原创作品,为梦而战。转载请标明出处

http://blog.csdn.net/woshixingaaa/archive/2011/05/29/6452688.aspx

帧缓冲(frame buffer)是Linux视频系统的核心概念,因此先了解一下他的功能。

因为视频适配器可能基于不同的硬件体系架构,较高内核层和应用程序的实现可能会因视频卡的不同而不同,这会导致在使用不同视频卡的时需要采用不同的方案。随之而来的低可移植性和冗余的代码需要大量的投入和维护开销。帧缓冲的概念解决了这个问题,它进行了一般化的抽象并规定编程接口,从而开发人员可以以与平台无关的方式编写应用层和较高内核层程序。因此,内核的帧缓冲接口允许应用程序与底层图形硬件的变化无关,如果应用和显示器驱动程序遵循帧缓冲接口,应用程序不用改变就可以在不同类型的视频硬件上运行。

s3c2410在Linux系统中的framebuffer驱动框架:

再来看framebuffer中用到的各种数据结构:

struct fb_fix_screeninfo { char id[16]; /*字符串形式的标识符*/ unsigned long smem_start; /*fb缓冲内存的开始位置(物理地址)*/ __u32 smem_len; /*fb缓冲的长度*/ __u32 type; /*FB_TYPE_* */ __u32 type_aux; /*Interleave*/ __u32 visual; /*FB_VISUAL_* */ __u16 xpanstep; /*如果没有硬件panning,赋0*/ __u16 ypanstep; __u16 ywrapstep; __u32 line_length; /*一行的字节数*/ unsigned long mmio_start; /*内存映射I/O的开始位置*/ __u32 mmio_len; /*内存映射I/O的长度*/ __u32 accel; __u16 reserved[3]; /*保留*/ };

struct fb_var_screeninfo { /*可见解析度*/ __u32 xres; __u32 yres; /*虚拟解析度*/ __u32 xres_virtual; __u32 yres_virtual; /*虚拟到可见之间的偏移*/ __u32 xoffset; __u32 yoffset; __u32 bits_per_pixel; /*每像素的位数,BPP*/ __u32 grayscale; /*非0时指灰度*/ /*fb缓存的R/G/B位域*/ struct fb_bitfield red; struct fb_bitfield green; struct fb_bitfield blue; struct fb_bitfield transp; /*透明度*/ __u32 nonstd; /*!=0非标准像素格式*/ __u32 activate; __u32 height; /*高度*/ __u32 width; /*宽度*/ __u32 accel_flags; /*除pixclock本身外,其他都以像素时钟为单位*/ __u32 pixclock; /*像素时钟(皮秒)*/ __u32 left_margin; /*行切换:从同步到绘图之间的延迟*/ __u32 right_margin; /*行切换:从绘图到同步之间的延迟*/ __u32 upper_margin; /*帧切换:从同步到绘图之间的延迟*/ __u32 lower_margin; /*帧切换:从绘图到同步之间的延迟*/ __u32 hsync_len; /*水平同步的长度*/ __u32 vsync_len; /*垂直同步的长度*/ __u32 sync; __u32 vmode; __u32 rotate; /*顺时针旋转的角度*/ __u32 reserved[5]; /*保留*/ };

看下图可能会对fb_var_screeninfo中涉及的时序更清楚一些了。

struct fb_cmap { __u32 start; /*第1个元素入口*/ __u32 len; /*元素数量*/ /*R,G,B,透明度*/ __u16 *red; __u16 *green; __u16 *blue; __u16 *transp; };

struct fb_bitfield { __u32 offset; /*位域的偏移*/ __u32 length; /*位域的长度*/ __u32 msb_right; /*!=0 MSB在右边*/ };

struct fb_ops { struct module *owner; /*打开/释放*/ int (*fb_open)(struct fb_info *info, int user); int (*fb_release)(struct fb_info *info, int user); /*对于非线性布局的/常规内存映射无法工作的帧缓冲设备需要*/ ssize_t (*fb_read)(struct fb_info *info, char __user *buf, size_t count, loff_t *ppos); ssize_t (*fb_write)(struct fb_info *info, const char __user *buf, size_t count, loff_t *ppos); /*检测可变参数,并调整到支持的值*/ int (*fb_check_var)(struct fb_var_screeninfo *var, struct fb_info *info); /*根据info->var设置video模式*/ int (*fb_set_par)(struct fb_info *info); /*设置color寄存器*/ int (*fb_setcolreg)(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *info); /*批量设置color寄存器,设置颜色表*/ int (*fb_setcmap)(struct fb_cmap *cmap, struct fb_info *info); /*显示空白*/ int (*fb_blank)(int blank, struct fb_info *info); /*pan显示*/ int (*fb_pan_display)(struct fb_var_screeninfo *var, struct fb_info *info); /*矩形填充*/ void (*fb_fillrect) (struct fb_info *info, const struct fb_fillrect *rect); /*数据复制*/ void (*fb_copyarea) (struct fb_info *info, const struct fb_copyarea *region); /*图形填充*/ void (*fb_imageblit) (struct fb_info *info, const struct fb_image *image); /*绘制光标*/ int (*fb_cursor) (struct fb_info *info, struct fb_cursor *cursor); /*旋转显示*/ void (*fb_rotate)(struct fb_info *info, int angle); /*等待blit空闲*/ int (*fb_sync)(struct fb_info *info); /*fb特定的ioctl*/ int (*fb_ioctl)(struct fb_info *info, unsigned int cmd, unsigned long arg); /*处理32位的compat ioctl*/ int (*fb_compat_ioctl)(struct fb_info *info, unsigned cmd, unsigned long arg); /*fb特定的mmap*/ int (*fb_mmap)(struct fb_info *info, struct vm_area_struct *vma); /*保存目前的硬件状态*/ void (*fb_save_state)(struct fb_info *info); /*恢复被保存的硬件状态*/ void (*fb_restore_state)(struct fb_info *info); /**/ void (*fb_get_caps)(struct fb_info *info, struct fb_blit_caps *caps, struct fb_var_screeninfo *var); };

struct fb_info { int node; int flags; struct mutex lock; /*用于open/release/ioctl的锁*/ struct fb_var_screeninfo var; /*可变参数*/ struct fb_fix_screeninfo fix; /*固定参数*/ struct fb_monspecs monspecs; /*显示器标准*/ struct work_struct queue; /*帧缓冲事件队列*/ struct fb_pixmap pixmap; /*图像硬件mapper*/ struct fb_pixmap sprite; /*光标硬件mapper*/ struct fb_cmap cmap; /*目前的颜色表*/ struct list_head modelist; struct fb_videomode *mode; /*目前的video模式*/ #ifdef CONFIG_FB_BACKLIGHT struct backlight_device *bl_dev; /*对应的背光设备*/ struct mutex bl_curve_mutex; /*背光调整*/ u8 bl_curve[FB_BACKLIGHT_LEVELS]; #endif #ifdef CONFIG_FB_DEFERRED_IO struct delayed_work deferred_work; struct fb_deferred_io *fbdefio; #endif struct fb_ops *fbops; /*帧缓冲操作*/ struct device *device; /*父设备*/ struct device *dev; /*fb设备*/ int class_flag; /*私有sysfs标志*/ #ifdef CONFIG_FB_TILEBLITTING struct fb_tile_ops *tileops; /*图块blitting*/ #endif char __iomem *screen_base; /*虚拟基地址*/ unsigned long screen_size; /*ioremapped的虚拟内存大小*/ void *pseudo_palette; /*伪16色颜色表*/ #define FBINFO_STATE_RUNNING 0 #define FBINFO_STATE_SUSPENDED 1 u32 state; /*硬件状态,如挂起*/ void *fbcon_par; void *par; };

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值