ivpu_gem.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2020-2023 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_pin(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 ivpu_bo *ivpu_bo_create(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx,
  26. struct ivpu_addr_range *range, u64 size, u32 flags);
  27. struct ivpu_bo *ivpu_bo_create_global(struct ivpu_device *vdev, u64 size, u32 flags);
  28. void ivpu_bo_free(struct ivpu_bo *bo);
  29. int ivpu_bo_create_ioctl(struct drm_device *dev, void *data, struct drm_file *file);
  30. int ivpu_bo_info_ioctl(struct drm_device *dev, void *data, struct drm_file *file);
  31. int ivpu_bo_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *file);
  32. void ivpu_bo_list(struct drm_device *dev, struct drm_printer *p);
  33. void ivpu_bo_list_print(struct drm_device *dev);
  34. static inline struct ivpu_bo *to_ivpu_bo(struct drm_gem_object *obj)
  35. {
  36. return container_of(obj, struct ivpu_bo, base.base);
  37. }
  38. static inline void *ivpu_bo_vaddr(struct ivpu_bo *bo)
  39. {
  40. return bo->base.vaddr;
  41. }
  42. static inline size_t ivpu_bo_size(struct ivpu_bo *bo)
  43. {
  44. return bo->base.base.size;
  45. }
  46. static inline u32 ivpu_bo_cache_mode(struct ivpu_bo *bo)
  47. {
  48. return bo->flags & DRM_IVPU_BO_CACHE_MASK;
  49. }
  50. static inline struct ivpu_device *ivpu_bo_to_vdev(struct ivpu_bo *bo)
  51. {
  52. return to_ivpu_device(bo->base.base.dev);
  53. }
  54. static inline bool ivpu_bo_is_snooped(struct ivpu_bo *bo)
  55. {
  56. if (ivpu_is_force_snoop_enabled(ivpu_bo_to_vdev(bo)))
  57. return true;
  58. return ivpu_bo_cache_mode(bo) == DRM_IVPU_BO_CACHED;
  59. }
  60. static inline void *ivpu_to_cpu_addr(struct ivpu_bo *bo, u32 vpu_addr)
  61. {
  62. if (vpu_addr < bo->vpu_addr)
  63. return NULL;
  64. if (vpu_addr >= (bo->vpu_addr + ivpu_bo_size(bo)))
  65. return NULL;
  66. return ivpu_bo_vaddr(bo) + (vpu_addr - bo->vpu_addr);
  67. }
  68. static inline u32 cpu_to_vpu_addr(struct ivpu_bo *bo, void *cpu_addr)
  69. {
  70. if (cpu_addr < ivpu_bo_vaddr(bo))
  71. return 0;
  72. if (cpu_addr >= (ivpu_bo_vaddr(bo) + ivpu_bo_size(bo)))
  73. return 0;
  74. return bo->vpu_addr + (cpu_addr - ivpu_bo_vaddr(bo));
  75. }
  76. #endif /* __IVPU_GEM_H__ */