FrameBuffer系列 之 相关结构与结构体

时间:2022-06-07 23:21:59

在linux中,fb设备驱动的源码主要在Fb.h (linux2.6.28\include\linux)和Fbmem.c(linux2.6.28\drivers\video)两个文件中,它们是fb设备驱动的中间层,为上层提供系统调用,为底层驱动提供接口。

FrameBuffer系列 之 相关结构与结构体

在fb.h文件中有fb驱动需要使用的很多结构,我们先对这些结构体进行说明:

1.  帧缓冲区描述符fb_info

一个帧缓冲区对应一个struct fb_info结构,它包括了帧缓冲设备的属性和操作的完整集合,每个帧设备都有一个fb_info结构体。源码如下:

struct fb_info {

atomic_tcount;

intnode;

intflags;

structmutex lock;             /* Lock foropen/release/ioctl funcs */

structmutex mm_lock;              /* Lock forfb_mmap and smem_* fields */

structfb_var_screeninfo var;    /* Current var缓冲区的可变参数
*/

structfb_fix_screeninfo fix;       /* Currentfix缓冲区的固定参数*/

structfb_monspecs monspecs;/* Current Monitorspecs当前显示器标示*/

structwork_struct queue; /* Framebuffer eventqueue
帧缓冲事件队列*/

structfb_pixmap pixmap; /* Image hardwaremapper图像硬件mapper*/

structfb_pixmap sprite;    /* Cursor hardwaremapper光标硬件mapper
*/

structfb_cmap cmap;               /* Currentcmap */

structlist_head modelist;     /* mode list */

structfb_videomode *mode;     /* current mode
当前视频模式*/

#ifdef CONFIG_FB_BACKLIGHT /*如果配置了LCD支持背光灯
*/

/*assigned backlight device */

/*set before framebuffer registration,

remove after unregister */

structbacklight_device *bl_dev;

/*Backlight level curve */

structmutex bl_curve_mutex;

u8bl_curve[FB_BACKLIGHT_LEVELS];

#endif

#ifdef CONFIG_FB_DEFERRED_IO

structdelayed_work deferred_work;

structfb_deferred_io *fbdefio;

#endif

structfb_ops *fbops;/*帧缓冲区操作函数*/

structdevice *device;       /* This is theparent
父设备 */

structdevice *dev;            /* This is thisfb devicefb设备*/

intclass_flag;                   /* privatesysfs flags */

#ifdef CONFIG_FB_TILEBLITTING

structfb_tile_ops *tileops;   /* Tile Blitting*/

#endif

char__iomem *screen_base;   /* Virtualaddress */

unsignedlong screen_size;      /* Amount ofioremapped VRAM or 0 */

void*pseudo_palette;               /* Fakepalette of 16 colors位调色板*/

#define FBINFO_STATE_RUNNING0

#define FBINFO_STATE_SUSPENDED   1

u32state;                 /* Hardware statei.e suspend */

void*fbcon_par;               /* fbconuse-only private area */

/*From here on everything is device dependent */

void*par;

/*we need the PCI or similar aperture base/size not

smem_start/size as smem_start may just be anobject

allocated inside the aperture so may notactually overlap */

structapertures_struct {

unsignedint count;

structaperture {

resource_size_tbase;

resource_size_tsize;

}ranges[0];

}*apertures;

};

2.  帧缓冲区操作符表fb_ops

fb_ops结构体用来实现对帧缓冲设备的操作,这些函数需要驱动开发人员编写,

/*

* Frame bufferoperations

*

* LOCKING NOTE: thosefunctions must _ALL_ be called with the console

* semaphore held, thisis the only suitable locking mechanism we have

* in 2.6. Some may becalled at interrupt time at this point though.

*

* The exception tothis is the debug related hooks. Puttingthe fb

* into a debug state(e.g. flipping to the kernel console) and restoring

* it must be done in alock-free manner, so low level drivers should

* keep track of theinitial console (if applicable) and may need to

* perform direct,unlocked hardware writes in these hooks.

*/

struct fb_ops {

/* open/releaseand usage marking */

struct module*owner;

/*打开与释放操作
*/

int(*fb_open)(struct fb_info *info, int user);

int(*fb_release)(struct fb_info *info, int user);

/* Forframebuffers with strange non linear layouts or that do not

* work with normal memory mapped access针对非线性布局或标准内存映射无法访问

*/

ssize_t (*fb_read)(structfb_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);

/* checks varand eventually tweaks it to something supported,

* DO NOT MODIFY PAR

*检测帧缓冲区可变变量,并调整为可用值*/

int(*fb_check_var)(struct fb_var_screeninfo *var, struct fb_info *info);

/* set the videomode according to info->var设置视频模式
*/

int(*fb_set_par)(struct fb_info *info);

/* set colorregister设置color寄存器*/

int(*fb_setcolreg)(unsigned regno, unsigned red, unsigned green,

unsigned blue, unsigned transp, structfb_info *info);

/* set colorregisters in batch批量设置color寄存器,设置颜色表
*/

int(*fb_setcmap)(struct fb_cmap *cmap, struct fb_info *info);

/* blank display空白显示*/

int(*fb_blank)(int blank, struct fb_info *info);

/* pan displaypan显示*/

int(*fb_pan_display)(struct fb_var_screeninfo *var, struct fb_info *info);

/* Draws arectangle画矩形*/

void(*fb_fillrect) (struct fb_info *info, const struct fb_fillrect *rect);

/* Copy datafrom area to another复制缓存区数据到指定区域
*/

void(*fb_copyarea) (struct fb_info *info, const struct fb_copyarea *region);

/* Draws a imageto the display在帧缓冲区显示一个图片
*/

void(*fb_imageblit) (struct fb_info *info, const struct fb_image *image);

/* Draws cursor光标绘制*/

int (*fb_cursor)(struct fb_info *info, struct fb_cursor *cursor);

/* Rotates thedisplay旋转显示*/

void(*fb_rotate)(struct fb_info *info, int angle);

/* wait for blitidle, optional 等待blit空闲,可选*/

int(*fb_sync)(struct fb_info *info);

/* perform fbspecific ioctl (optional)fb特定的ioctl操作*/

int(*fb_ioctl)(struct fb_info *info, unsigned int cmd,

unsignedlong arg);

/* Handle 32bitcompat ioctl (optional) */

int(*fb_compat_ioctl)(struct fb_info *info, unsigned cmd,

unsignedlong arg);

/* perform fbspecific mmapfb特定的mmap操作*/

int(*fb_mmap)(struct fb_info *info, struct vm_area_struct *vma);

/* getcapability given var */

void(*fb_get_caps)(struct fb_info *info, struct fb_blit_caps *caps,

struct fb_var_screeninfo *var);

/* teardown anyresources to do with this framebuffer */

void(*fb_destroy)(struct fb_info *info);

/* called at KDBenter and leave time to prepare the console */

int(*fb_debug_enter)(struct fb_info *info);

int(*fb_debug_leave)(struct fb_info *info);

};

3.  帧缓冲区固定参数描述符

fb_fix_screeninfo结构体中,记录了用户不能修改的固定显示控制器参数。这些固定的参数如缓冲区的物理地址、缓冲区的长度等等。

struct fb_fix_screeninfo {

char id[16];                       /* identification stringeg "TT Builtin" */

unsigned longsmem_start;      /* Start of frame buffermemFB开始的位置*/

/*(physical address)物理地址
*/

__u32 smem_len;                     /* Length of frame buffermemFB的长度*/

__u32 type;                       /* see FB_TYPE_*   FB类型  */

__u32 type_aux;               /* Interleave for interleavedPlanes分界*/

__u32 visual;                    /* see FB_VISUAL_*FB使用的色彩模式       */

__u16 xpanstep;/*zero if no hardware panning */

__u16 ypanstep;               /* zero if no hardwarepanning */

__u16 ywrapstep;             /* zero if no hardware ywrap   */

__u32line_length;            /* length of aline in bytes 1行的字节数 */

unsigned longmmio_start;       /* Start of MemoryMapped I/O */

/*(physical address)内存IO映射的开始位置 物理地址*/

__u32 mmio_len;                      /* Length of MemoryMapped I/O 长度*/

__u32 accel;                     /* Indicate to driverwhich */

/* specific chip/card we have 
*/

__u16reserved[3];           /* Reserved forfuture compatibility */

};

4.  帧缓冲区可变参数描述符

fb_var_screeninfo结构体中存储了用户可以修改的显示器控制参数,例如屏幕分辨率、透明度等等

struct fb_var_screeninfo {

__u32 xres;                       /* visible resolution   可见解析度,即分辨率*/

__u32 yres;

__u32xres_virtual;           /* virtual resolution   虚拟解析度     */

__u32yres_virtual;

__u32 xoffset;                   /* offset from virtual tovisible */

__u32 yoffset;                   /* resolution     虚拟与可见之间的偏移   */

__u32bits_per_pixel;        /* guess what           每像素位数     */

__u32 grayscale;      /* != 0 Graylevels instead of colors时为灰度
*/

structfb_bitfield red;/* bitfield in fb mem iftrue color, */

structfb_bitfield green;     /* else onlylength is significant */

structfb_bitfield blue; /*RGB位域
*/

struct fb_bitfieldtransp;    /* transparency
透明度*/

__u32 nonstd;  /* != 0 Non standard pixel format
!=0非标准像素格式*/

__u32 activate;         /* see FB_ACTIVATE_*            */

__u32 height;                    /* height of picture inmm mm中的屏幕高度 */

__u32 width;                     /* width of picture inmm mm中的屏幕宽度  */

__u32accel_flags;            /* (OBSOLETE) seefb_info.flags标示
*/

/* Timing: Allvalues in pixclocks, except pixclock (of course) */

__u32 pixclock;/* pixel clock in ps (pico seconds)
像素时钟皮秒*/

/*  行切换:绘图与同步间的延时 */

__u32left_margin;   /* time from sync topicture */

__u32right_margin;/* time from picture to sync */

      /*  
帧切换:绘图与同步间的延时 */

__u32upper_margin;/* time from sync to picture */

__u32lower_margin;

__u32 hsync_len;             /* length of horizontal sync       水平同步长度*/

__u32 vsync_len;              /* length of vertical sync垂直同步长度*/

__u32 sync;                      /* see FB_SYNC_*           */

__u32 vmode;                   /* see FB_VMODE_*        */

__u32 rotate;   /* angle we rotate counter clockwise顺时针旋转的角度*/

__u32reserved[5];           /* Reserved forfuture compatibility */

}

5.  帧缓冲区调色板描述符

fb_cmap结构体中记录了颜色板信息,即调色板信息。,用户空间可以通过ioctl()的FBIOGETCMAP和FBIOPUTCMAP命令读取或设定颜色表。

struct fb_cmap {

__u32 start;               /* First entry 第一个颜色入口*/

__u32 len;                  /* Number of entries
元素个数*/

__u16 *red;                /* Red values      RGB的值*/

__u16 *green;

__u16 *blue;

__u16 *transp;                  /* transparency, can be NULL透明度*/

};

FrameBuffer系列 之 相关结构与结构体

上面这些结构体之间有什么关系呢?看下图:

FrameBuffer系列 之 相关结构与结构体

6.  帧缓冲区像素描述符

fb_bitfield结构体描述每一像素显示缓冲区的组织方式,包含位域偏移、位域长度和MSB指示,

/* Interpretation of offset for color fields: All offsets arefrom the right,

* inside a"pixel" value, which is exactly 'bits_per_pixel' wide (means: you

* can use the offsetas right argument to <<). A pixel afterwards is a bit

* stream and iswritten to video memory as that unmodified.

*

* For pseudocolor:offset and length should be the same for all color

* components. Offsetspecifies the position of the least significant bit

* of the palletteindex in a pixel value. Length indicates the number

* of available paletteentries (i.e. # of entries = 1 << length).

*/

struct fb_bitfield {

__u32 offset;              /* beginning of bitfield位于偏移*/

__u32 length;                    /* length of bitfield     位域长度   */

__u32 msb_right;       /* != 0 : Most significant bit is */

/*rightMSB
*/

};

FrameBuffer系列 之 介绍

http://blog.csdn.net/younger_china/article/details/14479859

FrameBuffer系列 之 相关结构与结构体

http://blog.csdn.net/younger_china/article/details/14480967

FrameBuffer系列 之 简单编程

http://blog.csdn.net/younger_china/article/details/14236251

FrameBuffer系列

显示图片

http://blog.csdn.net/younger_china/article/details/14481755

FrameBuffer系列

一点资源

http://blog.csdn.net/younger_china/article/details/14482049