1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2020-2023 Intel Corporation
8 #include <drm/drm_gem.h>
9 #include <drm/drm_gem_shmem_helper.h>
10 #include <drm/drm_mm.h>
12 struct ivpu_file_priv;
15 struct drm_gem_shmem_object base;
16 struct ivpu_mmu_context *ctx;
17 struct list_head bo_list_node;
18 struct drm_mm_node mm_node;
20 struct mutex lock; /* Protects: ctx, mmu_mapped, vpu_addr */
24 u32 job_status; /* Valid only for command buffer */
28 int ivpu_bo_pin(struct ivpu_bo *bo);
29 void ivpu_bo_remove_all_bos_from_context(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx);
31 struct drm_gem_object *ivpu_gem_create_object(struct drm_device *dev, size_t size);
32 struct ivpu_bo *ivpu_bo_alloc_internal(struct ivpu_device *vdev, u64 vpu_addr, u64 size, u32 flags);
33 void ivpu_bo_free_internal(struct ivpu_bo *bo);
35 int ivpu_bo_create_ioctl(struct drm_device *dev, void *data, struct drm_file *file);
36 int ivpu_bo_info_ioctl(struct drm_device *dev, void *data, struct drm_file *file);
37 int ivpu_bo_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *file);
39 void ivpu_bo_list(struct drm_device *dev, struct drm_printer *p);
40 void ivpu_bo_list_print(struct drm_device *dev);
42 static inline struct ivpu_bo *to_ivpu_bo(struct drm_gem_object *obj)
44 return container_of(obj, struct ivpu_bo, base.base);
47 static inline void *ivpu_bo_vaddr(struct ivpu_bo *bo)
49 return bo->base.vaddr;
52 static inline size_t ivpu_bo_size(struct ivpu_bo *bo)
54 return bo->base.base.size;
57 static inline u32 ivpu_bo_cache_mode(struct ivpu_bo *bo)
59 return bo->flags & DRM_IVPU_BO_CACHE_MASK;
62 static inline bool ivpu_bo_is_snooped(struct ivpu_bo *bo)
64 return ivpu_bo_cache_mode(bo) == DRM_IVPU_BO_CACHED;
67 static inline struct ivpu_device *ivpu_bo_to_vdev(struct ivpu_bo *bo)
69 return to_ivpu_device(bo->base.base.dev);
72 static inline void *ivpu_to_cpu_addr(struct ivpu_bo *bo, u32 vpu_addr)
74 if (vpu_addr < bo->vpu_addr)
77 if (vpu_addr >= (bo->vpu_addr + ivpu_bo_size(bo)))
80 return ivpu_bo_vaddr(bo) + (vpu_addr - bo->vpu_addr);
83 static inline u32 cpu_to_vpu_addr(struct ivpu_bo *bo, void *cpu_addr)
85 if (cpu_addr < ivpu_bo_vaddr(bo))
88 if (cpu_addr >= (ivpu_bo_vaddr(bo) + ivpu_bo_size(bo)))
91 return bo->vpu_addr + (cpu_addr - ivpu_bo_vaddr(bo));
94 #endif /* __IVPU_GEM_H__ */