1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#include "drmP.h"
27#include "drm/drm.h"
28#include "qxl_drv.h"
29#include "qxl_object.h"
30
31void qxl_gem_object_free(struct drm_gem_object *gobj)
32{
33 struct qxl_bo *qobj = gem_to_qxl_bo(gobj);
34 struct qxl_device *qdev;
35 struct ttm_buffer_object *tbo;
36
37 qdev = (struct qxl_device *)gobj->dev->dev_private;
38
39 qxl_surface_evict(qdev, qobj, false);
40
41 tbo = &qobj->tbo;
42 ttm_bo_unref(&tbo);
43}
44
45int qxl_gem_object_create(struct qxl_device *qdev, int size,
46 int alignment, int initial_domain,
47 bool discardable, bool kernel,
48 struct qxl_surface *surf,
49 struct drm_gem_object **obj)
50{
51 struct qxl_bo *qbo;
52 int r;
53
54 *obj = NULL;
55
56 if (alignment < PAGE_SIZE)
57 alignment = PAGE_SIZE;
58 r = qxl_bo_create(qdev, size, kernel, false, initial_domain, surf, &qbo);
59 if (r) {
60 if (r != -ERESTARTSYS)
61 DRM_ERROR(
62 "Failed to allocate GEM object (%d, %d, %u, %d)\n",
63 size, initial_domain, alignment, r);
64 return r;
65 }
66 *obj = &qbo->gem_base;
67
68 mutex_lock(&qdev->gem.mutex);
69 list_add_tail(&qbo->list, &qdev->gem.objects);
70 mutex_unlock(&qdev->gem.mutex);
71
72 return 0;
73}
74
75int qxl_gem_object_create_with_handle(struct qxl_device *qdev,
76 struct drm_file *file_priv,
77 u32 domain,
78 size_t size,
79 struct qxl_surface *surf,
80 struct qxl_bo **qobj,
81 uint32_t *handle)
82{
83 struct drm_gem_object *gobj;
84 int r;
85
86 BUG_ON(!qobj);
87 BUG_ON(!handle);
88
89 r = qxl_gem_object_create(qdev, size, 0,
90 domain,
91 false, false, surf,
92 &gobj);
93 if (r)
94 return -ENOMEM;
95 r = drm_gem_handle_create(file_priv, gobj, handle);
96 if (r)
97 return r;
98
99 *qobj = gem_to_qxl_bo(gobj);
100 drm_gem_object_unreference_unlocked(gobj);
101 return 0;
102}
103
104int qxl_gem_object_open(struct drm_gem_object *obj, struct drm_file *file_priv)
105{
106 return 0;
107}
108
109void qxl_gem_object_close(struct drm_gem_object *obj,
110 struct drm_file *file_priv)
111{
112}
113
114int qxl_gem_init(struct qxl_device *qdev)
115{
116 INIT_LIST_HEAD(&qdev->gem.objects);
117 return 0;
118}
119
120void qxl_gem_fini(struct qxl_device *qdev)
121{
122 qxl_bo_force_delete(qdev);
123}
124