qxl_object.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright 2013 Red Hat Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Dave Airlie
  23. * Alon Levy
  24. */
  25. #ifndef QXL_OBJECT_H
  26. #define QXL_OBJECT_H
  27. #include "qxl_drv.h"
  28. static inline int qxl_bo_reserve(struct qxl_bo *bo, bool no_wait)
  29. {
  30. int r;
  31. r = ttm_bo_reserve(&bo->tbo, true, no_wait, false, 0);
  32. if (unlikely(r != 0)) {
  33. if (r != -ERESTARTSYS) {
  34. struct qxl_device *qdev = (struct qxl_device *)bo->gem_base.dev->dev_private;
  35. dev_err(qdev->dev, "%p reserve failed\n", bo);
  36. }
  37. return r;
  38. }
  39. return 0;
  40. }
  41. static inline void qxl_bo_unreserve(struct qxl_bo *bo)
  42. {
  43. ttm_bo_unreserve(&bo->tbo);
  44. }
  45. static inline u64 qxl_bo_gpu_offset(struct qxl_bo *bo)
  46. {
  47. return bo->tbo.offset;
  48. }
  49. static inline unsigned long qxl_bo_size(struct qxl_bo *bo)
  50. {
  51. return bo->tbo.num_pages << PAGE_SHIFT;
  52. }
  53. static inline bool qxl_bo_is_reserved(struct qxl_bo *bo)
  54. {
  55. return !!atomic_read(&bo->tbo.reserved);
  56. }
  57. static inline u64 qxl_bo_mmap_offset(struct qxl_bo *bo)
  58. {
  59. return bo->tbo.addr_space_offset;
  60. }
  61. static inline int qxl_bo_wait(struct qxl_bo *bo, u32 *mem_type,
  62. bool no_wait)
  63. {
  64. int r;
  65. r = ttm_bo_reserve(&bo->tbo, true, no_wait, false, 0);
  66. if (unlikely(r != 0)) {
  67. if (r != -ERESTARTSYS) {
  68. struct qxl_device *qdev = (struct qxl_device *)bo->gem_base.dev->dev_private;
  69. dev_err(qdev->dev, "%p reserve failed for wait\n",
  70. bo);
  71. }
  72. return r;
  73. }
  74. spin_lock(&bo->tbo.bdev->fence_lock);
  75. if (mem_type)
  76. *mem_type = bo->tbo.mem.mem_type;
  77. if (bo->tbo.sync_obj)
  78. r = ttm_bo_wait(&bo->tbo, true, true, no_wait);
  79. spin_unlock(&bo->tbo.bdev->fence_lock);
  80. ttm_bo_unreserve(&bo->tbo);
  81. return r;
  82. }
  83. extern int qxl_bo_create(struct qxl_device *qdev,
  84. unsigned long size,
  85. bool kernel, u32 domain,
  86. struct qxl_surface *surf,
  87. struct qxl_bo **bo_ptr);
  88. extern int qxl_bo_kmap(struct qxl_bo *bo, void **ptr);
  89. extern void qxl_bo_kunmap(struct qxl_bo *bo);
  90. void *qxl_bo_kmap_atomic_page(struct qxl_device *qdev, struct qxl_bo *bo, int page_offset);
  91. void qxl_bo_kunmap_atomic_page(struct qxl_device *qdev, struct qxl_bo *bo, void *map);
  92. extern struct qxl_bo *qxl_bo_ref(struct qxl_bo *bo);
  93. extern void qxl_bo_unref(struct qxl_bo **bo);
  94. extern int qxl_bo_pin(struct qxl_bo *bo, u32 domain, u64 *gpu_addr);
  95. extern int qxl_bo_unpin(struct qxl_bo *bo);
  96. extern void qxl_ttm_placement_from_domain(struct qxl_bo *qbo, u32 domain);
  97. extern bool qxl_ttm_bo_is_qxl_bo(struct ttm_buffer_object *bo);
  98. extern int qxl_bo_list_add(struct qxl_reloc_list *reloc_list, struct qxl_bo *bo);
  99. extern void qxl_bo_list_unreserve(struct qxl_reloc_list *reloc_list, bool failed);
  100. #endif