字符设备驱动结构
作者:贾献华
- 2022 年 7 月 28 日
本文字数:865 字
阅读完需:约 3 分钟
https://elixir.bootlin.com/linux/latest/source/include/linux/cdev.h#L14
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _LINUX_CDEV_H
#define _LINUX_CDEV_H
#include <linux/kobject.h>
#include <linux/kdev_t.h>
#include <linux/list.h>
#include <linux/device.h>
struct file_operations;
struct inode;
struct module;
struct cdev {
struct kobject kobj;
struct module *owner;
const struct file_operations *ops;
struct list_head list;
dev_t dev;
unsigned int count;
} __randomize_layout;
void cdev_init(struct cdev *, const struct file_operations *);
struct cdev *cdev_alloc(void);
void cdev_put(struct cdev *p);
int cdev_add(struct cdev *, dev_t, unsigned);
void cdev_set_parent(struct cdev *p, struct kobject *kobj);
int cdev_device_add(struct cdev *cdev, struct device *dev);
void cdev_device_del(struct cdev *cdev, struct device *dev);
void cdev_del(struct cdev *);
void cd_forget(struct inode *);
#endif
复制代码
https://elixir.bootlin.com/linux/latest/source/include/linux/kobject.h#L64
struct kobject {
const char *name;
struct list_head entry;
struct kobject *parent;
struct kset *kset;
const struct kobj_type *ktype;
struct kernfs_node *sd; /* sysfs directory entry */
struct kref kref;
#ifdef CONFIG_DEBUG_KOBJECT_RELEASE
struct delayed_work release;
#endif
unsigned int state_initialized:1;
unsigned int state_in_sysfs:1;
unsigned int state_add_uevent_sent:1;
unsigned int state_remove_uevent_sent:1;
unsigned int uevent_suppress:1;
};
复制代码
动态申请
alloc_chrdev_region
复制代码
已知设备的设备号
register_chrdev_region
复制代码
原型
extern int alloc_chrdev_region(dev_t *, unsigned, unsigned, const char *);
extern int register_chrdev_region(dev_t, unsigned, const char *);
复制代码
注销
extern void unregister_chrdev_region(dev_t, unsigned);
复制代码
复制代码
划线
评论
复制
发布于: 2 小时前阅读数: 10
贾献华
关注
及时当勉励 岁月不待人 2018.06.04 加入
https://2022.iosdevlog.com
评论