0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
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 }