注册自定义总线

1、在/sys/bus下注册一个自定义总线

#include<linux/module.h>
#include<linux/init.h>
#include<linux/kernel.h>
#include<linux/kobject.h>
#include<linux/slab.h>
#include<linux/sysfs.h>
#include<linux/device.h>
#include "my_bus.h"#if 0
struct bus_type {const char		*name;const char		*dev_name;struct device		*dev_root;struct device_attribute	*dev_attrs;	/* use dev_groups instead */const struct attribute_group **bus_groups;const struct attribute_group **dev_groups;const struct attribute_group **drv_groups;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 (*online)(struct device *dev);int (*offline)(struct device *dev);int (*suspend)(struct device *dev, pm_message_t state);int (*resume)(struct device *dev);const struct dev_pm_ops *pm;const struct iommu_ops *iommu_ops;struct subsys_private *p;struct lock_class_key lock_key;
};
int bus_register(struct bus_type *bus)
#endifstruct bus_type my_bus = {.name = "my_bus",.match = my_bus_match,.probe = my_bus_probe,
};int my_bus_match(struct device *dev, struct device_driver *drv)
{return (strcmp(dev_name(dev),drv->name) == 0);
}int my_bus_probe(struct device *dev)
{struct device_driver *drv = dev->driver;if(drv->probe)drv->probe(dev);return 0;
}static int my_bus_init(void)
{int ret;ret = bus_register(&my_bus);return ret;
}static void my_bus_exit(void)
{bus_unregister(&my_bus);
}module_init(my_bus_init);
module_exit(my_bus_exit);
MODULE_LICENSE("GPL");
//my_bus.h
#ifndef _ATTR_H_
#define _ATTR_H_int my_bus_match(struct device *dev, struct device_driver *drv);
int my_bus_probe(struct device *dev);#endif

在这里插入图片描述

2、在总线目录下创建自己的属性文件

#include<linux/module.h>
#include<linux/init.h>
#include<linux/kernel.h>
#include<linux/kobject.h>
#include<linux/slab.h>
#include<linux/sysfs.h>
#include<linux/device.h>
#include "my_bus.h"#if 0
struct bus_type {const char		*name;const char		*dev_name;struct device		*dev_root;struct device_attribute	*dev_attrs;	/* use dev_groups instead */const struct attribute_group **bus_groups;const struct attribute_group **dev_groups;const struct attribute_group **drv_groups;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 (*online)(struct device *dev);int (*offline)(struct device *dev);int (*suspend)(struct device *dev, pm_message_t state);int (*resume)(struct device *dev);const struct dev_pm_ops *pm;const struct iommu_ops *iommu_ops;struct subsys_private *p;struct lock_class_key lock_key;
};
int bus_register(struct bus_type *bus)
static struct bus_attribute bus_attr_uevent = __ATTR(uevent, S_IWUSR, NULL,bus_uevent_store);int bus_create_file(struct bus_type *bus, struct bus_attribute *attr)struct bus_attribute {struct attribute	attr;ssize_t (*show)(struct bus_type *bus, char *buf);ssize_t (*store)(struct bus_type *bus, const char *buf, size_t count);
};
void bus_remove_file(struct bus_type *bus, struct bus_attribute *attr)
#endifstruct bus_type my_bus = {.name = "my_bus",.match = my_bus_match,.probe = my_bus_probe,
};
static struct bus_attribute my_bus_attr = __ATTR(attr1, 0660, my_bus_attr_show,my_bus_attr_store);ssize_t my_bus_attr_show(struct bus_type *bus, char *buf)
{ssize_t ret;ret = sprintf(buf,"this is in my_bus_attr_show\n");return ret;
}
ssize_t my_bus_attr_store(struct bus_type *bus, const char *buf, size_t count)
{printk("my_bus_attr_store:buf = %s\n",buf);return count;
}int my_bus_match(struct device *dev, struct device_driver *drv)
{return (strcmp(dev_name(dev),drv->name) == 0);
}int my_bus_probe(struct device *dev)
{struct device_driver *drv = dev->driver;if(drv->probe)drv->probe(dev);return 0;
}static int my_bus_init(void)
{int ret;ret = bus_register(&my_bus);ret = bus_create_file(&my_bus, &my_bus_attr);return ret;
}static void my_bus_exit(void)
{bus_remove_file(&my_bus, &my_bus_attr);bus_unregister(&my_bus);
}module_init(my_bus_init);
module_exit(my_bus_exit);
MODULE_LICENSE("GPL");
#ifndef _ATTR_H_
#define _ATTR_H_int my_bus_match(struct device *dev, struct device_driver *drv);
int my_bus_probe(struct device *dev);ssize_t my_bus_attr_show(struct bus_type *bus, char *buf);
ssize_t my_bus_attr_store(struct bus_type *bus, const char *buf, size_t count);
#endif

在这里插入图片描述

3、一些结构体和api介绍

3.1 struct bus_type

The bus type of the device
在这里插入图片描述

3.2 bus_register

注册一个总线
在这里插入图片描述

3.3 bus_unregister

去除一个总线
在这里插入图片描述

3.4 bus_create_file

总线目录下创建属性文件api
在这里插入图片描述

3.5 struct bus_attribute

在这里插入图片描述

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

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

相关文章

bug修复 修复修复修复

好的&#xff0c;这里是更新后的代码&#xff0c;将所有 inRange 函数的第一个变量替换为 ZoomOutimage&#xff1a; // 绿色分岔路 if (divergerColor "green" && nextColor "null") {cv::Mat frameGreen, frameRed;frame2.copyTo(frameGreen)…

如何在 Fedora 中使用 `shred` 擦除驱动器或文件

English Version: https://blog.csdn.net/sch0120/article/details/140390161 如何在 Fedora 中使用 shred 擦除驱动器或文件 安全擦除驱动器对于保护您的敏感数据免受未授权访问至关重要。在这篇博文中&#xff0c;我们将学习如何在 Fedora 中使用 shred 命令安全擦除整个驱…

FATE Flow 源码解析 - 作业提交处理流程

背景介绍 FATE 是隐私计算中最有名的开源项目了&#xff0c;从 star 的数量上来看也可以看出来。截止 2023 年 3 月共收获 4.9k 个 star&#xff0c;但是 FATE 一直被认为代码框架复杂&#xff0c;难以理解&#xff0c;作为一个相关的从业者&#xff0c;后续会持续对 FATE 项目…

React@16.x(56)Redux@4.x(5)- 实现 createStore

目录 1&#xff0c;分析2&#xff0c;实现2.1&#xff0c;基础实现2.2&#xff0c;优化2.2.1&#xff0c;随机字符串2.2.2&#xff0c;action 的判断2.2.2&#xff0c;监听器的优化 2.3&#xff0c;最终形态 1&#xff0c;分析 createStore()&#xff0c;参数1为 reducer&…

0601STM32TIM

TOC 分为四部分&#xff0c;八小节 一部分&#xff1a;主要讲定时器基本定时的功能&#xff0c;也就是定一个事件&#xff0c;让定时器每隔这个时间产生一个中断&#xff0c;来实现每隔一个固定时间来执行一段程序的目的&#xff0c;比如做一个时钟、秒表&#xff0c;或者使用一…

【Linux】1w详解如何实现一个简单的shell

目录 实现思路 1. 交互 获取命令行 2. 子串分割 解析命令行 3. 指令的判断 内建命令 4. 普通命令的执行 补充&#xff1a;vim 文本替换 整体代码 重点思考 1.getenv和putenv是什么意思 2.代码extern char **environ; 3.内建命令是什么 4.lastcode WEXITSTATUS(sta…

Java-final关键字详解

Java-final关键字详解 一、引言 二、什么是 final 关键字&#xff1f; 三、final 变量 final 局部变量 final 实例变量 final 静态变量 四、final 方法 五、final 类 六、final 关键字的实际应用 1. 定义常量 2. 防止方法被重写 3. 创建不可变类 4. 优化性能 七、…

切割01串(牛客小白月赛98)

题意&#xff1a; 给三个整数n&#xff0c;l&#xff0c;r&#xff0c;和一个字符串s&#xff0c;满足l<|c0-c1|<r就可以切成字符串a和字符串b&#xff0c;c0为字符串a左侧出现0的次数&#xff0c;c1为字符串b右侧出现1的次数&#xff0c;求最多切割次数 知识点&#x…

Onnx 1-深度学习-概述1

Onnx 1-深度学习-概述1 一: Onnx 概念1> Onnx 介绍2> Onnx 的作用3> Onnx 应用场景4> Onnx 文件格式1. Protobuf 特点2. onnx.proto3协议3> Onnx 模型基本操作二:Onnx API1> 算子详解2> Onnx 算子介绍三: Onnx 模型1> Onnx 函数功能

昇思学习打卡-8-计算机视觉/FCN图像语义分割

目录 FCN介绍FCN所用的技术训练数据的可视化模型训练模型推理FCN的优点和不足优点不足 FCN介绍 FCN主要用于图像分割领域&#xff0c;是一种端到端的分割方法&#xff0c;是深度学习应用在图像语义分割的开山之作。通过进行像素级的预测直接得出与原图大小相等的label map。因…

【C++基础】初识C++(2)--引用、const、inline、nullptr

目录 一、引用 1.1 引用的概念和定义 1.2 引用的特性 1.3引用的使用 1.4 const引用 1.5 指针和引用的关系 二、inline 三、nullptr 一、引用 1.1 引用的概念和定义 引⽤不是新定义⼀个变量&#xff0c;⽽是给已存在变量取了⼀个别名&#xff0c;编译器不会为引⽤…

微软的人工智能语音生成器在测试中达到与人类同等水平

微软公司开发了一种新的神经编解码语言模型 Vall-E&#xff0c;在自然度、语音鲁棒性和说话者相似性方面都超越了以前的成果。它是同类产品中第一个在两个流行基准测试中达到人类同等水平的产品&#xff0c;而且显然非常逼真&#xff0c;以至于微软不打算向公众开放。 VALL-E …

Node.js 模块系统

Node.js 模块系统 Node.js 的模块系统是其核心特性之一,它允许开发者将代码组织成可重用的模块。这种系统促进了代码的模块化,使得大型应用程序的构建和管理变得更加容易。本文将深入探讨 Node.js 的模块系统,包括其工作原理、如何创建和使用模块,以及模块系统的优势和局限…

【每日一练】python类和对象现实举例详细讲解

""" 本节课程目的&#xff1a; 1.掌握类描述现实世界实物思想 2.掌握类和对象的关系 3.理解什么事面向对象 """ #比如设计一个闹钟&#xff0c;在这里就新建一个类 class Clock:idNone #闹钟的序列号&#xff0c;也就是类的属性priceNone #闹…

Git最常用操作速查表

Git常用操作 文章目录 Git常用操作1. 克隆/拉取2. 分支操作1. 查看分支2. 创建分支3. 切换到分支4. 删除分支5. 删除远程分支6. 推送分支到远程 3. 暂存库操作4. Git团队规范1. 原则2. 分支设计3. commit备注一般规范 1. 克隆/拉取 git clone xxx 从远程仓库克隆 git rebase…

【开源之美】:WinMerge Files

一、引言 强大的windows端文件比较工具&#xff0c;跟Beyond Compare相比&#xff0c;更为强大。但是这里我们推荐他的原因&#xff0c;不仅是因为作为一个使用的工具&#xff0c;主要是因为他开源&#xff0c;可以通过调试优秀的源代码&#xff0c;进一步的提升C项目设计和编…

Alternative to Receptive field in Transformers and what factors impact it

题意&#xff1a;Transformer中感受野的替代概念及其影响因素 问题背景&#xff1a; I have two transformer networks. One with 3 heads per attention and 15 layers in total and second one with 5 heads per layer and 30 layers in total. Given an arbitrary set of d…

什么是数据模型?数据模型与数据治理有什么关系?

在企业数据治理的广阔领域中&#xff0c;首要且关键的一步是明确沟通数据治理的需求。这包括对企业所持有的数据种类、数据存储位置、以及当前数据管理的具体情况有一个清晰的了解和记录。了解企业的数据资产是制定有效数据治理策略的基础。企业需要识别和盘点所有类型的数据资…

AIGC产品经理学习路径

基础篇&#xff08;课时 2 &#xff09; AIGC 行业视角 AIGC 的行业发展演进&#xff1a;传统模型/深度学习/大模型 AIGC 的产品设计演进&#xff1a;AI Embedded / AI Copilot / AI Agen AIGC 的行业产业全景图 AIGC 的产品应用全景图 AIGC 职业视角 AI 产品经理/ AIGC…

2974.最小数字游戏

1.题目描述 你有一个下标从 0 开始、长度为 偶数 的整数数组 nums &#xff0c;同时还有一个空数组 arr 。Alice 和 Bob 决定玩一个游戏&#xff0c;游戏中每一轮 Alice 和 Bob 都会各自执行一次操作。游戏规则如下&#xff1a; 每一轮&#xff0c;Alice 先从 nums 中移除一个 …