2 * Copyright 2013 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
22 * Authors: Dave Airlie
29 #include "qxl_object.h"
31 int qxl_gem_object_init(struct drm_gem_object *obj)
33 /* we do nothings here */
37 void qxl_gem_object_free(struct drm_gem_object *gobj)
39 struct qxl_bo *qobj = gem_to_qxl_bo(gobj);
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)
55 /* At least align on page size */
56 if (alignment < PAGE_SIZE)
57 alignment = PAGE_SIZE;
58 r = qxl_bo_create(qdev, size, kernel, false, initial_domain, surf, &qbo);
60 if (r != -ERESTARTSYS)
62 "Failed to allocate GEM object (%d, %d, %u, %d)\n",
63 size, initial_domain, alignment, r);
66 *obj = &qbo->gem_base;
68 mutex_lock(&qdev->gem.mutex);
69 list_add_tail(&qbo->list, &qdev->gem.objects);
70 mutex_unlock(&qdev->gem.mutex);
75 int qxl_gem_object_create_with_handle(struct qxl_device *qdev,
76 struct drm_file *file_priv,
79 struct qxl_surface *surf,
83 struct drm_gem_object *gobj;
89 r = qxl_gem_object_create(qdev, size, 0,
95 r = drm_gem_handle_create(file_priv, gobj, handle);
98 /* drop reference from allocate - handle holds it now */
99 *qobj = gem_to_qxl_bo(gobj);
100 drm_gem_object_unreference_unlocked(gobj);
104 int qxl_gem_object_pin(struct drm_gem_object *obj, uint32_t pin_domain,
107 struct qxl_bo *qobj = obj->driver_private;
110 r = qxl_bo_reserve(qobj, false);
111 if (unlikely(r != 0))
113 r = qxl_bo_pin(qobj, pin_domain, gpu_addr);
114 qxl_bo_unreserve(qobj);
118 void qxl_gem_object_unpin(struct drm_gem_object *obj)
120 struct qxl_bo *qobj = obj->driver_private;
123 r = qxl_bo_reserve(qobj, false);
124 if (likely(r == 0)) {
126 qxl_bo_unreserve(qobj);
130 int qxl_gem_object_open(struct drm_gem_object *obj, struct drm_file *file_priv)
135 void qxl_gem_object_close(struct drm_gem_object *obj,
136 struct drm_file *file_priv)
140 int qxl_gem_init(struct qxl_device *qdev)
142 INIT_LIST_HEAD(&qdev->gem.objects);
146 void qxl_gem_fini(struct qxl_device *qdev)
148 qxl_bo_force_delete(qdev);