mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Brajesh Gupta <Brajesh.Gupta@imgtec.com>
To: Luigi Santivetti <Luigi.Santivetti@imgtec.com>,
	"aou@eecs.berkeley.edu" <aou@eecs.berkeley.edu>,
	"tzimmermann@suse.de" <tzimmermann@suse.de>,
	"simona@ffwll.ch" <simona@ffwll.ch>,
	"pjw@kernel.org" <pjw@kernel.org>,
	"alex@ghiti.fr" <alex@ghiti.fr>,
	"airlied@gmail.com" <airlied@gmail.com>,
	Alessio Belle <Alessio.Belle@imgtec.com>,
	"maarten.lankhorst@linux.intel.com"
	<maarten.lankhorst@linux.intel.com>,
	Alexandru Dadu <Alexandru.Dadu@imgtec.com>,
	"mripard@kernel.org" <mripard@kernel.org>,
	"palmer@dabbelt.com" <palmer@dabbelt.com>
Cc: "dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"linux-riscv@lists.infradead.org"
	<linux-riscv@lists.infradead.org>,
	"imagination@lists.freedesktop.org"
	<imagination@lists.freedesktop.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] drm/imagination: Manage FW VM context from its init and fini callbacks
Date: Thu, 13 Aug 2026 04:47:03 +0000	[thread overview]
Message-ID: <3530a7d628216dd41943db32cde94bd3c1d5620c.camel@imgtec.com> (raw)
In-Reply-To: <20260810-b4-upstream-manage-fw-vm-context-from-init-and-fini-v1-1-2c6229e36e5e@imgtec.com>

On Mon, 2026-08-10 at 15:31 +0300, Alexandru Dadu wrote:
Hi Alexandru,
> From: Alessio Belle <alessio.belle@imgtec.com>
> 
> While the MIPS firmware virtual memory context is created and destroyed
> from within the MIPS firmware init and fini callbacks, the META and
> RISC-V firmware contexts are created and destroyed from within blocks
> right before or after those callbacks.
> 
> Match the logic for all firmware processors by moving those blocks to
> the META and RISC-V init and fini callbacks.
> 
> Signed-off-by: Alessio Belle <alessio.belle@imgtec.com>
> ---
> Signed-off-by: Alexandru Dadu <alexandru.dadu@imgtec.com>
> ---
>  drivers/gpu/drm/imagination/pvr_device.c   | 25 +------------------------
>  drivers/gpu/drm/imagination/pvr_fw.c       |  6 ++----
>  drivers/gpu/drm/imagination/pvr_fw.h       |  2 +-
>  drivers/gpu/drm/imagination/pvr_fw_meta.c  | 12 ++++++++++++
>  drivers/gpu/drm/imagination/pvr_fw_riscv.c | 12 ++++++++++++
>  5 files changed, 28 insertions(+), 29 deletions(-)
> 
> diff --git a/drivers/gpu/drm/imagination/pvr_device.c b/drivers/gpu/drm/imagination/pvr_device.c
> index 54fe4180c73c..35eaa54f75ed 100644
> --- a/drivers/gpu/drm/imagination/pvr_device.c
> +++ b/drivers/gpu/drm/imagination/pvr_device.c
> @@ -697,25 +697,7 @@ pvr_device_gpu_init(struct pvr_device *pvr_dev)
>  	if (err)
>  		return err;
>  
> -	if (pvr_dev->fw_dev.processor_type != PVR_FW_PROCESSOR_TYPE_MIPS) {
> -		pvr_dev->kernel_vm_ctx = pvr_vm_create_context(pvr_dev, false);
> -		if (IS_ERR(pvr_dev->kernel_vm_ctx))
> -			return PTR_ERR(pvr_dev->kernel_vm_ctx);
> -	}
> -
> -	err = pvr_fw_init(pvr_dev);
> -	if (err)
> -		goto err_vm_ctx_put;
> -
> -	return 0;
> -
> -err_vm_ctx_put:
> -	if (pvr_dev->fw_dev.processor_type != PVR_FW_PROCESSOR_TYPE_MIPS) {
> -		pvr_vm_context_put(pvr_dev->kernel_vm_ctx);
> -		pvr_dev->kernel_vm_ctx = NULL;
> -	}
> -
> -	return err;
> +	return pvr_fw_init(pvr_dev);
>  }
>  
>  /**
> @@ -726,11 +708,6 @@ static void
>  pvr_device_gpu_fini(struct pvr_device *pvr_dev)
>  {
>  	pvr_fw_fini(pvr_dev);
> -
> -	if (pvr_dev->fw_dev.processor_type != PVR_FW_PROCESSOR_TYPE_MIPS) {
> -		WARN_ON(!pvr_vm_context_put(pvr_dev->kernel_vm_ctx));
> -		pvr_dev->kernel_vm_ctx = NULL;
> -	}
>  }
>  
>  /**
> diff --git a/drivers/gpu/drm/imagination/pvr_fw.c b/drivers/gpu/drm/imagination/pvr_fw.c
> index 850a3ec8e775..58ee51cd65df 100644
> --- a/drivers/gpu/drm/imagination/pvr_fw.c
> +++ b/drivers/gpu/drm/imagination/pvr_fw.c
> @@ -1029,8 +1029,7 @@ pvr_fw_init(struct pvr_device *pvr_dev)
>  err_mm_takedown:
>  	drm_mm_takedown(&fw_dev->fw_mm);
>  
> -	if (fw_dev->defs->fini)
> -		fw_dev->defs->fini(pvr_dev);
> +	fw_dev->defs->fini(pvr_dev);
>  
>  	return err;
>  }
> @@ -1063,8 +1062,7 @@ pvr_fw_fini(struct pvr_device *pvr_dev)
>  
>  	drm_mm_takedown(&fw_dev->fw_mm);
>  
> -	if (fw_dev->defs->fini)
> -		fw_dev->defs->fini(pvr_dev);
> +	fw_dev->defs->fini(pvr_dev);
>  }
>  
>  /**
> diff --git a/drivers/gpu/drm/imagination/pvr_fw.h b/drivers/gpu/drm/imagination/pvr_fw.h
> index 3390c84e4fd3..4b25291135b6 100644
> --- a/drivers/gpu/drm/imagination/pvr_fw.h
> +++ b/drivers/gpu/drm/imagination/pvr_fw.h
> @@ -86,7 +86,7 @@ struct pvr_fw_defs {
>  	 * FW processor specific finalisation.
>  	 * @pvr_dev: Target PowerVR device.
>  	 *
> -	 * This function is optional.
> +	 * This function is mandatory.
>  	 */
>  	void (*fini)(struct pvr_device *pvr_dev);
>  
> diff --git a/drivers/gpu/drm/imagination/pvr_fw_meta.c b/drivers/gpu/drm/imagination/pvr_fw_meta.c
> index 9ff03bc60a08..6c5dc711e81e 100644
> --- a/drivers/gpu/drm/imagination/pvr_fw_meta.c
> +++ b/drivers/gpu/drm/imagination/pvr_fw_meta.c
> @@ -500,9 +500,20 @@ pvr_meta_init(struct pvr_device *pvr_dev)
>  {
>  	pvr_fw_heap_info_init(pvr_dev, ROGUE_FW_HEAP_META_SHIFT, 0);
>  
> +	pvr_dev->kernel_vm_ctx = pvr_vm_create_context(pvr_dev, false);
> +	if (IS_ERR(pvr_dev->kernel_vm_ctx))
> +		return PTR_ERR(pvr_dev->kernel_vm_ctx);
> +
>  	return 0;
>  }
>  
> +static void
> +pvr_meta_fini(struct pvr_device *pvr_dev)
> +{
> +	WARN_ON(!pvr_vm_context_put(pvr_dev->kernel_vm_ctx));
> +	pvr_dev->kernel_vm_ctx = NULL;
> +}
> +
>  static u32
>  pvr_meta_get_fw_addr_with_offset(struct pvr_fw_object *fw_obj, u32 offset)
>  {
> @@ -550,6 +561,7 @@ pvr_meta_irq_clear(struct pvr_device *pvr_dev)
>  
>  const struct pvr_fw_defs pvr_fw_defs_meta = {
>  	.init = pvr_meta_init,
> +	.fini = pvr_meta_fini,
>  	.fw_process = pvr_meta_fw_process,
>  	.vm_map = pvr_meta_vm_map,
>  	.vm_unmap = pvr_meta_vm_unmap,
> diff --git a/drivers/gpu/drm/imagination/pvr_fw_riscv.c b/drivers/gpu/drm/imagination/pvr_fw_riscv.c
> index fc13d483be9a..58bacc522e72 100644
> --- a/drivers/gpu/drm/imagination/pvr_fw_riscv.c
> +++ b/drivers/gpu/drm/imagination/pvr_fw_riscv.c
> @@ -103,9 +103,20 @@ pvr_riscv_init(struct pvr_device *pvr_dev)
>  {
>  	pvr_fw_heap_info_init(pvr_dev, ROGUE_FW_HEAP_RISCV_SHIFT, 0);
>  
> +	pvr_dev->kernel_vm_ctx = pvr_vm_create_context(pvr_dev, false);
> +	if (IS_ERR(pvr_dev->kernel_vm_ctx))
> +		return PTR_ERR(pvr_dev->kernel_vm_ctx);
> +
>  	return 0;
>  }
>  
> +static void
> +pvr_riscv_fini(struct pvr_device *pvr_dev)
> +{
> +	WARN_ON(!pvr_vm_context_put(pvr_dev->kernel_vm_ctx));
> +	pvr_dev->kernel_vm_ctx = NULL;
> +}
> +
>  static u32
>  pvr_riscv_get_fw_addr_with_offset(struct pvr_fw_object *fw_obj, u32 offset)
>  {
> @@ -154,6 +165,7 @@ pvr_riscv_irq_clear(struct pvr_device *pvr_dev)
>  
>  const struct pvr_fw_defs pvr_fw_defs_riscv = {
>  	.init = pvr_riscv_init,
> +	.fini = pvr_riscv_fini,
>  	.fw_process = pvr_riscv_fw_process,
>  	.vm_map = pvr_riscv_vm_map,
>  	.vm_unmap = pvr_riscv_vm_unmap,
> 
> ---
> base-commit: e55fead22ff9ee047ab9f1903860c4b43043514e
> change-id: 20260810-b4-upstream-manage-fw-vm-context-from-init-and-fini-195cdd01cc60
> 
> Best regards,
> --  
> Alexandru Dadu <alexandru.dadu@imgtec.com>
> 
Reviewed by: Brajesh Gupta <brajesh.gupta@imgtec.com>

Thanks,
Brajesh

      reply	other threads:[~2026-08-13  4:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-10 12:31 Alexandru Dadu
2026-08-13  4:47 ` Brajesh Gupta [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3530a7d628216dd41943db32cde94bd3c1d5620c.camel@imgtec.com \
    --to=brajesh.gupta@imgtec.com \
    --cc=Alessio.Belle@imgtec.com \
    --cc=Alexandru.Dadu@imgtec.com \
    --cc=Luigi.Santivetti@imgtec.com \
    --cc=airlied@gmail.com \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=imagination@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®