Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _DEVICE_DEVRES_H_
3#define _DEVICE_DEVRES_H_
4
5#include <linux/err.h>
6#include <linux/gfp_types.h>
7#include <linux/numa.h>
8#include <linux/overflow.h>
9#include <linux/stdarg.h>
10#include <linux/types.h>
11
12struct device;
13struct device_node;
14struct resource;
15
16/* device resource management */
17typedef void (*dr_release_t)(struct device *dev, void *res);
18typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data);
19
20void * __malloc
21__devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, int nid, const char *name);
22#define devres_alloc(release, size, gfp) \
23 __devres_alloc_node(release, size, gfp, NUMA_NO_NODE, #release)
24#define devres_alloc_node(release, size, gfp, nid) \
25 __devres_alloc_node(release, size, gfp, nid, #release)
26
27void devres_for_each_res(struct device *dev, dr_release_t release,
28 dr_match_t match, void *match_data,
29 void (*fn)(struct device *, void *, void *),
30 void *data);
31void devres_free(void *res);
32void devres_add(struct device *dev, void *res);
33void *devres_find(struct device *dev, dr_release_t release, dr_match_t match, void *match_data);
34void *devres_get(struct device *dev, void *new_res, dr_match_t match, void *match_data);
35void *devres_remove(struct device *dev, dr_release_t release, dr_match_t match, void *match_data);
36int devres_destroy(struct device *dev, dr_release_t release, dr_match_t match, void *match_data);
37int devres_release(struct device *dev, dr_release_t release, dr_match_t match, void *match_data);
38
39/* devres group */
40void * __must_check devres_open_group(struct device *dev, void *id, gfp_t gfp);
41void devres_close_group(struct device *dev, void *id);
42void devres_remove_group(struct device *dev, void *id);
43int devres_release_group(struct device *dev, void *id);
44
45/* managed devm_k.alloc/kfree for device drivers */
46void * __alloc_size(2)
47devm_kmalloc(struct device *dev, size_t size, gfp_t gfp);
48void * __must_check __realloc_size(3)
49devm_krealloc(struct device *dev, void *ptr, size_t size, gfp_t gfp);
50static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp)
51{
52 return devm_kmalloc(dev, size, gfp | __GFP_ZERO);
53}
54static inline void *devm_kmalloc_array(struct device *dev, size_t n, size_t size, gfp_t flags)
55{
56 size_t bytes;
57
58 if (unlikely(check_mul_overflow(n, size, &bytes)))
59 return NULL;
60
61 return devm_kmalloc(dev, bytes, flags);
62}
63static inline void *devm_kcalloc(struct device *dev, size_t n, size_t size, gfp_t flags)
64{
65 return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO);
66}
67static inline __realloc_size(3, 4) void * __must_check
68devm_krealloc_array(struct device *dev, void *p, size_t new_n, size_t new_size, gfp_t flags)
69{
70 size_t bytes;
71
72 if (unlikely(check_mul_overflow(new_n, new_size, &bytes)))
73 return NULL;
74
75 return devm_krealloc(dev, p, bytes, flags);
76}
77
78void devm_kfree(struct device *dev, const void *p);
79
80void * __realloc_size(3)
81devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp);
82static inline void *devm_kmemdup_array(struct device *dev, const void *src,
83 size_t n, size_t size, gfp_t flags)
84{
85 return devm_kmemdup(dev, src, size_mul(size, n), flags);
86}
87
88char * __malloc
89devm_kstrdup(struct device *dev, const char *s, gfp_t gfp);
90const char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp);
91char * __printf(3, 0) __malloc
92devm_kvasprintf(struct device *dev, gfp_t gfp, const char *fmt, va_list ap);
93char * __printf(3, 4) __malloc
94devm_kasprintf(struct device *dev, gfp_t gfp, const char *fmt, ...);
95
96unsigned long devm_get_free_pages(struct device *dev, gfp_t gfp_mask, unsigned int order);
97void devm_free_pages(struct device *dev, unsigned long addr);
98
99#ifdef CONFIG_HAS_IOMEM
100
101void __iomem *devm_ioremap_resource(struct device *dev, const struct resource *res);
102void __iomem *devm_ioremap_resource_wc(struct device *dev, const struct resource *res);
103
104void __iomem *devm_of_iomap(struct device *dev, struct device_node *node, int index,
105 resource_size_t *size);
106#else
107
108static inline
109void __iomem *devm_ioremap_resource(struct device *dev, const struct resource *res)
110{
111 return IOMEM_ERR_PTR(-EINVAL);
112}
113
114static inline
115void __iomem *devm_ioremap_resource_wc(struct device *dev, const struct resource *res)
116{
117 return IOMEM_ERR_PTR(-EINVAL);
118}
119
120static inline
121void __iomem *devm_of_iomap(struct device *dev, struct device_node *node, int index,
122 resource_size_t *size)
123{
124 return IOMEM_ERR_PTR(-EINVAL);
125}
126
127#endif
128
129#endif /* _DEVICE_DEVRES_H_ */