15ca02815Sjsg /* SPDX-License-Identifier: GPL-2.0 OR MIT */
25ca02815Sjsg
35ca02815Sjsg #include <drm/ttm/ttm_resource.h>
45ca02815Sjsg #include <drm/ttm/ttm_device.h>
55ca02815Sjsg #include <drm/ttm/ttm_placement.h>
65ca02815Sjsg #include <linux/slab.h>
75ca02815Sjsg
85ca02815Sjsg #include "ttm_module.h"
95ca02815Sjsg
ttm_sys_man_alloc(struct ttm_resource_manager * man,struct ttm_buffer_object * bo,const struct ttm_place * place,struct ttm_resource ** res)105ca02815Sjsg static int ttm_sys_man_alloc(struct ttm_resource_manager *man,
115ca02815Sjsg struct ttm_buffer_object *bo,
125ca02815Sjsg const struct ttm_place *place,
135ca02815Sjsg struct ttm_resource **res)
145ca02815Sjsg {
155ca02815Sjsg *res = kzalloc(sizeof(**res), GFP_KERNEL);
165ca02815Sjsg if (!*res)
175ca02815Sjsg return -ENOMEM;
185ca02815Sjsg
195ca02815Sjsg ttm_resource_init(bo, place, *res);
205ca02815Sjsg return 0;
215ca02815Sjsg }
225ca02815Sjsg
ttm_sys_man_free(struct ttm_resource_manager * man,struct ttm_resource * res)235ca02815Sjsg static void ttm_sys_man_free(struct ttm_resource_manager *man,
245ca02815Sjsg struct ttm_resource *res)
255ca02815Sjsg {
26*1bb76ff1Sjsg ttm_resource_fini(man, res);
275ca02815Sjsg kfree(res);
285ca02815Sjsg }
295ca02815Sjsg
305ca02815Sjsg static const struct ttm_resource_manager_func ttm_sys_manager_func = {
315ca02815Sjsg .alloc = ttm_sys_man_alloc,
325ca02815Sjsg .free = ttm_sys_man_free,
335ca02815Sjsg };
345ca02815Sjsg
ttm_sys_man_init(struct ttm_device * bdev)355ca02815Sjsg void ttm_sys_man_init(struct ttm_device *bdev)
365ca02815Sjsg {
375ca02815Sjsg struct ttm_resource_manager *man = &bdev->sysman;
385ca02815Sjsg
395ca02815Sjsg /*
405ca02815Sjsg * Initialize the system memory buffer type.
415ca02815Sjsg * Other types need to be driver / IOCTL initialized.
425ca02815Sjsg */
435ca02815Sjsg man->use_tt = true;
445ca02815Sjsg man->func = &ttm_sys_manager_func;
455ca02815Sjsg
46*1bb76ff1Sjsg ttm_resource_manager_init(man, bdev, 0);
475ca02815Sjsg ttm_set_driver_manager(bdev, TTM_PL_SYSTEM, man);
485ca02815Sjsg ttm_resource_manager_set_used(man, true);
495ca02815Sjsg }
50