在自定义总线下注册设备

1、自定义总线下注册设备

//my_bus_dev.c
#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_dev.h"#if 0
int device_register(struct device *dev)
void	(*release)(struct device *dev);
#endif
extern struct bus_type my_bus;struct device my_bus_dev = {.init_name = "my_bus_dev",.bus = &my_bus,.release = my_bus_dev_release,.devt = ((255<<20|0)),
}; static void my_bus_dev_release(struct device *dev)
{printk("this is in my_bus_dev_release\n");
}static int my_bus_dev_init(void)
{int ret;ret = device_register(&my_bus_dev);return ret;
}static void my_bus_dev_exit(void)
{device_unregister(&my_bus_dev);
}module_init(my_bus_dev_init);
module_exit(my_bus_dev_exit);
MODULE_LICENSE("GPL");
//my_bus_dev.h
#ifndef _ATTR_H_
#define _ATTR_H_static void my_bus_dev_release(struct device *dev);
#endif
#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,
};
EXPORT_SYMBOL_GPL(my_bus);
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");
//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);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

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2、一些结构体和api介绍

2.1 device_register

在这里插入图片描述

2.2 struct device

The basic device structure

在这里插入图片描述
在这里插入图片描述

2.3 device_add

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

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

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

相关文章

solidity实战练习3——荷兰拍卖

//SPDX-License-Identifier:MIT pragma solidity ^0.8.24; interface IERC721{function transFrom(address _from,address _to,uint nftid) external ; }contract DutchAuction { address payable immutable seller;//卖方uint immutable startTime;//拍卖开始时间uint immut…

Eureka 介绍与使用

Eureka 是一个开源的服务发现框架&#xff0c;它主要用于在分布式系统中管理和发现服务实例。它由 Netflix 开发并开源&#xff0c;是 Netflix OSS 中的一部分。 使用 Eureka 可以方便地将新的服务实例注册到 Eureka 服务器&#xff0c;并且让其他服务通过 Eureka 服务器来发现…

今日科技圈最新时事新闻(2024年7月12日

一、智能硬件与电子产品 小米Redmi G Pro 2024游戏本新版本发布 发布时间&#xff1a;7月12日上午10点产品亮点&#xff1a; 搭载英特尔酷睿i7-14650HX处理器&#xff0c;拥有16个核心和24个线程&#xff0c;性能释放高达130W。配备140W满血释放的RTX 4060显卡&#xff0c;提…

属于马云的时代结束了

关注卢松松&#xff0c;会经常给你分享一些我的经验和观点。 马云突然回国了&#xff0c;还出现在阿里巴巴的大厦里。大家都非常激动&#xff0c;阿里沸腾了&#xff0c;整个杭州&#xff0c;甚至全网都沸腾了&#xff0c;日本慌了&#xff0c;美国坐不住了&#xff0c;欧洲陷…

目前分布式光纤测温系统的主流架构有哪些?

分布式光纤测温技术的主流架构&#xff0c;历经多个阶段的发展和演变&#xff0c;每种架构都有其独特的特点和优势。回顾过去的发展历程&#xff0c;我们可以看到三种主要架构的演进&#xff0c;每一次创新都在不同程度上推动了技术的进步和市场的发展。 首先&#xff0c;2005…

基于节点嵌入的链接预测(暂时这样吧)

基于节点嵌入的链接预测 补充知识&#xff1a;图自编码器&#xff08;Graph Autoencoder, GAE&#xff09;:变分图自编码器&#xff08;Variational Graph Autoencoder ,VGAE&#xff09;:二级目录三级目录 补充知识&#xff1a; 用一个例子来帮助理解&#xff0c;假设我们有一…

CSS技巧专栏:一日一例 5-纯CSS实现背景色从四周向中心填充的按钮特效

特此说明 本专题专注于讲解如何使用CSS制作按钮特效。前置的准备工作和按钮的基本样式,都在本专栏第一篇文章中又详细说明。自本专栏第四篇文章起,本专栏都将直接跳过前面的内容,不再重复复制,需要了解按钮基础样式的同学,请移步:《CSS技巧 - 一日一例 (1):会讨好的热…

关键路径-matlab

路径上边的数目称为路径长度 图的基本知识 求最短路径&#xff08;Dijkstra算法&#xff09; 2. 待继续尝试 ①Dijkstra ②floyd_all.m 一 二 ③ LeetCode [329. 矩阵中的最长递增路径]

SpringCloud---zuul路由网关

zuul网关 zuul网关定义 Zuul 是netflix开源的一个API Gateway 服务器, 本质上是一个web servlet(filter)应用。Zuul 在云平台上提供动态路由&#xff0c;监控&#xff0c;弹性&#xff0c;安全等边缘服务的框架。Zuul 相当于是设备和 Netflix 流应用的 Web 网站后端所有请求的…

Kithara与OpenCV (二)

Kithara使用OpenCV QT 进行特征检测 目录 Kithara使用OpenCV QT 进行特征检测OpenCV 特征检测简介Qt应用框架简介项目说明关键代码抖动测试测试平台&#xff1a;测试结果&#xff1a;结论 OpenCV 特征检测简介 OpenCV是一个开源的计算机视觉库&#xff0c;提供了各种图像处理…

一图展示免费开源的分布式版本控制系统​Git

文章目录 前言一、安装Git二、Git配置三、git命令 前言 Git是一个开源的分布式版本控制系统&#xff0c;可以有效、高速地处理从很小到非常大的项目版本管理。也是Linus Torvalds为了帮助管理Linux内核开发而开发的一个开放源码的版本控制软件。 一、安装Git Windows操作系统…

如何更好的优化 ListView 控件的性能

&#x1f604;作者简介&#xff1a; 小曾同学.com,一个致力于测试开发的博主⛽️&#xff0c;主要职责&#xff1a;测试开发、CI/CD&#xff0c;日常还会涉及Android开发工作。 如果文章知识点有错误的地方&#xff0c;还请大家指正&#xff0c;让我们一起学习&#xff0c;一起…

MongoDB教程(四):mongoDB索引

&#x1f49d;&#x1f49d;&#x1f49d;首先&#xff0c;欢迎各位来到我的博客&#xff0c;很高兴能够在这里和您见面&#xff01;希望您在这里不仅可以有所收获&#xff0c;同时也能感受到一份轻松欢乐的氛围&#xff0c;祝你生活愉快&#xff01; 文章目录 引言一、MongoD…

windows查看局域网所有设备ip

windows如何查看局域网所有设备ip 操作方法 一 . 在搜索栏里输入cmd 二 .在命令行黑窗口输入arp -a 三 . 最上面显示的动态地址就是所有设备ip

Redis:高性能的开源缓存数据库

简介&#xff1a; Redis&#xff08;Remote Dictionary Server&#xff09;是一个基于内存的开源缓存数据库&#xff0c;常用于缓存、消息队列、分布式锁等场景。它被设计成快速、可靠且易于使用的数据库系统&#xff0c;具有高性能、高可用、可扩展性等特点。本篇博客将介绍Re…

IOS上微信小程序密码框光标离开提示存储密码解决方案

问题&#xff1a; ios密码框输入密码光标离开之后会提示存储密码的弹窗 解决方案 1、在苹果手机上面把 “自动填充密码”关闭&#xff0c;但是苹果这个默认开启&#xff0c;而且大部分客户也不会去自己关闭。 2、欺骗苹果手机&#xff0c;代码实现。 先说解决思路&#xf…

80. UE5 RPG 实现UI显示技能冷却进度功能

在上一篇文章里&#xff0c;我们实现了通过GE给技能增加资源消耗和技能冷却功能。UI也能够显示角色能够使用的技能的UI&#xff0c;现在还有一个问题&#xff0c;我们希望在技能释放进去冷却时&#xff0c;技能变成灰色&#xff0c;并在技能冷却完成&#xff0c;技能可以再次使…

Spring Boot 框架知识汇总

1、什么是SpringBoot&#xff1f; 通过Spring Boot&#xff0c;可以轻松地创建独立的&#xff0c;基于生产级别的Spring的应用程序&#xff0c;您可以“运行"它们。大多数Spring Boot应用程序需要最少的Spring配置&#xff0c;集成了大量常用的第三方库配置&#xff0c;使…

React有哪些应用场景

React 是一个由 Facebook 开发并广泛使用的 JavaScript 库&#xff0c;专门用于构建用户界面。由于其灵活性和强大的生态系统&#xff0c;React 被广泛应用于多种场景。以下是一些 React 的主要应用场景&#xff1a; 1. 单页面应用&#xff08;SPA&#xff09; React 的组件化…

在Anaconda环境中安装TensorFlow+启动jupyter notebook

1.打开cmd&#xff0c;输入C:\Users\xy>conda create -n tensorflow python3.7 这是在环境中创建了一个名为tensorflow的环境&#xff0c;具体会显示以下信息&#xff1a; C:\Users\xy>conda create -n tensorflow python3.7 Retrieving notices: ...working... done Co…