LCOV - code coverage report
Current view: top level - drivers/gpu/drm/virtio - virtgpu_object.c (source / functions) Hit Total Coverage
Test: combined.info Lines: 0 67 0.0 %
Date: 2022-04-01 14:35:51 Functions: 0 4 0.0 %
Branches: 0 28 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (C) 2015 Red Hat, Inc.
       3                 :            :  * All Rights Reserved.
       4                 :            :  *
       5                 :            :  * Permission is hereby granted, free of charge, to any person obtaining
       6                 :            :  * a copy of this software and associated documentation files (the
       7                 :            :  * "Software"), to deal in the Software without restriction, including
       8                 :            :  * without limitation the rights to use, copy, modify, merge, publish,
       9                 :            :  * distribute, sublicense, and/or sell copies of the Software, and to
      10                 :            :  * permit persons to whom the Software is furnished to do so, subject to
      11                 :            :  * the following conditions:
      12                 :            :  *
      13                 :            :  * The above copyright notice and this permission notice (including the
      14                 :            :  * next paragraph) shall be included in all copies or substantial
      15                 :            :  * portions of the Software.
      16                 :            :  *
      17                 :            :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
      18                 :            :  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
      19                 :            :  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
      20                 :            :  * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
      21                 :            :  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
      22                 :            :  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
      23                 :            :  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
      24                 :            :  */
      25                 :            : 
      26                 :            : #include <linux/moduleparam.h>
      27                 :            : 
      28                 :            : #include "virtgpu_drv.h"
      29                 :            : 
      30                 :            : static int virtio_gpu_virglrenderer_workaround = 1;
      31                 :            : module_param_named(virglhack, virtio_gpu_virglrenderer_workaround, int, 0400);
      32                 :            : 
      33                 :          0 : static int virtio_gpu_resource_id_get(struct virtio_gpu_device *vgdev,
      34                 :            :                                        uint32_t *resid)
      35                 :            : {
      36         [ #  # ]:          0 :         if (virtio_gpu_virglrenderer_workaround) {
      37                 :            :                 /*
      38                 :            :                  * Hack to avoid re-using resource IDs.
      39                 :            :                  *
      40                 :            :                  * virglrenderer versions up to (and including) 0.7.0
      41                 :            :                  * can't deal with that.  virglrenderer commit
      42                 :            :                  * "f91a9dd35715 Fix unlinking resources from hash
      43                 :            :                  * table." (Feb 2019) fixes the bug.
      44                 :            :                  */
      45                 :          0 :                 static atomic_t seqno = ATOMIC_INIT(0);
      46                 :          0 :                 int handle = atomic_inc_return(&seqno);
      47                 :          0 :                 *resid = handle + 1;
      48                 :            :         } else {
      49                 :          0 :                 int handle = ida_alloc(&vgdev->resource_ida, GFP_KERNEL);
      50         [ #  # ]:          0 :                 if (handle < 0)
      51                 :            :                         return handle;
      52                 :          0 :                 *resid = handle + 1;
      53                 :            :         }
      54                 :            :         return 0;
      55                 :            : }
      56                 :            : 
      57                 :          0 : static void virtio_gpu_resource_id_put(struct virtio_gpu_device *vgdev, uint32_t id)
      58                 :            : {
      59                 :          0 :         if (!virtio_gpu_virglrenderer_workaround) {
      60                 :          0 :                 ida_free(&vgdev->resource_ida, id - 1);
      61                 :            :         }
      62                 :            : }
      63                 :            : 
      64                 :          0 : static void virtio_gpu_free_object(struct drm_gem_object *obj)
      65                 :            : {
      66                 :          0 :         struct virtio_gpu_object *bo = gem_to_virtio_gpu_obj(obj);
      67                 :          0 :         struct virtio_gpu_device *vgdev = bo->base.base.dev->dev_private;
      68                 :            : 
      69         [ #  # ]:          0 :         if (bo->pages)
      70                 :          0 :                 virtio_gpu_object_detach(vgdev, bo);
      71         [ #  # ]:          0 :         if (bo->created)
      72                 :          0 :                 virtio_gpu_cmd_unref_resource(vgdev, bo->hw_res_handle);
      73         [ #  # ]:          0 :         virtio_gpu_resource_id_put(vgdev, bo->hw_res_handle);
      74                 :            : 
      75                 :          0 :         drm_gem_shmem_free_object(obj);
      76                 :          0 : }
      77                 :            : 
      78                 :            : static const struct drm_gem_object_funcs virtio_gpu_gem_funcs = {
      79                 :            :         .free = virtio_gpu_free_object,
      80                 :            :         .open = virtio_gpu_gem_object_open,
      81                 :            :         .close = virtio_gpu_gem_object_close,
      82                 :            : 
      83                 :            :         .print_info = drm_gem_shmem_print_info,
      84                 :            :         .pin = drm_gem_shmem_pin,
      85                 :            :         .unpin = drm_gem_shmem_unpin,
      86                 :            :         .get_sg_table = drm_gem_shmem_get_sg_table,
      87                 :            :         .vmap = drm_gem_shmem_vmap,
      88                 :            :         .vunmap = drm_gem_shmem_vunmap,
      89                 :            :         .mmap = &drm_gem_shmem_mmap,
      90                 :            : };
      91                 :            : 
      92                 :          0 : struct drm_gem_object *virtio_gpu_create_object(struct drm_device *dev,
      93                 :            :                                                 size_t size)
      94                 :            : {
      95                 :          0 :         struct virtio_gpu_object *bo;
      96                 :            : 
      97                 :          0 :         bo = kzalloc(sizeof(*bo), GFP_KERNEL);
      98         [ #  # ]:          0 :         if (!bo)
      99                 :            :                 return NULL;
     100                 :            : 
     101                 :          0 :         bo->base.base.funcs = &virtio_gpu_gem_funcs;
     102                 :          0 :         bo->base.map_cached = true;
     103                 :          0 :         return &bo->base.base;
     104                 :            : }
     105                 :            : 
     106                 :          0 : int virtio_gpu_object_create(struct virtio_gpu_device *vgdev,
     107                 :            :                              struct virtio_gpu_object_params *params,
     108                 :            :                              struct virtio_gpu_object **bo_ptr,
     109                 :            :                              struct virtio_gpu_fence *fence)
     110                 :            : {
     111                 :          0 :         struct virtio_gpu_object_array *objs = NULL;
     112                 :          0 :         struct drm_gem_shmem_object *shmem_obj;
     113                 :          0 :         struct virtio_gpu_object *bo;
     114                 :          0 :         int ret;
     115                 :            : 
     116                 :          0 :         *bo_ptr = NULL;
     117                 :            : 
     118                 :          0 :         params->size = roundup(params->size, PAGE_SIZE);
     119                 :          0 :         shmem_obj = drm_gem_shmem_create(vgdev->ddev, params->size);
     120         [ #  # ]:          0 :         if (IS_ERR(shmem_obj))
     121                 :          0 :                 return PTR_ERR(shmem_obj);
     122                 :          0 :         bo = gem_to_virtio_gpu_obj(&shmem_obj->base);
     123                 :            : 
     124                 :          0 :         ret = virtio_gpu_resource_id_get(vgdev, &bo->hw_res_handle);
     125         [ #  # ]:          0 :         if (ret < 0)
     126                 :          0 :                 goto err_free_gem;
     127                 :            : 
     128                 :          0 :         bo->dumb = params->dumb;
     129                 :            : 
     130         [ #  # ]:          0 :         if (fence) {
     131                 :          0 :                 ret = -ENOMEM;
     132                 :          0 :                 objs = virtio_gpu_array_alloc(1);
     133         [ #  # ]:          0 :                 if (!objs)
     134                 :          0 :                         goto err_put_id;
     135                 :          0 :                 virtio_gpu_array_add_obj(objs, &bo->base.base);
     136                 :            : 
     137                 :          0 :                 ret = virtio_gpu_array_lock_resv(objs);
     138         [ #  # ]:          0 :                 if (ret != 0)
     139                 :          0 :                         goto err_put_objs;
     140                 :            :         }
     141                 :            : 
     142         [ #  # ]:          0 :         if (params->virgl) {
     143                 :          0 :                 virtio_gpu_cmd_resource_create_3d(vgdev, bo, params,
     144                 :            :                                                   objs, fence);
     145                 :            :         } else {
     146                 :          0 :                 virtio_gpu_cmd_create_resource(vgdev, bo, params,
     147                 :            :                                                objs, fence);
     148                 :            :         }
     149                 :            : 
     150                 :          0 :         ret = virtio_gpu_object_attach(vgdev, bo, NULL);
     151         [ #  # ]:          0 :         if (ret != 0) {
     152                 :          0 :                 virtio_gpu_free_object(&shmem_obj->base);
     153                 :          0 :                 return ret;
     154                 :            :         }
     155                 :            : 
     156                 :          0 :         *bo_ptr = bo;
     157                 :          0 :         return 0;
     158                 :            : 
     159                 :            : err_put_objs:
     160                 :          0 :         virtio_gpu_array_put_free(objs);
     161                 :          0 : err_put_id:
     162         [ #  # ]:          0 :         virtio_gpu_resource_id_put(vgdev, bo->hw_res_handle);
     163                 :          0 : err_free_gem:
     164                 :          0 :         drm_gem_shmem_free_object(&shmem_obj->base);
     165                 :          0 :         return ret;
     166                 :            : }

Generated by: LCOV version 1.14