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_mm.h>
11 #define DRM_IVPU_BO_NOSNOOP 0x10000000
15 struct ivpu_file_priv;
18 struct drm_gem_object base;
19 const struct ivpu_bo_ops *ops;
21 struct ivpu_mmu_context *ctx;
22 struct list_head ctx_node;
23 struct drm_mm_node mm_node;
25 struct mutex lock; /* Protects: pages, sgt, mmu_mapped */
39 IVPU_BO_TYPE_SHMEM = 1,
40 IVPU_BO_TYPE_INTERNAL,
45 enum ivpu_bo_type type;
47 int (*alloc_pages)(struct ivpu_bo *bo);
48 void (*free_pages)(struct ivpu_bo *bo);
49 int (*map_pages)(struct ivpu_bo *bo);
50 void (*unmap_pages)(struct ivpu_bo *bo);
53 int ivpu_bo_pin(struct ivpu_bo *bo);
54 void ivpu_bo_remove_all_bos_from_context(struct ivpu_mmu_context *ctx);
55 void ivpu_bo_list(struct drm_device *dev, struct drm_printer *p);
56 void ivpu_bo_list_print(struct drm_device *dev);
59 ivpu_bo_alloc_internal(struct ivpu_device *vdev, u64 vpu_addr, u64 size, u32 flags);
60 void ivpu_bo_free_internal(struct ivpu_bo *bo);
61 struct drm_gem_object *ivpu_gem_prime_import(struct drm_device *dev, struct dma_buf *dma_buf);
62 void ivpu_bo_unmap_sgt_and_remove_from_context(struct ivpu_bo *bo);
64 int ivpu_bo_create_ioctl(struct drm_device *dev, void *data, struct drm_file *file);
65 int ivpu_bo_info_ioctl(struct drm_device *dev, void *data, struct drm_file *file);
66 int ivpu_bo_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *file);
68 static inline struct ivpu_bo *to_ivpu_bo(struct drm_gem_object *obj)
70 return container_of(obj, struct ivpu_bo, base);
73 static inline struct page *ivpu_bo_get_page(struct ivpu_bo *bo, u64 offset)
75 if (offset > bo->base.size || !bo->pages)
78 return bo->pages[offset / PAGE_SIZE];
81 static inline u32 ivpu_bo_cache_mode(struct ivpu_bo *bo)
83 return bo->flags & DRM_IVPU_BO_CACHE_MASK;
86 static inline bool ivpu_bo_is_snooped(struct ivpu_bo *bo)
88 if (bo->flags & DRM_IVPU_BO_NOSNOOP)
91 return ivpu_bo_cache_mode(bo) == DRM_IVPU_BO_CACHED;
94 static inline pgprot_t ivpu_bo_pgprot(struct ivpu_bo *bo, pgprot_t prot)
96 if (bo->flags & DRM_IVPU_BO_WC)
97 return pgprot_writecombine(prot);
99 if (bo->flags & DRM_IVPU_BO_UNCACHED)
100 return pgprot_noncached(prot);
105 static inline struct ivpu_device *ivpu_bo_to_vdev(struct ivpu_bo *bo)
107 return to_ivpu_device(bo->base.dev);
110 static inline void *ivpu_to_cpu_addr(struct ivpu_bo *bo, u32 vpu_addr)
112 if (vpu_addr < bo->vpu_addr)
115 if (vpu_addr >= (bo->vpu_addr + bo->base.size))
118 return bo->kvaddr + (vpu_addr - bo->vpu_addr);
121 static inline u32 cpu_to_vpu_addr(struct ivpu_bo *bo, void *cpu_addr)
123 if (cpu_addr < bo->kvaddr)
126 if (cpu_addr >= (bo->kvaddr + bo->base.size))
129 return bo->vpu_addr + (cpu_addr - bo->kvaddr);
132 #endif /* __IVPU_GEM_H__ */