android显示屏的更换---源码分析1

本文深入分析Linux内核源码,聚焦于Android显示屏驱动的实现。重点探讨了fb.h中的关键结构fb_info和fb_ops,以及fbmem.c的详细内容,为理解LCD驱动的工作原理提供指导。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

上一篇建立了source insight的 liunx源码工程

源码分析:

     打开source insight建立的源码工程SI_Linux 

     在源码工程中,对应LCD驱动drivers/video/fbmem.c和  include/linux/fb.h 这两个文件非常重要

fb.h中重要的两个结构fb_info、fb_ops

fb_info

struct fb_info {
	atomic_t count;                 /*反应在fbmem.c中定义的设备有多少个,原子操作:即不能被中断、线程切换*/
	int node;
	int flags;
	struct mutex lock;		/* 用于 open/release/ioctl 的互斥锁,互斥锁功能:保护资源 */
	struct mutex mm_lock;		/* 用于 fb_mmap and smem_* fields 互斥锁*/
	struct fb_var_screeninfo var;	/* 可变参数<span style="font-family: Arial, Helvetica, sans-serif;">,用户可以修改的显示器控制参数,如分辨率、像素信息</span> */
	struct fb_fix_screeninfo fix;	/* 固定参数,用户不能修改的显示器控制参数 */
	struct fb_monspecs monspecs;	/* Current Monitor specs */
	struct work_struct queue;	/* Framebuffer event queue */
	struct fb_pixmap pixmap;	/* Image hardware mapper */
	struct fb_pixmap sprite;	/* Cursor hardware mapper */
	struct fb_cmap cmap;		/* Current cmap */
	struct list_head modelist;      /* mode list */
	struct fb_videomode *mode;	/* current mode */

#ifdef CONFIG_FB_BACKLIGHT
	/* assigned backlight device */
	/* set before framebuffer registration, 
	   remove after unregister */
	struct backlight_device *bl_dev;

	/* Backlight level curve */
	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;		/* This is the parent */
	struct device *dev;		/* This is this fb device */
	int class_flag;                    /* private sysfs flags */
#ifdef CONFIG_FB_TILEBLITTING
	struct fb_tile_ops *tileops;    /* Tile Blitting */
#endif
	char __iomem *screen_base;	/* Virtual address */
	unsigned long screen_size;	/* Amount of ioremapped VRAM or 0 */ 
	void *pseudo_palette;		/* Fake palette of 16 colors */ 
#define FBINFO_STATE_RUNNING	0
#define FBINFO_STATE_SUSPENDED	1
	u32 state;			/* Hardware state i.e suspend */
	void *fbcon_par;                /* fbcon use-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 an object
	   allocated inside the aperture so may not actually overlap */
	struct apertures_struct {
		unsigned int count;
		struct aperture {
			resource_size_t base;
			resource_size_t size;
		} ranges[0];
	} *apertures;
};

fb_ops

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);

	/* For framebuffers with strange non linear layouts or that do not
	 * work with normal memory mapped access
 <span style="white-space:pre">	</span> *对于非线性布局的,常规内存映射无法工作的帧缓冲设备访问
	 */
	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);

	/* checks var and 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 video mode according to info->var */
	int (*fb_set_par)(struct fb_info *info);

	/* set color register */
	int (*fb_setcolreg)(unsigned regno, unsigned red, unsigned green,
			    unsigned blue, unsigned transp, struct fb_info *info);

	/* set color registers in batch */
	int (*fb_setcmap)(struct fb_cmap *cmap, struct fb_info *info);

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

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

	/* Draws a rectangle */
	void (*fb_fillrect) (struct fb_info *info, const struct fb_fillrect *rect);
	/* Copy data from area to another */
	void (*fb_copyarea) (struct fb_info *info, const struct fb_copyarea *region);
	/* Draws a image to 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 the display */
	void (*fb_rotate)(struct fb_info *info, int angle);

	/* wait for blit idle, optional */
	int (*fb_sync)(struct fb_info *info);

	/* perform fb specific ioctl (optional) */
	int (*fb_ioctl)(struct fb_info *info, unsigned int cmd,
			unsigned long arg);

	/* Handle 32bit compat ioctl (optional) */
	int (*fb_compat_ioctl)(struct fb_info *info, unsigned cmd,
			unsigned long arg);

	/* perform fb specific mmap */
	int (*fb_mmap)(struct fb_info *info, struct vm_area_struct *vma);

	/* get capability given var */
	void (*fb_get_caps)(struct fb_info *info, struct fb_blit_caps *caps,
			    struct fb_var_screeninfo *var);

	/* teardown any resources to do with this framebuffer */
	void (*fb_destroy)(struct fb_info *info);

	/* called at KDB enter and leave time to prepare the console */
	int (*fb_debug_enter)(struct fb_info *info);
	int (*fb_debug_leave)(struct fb_info *info);
};

fbmem.c分析

1、整体分析
module_init(fbmem_init);
module_exit(fbmem_exit);
这两行代码是,作为内核模块的,加载、卸载
这里主要分析加载的代码,fbmem_init是一个函数入口地址,找到它:右键---》Jump to definition,进入fbmem_init函数
2、fbmem_init函数分析
static int __init<span style="white-space:pre">					</span>/*__init是将函数加载到初始化段,是内核模块的固定格式,同样静态函数static*/
fbmem_init(void)
{
	proc_create("fb", 0, NULL, &fb_proc_fops);<span style="white-space:pre">	</span>/*在android系统 /proc文件夹下建立fb文件,如图cat_proc_fb.png,在系统启动/proc/fb的内容*/

	if (register_chrdev(FB_MAJOR,"fb",&fb_fops))<span style="white-space:pre">	</span>/*注册驱动,重点研究fb_fops*/
		printk("unable to get major %d for fb devs\n", FB_MAJOR);

	fb_class = class_create(THIS_MODULE, "graphics");/*<span style="font-family: Arial, Helvetica, sans-serif;">在android系统 /sys/class下建立graphic连接</span><span style="font-family: Arial, Helvetica, sans-serif;">*/</span>
	if (IS_ERR(fb_class)) {
		printk(KERN_WARNING "Unable to create fb class; errno = %ld\n", PTR_ERR(fb_class));
		fb_class = NULL;
	}
	return 0;
}
右键---》Jump to definition,进入 fb_fops函数

3、进入 fb_fops结构体,这也是核心驱动函数,将我们要底层的操作函数,通过函数指针,构造结构体
static const struct file_operations fb_fops = {
	.owner =	THIS_MODULE,<span style="white-space:pre">			</span>/*固定格式*/
	.read =		fb_read,<span style="white-space:pre">			</span>/*定义读的底层函数*/
	.write =	fb_write,
	.unlocked_ioctl = fb_ioctl,
#ifdef CONFIG_COMPAT
	.compat_ioctl = fb_compat_ioctl,
#endif
	.mmap =		fb_mmap,
	.open =		fb_open,<span style="white-space:pre">			</span>/*定义打开的函数,*/
	.release =	fb_release,
#ifdef HAVE_ARCH_FB_UNMAPPED_AREA
	.get_unmapped_area = get_fb_unmapped_area,
#endif
#ifdef CONFIG_FB_DEFERRED_IO
	.fsync =	fb_deferred_io_fsync,
#endif
	.llseek =	default_llseek,
};



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值