Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2013 Red Hat Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  *
0022  * Authors: Dave Airlie
0023  *          Alon Levy
0024  */
0025 
0026 #include <drm/drm.h>
0027 
0028 #include "qxl_drv.h"
0029 #include "qxl_object.h"
0030 
0031 void qxl_gem_object_free(struct drm_gem_object *gobj)
0032 {
0033     struct qxl_bo *qobj = gem_to_qxl_bo(gobj);
0034     struct qxl_device *qdev;
0035     struct ttm_buffer_object *tbo;
0036 
0037     qdev = to_qxl(gobj->dev);
0038 
0039     qxl_surface_evict(qdev, qobj, false);
0040 
0041     tbo = &qobj->tbo;
0042     ttm_bo_put(tbo);
0043 }
0044 
0045 int qxl_gem_object_create(struct qxl_device *qdev, int size,
0046               int alignment, int initial_domain,
0047               bool discardable, bool kernel,
0048               struct qxl_surface *surf,
0049               struct drm_gem_object **obj)
0050 {
0051     struct qxl_bo *qbo;
0052     int r;
0053 
0054     *obj = NULL;
0055     /* At least align on page size */
0056     if (alignment < PAGE_SIZE)
0057         alignment = PAGE_SIZE;
0058     r = qxl_bo_create(qdev, size, kernel, false, initial_domain, 0, surf, &qbo);
0059     if (r) {
0060         if (r != -ERESTARTSYS)
0061             DRM_ERROR(
0062             "Failed to allocate GEM object (%d, %d, %u, %d)\n",
0063                   size, initial_domain, alignment, r);
0064         return r;
0065     }
0066     *obj = &qbo->tbo.base;
0067 
0068     mutex_lock(&qdev->gem.mutex);
0069     list_add_tail(&qbo->list, &qdev->gem.objects);
0070     mutex_unlock(&qdev->gem.mutex);
0071 
0072     return 0;
0073 }
0074 
0075 int qxl_gem_object_create_with_handle(struct qxl_device *qdev,
0076                       struct drm_file *file_priv,
0077                       u32 domain,
0078                       size_t size,
0079                       struct qxl_surface *surf,
0080                       struct qxl_bo **qobj,
0081                       uint32_t *handle)
0082 {
0083     struct drm_gem_object *gobj;
0084     int r;
0085 
0086     BUG_ON(!qobj);
0087     BUG_ON(!handle);
0088 
0089     r = qxl_gem_object_create(qdev, size, 0,
0090                   domain,
0091                   false, false, surf,
0092                   &gobj);
0093     if (r)
0094         return -ENOMEM;
0095     r = drm_gem_handle_create(file_priv, gobj, handle);
0096     if (r)
0097         return r;
0098     /* drop reference from allocate - handle holds it now */
0099     *qobj = gem_to_qxl_bo(gobj);
0100     drm_gem_object_put(gobj);
0101     return 0;
0102 }
0103 
0104 int qxl_gem_object_open(struct drm_gem_object *obj, struct drm_file *file_priv)
0105 {
0106     return 0;
0107 }
0108 
0109 void qxl_gem_object_close(struct drm_gem_object *obj,
0110               struct drm_file *file_priv)
0111 {
0112 }
0113 
0114 void qxl_gem_init(struct qxl_device *qdev)
0115 {
0116     INIT_LIST_HEAD(&qdev->gem.objects);
0117 }
0118 
0119 void qxl_gem_fini(struct qxl_device *qdev)
0120 {
0121     qxl_bo_force_delete(qdev);
0122 }