Commit 8d88e4cd authored by Jacek Lawrynowicz's avatar Jacek Lawrynowicz

accel/ivpu: Use GEM shmem helper for all buffers

Use struct drm_gem_shmem_object as a base for struct ivpu_bo.
This cuts by 50% the buffer management code.
Signed-off-by: default avatarJacek Lawrynowicz <jacek.lawrynowicz@linux.intel.com>
Reviewed-by: default avatarJeffrey Hugo <quic_jhugo@quicinc.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20231031073156.1301669-5-stanislaw.gruszka@linux.intel.com
parent 48d45fac
...@@ -6,7 +6,7 @@ config DRM_ACCEL_IVPU ...@@ -6,7 +6,7 @@ config DRM_ACCEL_IVPU
depends on X86_64 && !UML depends on X86_64 && !UML
depends on PCI && PCI_MSI depends on PCI && PCI_MSI
select FW_LOADER select FW_LOADER
select SHMEM select DRM_GEM_SHMEM_HELPER
select GENERIC_ALLOCATOR select GENERIC_ALLOCATOR
help help
Choose this option if you have a system with an 14th generation Choose this option if you have a system with an 14th generation
......
...@@ -360,7 +360,7 @@ int ivpu_boot(struct ivpu_device *vdev) ...@@ -360,7 +360,7 @@ int ivpu_boot(struct ivpu_device *vdev)
int ret; int ret;
/* Update boot params located at first 4KB of FW memory */ /* Update boot params located at first 4KB of FW memory */
ivpu_fw_boot_params_setup(vdev, vdev->fw->mem->kvaddr); ivpu_fw_boot_params_setup(vdev, ivpu_bo_vaddr(vdev->fw->mem));
ret = ivpu_hw_boot_fw(vdev); ret = ivpu_hw_boot_fw(vdev);
if (ret) { if (ret) {
...@@ -409,7 +409,9 @@ static const struct drm_driver driver = { ...@@ -409,7 +409,9 @@ static const struct drm_driver driver = {
.open = ivpu_open, .open = ivpu_open,
.postclose = ivpu_postclose, .postclose = ivpu_postclose,
.gem_prime_import = ivpu_gem_prime_import,
.gem_create_object = ivpu_gem_create_object,
.gem_prime_import_sg_table = drm_gem_shmem_prime_import_sg_table,
.ioctls = ivpu_drm_ioctls, .ioctls = ivpu_drm_ioctls,
.num_ioctls = ARRAY_SIZE(ivpu_drm_ioctls), .num_ioctls = ARRAY_SIZE(ivpu_drm_ioctls),
......
This diff is collapsed.
...@@ -6,83 +6,52 @@ ...@@ -6,83 +6,52 @@
#define __IVPU_GEM_H__ #define __IVPU_GEM_H__
#include <drm/drm_gem.h> #include <drm/drm_gem.h>
#include <drm/drm_gem_shmem_helper.h>
#include <drm/drm_mm.h> #include <drm/drm_mm.h>
struct dma_buf;
struct ivpu_bo_ops;
struct ivpu_file_priv; struct ivpu_file_priv;
struct ivpu_bo { struct ivpu_bo {
struct drm_gem_object base; struct drm_gem_shmem_object base;
const struct ivpu_bo_ops *ops;
struct ivpu_mmu_context *ctx; struct ivpu_mmu_context *ctx;
struct list_head bo_list_node; struct list_head bo_list_node;
struct drm_mm_node mm_node; struct drm_mm_node mm_node;
struct mutex lock; /* Protects: pages, sgt, ctx, mmu_mapped, vpu_addr */ struct mutex lock; /* Protects: ctx, mmu_mapped, vpu_addr */
struct sg_table *sgt;
struct page **pages;
bool mmu_mapped;
void *kvaddr;
u64 vpu_addr; u64 vpu_addr;
u32 handle; u32 handle;
u32 flags; u32 flags;
u32 job_status; u32 job_status; /* Valid only for command buffer */
}; bool mmu_mapped;
enum ivpu_bo_type {
IVPU_BO_TYPE_SHMEM = 1,
IVPU_BO_TYPE_INTERNAL,
IVPU_BO_TYPE_PRIME,
};
struct ivpu_bo_ops {
enum ivpu_bo_type type;
const char *name;
int (*alloc_pages)(struct ivpu_bo *bo);
void (*free_pages)(struct ivpu_bo *bo);
int (*map_pages)(struct ivpu_bo *bo);
void (*unmap_pages)(struct ivpu_bo *bo);
}; };
int ivpu_bo_pin(struct ivpu_bo *bo); int ivpu_bo_pin(struct ivpu_bo *bo);
void ivpu_bo_remove_all_bos_from_context(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx); void ivpu_bo_remove_all_bos_from_context(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx);
void ivpu_bo_list(struct drm_device *dev, struct drm_printer *p);
void ivpu_bo_list_print(struct drm_device *dev);
struct ivpu_bo * struct drm_gem_object *ivpu_gem_create_object(struct drm_device *dev, size_t size);
ivpu_bo_alloc_internal(struct ivpu_device *vdev, u64 vpu_addr, u64 size, u32 flags); struct ivpu_bo *ivpu_bo_alloc_internal(struct ivpu_device *vdev, u64 vpu_addr, u64 size, u32 flags);
void ivpu_bo_free_internal(struct ivpu_bo *bo); void ivpu_bo_free_internal(struct ivpu_bo *bo);
struct drm_gem_object *ivpu_gem_prime_import(struct drm_device *dev, struct dma_buf *dma_buf);
void ivpu_bo_unmap_sgt_and_remove_from_context(struct ivpu_bo *bo);
int ivpu_bo_create_ioctl(struct drm_device *dev, void *data, struct drm_file *file); int ivpu_bo_create_ioctl(struct drm_device *dev, void *data, struct drm_file *file);
int ivpu_bo_info_ioctl(struct drm_device *dev, void *data, struct drm_file *file); int ivpu_bo_info_ioctl(struct drm_device *dev, void *data, struct drm_file *file);
int ivpu_bo_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *file); int ivpu_bo_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *file);
void ivpu_bo_list(struct drm_device *dev, struct drm_printer *p);
void ivpu_bo_list_print(struct drm_device *dev);
static inline struct ivpu_bo *to_ivpu_bo(struct drm_gem_object *obj) static inline struct ivpu_bo *to_ivpu_bo(struct drm_gem_object *obj)
{ {
return container_of(obj, struct ivpu_bo, base); return container_of(obj, struct ivpu_bo, base.base);
} }
static inline void *ivpu_bo_vaddr(struct ivpu_bo *bo) static inline void *ivpu_bo_vaddr(struct ivpu_bo *bo)
{ {
return bo->kvaddr; return bo->base.vaddr;
} }
static inline size_t ivpu_bo_size(struct ivpu_bo *bo) static inline size_t ivpu_bo_size(struct ivpu_bo *bo)
{ {
return bo->base.size; return bo->base.base.size;
}
static inline struct page *ivpu_bo_get_page(struct ivpu_bo *bo, u64 offset)
{
if (offset > ivpu_bo_size(bo) || !bo->pages)
return NULL;
return bo->pages[offset / PAGE_SIZE];
} }
static inline u32 ivpu_bo_cache_mode(struct ivpu_bo *bo) static inline u32 ivpu_bo_cache_mode(struct ivpu_bo *bo)
...@@ -95,20 +64,9 @@ static inline bool ivpu_bo_is_snooped(struct ivpu_bo *bo) ...@@ -95,20 +64,9 @@ static inline bool ivpu_bo_is_snooped(struct ivpu_bo *bo)
return ivpu_bo_cache_mode(bo) == DRM_IVPU_BO_CACHED; return ivpu_bo_cache_mode(bo) == DRM_IVPU_BO_CACHED;
} }
static inline pgprot_t ivpu_bo_pgprot(struct ivpu_bo *bo, pgprot_t prot)
{
if (bo->flags & DRM_IVPU_BO_WC)
return pgprot_writecombine(prot);
if (bo->flags & DRM_IVPU_BO_UNCACHED)
return pgprot_noncached(prot);
return prot;
}
static inline struct ivpu_device *ivpu_bo_to_vdev(struct ivpu_bo *bo) static inline struct ivpu_device *ivpu_bo_to_vdev(struct ivpu_bo *bo)
{ {
return to_ivpu_device(bo->base.dev); return to_ivpu_device(bo->base.base.dev);
} }
static inline void *ivpu_to_cpu_addr(struct ivpu_bo *bo, u32 vpu_addr) static inline void *ivpu_to_cpu_addr(struct ivpu_bo *bo, u32 vpu_addr)
......
...@@ -266,7 +266,7 @@ static void job_release(struct kref *ref) ...@@ -266,7 +266,7 @@ static void job_release(struct kref *ref)
for (i = 0; i < job->bo_count; i++) for (i = 0; i < job->bo_count; i++)
if (job->bos[i]) if (job->bos[i])
drm_gem_object_put(&job->bos[i]->base); drm_gem_object_put(&job->bos[i]->base.base);
dma_fence_put(job->done_fence); dma_fence_put(job->done_fence);
ivpu_file_priv_put(&job->file_priv); ivpu_file_priv_put(&job->file_priv);
...@@ -450,7 +450,7 @@ ivpu_job_prepare_bos_for_submit(struct drm_file *file, struct ivpu_job *job, u32 ...@@ -450,7 +450,7 @@ ivpu_job_prepare_bos_for_submit(struct drm_file *file, struct ivpu_job *job, u32
} }
bo = job->bos[CMD_BUF_IDX]; bo = job->bos[CMD_BUF_IDX];
if (!dma_resv_test_signaled(bo->base.resv, DMA_RESV_USAGE_READ)) { if (!dma_resv_test_signaled(bo->base.base.resv, DMA_RESV_USAGE_READ)) {
ivpu_warn(vdev, "Buffer is already in use\n"); ivpu_warn(vdev, "Buffer is already in use\n");
return -EBUSY; return -EBUSY;
} }
...@@ -470,7 +470,7 @@ ivpu_job_prepare_bos_for_submit(struct drm_file *file, struct ivpu_job *job, u32 ...@@ -470,7 +470,7 @@ ivpu_job_prepare_bos_for_submit(struct drm_file *file, struct ivpu_job *job, u32
} }
for (i = 0; i < buf_count; i++) { for (i = 0; i < buf_count; i++) {
ret = dma_resv_reserve_fences(job->bos[i]->base.resv, 1); ret = dma_resv_reserve_fences(job->bos[i]->base.base.resv, 1);
if (ret) { if (ret) {
ivpu_warn(vdev, "Failed to reserve fences: %d\n", ret); ivpu_warn(vdev, "Failed to reserve fences: %d\n", ret);
goto unlock_reservations; goto unlock_reservations;
...@@ -479,7 +479,7 @@ ivpu_job_prepare_bos_for_submit(struct drm_file *file, struct ivpu_job *job, u32 ...@@ -479,7 +479,7 @@ ivpu_job_prepare_bos_for_submit(struct drm_file *file, struct ivpu_job *job, u32
for (i = 0; i < buf_count; i++) { for (i = 0; i < buf_count; i++) {
usage = (i == CMD_BUF_IDX) ? DMA_RESV_USAGE_WRITE : DMA_RESV_USAGE_BOOKKEEP; usage = (i == CMD_BUF_IDX) ? DMA_RESV_USAGE_WRITE : DMA_RESV_USAGE_BOOKKEEP;
dma_resv_add_fence(job->bos[i]->base.resv, job->done_fence, usage); dma_resv_add_fence(job->bos[i]->base.base.resv, job->done_fence, usage);
} }
unlock_reservations: unlock_reservations:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment