Commit | Line | Data |
---|---|---|
f64122c1 DA |
1 | /* |
2 | * Copyright 2013 Red Hat Inc. | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining a | |
5 | * copy of this software and associated documentation files (the "Software"), | |
6 | * to deal in the Software without restriction, including without limitation | |
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
8 | * and/or sell copies of the Software, and to permit persons to whom the | |
9 | * Software is furnished to do so, subject to the following conditions: | |
10 | * | |
11 | * The above copyright notice and this permission notice shall be included in | |
12 | * all copies or substantial portions of the Software. | |
13 | * | |
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
17 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
20 | * OTHER DEALINGS IN THE SOFTWARE. | |
21 | * | |
22 | * Authors: Dave Airlie | |
23 | * Alon Levy | |
24 | */ | |
25 | ||
26 | #include "drmP.h" | |
27 | #include "drm/drm.h" | |
28 | #include "qxl_drv.h" | |
29 | #include "qxl_object.h" | |
30 | ||
31 | int qxl_gem_object_init(struct drm_gem_object *obj) | |
32 | { | |
33 | /* we do nothings here */ | |
34 | return 0; | |
35 | } | |
36 | ||
37 | void qxl_gem_object_free(struct drm_gem_object *gobj) | |
38 | { | |
39 | struct qxl_bo *qobj = gem_to_qxl_bo(gobj); | |
40 | ||
41 | if (qobj) | |
42 | qxl_bo_unref(&qobj); | |
43 | } | |
44 | ||
45 | int 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 | /* At least align on page size */ | |
56 | if (alignment < PAGE_SIZE) | |
57 | alignment = PAGE_SIZE; | |
58 | r = qxl_bo_create(qdev, size, kernel, 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 | ||
75 | int 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 | /* drop reference from allocate - handle holds it now */ | |
99 | *qobj = gem_to_qxl_bo(gobj); | |
100 | drm_gem_object_unreference_unlocked(gobj); | |
101 | return 0; | |
102 | } | |
103 | ||
104 | int qxl_gem_object_pin(struct drm_gem_object *obj, uint32_t pin_domain, | |
105 | uint64_t *gpu_addr) | |
106 | { | |
107 | struct qxl_bo *qobj = obj->driver_private; | |
108 | int r; | |
109 | ||
110 | r = qxl_bo_reserve(qobj, false); | |
111 | if (unlikely(r != 0)) | |
112 | return r; | |
113 | r = qxl_bo_pin(qobj, pin_domain, gpu_addr); | |
114 | qxl_bo_unreserve(qobj); | |
115 | return r; | |
116 | } | |
117 | ||
118 | void qxl_gem_object_unpin(struct drm_gem_object *obj) | |
119 | { | |
120 | struct qxl_bo *qobj = obj->driver_private; | |
121 | int r; | |
122 | ||
123 | r = qxl_bo_reserve(qobj, false); | |
124 | if (likely(r == 0)) { | |
125 | qxl_bo_unpin(qobj); | |
126 | qxl_bo_unreserve(qobj); | |
127 | } | |
128 | } | |
129 | ||
130 | int qxl_gem_set_domain(struct drm_gem_object *gobj, | |
131 | uint32_t rdomain, uint32_t wdomain) | |
132 | { | |
133 | struct qxl_bo *qobj; | |
134 | uint32_t domain; | |
135 | int r; | |
136 | ||
137 | /* FIXME: reeimplement */ | |
138 | qobj = gobj->driver_private; | |
139 | /* work out where to validate the buffer to */ | |
140 | domain = wdomain; | |
141 | if (!domain) | |
142 | domain = rdomain; | |
143 | if (!domain) { | |
144 | /* Do nothings */ | |
145 | pr_warn("Set domain withou domain !\n"); | |
146 | return 0; | |
147 | } | |
148 | if (domain == QXL_GEM_DOMAIN_CPU) { | |
149 | /* Asking for cpu access wait for object idle */ | |
150 | r = qxl_bo_wait(qobj, NULL, false); | |
151 | if (r) { | |
152 | pr_err("Failed to wait for object !\n"); | |
153 | return r; | |
154 | } | |
155 | } | |
156 | return 0; | |
157 | } | |
158 | ||
159 | int qxl_gem_object_open(struct drm_gem_object *obj, struct drm_file *file_priv) | |
160 | { | |
161 | return 0; | |
162 | } | |
163 | ||
164 | void qxl_gem_object_close(struct drm_gem_object *obj, | |
165 | struct drm_file *file_priv) | |
166 | { | |
167 | } | |
168 | ||
169 | int qxl_gem_init(struct qxl_device *qdev) | |
170 | { | |
171 | INIT_LIST_HEAD(&qdev->gem.objects); | |
172 | return 0; | |
173 | } | |
174 | ||
175 | void qxl_gem_fini(struct qxl_device *qdev) | |
176 | { | |
177 | qxl_bo_force_delete(qdev); | |
178 | } |