vmwgfx_system_manager.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* SPDX-License-Identifier: GPL-2.0 OR MIT */
  2. /*
  3. * Copyright 2021 VMware, Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person
  6. * obtaining a copy of this software and associated documentation
  7. * files (the "Software"), to deal in the Software without
  8. * restriction, including without limitation the rights to use, copy,
  9. * modify, merge, publish, distribute, sublicense, and/or sell copies
  10. * of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be
  14. * included in all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  20. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  21. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE.
  24. *
  25. */
  26. #include "vmwgfx_drv.h"
  27. #include <drm/ttm/ttm_device.h>
  28. #include <drm/ttm/ttm_placement.h>
  29. #include <drm/ttm/ttm_resource.h>
  30. #include <linux/slab.h>
  31. static int vmw_sys_man_alloc(struct ttm_resource_manager *man,
  32. struct ttm_buffer_object *bo,
  33. const struct ttm_place *place,
  34. struct ttm_resource **res)
  35. {
  36. *res = kzalloc_obj(**res);
  37. if (!*res)
  38. return -ENOMEM;
  39. ttm_resource_init(bo, place, *res);
  40. return 0;
  41. }
  42. static void vmw_sys_man_free(struct ttm_resource_manager *man,
  43. struct ttm_resource *res)
  44. {
  45. ttm_resource_fini(man, res);
  46. kfree(res);
  47. }
  48. static const struct ttm_resource_manager_func vmw_sys_manager_func = {
  49. .alloc = vmw_sys_man_alloc,
  50. .free = vmw_sys_man_free,
  51. };
  52. int vmw_sys_man_init(struct vmw_private *dev_priv)
  53. {
  54. struct ttm_device *bdev = &dev_priv->bdev;
  55. struct ttm_resource_manager *man = kzalloc_obj(*man);
  56. if (!man)
  57. return -ENOMEM;
  58. man->use_tt = true;
  59. man->func = &vmw_sys_manager_func;
  60. ttm_resource_manager_init(man, bdev, 0);
  61. ttm_set_driver_manager(bdev, VMW_PL_SYSTEM, man);
  62. ttm_resource_manager_set_used(man, true);
  63. return 0;
  64. }
  65. void vmw_sys_man_fini(struct vmw_private *dev_priv)
  66. {
  67. struct ttm_resource_manager *man = ttm_manager_type(&dev_priv->bdev,
  68. VMW_PL_SYSTEM);
  69. ttm_resource_manager_evict_all(&dev_priv->bdev, man);
  70. ttm_resource_manager_set_used(man, false);
  71. ttm_resource_manager_cleanup(man);
  72. ttm_set_driver_manager(&dev_priv->bdev, VMW_PL_SYSTEM, NULL);
  73. kfree(man);
  74. }