From fd68dce7ae31a84b1e7c4e2e1a66957b29cf7b5a Mon Sep 17 00:00:00 2001 From: "Rob Herring (Arm)" <robh@kernel.org> Date: Thu, 25 Jul 2024 16:30:10 -0500 Subject: [PATCH] drm: panthor-rs: Hook up driver File::open() Needs drop implemented to replace post_close functionality. Signed-off-by: Rob Herring (Arm) <robh@kernel.org> --- drivers/gpu/drm/panthor-rs/file.rs | 22 ++++++++++-- drivers/gpu/drm/panthor-rs/panthor_drv.c | 40 ---------------------- drivers/gpu/drm/panthor-rs/panthor_mmu.c | 12 +++---- drivers/gpu/drm/panthor-rs/panthor_mmu.h | 2 +- drivers/gpu/drm/panthor-rs/panthor_sched.c | 7 ++-- drivers/gpu/drm/panthor-rs/panthor_sched.h | 2 +- 6 files changed, 30 insertions(+), 55 deletions(-) diff --git a/drivers/gpu/drm/panthor-rs/file.rs b/drivers/gpu/drm/panthor-rs/file.rs index 1146fbefda5bf..7ebbce7c88150 100644 --- a/drivers/gpu/drm/panthor-rs/file.rs +++ b/drivers/gpu/drm/panthor-rs/file.rs @@ -28,15 +28,31 @@ use kernel::{ pub(crate) type DrmFile = drm::file::File<File>; /// State associated with a client. -pub(crate) struct File(); +#[repr(C)] +pub(crate) struct File { + ptdev: *mut bindings::panthor_device, + // TODO make these embedded structs? + vms: *mut bindings::panthor_vm_pool, + groups: *mut bindings::panthor_group_pool, +} impl drm::file::DriverFile for File { type Driver = PanthorDriver; - fn open(_dev: &DrmDevice<Self::Driver>) -> Result<Pin<Box<Self>>> { + fn open(dev: &DrmDevice<Self::Driver>) -> Result<Pin<KBox<Self>>> { + let ptdev = dev.data().ptdev; pr_info!("DRM Device :: open()\n"); - Ok(Box::into_pin(Box::new(Self(), GFP_KERNEL)?)) + // TODO allocation error handling + Ok(KBox::new( + Self { + ptdev, + vms: unsafe { bindings::panthor_vm_pool_create() }, + groups: unsafe { bindings::panthor_group_pool_create() }, + }, + GFP_KERNEL, + )? + .into()) } } diff --git a/drivers/gpu/drm/panthor-rs/panthor_drv.c b/drivers/gpu/drm/panthor-rs/panthor_drv.c index 27c958da6bc81..d2e50d2d737f3 100644 --- a/drivers/gpu/drm/panthor-rs/panthor_drv.c +++ b/drivers/gpu/drm/panthor-rs/panthor_drv.c @@ -1264,46 +1264,6 @@ static int panthor_ioctl_vm_get_state(struct drm_device *ddev, void *data, return 0; } -static int -panthor_open(struct drm_device *ddev, struct drm_file *file) -{ - struct panthor_device *ptdev = container_of(ddev, struct panthor_device, base); - struct panthor_file *pfile; - int ret; - - if (!try_module_get(THIS_MODULE)) - return -EINVAL; - - pfile = kzalloc(sizeof(*pfile), GFP_KERNEL); - if (!pfile) { - ret = -ENOMEM; - goto err_put_mod; - } - - pfile->ptdev = ptdev; - - ret = panthor_vm_pool_create(pfile); - if (ret) - goto err_free_file; - - ret = panthor_group_pool_create(pfile); - if (ret) - goto err_destroy_vm_pool; - - file->driver_priv = pfile; - return 0; - -err_destroy_vm_pool: - panthor_vm_pool_destroy(pfile); - -err_free_file: - kfree(pfile); - -err_put_mod: - module_put(THIS_MODULE); - return ret; -} - static void panthor_postclose(struct drm_device *ddev, struct drm_file *file) { diff --git a/drivers/gpu/drm/panthor-rs/panthor_mmu.c b/drivers/gpu/drm/panthor-rs/panthor_mmu.c index 145b8c680066b..24f4168d70f84 100644 --- a/drivers/gpu/drm/panthor-rs/panthor_mmu.c +++ b/drivers/gpu/drm/panthor-rs/panthor_mmu.c @@ -1606,14 +1606,14 @@ void panthor_vm_pool_destroy(struct panthor_file *pfile) * * Return: 0 on success, a negative error code otherwise. */ -int panthor_vm_pool_create(struct panthor_file *pfile) +struct panthor_vm_pool *panthor_vm_pool_create(void) { - pfile->vms = kzalloc(sizeof(*pfile->vms), GFP_KERNEL); - if (!pfile->vms) - return -ENOMEM; + struct panthor_vm_pool *vms = kzalloc(sizeof(*vms), GFP_KERNEL); + if (!vms) + return NULL; - xa_init_flags(&pfile->vms->xa, XA_FLAGS_ALLOC1); - return 0; + xa_init_flags(&vms->xa, XA_FLAGS_ALLOC1); + return vms; } /* dummy TLB ops, the real TLB flush happens in panthor_vm_flush_range() */ diff --git a/drivers/gpu/drm/panthor-rs/panthor_mmu.h b/drivers/gpu/drm/panthor-rs/panthor_mmu.h index 3721b46babf83..2e41452f39dc3 100644 --- a/drivers/gpu/drm/panthor-rs/panthor_mmu.h +++ b/drivers/gpu/drm/panthor-rs/panthor_mmu.h @@ -55,7 +55,7 @@ struct dma_resv *panthor_vm_resv(struct panthor_vm *vm); struct drm_gem_object *panthor_vm_root_gem(struct panthor_vm *vm); void panthor_vm_pool_destroy(struct panthor_file *pfile); -int panthor_vm_pool_create(struct panthor_file *pfile); +struct panthor_vm_pool *panthor_vm_pool_create(void); int panthor_vm_pool_create_vm(struct panthor_device *ptdev, struct panthor_vm_pool *pool, struct drm_panthor_vm_create *args); diff --git a/drivers/gpu/drm/panthor-rs/panthor_sched.c b/drivers/gpu/drm/panthor-rs/panthor_sched.c index 7649dd3554521..38eb93dfacfa5 100644 --- a/drivers/gpu/drm/panthor-rs/panthor_sched.c +++ b/drivers/gpu/drm/panthor-rs/panthor_sched.c @@ -3291,17 +3291,16 @@ int panthor_group_get_state(struct panthor_file *pfile, return 0; } -int panthor_group_pool_create(struct panthor_file *pfile) +struct panthor_group_pool *panthor_group_pool_create(void) { struct panthor_group_pool *gpool; gpool = kzalloc(sizeof(*gpool), GFP_KERNEL); if (!gpool) - return -ENOMEM; + return NULL; xa_init_flags(&gpool->xa, XA_FLAGS_ALLOC1); - pfile->groups = gpool; - return 0; + return gpool; } void panthor_group_pool_destroy(struct panthor_file *pfile) diff --git a/drivers/gpu/drm/panthor-rs/panthor_sched.h b/drivers/gpu/drm/panthor-rs/panthor_sched.h index 3a30d2328b308..ec804894b3982 100644 --- a/drivers/gpu/drm/panthor-rs/panthor_sched.h +++ b/drivers/gpu/drm/panthor-rs/panthor_sched.h @@ -34,7 +34,7 @@ struct panthor_vm *panthor_job_vm(struct drm_sched_job *sched_job); void panthor_job_put(struct drm_sched_job *job); void panthor_job_update_resvs(struct drm_exec *exec, struct drm_sched_job *job); -int panthor_group_pool_create(struct panthor_file *pfile); +struct panthor_group_pool *panthor_group_pool_create(void); void panthor_group_pool_destroy(struct panthor_file *pfile); int panthor_sched_init(struct panthor_device *ptdev); -- GitLab