embox

Форк
0
/
drm_gem.c 
110 строк · 2.8 Кб
1
/**
2
 * @file
3
 *
4
 * @date Jan 19, 2018
5
 * @author Anton Bondarev
6
 */
7

8
#include <util/log.h>
9

10
#include <stdint.h>
11
#include <pthread.h>
12

13
#include <linux/idr.h>
14
#include <linux/pagemap.h>
15

16
#include <embox_drm/drm_gem.h>
17
#include <embox_drm/drm_priv.h>
18

19
/**
20
 * drm_gem_object_lookup - look up a GEM object from it's handle
21
 * @filp: DRM file private date
22
 * @handle: userspace handle
23
 *
24
 * Returns:
25
 *
26
 * A reference to the object named by the handle if such exists on @filp, NULL
27
 * otherwise.
28
 */
29
struct drm_gem_object *
30
drm_gem_object_lookup(struct drm_file *filp, uint32_t handle) {
31
	struct drm_gem_object *obj;
32

33
	pthread_mutex_lock(&filp->table_lock);
34

35
	obj = idr_find(&filp->object_idr, handle);
36

37
	pthread_mutex_unlock(&filp->table_lock);
38

39
	return obj;
40
}
41

42
/**
43
 * drm_gem_handle_create_tail - internal functions to create a handle
44
 * @file_priv: drm file-private structure to register the handle for
45
 * @obj: object to register
46
 * @handlep: pointer to return the created handle to the caller
47
 *
48
 * This expects the dev->object_name_lock to be held already and will drop it
49
 * before returning. Used to avoid races in establishing new handles when
50
 * importing an object from either an flink name or a dma-buf.
51
 *
52
 * Handles must be release again through drm_gem_handle_delete(). This is done
53
 * when userspace closes @file_priv for all attached handles, or through the
54
 * GEM_CLOSE ioctl for individual handles.
55
 */
56
int drm_gem_handle_create_tail(struct drm_file *file_priv,
57
			   struct drm_gem_object *obj,
58
			   uint32_t *handlep) {
59
	int ret;
60

61
	obj->handle_count++;
62

63
	pthread_mutex_lock(&file_priv->table_lock);
64

65
	ret = idr_alloc(&file_priv->object_idr, obj, 1, 0, GFP_NOWAIT);
66

67
	if (ret < 0) {
68
		return ret;
69
	}
70

71
	pthread_mutex_unlock(&file_priv->table_lock);
72

73
	*handlep = ret;
74

75
	return 0;
76
}
77

78
/**
79
 * drm_gem_handle_create - create a gem handle for an object
80
 * @file_priv: drm file-private structure to register the handle for
81
 * @obj: object to register
82
 * @handlep: pionter to return the created handle to the caller
83
 *
84
 * Create a handle for this object. This adds a handle reference
85
 * to the object, which includes a regular reference count. Callers
86
 * will likely want to dereference the object afterwards.
87
 */
88
int drm_gem_handle_create(struct drm_file *file_priv,
89
			  struct drm_gem_object *obj,
90
			  uint32_t *handlep) {
91
	return drm_gem_handle_create_tail(file_priv, obj, handlep);
92
}
93

94
/**
95
 * drm_gem_object_init - initialize an allocated shmem-backed GEM object
96
 * @dev: drm_device the object should be initialized for
97
 * @obj: drm_gem_object to initialize
98
 * @size: object size
99
 *
100
 * Initialize an already allocated GEM object of the specified size with
101
 * shmfs backing store.
102
 */
103
int drm_gem_object_init(struct drm_device *dev,
104
			struct drm_gem_object *obj, size_t size) {
105
	*obj = (struct drm_gem_object) {
106
		.dev  = dev,
107
		.size = size,
108
	};
109
	return 0;
110
}
111

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.