1 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
3 * Copyright 2021 VMware, Inc.
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use, copy,
9 * modify, merge, publish, distribute, sublicense, and/or sell copies
10 * of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 #include "vmwgfx_drv.h"
29 #include <drm/ttm/ttm_device.h>
30 #include <drm/ttm/ttm_placement.h>
31 #include <drm/ttm/ttm_resource.h>
32 #include <linux/slab.h>
35 static int vmw_sys_man_alloc(struct ttm_resource_manager *man,
36 struct ttm_buffer_object *bo,
37 const struct ttm_place *place,
38 struct ttm_resource **res)
40 *res = kzalloc(sizeof(**res), GFP_KERNEL);
44 ttm_resource_init(bo, place, *res);
48 static void vmw_sys_man_free(struct ttm_resource_manager *man,
49 struct ttm_resource *res)
51 ttm_resource_fini(man, res);
55 static const struct ttm_resource_manager_func vmw_sys_manager_func = {
56 .alloc = vmw_sys_man_alloc,
57 .free = vmw_sys_man_free,
60 int vmw_sys_man_init(struct vmw_private *dev_priv)
62 struct ttm_device *bdev = &dev_priv->bdev;
63 struct ttm_resource_manager *man =
64 kzalloc(sizeof(*man), GFP_KERNEL);
70 man->func = &vmw_sys_manager_func;
72 ttm_resource_manager_init(man, bdev, 0);
73 ttm_set_driver_manager(bdev, VMW_PL_SYSTEM, man);
74 ttm_resource_manager_set_used(man, true);
78 void vmw_sys_man_fini(struct vmw_private *dev_priv)
80 struct ttm_resource_manager *man = ttm_manager_type(&dev_priv->bdev,
83 ttm_resource_manager_evict_all(&dev_priv->bdev, man);
85 ttm_resource_manager_set_used(man, false);
86 ttm_resource_manager_cleanup(man);
88 ttm_set_driver_manager(&dev_priv->bdev, VMW_PL_SYSTEM, NULL);