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 	kfree(res);
27 }
28 
29 static const struct ttm_resource_manager_func ttm_sys_manager_func = {
30 	.alloc = ttm_sys_man_alloc,
31 	.free = ttm_sys_man_free,
32 };
33 
34 void ttm_sys_man_init(struct ttm_device *bdev)
35 {
36 	struct ttm_resource_manager *man = &bdev->sysman;
37 
38 	/*
39 	 * Initialize the system memory buffer type.
40 	 * Other types need to be driver / IOCTL initialized.
41 	 */
42 	man->use_tt = true;
43 	man->func = &ttm_sys_manager_func;
44 
45 	ttm_resource_manager_init(man, 0);
46 	ttm_set_driver_manager(bdev, TTM_PL_SYSTEM, man);
47 	ttm_resource_manager_set_used(man, true);
48 }
49