Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
0002 /*
0003  * Copyright 2021 VMware, Inc.
0004  *
0005  * Permission is hereby granted, free of charge, to any person
0006  * obtaining a copy of this software and associated documentation
0007  * files (the "Software"), to deal in the Software without
0008  * restriction, including without limitation the rights to use, copy,
0009  * modify, merge, publish, distribute, sublicense, and/or sell copies
0010  * of the Software, and to permit persons to whom the Software is
0011  * furnished to do so, subject to the following conditions:
0012  *
0013  * The above copyright notice and this permission notice shall be
0014  * included in all copies or substantial portions of the Software.
0015  *
0016  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0017  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0018  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0019  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
0020  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
0021  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0022  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0023  * SOFTWARE.
0024  *
0025  */
0026 
0027 #include "vmwgfx_drv.h"
0028 
0029 #include <drm/ttm/ttm_bo_driver.h>
0030 #include <drm/ttm/ttm_device.h>
0031 #include <drm/ttm/ttm_placement.h>
0032 #include <drm/ttm/ttm_resource.h>
0033 #include <linux/slab.h>
0034 
0035 
0036 static int vmw_sys_man_alloc(struct ttm_resource_manager *man,
0037                  struct ttm_buffer_object *bo,
0038                  const struct ttm_place *place,
0039                  struct ttm_resource **res)
0040 {
0041     *res = kzalloc(sizeof(**res), GFP_KERNEL);
0042     if (!*res)
0043         return -ENOMEM;
0044 
0045     ttm_resource_init(bo, place, *res);
0046     return 0;
0047 }
0048 
0049 static void vmw_sys_man_free(struct ttm_resource_manager *man,
0050                  struct ttm_resource *res)
0051 {
0052     ttm_resource_fini(man, res);
0053     kfree(res);
0054 }
0055 
0056 static const struct ttm_resource_manager_func vmw_sys_manager_func = {
0057     .alloc = vmw_sys_man_alloc,
0058     .free = vmw_sys_man_free,
0059 };
0060 
0061 int vmw_sys_man_init(struct vmw_private *dev_priv)
0062 {
0063     struct ttm_device *bdev = &dev_priv->bdev;
0064     struct ttm_resource_manager *man =
0065             kzalloc(sizeof(*man), GFP_KERNEL);
0066 
0067     if (!man)
0068         return -ENOMEM;
0069 
0070     man->use_tt = true;
0071     man->func = &vmw_sys_manager_func;
0072 
0073     ttm_resource_manager_init(man, bdev, 0);
0074     ttm_set_driver_manager(bdev, VMW_PL_SYSTEM, man);
0075     ttm_resource_manager_set_used(man, true);
0076     return 0;
0077 }
0078 
0079 void vmw_sys_man_fini(struct vmw_private *dev_priv)
0080 {
0081     struct ttm_resource_manager *man = ttm_manager_type(&dev_priv->bdev,
0082                                 VMW_PL_SYSTEM);
0083 
0084     ttm_resource_manager_evict_all(&dev_priv->bdev, man);
0085 
0086     ttm_resource_manager_set_used(man, false);
0087     ttm_resource_manager_cleanup(man);
0088 
0089     ttm_set_driver_manager(&dev_priv->bdev, VMW_PL_SYSTEM, NULL);
0090     kfree(man);
0091 }