要使用 I/O 内存首先要申请 , 然后要映射 , 而要使用 I/O 端口首先要申请 , 或者叫请求 , 对于 I/O 端口的请求意思是让内核知道你要访问这个端口 , 这样内核知道了以后它就不会再让别人也访问这个端口了 . 毕竟这个世界僧多粥少啊 . 申请 I/O 端口的函数是 request_region, 这个函数来自 include/linux/ioport.h,
/* Convenience shorthand with allocation */
#define request_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name))
#define request_mem_region(start,n,name) __request_region(&iomem_resource, (start), (n), (name))
#define rename_region(region, newname) do { (region)->name = (newname); } while (0)
extern struct resource * __request_region(struct resource *,
resource_size_t start,
resource_size_t n, const char *name);
这里我们看到的那个 request_mem_region 是申请 I/O 内存用的 . 申请了之后 , 还需要使用 ioremap 或者 ioremap_nocache 函数来映射 .对于 request_region, 三个参数 start,n,name 表示你想使用从 start 开始的 size 为 n 的 I/O port 资源 ,name 自然就是你的名字了
实例:led驱动
。。。。。。。。。。。。。。。。。。
if(!request_mem_region(S3C_GPB_BASE, S3C_GPB_LEN, "s3c2440 led"))
{
return -EBUSY;
}
if( !(s3c_gpb_membase=ioremap(S3C_GPB_BASE, S3C_GPB_LEN)) )
{
release_mem_region(S3C_GPB_BASE, S3C_GPB_LEN);
return -ENOMEM;
}
。。。。。。。。。。。。。。。。。。。。。。。。。。