linux杂项设备+设备节点,linux driver ------ platform模型,通过杂项设备(主设备号是10)注册设备节点...

注册完设备和驱动之后,就需要注册设备节点

Linux杂项设备出现的意义在于:有很多简单的外围字符设备,它们功能相对简单,一个设备占用一个主设备号对于内核资源来说太浪费。所以对于这些简单的字符设备它们共用一个主设备号,不同的设备使用不同的次设备号。

MISC_DYNAMIC_MINOR 表示由系统分配子设备号

生成helloword.ko文件后,执行 insmod helloworld,就可以在 dev/ 文件夹下看到 hello_device_node 文件,表明成功生成设备节点,执行 rmmod helloword,则节点消失。

helloworld.c

#include

#include

#include

#include

#include

#define DRIVER_NAME "hello"

#define NODE_NAME "hello_device_node"

MODULE_LICENSE("Dual BSD/GPL"); // required

MODULE_AUTHOR("liuShuiDeng");

static long hello_fs_ioctl(struct file *file, unsigned int cmd, unsigned long arg)

{

printk("cmd is %d, arg is %ld\n", cmd, arg);

return ;

}

static int hello_fs_release(struct inode *inode, struct file *file)

{

printk(KERN_EMERG "hello_fs_release");

return ;

}

static int hello_fs_open(struct inode *inode, struct file *file)

{

printk(KERN_EMERG "hello_fs_open");

return ;

}

static struct file_operations hello_fops = {

.owner = THIS_MODULE,

.open = hello_fs_open,

.release = hello_fs_release,

.unlocked_ioctl = hello_fs_ioctl,

};

static struct miscdevice hello_miscdevice = {

.minor = MISC_DYNAMIC_MINOR,

.name = NODE_NAME,

.fops = &hello_fops,

};

static int hello_probe(struct platform_device *p)

{

printk(KERN_EMERG "\nhello_probe\n");

misc_register(&hello_miscdevice);

return ;

}

static int hello_remove(struct platform_device *p)

{

printk(KERN_EMERG "\nhello_remove\n");

misc_deregister(&hello_miscdevice);

return ;

}

static void hello_shutdown(struct platform_device *p)

{

printk(KERN_EMERG "\nhello_shutdown\n");

}

static int hello_suspend(struct platform_device *p, pm_message_t state)

{

printk(KERN_EMERG "\nhello_suspend\n");

return ;

}

static int hello_resume(struct platform_device *p)

{

printk(KERN_EMERG "\nhello_resume\n");

return ;

}

static struct platform_driver hello_driver={

.probe = hello_probe,

.remove = hello_remove,

.shutdown = hello_shutdown,

.suspend = hello_suspend,

.resume = hello_resume,

.driver = {

.name = DRIVER_NAME,

.owner = THIS_MODULE,

},

};

static int hello_init(void) //insmod xxx.ko, execute it

{

printk(KERN_EMERG "\nhello world enter~\n\n");

platform_driver_register(&hello_driver);

return ;

}

static void hello_exit(void) //rmmod xxx( note: not xxx.ko ), execute it

{

printk(KERN_EMERG "\nhello world exit~\n\n");

platform_driver_unregister(&hello_driver);

}

module_init(hello_init);

module_exit(hello_exit);

Makefile

obj-m += helloworld.o # source file is helloworld.c

#kernel root directory

KDIR := /home/god/Desktop/logicalVolume/iTop4412_Kernel_3.

# directory of source file and Makefile

PWD ?= $(shell pwd)

all:

$(MAKE) -C $(KDIR) M=$(PWD) modules

rm -rf *.o

rm -rf Module.*

rm -rf modules.order

rm -rf *.mod.*

rm -rf .*.cmd

rm -rf .*versions

clean:

make -C $(KDIR) M=$(PWD) clean

linux driver ------ platform模型,驱动开发分析

一.platform总线.设备与驱动 在Linux 2.6 的设备驱动模型中,关心总线.设备和驱动3个实体,总线将设备和驱动绑定.在系统每注册一个设备的时候,会寻找与之匹配的驱动:相反的,在系统每注册 ...

Linux:主设备号和次设备号

http://www.linuxidc.com/Linux/2011-03/33863.htm     Linux的设备管理是和文件系统紧密结合的,各种设备都以文件的形式存放在/dev目录下,称为设备 ...

[ARM-Linux开发] 主设备号--驱动模块与设备节点联系的纽带

一.如何对设备操作 linux中对设备进行操作是通过文件的方式进行的,包括open.read.write.对于设备文件,一般称其为设备节点,节点有一个属性是设备号(主设备号.次设备号),其中主设备号将 ...

Linux 驱动学习笔记05--字符驱动实例,实现一个共享内存设备的驱动

断断续续学驱动,好不容易有空,做了段字符驱动的例子.主要还是跟书上学习在此记录下来,以后说不定能回过头来温故知新. 首先上驱动源码 gmem.c: /************************* ...

arm-linux字符设备驱动开发之---简单字符设备驱动

一.linux系统将设备分为3类:字符设备.块设备.网络设备.使用驱动程序: 1.字符设备:是指只能一个字节一个字节读写的设备,不能随机读取设备内存中的某一数据,读取数据需要按照先后数据.字符设备是面 ...

window 如何枚举设备并禁用该设备和启用该设备?如何注册设备热拔插消息通知?

目前实现的功能: 1.设备枚举 2.设置设备禁用和启用 3.注册设备热拔插消息通知 4.获取设备 vid pid 数值 需要链接的库 SetupAPI.lib DeviceManager 类如下: D ...

Linux下platform设备以及platform设备和驱动注册的先后顺序

platform是Linux系统提供的一种管理设备的手段,所有SOC系统中集成的独立的外设控制器.挂接在SOC内存空间的外设等都属Platform设备.如ARM S3C6410处理器中,把内部集成的I ...

linux driver ------ 字符设备驱动 之 “ 创建设备节点流程 ”

在字符设备驱动开发的入门教程中,最常见的就是用device_create()函数来创建设备节点了,但是在之后阅读内核源码的过程中却很少见device_create()的踪影了,取而代之的是device ...

linux driver module

本文将对Linux系统中的sysfs进行简单的分析,要分析sysfs就必须分析内核的driver-model(驱动模型),两者是紧密联系的.在分析过程中,本文将以platform总线和spi主控制器的 ...

随机推荐

yaf框架使用(centos6.5)

安装好php环境之后 安装扩展包 $yum install php-devel /usr/bin/ 就会出现phpize工具包 下载yaf-2.2.8.gz源文件,解压后,进入源文件 phpize [ ...

SSL certificate problem unable to get local issuer certificate解决办法

SSL certificate problem unable to get local issuer certificate 解决办法: 下载:ca-bundle.crt 将它放在自己的wamp或者x ...

JAVA读取XML文件数据

XML文档内容如下:

CDH中,如果管理CM中没有的属性

在CM配置管理中的"hive-site.xml 的 Hive 客户端高级配置代码段(安全阀)""仅适用于高级使用,逐个将字符串插入 hive-site.xml 的客户端配 ...

MySQL PLSQL Demo - 005.IF THEN ELSEIF THEN ELSE END IF

drop procedure if exists p_hello_world; create procedure p_hello_world(in v_id int) begin ) then sel ...

WeX5与阿里内测的Weex与有何纠葛?快来看HTML5开发圈那些逗逼事儿!

4月21日~23日,由infoQ主办的2016 Qcon大会北京站如期举行. HTML5开发已经成为移动开发/前端专题中无可争议的焦点,核心议题已经由前几年的是否该用HTML5转向了如何高性能.高效率 ...

Linux 学习记录 三(Vim 文书编辑器).

所有的Unix Like系统都会内建vi文书编辑器,其他的文书编辑器不一定存在,vim是vi的升级版,具有程序编辑的能力,可以主动的以字体颜色辨别语法的正确性,方便程序设计.vim 里 ...

Python学习之路基础篇--09Python基础,初识函数

函数可以分为内置函数 和 自定义函数.这次关注的主要是自定义函数.定义函数之后,就可以在任何需要它的地方调用. 1 返回值的重要性 返回值的3种情况 没有返回值 ---- 返回None 不定 retu ...

分析轮子(十)- HashMap.java 之概念梳理

注:玩的是JDK1.7版本 一:还是原来的风格,先上一下类的继承关系图,这样能够比较清楚的知道此类的相关特性 二:HashMap.java 的代码比较难看,所以,我看了几天,写的话也分开来写,这样能表 ...

Python---Pycharm如何直接上传自己的代码到GitHub

请提前到官网注册GitHub账号,提前在terminal或者cmd安装git,然后你要检测自己电脑是否存在 SSH key,然后需要把SSH key复制下来,粘贴到你的GitHub. - 第一步:安装 ...

你可能感兴趣的:(linux杂项设备+设备节点)