Linux Audio

Check our new training course

Open-source upstreaming

Need help get the support for your hardware in upstream Linux?
Loading...
v6.13.7
  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 <drm/drm.h>
 27
 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 = to_qxl(gobj->dev);
 38
 39	qxl_surface_evict(qdev, qobj, false);
 40
 41	tbo = &qobj->tbo;
 42	ttm_bo_put(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	/* 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, 0, 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->tbo.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/*
 76 * If the caller passed a valid gobj pointer, it is responsible to call
 77 * drm_gem_object_put() when it no longer needs to acess the object.
 78 *
 79 * If gobj is NULL, it is handled internally.
 80 */
 81int qxl_gem_object_create_with_handle(struct qxl_device *qdev,
 82				      struct drm_file *file_priv,
 83				      u32 domain,
 84				      size_t size,
 85				      struct qxl_surface *surf,
 86				      struct drm_gem_object **gobj,
 87				      uint32_t *handle)
 88{
 
 89	int r;
 90	struct drm_gem_object *local_gobj;
 91
 
 92	BUG_ON(!handle);
 93
 94	r = qxl_gem_object_create(qdev, size, 0,
 95				  domain,
 96				  false, false, surf,
 97				  &local_gobj);
 98	if (r)
 99		return -ENOMEM;
100	r = drm_gem_handle_create(file_priv, local_gobj, handle);
101	if (r)
102		return r;
103
104	if (gobj)
105		*gobj = local_gobj;
106	else
107		/* drop reference from allocate - handle holds it now */
108		drm_gem_object_put(local_gobj);
109
110	return 0;
111}
112
113int qxl_gem_object_open(struct drm_gem_object *obj, struct drm_file *file_priv)
114{
115	return 0;
116}
117
118void qxl_gem_object_close(struct drm_gem_object *obj,
119			  struct drm_file *file_priv)
120{
121}
122
123void qxl_gem_init(struct qxl_device *qdev)
124{
125	INIT_LIST_HEAD(&qdev->gem.objects);
 
126}
127
128void qxl_gem_fini(struct qxl_device *qdev)
129{
130	qxl_bo_force_delete(qdev);
131}
v3.15
  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
 31void qxl_gem_object_free(struct drm_gem_object *gobj)
 32{
 33	struct qxl_bo *qobj = gem_to_qxl_bo(gobj);
 
 
 
 
 
 
 34
 35	if (qobj)
 36		qxl_bo_unref(&qobj);
 37}
 38
 39int qxl_gem_object_create(struct qxl_device *qdev, int size,
 40			  int alignment, int initial_domain,
 41			  bool discardable, bool kernel,
 42			  struct qxl_surface *surf,
 43			  struct drm_gem_object **obj)
 44{
 45	struct qxl_bo *qbo;
 46	int r;
 47
 48	*obj = NULL;
 49	/* At least align on page size */
 50	if (alignment < PAGE_SIZE)
 51		alignment = PAGE_SIZE;
 52	r = qxl_bo_create(qdev, size, kernel, false, initial_domain, surf, &qbo);
 53	if (r) {
 54		if (r != -ERESTARTSYS)
 55			DRM_ERROR(
 56			"Failed to allocate GEM object (%d, %d, %u, %d)\n",
 57				  size, initial_domain, alignment, r);
 58		return r;
 59	}
 60	*obj = &qbo->gem_base;
 61
 62	mutex_lock(&qdev->gem.mutex);
 63	list_add_tail(&qbo->list, &qdev->gem.objects);
 64	mutex_unlock(&qdev->gem.mutex);
 65
 66	return 0;
 67}
 68
 
 
 
 
 
 
 69int qxl_gem_object_create_with_handle(struct qxl_device *qdev,
 70				      struct drm_file *file_priv,
 71				      u32 domain,
 72				      size_t size,
 73				      struct qxl_surface *surf,
 74				      struct qxl_bo **qobj,
 75				      uint32_t *handle)
 76{
 77	struct drm_gem_object *gobj;
 78	int r;
 
 79
 80	BUG_ON(!qobj);
 81	BUG_ON(!handle);
 82
 83	r = qxl_gem_object_create(qdev, size, 0,
 84				  domain,
 85				  false, false, surf,
 86				  &gobj);
 87	if (r)
 88		return -ENOMEM;
 89	r = drm_gem_handle_create(file_priv, gobj, handle);
 90	if (r)
 91		return r;
 92	/* drop reference from allocate - handle holds it now */
 93	*qobj = gem_to_qxl_bo(gobj);
 94	drm_gem_object_unreference_unlocked(gobj);
 
 
 
 
 95	return 0;
 96}
 97
 98int qxl_gem_object_open(struct drm_gem_object *obj, struct drm_file *file_priv)
 99{
100	return 0;
101}
102
103void qxl_gem_object_close(struct drm_gem_object *obj,
104			  struct drm_file *file_priv)
105{
106}
107
108int qxl_gem_init(struct qxl_device *qdev)
109{
110	INIT_LIST_HEAD(&qdev->gem.objects);
111	return 0;
112}
113
114void qxl_gem_fini(struct qxl_device *qdev)
115{
116	qxl_bo_force_delete(qdev);
117}