xref: /openbmc/linux/include/drm/drm_managed.h (revision c23d686f)
1 // SPDX-License-Identifier: GPL-2.0
2 
3 #ifndef _DRM_MANAGED_H_
4 #define _DRM_MANAGED_H_
5 
6 #include <linux/gfp.h>
7 #include <linux/overflow.h>
8 #include <linux/types.h>
9 
10 struct drm_device;
11 
12 typedef void (*drmres_release_t)(struct drm_device *dev, void *res);
13 
14 #define drmm_add_action(dev, action, data) \
15 	__drmm_add_action(dev, action, data, #action)
16 
17 int __must_check __drmm_add_action(struct drm_device *dev,
18 				   drmres_release_t action,
19 				   void *data, const char *name);
20 
21 #define drmm_add_action_or_reset(dev, action, data) \
22 	__drmm_add_action_or_reset(dev, action, data, #action)
23 
24 int __must_check __drmm_add_action_or_reset(struct drm_device *dev,
25 					    drmres_release_t action,
26 					    void *data, const char *name);
27 
28 void drmm_add_final_kfree(struct drm_device *dev, void *container);
29 
30 void *drmm_kmalloc(struct drm_device *dev, size_t size, gfp_t gfp) __malloc;
31 static inline void *drmm_kzalloc(struct drm_device *dev, size_t size, gfp_t gfp)
32 {
33 	return drmm_kmalloc(dev, size, gfp | __GFP_ZERO);
34 }
35 static inline void *drmm_kmalloc_array(struct drm_device *dev,
36 				       size_t n, size_t size, gfp_t flags)
37 {
38 	size_t bytes;
39 
40 	if (unlikely(check_mul_overflow(n, size, &bytes)))
41 		return NULL;
42 
43 	return drmm_kmalloc(dev, bytes, flags);
44 }
45 static inline void *drmm_kcalloc(struct drm_device *dev,
46 				 size_t n, size_t size, gfp_t flags)
47 {
48 	return drmm_kmalloc_array(dev, n, size, flags | __GFP_ZERO);
49 }
50 char *drmm_kstrdup(struct drm_device *dev, const char *s, gfp_t gfp);
51 
52 void drmm_kfree(struct drm_device *dev, void *data);
53 
54 #endif
55