radeon_bo.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Copyright © 2008 Dave Airlie
  3. * Copyright © 2008 Jérôme Glisse
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sub license, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  16. * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
  18. * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  21. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * The above copyright notice and this permission notice (including the
  24. * next paragraph) shall be included in all copies or substantial portions
  25. * of the Software.
  26. */
  27. /*
  28. * Authors:
  29. * Dave Airlie
  30. * Jérôme Glisse <glisse@freedesktop.org>
  31. */
  32. #include <libdrm_macros.h>
  33. #include <radeon_bo.h>
  34. #include <radeon_bo_int.h>
  35. drm_public void radeon_bo_debug(struct radeon_bo *bo, const char *op)
  36. {
  37. struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
  38. fprintf(stderr, "%s %p 0x%08X 0x%08X 0x%08X\n",
  39. op, bo, bo->handle, boi->size, boi->cref);
  40. }
  41. drm_public struct radeon_bo *
  42. radeon_bo_open(struct radeon_bo_manager *bom, uint32_t handle, uint32_t size,
  43. uint32_t alignment, uint32_t domains, uint32_t flags)
  44. {
  45. struct radeon_bo *bo;
  46. bo = bom->funcs->bo_open(bom, handle, size, alignment, domains, flags);
  47. return bo;
  48. }
  49. drm_public void radeon_bo_ref(struct radeon_bo *bo)
  50. {
  51. struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
  52. boi->cref++;
  53. boi->bom->funcs->bo_ref(boi);
  54. }
  55. drm_public struct radeon_bo *radeon_bo_unref(struct radeon_bo *bo)
  56. {
  57. struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
  58. if (bo == NULL)
  59. return NULL;
  60. boi->cref--;
  61. return boi->bom->funcs->bo_unref(boi);
  62. }
  63. drm_public int radeon_bo_map(struct radeon_bo *bo, int write)
  64. {
  65. struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
  66. return boi->bom->funcs->bo_map(boi, write);
  67. }
  68. drm_public int radeon_bo_unmap(struct radeon_bo *bo)
  69. {
  70. struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
  71. return boi->bom->funcs->bo_unmap(boi);
  72. }
  73. drm_public int radeon_bo_wait(struct radeon_bo *bo)
  74. {
  75. struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
  76. if (!boi->bom->funcs->bo_wait)
  77. return 0;
  78. return boi->bom->funcs->bo_wait(boi);
  79. }
  80. drm_public int radeon_bo_is_busy(struct radeon_bo *bo, uint32_t *domain)
  81. {
  82. struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
  83. return boi->bom->funcs->bo_is_busy(boi, domain);
  84. }
  85. drm_public int
  86. radeon_bo_set_tiling(struct radeon_bo *bo,
  87. uint32_t tiling_flags, uint32_t pitch)
  88. {
  89. struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
  90. return boi->bom->funcs->bo_set_tiling(boi, tiling_flags, pitch);
  91. }
  92. drm_public int
  93. radeon_bo_get_tiling(struct radeon_bo *bo,
  94. uint32_t *tiling_flags, uint32_t *pitch)
  95. {
  96. struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
  97. return boi->bom->funcs->bo_get_tiling(boi, tiling_flags, pitch);
  98. }
  99. drm_public int radeon_bo_is_static(struct radeon_bo *bo)
  100. {
  101. struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
  102. if (boi->bom->funcs->bo_is_static)
  103. return boi->bom->funcs->bo_is_static(boi);
  104. return 0;
  105. }
  106. drm_public int
  107. radeon_bo_is_referenced_by_cs(struct radeon_bo *bo, struct radeon_cs *cs)
  108. {
  109. struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
  110. return boi->cref > 1;
  111. }
  112. drm_public uint32_t radeon_bo_get_handle(struct radeon_bo *bo)
  113. {
  114. return bo->handle;
  115. }
  116. drm_public uint32_t radeon_bo_get_src_domain(struct radeon_bo *bo)
  117. {
  118. struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
  119. uint32_t src_domain;
  120. src_domain = boi->space_accounted & 0xffff;
  121. if (!src_domain)
  122. src_domain = boi->space_accounted >> 16;
  123. return src_domain;
  124. }