lcd驱动的fb_read函数分析
2012-09-15 20:25
344 查看
static
ssize_t fb_read(struct
file
*file,
char
__user *buf,
size_t count,
loff_t *ppos)
ssize_t fb_read(struct
file
*file,
char
__user *buf,
size_t count,
loff_t *ppos)
{
unsigned long p = *ppos;
struct inode *inode = file->f_dentry->d_inode;
int fbidx = iminor(inode);//取次设备号
struct fb_info *info = registered_fb[fbidx];
u32 *buffer, *dst;
u32 __iomem *src;
int c, i, cnt = 0, err = 0;
unsigned long total_size;
if (!info || ! info->screen_base)
return -ENODEV;
if (info->state != FBINFO_STATE_RUNNING)
return -EPERM;
if (info->fbops->fb_read)
return info->fbops->fb_read(file, buf, count, ppos);
total_size = info->screen_size;
if (total_size == 0)
total_size = info->fix.smem_len;
if (p >= total_size)
return 0;
if (count >= total_size)
count = total_size;
if (count + p > total_size)
count = total_size - p;
cnt = 0;
buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count,
GFP_KERNEL);
if (!buffer)
return -ENOMEM;
src = (u32 __iomem *) (info->screen_base + p);
if (info->fbops->fb_sync)
info->fbops->fb_sync(info);
while (count) {
c = (count > PAGE_SIZE) ? PAGE_SIZE : count;//每次操作不能大于PAGE_SIZE
dst = buffer;
for (i = c >> 2; i--; ) //c>>2,表示除以4,也就是下面的数据,一次性读4个字节,这样总共读取c/4次
*dst++ = fb_readl(src++); // 注意这里的src++实质:src是个u32*所以,每次++就会自增四个字节
if (c & 3) { //如果读取字节数不是4的倍数,则最后3个字节另外处理
u8 *dst8 = (u8 *) dst;// u8* , 使其能够按照一个一个char读取
u8 __iomem *src8 = (u8 __iomem *) src;
for (i = c & 3; i--;) //i取最后2位,即最后未处理的数据
*dst8++ = fb_readb(src8++);
src = (u32 __iomem *) src8;// 让src指向最后读取的地址,为下次while(count)做准备
}
if (copy_to_user(buf, buffer, c)) {
err = -EFAULT;
break;
}
*ppos += c;
buf += c;
cnt += c;
count -= c;
}
kfree(buffer);
return (err) ? err : cnt;
}
相关文章推荐
- 简单的分析了fb_read函数。
- MQX3.8源代码分析:GPIO(5)驱动安装函数 _io_dev_install_ext()
- mtk rda 从bootload开始分析如何加载lcd驱动
- LCD 驱动的整体分析
- mini2440驱动分析之LCD
- Linux驱动:LCD驱动框架分析
- s3c6410 LCD驱动的分析过程——定位相关源代码
- Linux-2.6.20的LCD驱动分析(四)[转]
- 高通平台LCD驱动分析
- 用R语言做数据分析(8)——数据的输入与输出之READ函数 3ff8
- linux-i2c驱动 之 i2c设备层的注册过程probe函数如何被调用分析
- Linux-2.6.38的LCD驱动分析(四)
- Writing Linux LCD drivers—深入分析framebuffer设备驱动的结构
- linux fb /lcd 驱动
- 应用层open(read、write、close)怎样调用驱动open(read、write、close)函数的?
- Linux 字符设备驱动开发基础(三)—— read()、write() 相关函数解析
- linux lcd驱动分析五
- 函数平台底层之旅——DM9000网卡驱动源码分析
- LInux LCD驱动分析
- Linux监控系统开发详解(三)--LCD驱动分析