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