栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

linux设备驱动实现mmap()

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

linux设备驱动实现mmap()

一、驱动代码 
//所有的模块代码都包含下面两个头文件  
#include   
#include   
  
#include  //定义dev_t类型  
#include  //定义struct cdev结构体及相关操作  
#include  //定义kmalloc接口  
#include //定义virt_to_phys接口  
#include //remap_pfn_range  
#include   
  
#define MAJOR_NUM 0  
#define MM_SIZE 4096  
  
static char driver_name[] = "mmap_driver1";//驱动模块名字  
static int dev_major = MAJOR_NUM;  
static int dev_minor = 0;  
char *buf = NULL;  
struct cdev *cdev = NULL;  
  
static int device_open(struct inode *inode, struct file *file)  
{  
    printk(KERN_alert"device openn");  
    buf = (char *)kmalloc(MM_SIZE, GFP_KERNEL);//内核申请内存只能按页申请,申请该内存以便后面把它当作虚拟设备  
    return 0;  
}  
  
static int device_close(struct inode *indoe, struct file *file)  
{  
    printk("devi
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/457885.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号