ttm_sys_manager.c 1.2 KB

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