Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3298807
  • 博文数量: 754
  • 博客积分: 10132
  • 博客等级: 上将
  • 技术积分: 7780
  • 用 户 组: 普通用户
  • 注册时间: 2008-01-14 23:36
文章分类

全部博文(754)

文章存档

2012年(3)

2011年(39)

2010年(66)

2009年(167)

2008年(479)

我的朋友

分类: LINUX

2009-03-06 10:53:06

static 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--; )//一次性读4个字节
   *dst++ = fb_readl(src++);
  if (c & 3) {//如果读取字节数不是4的倍数,则最后3个字节另外处理
   u8 *dst8 = (u8 *) dst;
   u8 __iomem *src8 = (u8 __iomem *) src;
   for (i = c & 3; i--;)
    *dst8++ = fb_readb(src8++);
   src = (u32 __iomem *) src8;
  }
  if (copy_to_user(buf, buffer, c)) {
   err = -EFAULT;
   break;
  }
  *ppos += c;
  buf += c;
  cnt += c;
  count -= c;
 }
 kfree(buffer);
 return (err) ? err : cnt;
}
阅读(1138) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~