当前位置: 技术问答>linux和unix
刚开始学写驱动,请大家帮我看一下,ioremap上后怎么降数据拷贝到用户空间??
来源: 互联网 发布时间:2015-09-05
本文导语: 下面是我写的驱动: #include #include #include //#include #include //#include //#include //#include //#include #include #include #include #include #include unsigned int test_major = 0; char *StartAddr = 0; MODULE_LICENSE("GPL")...
下面是我写的驱动:
#include
#include
#include
//#include
#include
//#include
//#include
//#include
//#include
#include
#include
#include
#include
#include
unsigned int test_major = 0;
char *StartAddr = 0;
MODULE_LICENSE("GPL");
static int read_test(struct inode *node,struct file *file,char *buf,int count,loff_t offset)
{
int add = 0;
char p = StartAddr + offset;
if (verify_area(VERIFY_WRITE,buf,count) == -EFAULT )
return -EFAULT;
while(count)
{
*buf = readb(p);
p++;count--;buf++;add++;
}
// copy_to_user(buf,StartAddr+offset,count);
// memcpy_fromio(buf,StartAddr+offset,count);
return add;
}
static int read_test24(struct file *file,char *buf,size_t count, loff_t offset)
{
return read_test(NULL,file,buf,count,offset);
}
static int write_test(struct inode *node ,struct file *file, const char *buf,int count,loff_t offset)
{
int left;
if (verify_area(VERIFY_READ,buf,count) == -EFAULT )
return -EFAULT;
for(left = count;left;left--)
{
*(StartAddr + offset + left) = *(buf + left);
}
return count;
}
static int write_test24(struct file *file,char *buf,size_t count ,loff_t offset)
{
return write_test(NULL,file,buf,count,offset);
}
static int open_test(struct inode *inode,struct file *file )
{
MOD_INC_USE_COUNT;
return 0;
}
static void release_test(struct inode *inode,struct file *file )
{
MOD_DEC_USE_COUNT;
}
// 在2.4中要一个返回值
static int release_test_24(struct inode *inode, struct file *file)
{
release_test(inode, file);
return 0;
}
static struct file_operations test_fops =
{
#if LINUX_VERSION_CODE
#include
#include
#include
//#include
#include
//#include
//#include
//#include
//#include
#include
#include
#include
#include
#include
unsigned int test_major = 0;
char *StartAddr = 0;
MODULE_LICENSE("GPL");
static int read_test(struct inode *node,struct file *file,char *buf,int count,loff_t offset)
{
int add = 0;
char p = StartAddr + offset;
if (verify_area(VERIFY_WRITE,buf,count) == -EFAULT )
return -EFAULT;
while(count)
{
*buf = readb(p);
p++;count--;buf++;add++;
}
// copy_to_user(buf,StartAddr+offset,count);
// memcpy_fromio(buf,StartAddr+offset,count);
return add;
}
static int read_test24(struct file *file,char *buf,size_t count, loff_t offset)
{
return read_test(NULL,file,buf,count,offset);
}
static int write_test(struct inode *node ,struct file *file, const char *buf,int count,loff_t offset)
{
int left;
if (verify_area(VERIFY_READ,buf,count) == -EFAULT )
return -EFAULT;
for(left = count;left;left--)
{
*(StartAddr + offset + left) = *(buf + left);
}
return count;
}
static int write_test24(struct file *file,char *buf,size_t count ,loff_t offset)
{
return write_test(NULL,file,buf,count,offset);
}
static int open_test(struct inode *inode,struct file *file )
{
MOD_INC_USE_COUNT;
return 0;
}
static void release_test(struct inode *inode,struct file *file )
{
MOD_DEC_USE_COUNT;
}
// 在2.4中要一个返回值
static int release_test_24(struct inode *inode, struct file *file)
{
release_test(inode, file);
return 0;
}
static struct file_operations test_fops =
{
#if LINUX_VERSION_CODE
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。