1 /* SPDX-License-Identifier: GPL-2.0 OR MIT */ 2 3 #include <drm/ttm/ttm_resource.h> 4 #include <drm/ttm/ttm_device.h> 5 #include <drm/ttm/ttm_placement.h> 6 #include <linux/slab.h> 7 8 #include "ttm_module.h" 9 10 static int ttm_sys_man_alloc(struct ttm_resource_manager *man, 11 struct ttm_buffer_object *bo, 12 const struct ttm_place *place, 13 struct ttm_resource **res) 14 { 15 *res = kzalloc(sizeof(**res), GFP_KERNEL); 16 if (!*res) 17 return -ENOMEM; 18 19 ttm_resource_init(bo, place, *res); 20 return 0; 21 } 22 23 static void ttm_sys_man_free(struct ttm_resource_manager *man, 24 struct ttm_resource *res) 25 { 26 ttm_resource_fini(man, res); 27 kfree(res); 28 } 29 30 static const struct ttm_resource_manager_func ttm_sys_manager_func = { 31 .alloc = ttm_sys_man_alloc, 32 .free = ttm_sys_man_free, 33 }; 34 35 void ttm_sys_man_init(struct ttm_device *bdev) 36 { 37 struct ttm_resource_manager *man = &bdev->sysman; 38 39 /* 40 * Initialize the system memory buffer type. 41 * Other types need to be driver / IOCTL initialized. 42 */ 43 man->use_tt = true; 44 man->func = &ttm_sys_manager_func; 45 46 ttm_resource_manager_init(man, bdev, 0); 47 ttm_set_driver_manager(bdev, TTM_PL_SYSTEM, man); 48 ttm_resource_manager_set_used(man, true); 49 } 50