/*
UIO(Userspace I/O)是运行在用户空间的I/O技术。Linux系统中一般的驱动设备都是运行在内核空间,而在用户空间用应用程序调用即可,
而UIO则是将驱动的很少一部分运行在内核空间,而在用户空间实现驱动的绝大多数功能!
使用UIO可以避免设备的驱动程序需要随着内核的更新而更新的问题!
怎么编写uio驱动详解
======================
为了用最简单的例子说明问题,我们在我们uio驱动的内核部分只映射了一块1024字节的
逻辑内存。没有申请中断。
这样加载上我们的驱动后,将会在/sys/class/uio/uio0/maps/map0中看到
addr name offset size。他们分别是映射内存的起始地址, 映射内存的名字,起始地址的页内偏移, 映射内存 的大小。
在uio驱动的用户空间部分,我们将打开addr, size以便使用映射好的内存。
*/
/**
* 编译驱动:
* Save this file name it simple.c
* # echo "obj-m := simple.o" > Makefile
* # make -Wall -C /lib/modules/`uname -r`/build M=`pwd` modules
* 加载模块:
* #modprobe uio
* #insmod simple.ko
*/
/*uio驱动的内核部分*/
#include
#include
#include
#include /* kmalloc, kfree */
struct uio_info kpart_info =
{
.name = "kpart",
.version = "0.1",
.irq = UIO_IRQ_NONE, //没有使用中断,所以初始为UIO_IRQ_NONE=0
/*当你没有实际的硬件设备,但是,还想产生中断的话,就可以把irq设置为UIO_IRQ_CUSTOM
如果有实际的硬件设备,那么irq应该是你的硬件设备实际使用的中断号。
*/
//初始化uio_info的handler字段,那么在产生中断时,你注册的中断处理函数将会被调用。
};
static int drv_kpart_probe(struct device *dev);
static int drv_kpart_remove(struct device *dev);
/*
struct platform_driver {
int (*probe)(struct platform_device *);
int (*remove)(struct platform_device *);
void (*shutdown)(struct platform_device *);
int (*suspend)(struct platform_device *, pm_message_t state);
int (*resume)(struct platform_device *);
struct de