VSF Documented
device.h
Go to the documentation of this file.
1#ifndef __VSF_LINUX_DEVICE_H__
2#define __VSF_LINUX_DEVICE_H__
3
4#include <linux/kobject.h>
5#include <linux/types.h>
6#include <linux/mutex.h>
7#include <linux/slab.h>
8#include <linux/sysfs.h>
9
10#include <linux/device/bus.h>
11#include <linux/device/class.h>
12#include <linux/device/driver.h>
13
14#include <linux/gfp.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
21 const char *name;
22 int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
23 void (*release)(struct device *dev);
24 const struct dev_pm_ops *pm;
25};
26
29 ssize_t (*show)(struct device *dev, struct device_attribute *attr, char *buf);
30 ssize_t (*store)(struct device *dev, struct device_attribute *attr, const char *buf, size_t count);
31};
32
33struct device {
34 struct kobject kobj;
35 struct device *parent;
36
38 const struct device_type *type;
39 struct bus_type *bus;
42};
43
44static inline struct device * kobj_to_dev(struct kobject *kobj)
45{
46 return vsf_container_of(kobj, struct device, kobj);
47}
48
49static inline const char * dev_bus_name(const struct device *dev)
50{
51 return dev->bus ? dev->bus->name : NULL;
52}
53
54static inline const char * dev_name(const struct device *dev)
55{
56 return kobject_name(&dev->kobj);
57}
58
59static inline void * dev_get_drvdata(const struct device *dev)
60{
61 return dev->driver_data;
62}
63
64static inline void dev_set_drvdata(struct device *dev, void *data)
65{
66 dev->driver_data = data;
67}
68
69#define dev_dbg(__dev, __fmt, ...) pr_debug(__fmt, ##__VA_ARGS__)
70#define dev_emerg(__dev, __fmt, ...) pr_emerg(__fmt, ##__VA_ARGS__)
71#define dev_crit(__dev, __fmt, ...) pr_crit(__fmt, ##__VA_ARGS__)
72#define dev_alert(__dev, __fmt, ...) pr_alert(__fmt, ##__VA_ARGS__)
73#define dev_err(__dev, __fmt, ...) pr_err(__fmt, ##__VA_ARGS__)
74#define dev_warn(__dev, __fmt, ...) pr_warn(__fmt, ##__VA_ARGS__)
75#define dev_notice(__dev, __fmt, ...) pr_notice(__fmt, ##__VA_ARGS__)
76#define dev_info(__dev, __fmt, ...) pr_info(__fmt, ##__VA_ARGS__)
77
78#define dev_level_once(__level, __dev, __fmt, ...) \
79 do { \
80 static bool __printed = false; \
81 if (!__printed) { \
82 __printed = true; \
83 __level(__dev, __fmt, ##__VA_ARGS__); \
84 } \
85 } while (0)
86#define dev_dbg_once(__dev, __fmt, ...) dev_level_once(dev_dbg, __dev, __fmt, ##__VA_ARGS__)
87#define dev_emerg_once(__dev, __fmt, ...) dev_level_once(dev_emerg, __dev, __fmt, ##__VA_ARGS__)
88#define dev_crit_once(__dev, __fmt, ...) dev_level_once(dev_crit, __dev, __fmt, ##__VA_ARGS__)
89#define dev_alert_once(__dev, __fmt, ...) dev_level_once(dev_alert, __dev, __fmt, ##__VA_ARGS__)
90#define dev_err_once(__dev, __fmt, ...) dev_level_once(dev_err, __dev, __fmt, ##__VA_ARGS__)
91#define dev_warn_once(__dev, __fmt, ...) dev_level_once(dev_warn, __dev, __fmt, ##__VA_ARGS__)
92#define dev_notice_once(__dev, __fmt, ...) dev_level_once(dev_notice, __dev, __fmt, ##__VA_ARGS__)
93#define dev_info_once(__dev, __fmt, ...) dev_level_once(dev_info, __dev, __fmt, ##__VA_ARGS__)
94
95extern struct device *get_device(struct device *dev);
96extern void put_device(struct device *dev);
97extern bool kill_device(struct device *dev);
98
99extern int dev_set_name(struct device *dev, const char *fmt, ...);
100
101#define device_wakeup_enable(__dev)
102#define device_wakeup_disable(__dev)
103
104static inline int device_is_registered(struct device *dev)
105{
106 return dev->kobj.state_in_sysfs;
107}
108extern int device_register(struct device *dev);
109extern void device_unregister(struct device *dev);
110extern void device_initialize(struct device *dev);
111extern int device_add(struct device *dev);
112extern void device_del(struct device *dev);
113
114static inline void * devm_kmalloc(struct device *dev, size_t size, gfp_t gfp)
115{
116 return kmalloc(size, gfp);
117}
118static inline void * devm_krealloc(struct device *dev, void *ptr, size_t size, gfp_t gfp)
119{
120 return krealloc(ptr, size, gfp);
121}
122static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp)
123{
124 return devm_kmalloc(dev, size, gfp | __GFP_ZERO);
125}
126static inline void devm_kfree(struct device *dev, const void *p)
127{
128 kfree(p);
129}
130
131extern char * devm_kvasprintf(struct device *dev, gfp_t gfp, const char *fmt, va_list ap);
132extern char * devm_kasprintf(struct device *dev, gfp_t gfp, const char *fmt, ...);
133
134#ifdef __cplusplus
135}
136#endif
137
138#endif
#define vsf_container_of(__ptr, __type, __member)
Definition __type.h:164
#define __GFP_ZERO
Definition gfp.h:12
unsigned int gfp_t
Definition gfp.h:10
struct ieee80211_ext_chansw_ie data
Definition ieee80211.h:80
__u32 u32
Definition types.h:73
#define NULL
Definition stddef.h:52
int ssize_t
Definition types.h:68
int device_register(struct device *dev)
Definition vsf_linux_core.c:581
char * devm_kasprintf(struct device *dev, gfp_t gfp, const char *fmt,...)
Definition vsf_linux_core.c:979
bool kill_device(struct device *dev)
int device_add(struct device *dev)
Definition vsf_linux_core.c:550
void device_unregister(struct device *dev)
Definition vsf_linux_core.c:587
int dev_set_name(struct device *dev, const char *fmt,...)
Definition vsf_linux_core.c:534
char * devm_kvasprintf(struct device *dev, gfp_t gfp, const char *fmt, va_list ap)
Definition vsf_linux_core.c:960
void device_initialize(struct device *dev)
Definition vsf_linux_core.c:545
void put_device(struct device *dev)
Definition vsf_linux_core.c:527
void device_del(struct device *dev)
Definition vsf_linux_core.c:573
struct device * get_device(struct device *dev)
Definition vsf_linux_core.c:519
Definition sysfs.h:10
Definition bus.h:15
const char * name
Definition bus.h:16
Definition pm.h:10
Definition device.h:27
struct attribute attr
Definition device.h:28
ssize_t(* show)(struct device *dev, struct device_attribute *attr, char *buf)
Definition device.h:29
ssize_t(* store)(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Definition device.h:30
Definition driver.h:28
Definition device.h:20
int(* uevent)(struct device *dev, struct kobj_uevent_env *env)
Definition device.h:22
const struct dev_pm_ops * pm
Definition device.h:24
const char * name
Definition device.h:21
void(* release)(struct device *dev)
Definition device.h:23
Definition device.h:33
const struct device_type * type
Definition device.h:38
struct device * parent
Definition device.h:35
struct bus_type * bus
Definition device.h:39
struct kobject kobj
Definition device.h:34
struct device_driver * driver
Definition device.h:40
u32 id
Definition device.h:37
void * driver_data
Definition device.h:41
Definition kobject.h:27
Definition kobject.h:14
bool state_in_sysfs
Definition kobject.h:20
uint32_t size
Definition vsf_memfs.h:50