设备驱动模型--存储技术原理分析笔记 基于2.6.43内核

news2024/9/29 1:18:52

本文为读书笔记,详细内容参考《存储原理技术分析》

1- 驱动模型

2- 总线类型

2.1- 重要数据结构

总线bus_type 和 bus_type_private 互相可以找到对方

struct bus_type {
    const char      *name;
    struct bus_attribute    *bus_attrs;
    struct device_attribute *dev_attrs;
    struct driver_attribute *drv_attrs;

    int (*match)(struct device *dev, struct device_driver *drv);
    int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
    int (*probe)(struct device *dev);
    int (*remove)(struct device *dev);          /* 设备和驱动解绑时的回调 */
    void (*shutdown)(struct device *dev);   /* 设备断电时的回调 */

    int (*suspend)(struct device *dev, pm_message_t state);   /* 进入节能状态时的回调 */

    int (*resume)(struct device *dev);     /* 恢复到正常状态时的回调 */

    const struct dev_pm_ops *pm;

    struct bus_type_private *p;
};
/**
 * struct bus_type_private - structure to hold the private to the driver core portions of the bus_type structure.
 *
 * @subsys - the struct kset that defines this bus.  This is the main kobject
 * @drivers_kset - the list of drivers associated with this bus
 * @devices_kset - the list of devices associated with this bus
 * @klist_devices - the klist to iterate over the @devices_kset
 * @klist_drivers - the klist to iterate over the @drivers_kset
 * @bus_notifier - the bus notifier list for anything that cares about things
 * on this bus.
 * @bus - pointer back to the struct bus_type that this structure is associated
 * with.
 *
 * This structure is the one that is the actual kobject allowing struct
 * bus_type to be statically allocated safely.  Nothing outside of the driver
 * core should ever touch these fields.
 */
struct bus_type_private {
    struct kset subsys;
    struct kset *drivers_kset;
    struct kset *devices_kset;
    struct klist klist_devices;
    struct klist klist_drivers;
    struct blocking_notifier_head bus_notifier;
    unsigned int drivers_autoprobe:1;
    struct bus_type *bus;
};

数据结构说明:

2.2- 总线注册

以PCI总线注册为例

2.2.1- pci总线注册

向系统中注册pci总线信息,总线名字为pci,总线的回调接口定义在pci_bus_type

drivers\pci\pci-driver.c
struct bus_type pci_bus_type = {
.name= "pci",
.match= pci_bus_match,
.uevent= pci_uevent,
.probe= pci_device_probe,
.remove= pci_device_remove,
.shutdown= pci_device_shutdown,
.dev_attrs= pci_dev_attrs,
.bus_attrs= pci_bus_attrs,
.pm= PCI_PM_OPS_PTR,
};
static int __init pci_driver_init(void)
{
return bus_register(&pci_bus_type);
}

2.2.2- 总线注册

主要动作:

1- kset_register : 在/sys/bus/路径下创建pci文件夹。

a- pci总线类型注册到的路径由priv->subsys.kobj.kset = bus_kset决定。buses_init中定义bus_kset为/sys/bus路径

b- 注册的pci总线名字在pci_bus_type.name定义。

2- 创建必要的文件

a- 创建/sys/bus/pci/uevent文件。用于通知用户态程序。bus_create_file(bus, &bus_attr_uevent);

b- 创建/sys/bus/pci/device文件。用于挂接pci设备。 kset_create_and_add("devices", NULL, &priv->subsys.kobj);

c- 创建/sys/bus/pci/drivers文件。用于挂接pci驱动。 kset_create_and_add("drivers", NULL, &priv->subsys.kobj);

d- 添加/sys/bus/pci/xxx_prob文件,包括drives_prob和drives_autoprob。add_probe_files(bus);

e- 添加属性文件/sys/bus/pci/xxx。例如rescan。 bus_add_attrs(bus);

注: 具体在系统/sys/bus/pci下注册了那些信息,可以自己去系统下看下。


drivers\base\bus.c
/**
 * bus_register - register a bus with the system.
 * @bus: bus.
 *
 * Once we have that, we registered the bus with the kobject
 * infrastructure, then register the children subsystems it has:
 * the devices and drivers that belong to the bus.
 */
int bus_register(struct bus_type *bus)
{
int retval;
struct bus_type_private *priv;
priv = kzalloc(sizeof(struct bus_type_private), GFP_KERNEL);
if (!priv)
return -ENOMEM;
priv->bus = bus;
bus->p = priv;
BLOCKING_INIT_NOTIFIER_HEAD(&priv->bus_notifier);
retval = kobject_set_name(&priv->subsys.kobj, "%s", bus->name);
if (retval)
goto out;
priv->subsys.kobj.kset = bus_kset;
priv->subsys.kobj.ktype = &bus_ktype;
priv->drivers_autoprobe = 1;
retval = kset_register(&priv->subsys);
if (retval)
goto out;
retval = bus_create_file(bus, &bus_attr_uevent);
if (retval)
goto bus_uevent_fail;
priv->devices_kset = kset_create_and_add("devices", NULL,
 &priv->subsys.kobj);
if (!priv->devices_kset) {
retval = -ENOMEM;
goto bus_devices_fail;
}
priv->drivers_kset = kset_create_and_add("drivers", NULL,
 &priv->subsys.kobj);
if (!priv->drivers_kset) {
retval = -ENOMEM;
goto bus_drivers_fail;
}
klist_init(&priv->klist_devices, klist_devices_get, klist_devices_put);
klist_init(&priv->klist_drivers, NULL, NULL);
retval = add_probe_files(bus);
if (retval)
goto bus_probe_files_fail;
retval = bus_add_attrs(bus);
if (retval)
goto bus_attrs_fail;
pr_debug("bus: '%s': registered\n", bus->name);
return 0;
bus_attrs_fail:
remove_probe_files(bus);
bus_probe_files_fail:
kset_unregister(bus->p->drivers_kset);
bus_drivers_fail:
kset_unregister(bus->p->devices_kset);
bus_devices_fail:
bus_remove_file(bus, &bus_attr_uevent);
bus_uevent_fail:
kset_unregister(&bus->p->subsys);
kfree(bus->p);
out:
bus->p = NULL;
return retval;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/375517.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

2023软件测试工程师全新技术栈,吃透这些,起薪就是25k~

相信每个准备软件测试面试的同学,不管你是大学刚毕业,满心憧憬着进入公司实习、非计算机行业转行软件测试、自学测试就业还是培训后就业,都会面临着众多的疑问和不解,那就是该怎么走出着第一步,今天本文一次性告诉你&a…

MK60DX256VLQ10(256KB)MK60DN256VLQ10 Kinetis K60 MCU FLASH

MK60DX256VLQ10(256KB)MK60DN256VLQ10 Kinetis K60 MCU 32BIT 256KB FLASH 144LQFP【说明】Kinetis K6x MCU系列是一个可扩展的组合,具有不同级别的集成,提供丰富的模拟、通信、定时和控制外设套件,以适应广泛的需求。应用楼宇自动化控制器人…

ARM中的寄存器

ARM工作模式 ARM有8个基本的工作模式 User 非特权模式,一般在执行上层的应用程序时ARM处于该模式FIQ 当一个高优先级中断产生后ARM将进入这种模式IRQ 当一个低优先级中断产生后ARM将进入这种模式SVC 当复位或执行软中断指令后ARM将进入这种模式Abort 当产生存取异常…

Linux 红帽9.0 本地源 与 网络源 搭建

本次我们使用的是 redhat 9.0 版本,是redhat 的最新版本,我们一起来对其进行 本地仓库 和 网络仓库的搭建部署~!!关于 本地仓库( 本地源 ),和 网络仓库 ( 网络源 )&#…

【项目实战】从0开始入门JDK源码 - LinkedList源码

一、源码位置 一般来说IDEA配置好JDK以后 ,JDK的源码其实也配置好了,本文是基于JDK1.8的源码说明 rt - java - util - LinkedList 二、 继承关系图 LinkedList public class LinkedList<E>extends AbstractSequentialList<E>implements

【计算机网络基础】

计算机网络基础网络的基本概念网络互联网IP地址MAC地址网络协议网络分层模型网络应用程序的通信流程网络的基本概念 网络 网络是由若干结点和链接这些结点的链路组成&#xff0c;网络中的结点可以是计算机&#xff0c;交换机&#xff0c;路由器等设备 网络设备&#xff1a;交…

绕过检测之Executor内存马浅析(内存马系列篇五)

写在前面 前面已经从代码层面讲解了Tomcat的架构&#xff0c;这是内存马系列文章的第五篇&#xff0c;带来的是Tomcat Executor类型的内存马实现。有了前面第四篇中的了解&#xff0c;才能更好的看懂内存马的构造。 前置 什么是Executor Executor是一种可以在Tomcat组件之间…

FastDDS-0.简介

FastDDS简介 eProsima Fast DDS 是 DDS (Data Distribution Service) 协议的一个C语言实现版本&#xff0c;该协议由 Object Management Group (OMG) 组织定义。 eProsima Fast DDS 库既提供了一个应用编程接口&#xff08;API&#xff09;&#xff0c;又提供了一种通信协议&a…

Qt——自定义Model

众所周知&#xff0c;Qt提供了一套Model/View框架供开发者使用&#xff0c;Model用来提供数据&#xff0c; View则用来提供视觉层的显示。实际上这是一套遵循MVC设计模式的GUI框架&#xff0c;因为Qt还提供了默认的Delegate作为Controller来作为控制器。 MVC的好处这里就不多说…

关于Ubuntu18.04 root账户登录的问题

关于Ubuntu18.04 root账户登录的问题一、 Ubuntu 18.04添加root用户登录1. 设置root用户2. 修改/root/.profile3. 修改/etc/pam.d目录下的gdm-autologin和gdm-password4. 修改50-ubuntu.conf5. 登录root账户二、Ubuntu18.04不能远程使用root账户登录的问题1. 修改sshd_config2.…

叠氮试剂79598-53-1,6-Azidohexanoic Acid,6-叠氮基己酸,末端羧酸可与伯胺基反应

●中文名&#xff1a;6-叠氮基己酸●英文名&#xff1a;6-Azidohexanoic Acid&#xff0c;6-Azidohexanoic COOH●外观以及性质&#xff1a;西安凯新生物科技有限公司供应的6-Azidohexanoic Acid浅黄色或者无色油状&#xff0c;叠氮化物可使用铜催化的Click化学与末端炔烃共轭&…

【深度探讨】如何利用区块链改善公共服务

发表时间&#xff1a;2022年5月4日 信息来源&#xff1a;bsvblockchain.org BSV区块链协会全力支持符合企业和政府对于节能降耗和合法合规等相关要求的区块链生态系统。 然而&#xff0c;虽然监管机构负责其监管范围内的技术服务的性质、目的和影响&#xff0c;但他们并不是全…

金三银四了,只能每天整理一下软件测试面试题给大家多多学习了,祝大家金三银四升职加薪,奥利给!

最近有童鞋和我抱怨&#xff0c;说网上很难搜到那些全面又合适的自动化测试面试题&#xff0c;这里根据我个人的经验以及收集整理的&#xff1a; 我还在文章最后面准备了一套视频&#xff0c;是关于简历和面试题方面的&#xff0c;真心建议现在在准备面试的兄弟去看看&#xf…

YB菜菜的毫米波雷达自学之路(四)——浅谈角度模糊

YB菜菜的毫米波雷达自学之路&#xff08;四&#xff09;——浅谈角度模糊前提说明主要内容&#xff1a;1. 一维平面天线阵列模糊函数及相关阐述1.1角度模糊函数定义1.2角度模糊函数案例与分析1.2.1 雷达阵列信息1.2.2 基础参数分析1.2.3 模糊函数图与波束方向图的关系探索与疑问…

华为OD机试模拟题 用 C++ 实现 - 简易压缩算法(2023.Q1)

最近更新的博客 【华为OD机试模拟题】用 C++ 实现 - 最多获得的短信条数(2023.Q1)) 文章目录 最近更新的博客使用说明简易压缩算法题目输入输出示例一输入输出说明示例二输入输出说明示例三输入输出说明

②【Java 组】蓝桥杯省赛真题解析 [振兴中华] [三部排序] 持续更新中...

个人简介&#xff1a;Java领域新星创作者&#xff1b;阿里云技术博主、星级博主、专家博主&#xff1b;正在Java学习的路上摸爬滚打&#xff0c;记录学习的过程~ 个人主页&#xff1a;.29.的博客 学习社区&#xff1a;进去逛一逛~ 蓝桥杯真题--持续更新中...一、振兴中华二、三…

【无标题】(2019)NOC编程猫创新编程复赛小学组真题含参考

&#xff08;2019&#xff09;NOC编程猫创新编程复赛小学组最后6道大题。前10道是选择填空题 略。 这道题是绘图题&#xff0c;没什么难度&#xff0c;大家绘制这2个正十边形要注意&#xff1a;一是不要超出舞台&#xff1b;二是这2个正十边形不要相交。 这里就不给出具体程序了…

RPC异步化原理

深入RPC&#xff0c;更好使用RPC&#xff0c;须从RPC框架整体性能考虑问题。得知道如何提升RPC框架的性能、稳定性、安全性、吞吐量及如何在分布式下快速定位问题。RPC框架如何压榨单机吞吐量&#xff1f; 1 前言 TPS一直上不去&#xff0c;压测时CPU压到40%&#xff5e;50%就…

Windows离线安装rust

目前rust安装常用的方式就是通过Rustup安装&#xff0c;此安装方式需要访问互联网。在生产环境中由于网络限制&#xff0c;不能直接访问互联网或者不能访问目标网站&#xff0c;这时候需要用离线安装的方式&#xff0c;本文将详细介绍离线安装步骤&#xff0c;并给出了vscode如…

记一次java.lang.ClassNotFoundException问题排查过程

记一次java.lang.ClassNotFoundException问题排查过程 同事提供一个or-simulation-engine.jar包&#xff08;非maven项目&#xff0c;内部依赖很多其他jar&#xff0c;这个包是手动打出来的&#xff09;给我&#xff0c;我集成到我的springboot项目中&#xff0c;在本地IDEA启…