ivpu_gem.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2020-2025 Intel Corporation
  4. */
  5. #ifndef __IVPU_GEM_H__
  6. #define __IVPU_GEM_H__
  7. #include <drm/drm_gem.h>
  8. #include <drm/drm_gem_shmem_helper.h>
  9. #include <drm/drm_mm.h>
  10. struct ivpu_file_priv;
  11. struct ivpu_bo {
  12. struct drm_gem_shmem_object base;
  13. struct ivpu_mmu_context *ctx;
  14. struct list_head bo_list_node;
  15. struct drm_mm_node mm_node;
  16. u64 vpu_addr;
  17. u32 flags;
  18. u32 job_status; /* Valid only for command buffer */
  19. u32 ctx_id;
  20. bool mmu_mapped;
  21. };
  22. int ivpu_bo_bind(struct ivpu_bo *bo);
  23. void ivpu_bo_unbind_all_bos_from_context(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx);
  24. struct drm_gem_object *ivpu_gem_create_object(struct drm_device *dev, size_t size);
  25. struct drm_gem_object *ivpu_gem_prime_import(struct drm_device *dev, struct dma_buf *dma_buf);
  26. struct ivpu_bo *ivpu_bo_create(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx,
  27. struct ivpu_addr_range *range, u64 size, u32 flags);
  28. struct ivpu_bo *ivpu_bo_create_runtime(struct ivpu_device *vdev, u64 addr, u64 size, u32 flags);
  29. struct ivpu_bo *ivpu_bo_create_global(struct ivpu_device *vdev, u64 size, u32 flags);
  30. void ivpu_bo_free(struct ivpu_bo *bo);
  31. int ivpu_bo_create_ioctl(struct drm_device *dev, void *data, struct drm_file *file);
  32. int ivpu_bo_info_ioctl(struct drm_device *dev, void *data, struct drm_file *file);
  33. int ivpu_bo_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *file);
  34. int ivpu_bo_create_from_userptr_ioctl(struct drm_device *dev, void *data,
  35. struct drm_file *file);
  36. void ivpu_bo_list(struct drm_device *dev, struct drm_printer *p);
  37. void ivpu_bo_list_print(struct drm_device *dev);
  38. static inline struct ivpu_bo *to_ivpu_bo(struct drm_gem_object *obj)
  39. {
  40. return container_of(obj, struct ivpu_bo, base.base);
  41. }
  42. static inline void *ivpu_bo_vaddr(struct ivpu_bo *bo)
  43. {
  44. return bo->base.vaddr;
  45. }
  46. static inline size_t ivpu_bo_size(struct ivpu_bo *bo)
  47. {
  48. return bo->base.base.size;
  49. }
  50. static inline u32 ivpu_bo_cache_mode(struct ivpu_bo *bo)
  51. {
  52. return bo->flags & DRM_IVPU_BO_CACHE_MASK;
  53. }
  54. static inline struct ivpu_device *ivpu_bo_to_vdev(struct ivpu_bo *bo)
  55. {
  56. return to_ivpu_device(bo->base.base.dev);
  57. }
  58. static inline bool ivpu_bo_is_snooped(struct ivpu_bo *bo)
  59. {
  60. if (ivpu_is_force_snoop_enabled(ivpu_bo_to_vdev(bo)))
  61. return true;
  62. return ivpu_bo_cache_mode(bo) == DRM_IVPU_BO_CACHED;
  63. }
  64. static inline bool ivpu_bo_is_read_only(struct ivpu_bo *bo)
  65. {
  66. return bo->flags & DRM_IVPU_BO_READ_ONLY;
  67. }
  68. static inline bool ivpu_bo_is_resident(struct ivpu_bo *bo)
  69. {
  70. return !!bo->base.pages;
  71. }
  72. static inline void *ivpu_to_cpu_addr(struct ivpu_bo *bo, u32 vpu_addr)
  73. {
  74. if (vpu_addr < bo->vpu_addr)
  75. return NULL;
  76. if (vpu_addr >= (bo->vpu_addr + ivpu_bo_size(bo)))
  77. return NULL;
  78. return ivpu_bo_vaddr(bo) + (vpu_addr - bo->vpu_addr);
  79. }
  80. static inline u32 cpu_to_vpu_addr(struct ivpu_bo *bo, void *cpu_addr)
  81. {
  82. if (cpu_addr < ivpu_bo_vaddr(bo))
  83. return 0;
  84. if (cpu_addr >= (ivpu_bo_vaddr(bo) + ivpu_bo_size(bo)))
  85. return 0;
  86. return bo->vpu_addr + (cpu_addr - ivpu_bo_vaddr(bo));
  87. }
  88. static inline bool ivpu_bo_is_mappable(struct ivpu_bo *bo)
  89. {
  90. return bo->flags & DRM_IVPU_BO_MAPPABLE;
  91. }
  92. #endif /* __IVPU_GEM_H__ */