From: Icenowy Zheng <uwu@icenowy.me>
To: Drew Fustini <fustini@kernel.org>, Guo Ren <guoren@kernel.org>,
Fu Wei <wefu@redhat.com>, Lucas Stach <l.stach@pengutronix.de>,
Russell King <linux+etnaviv@armlinux.org.uk>,
Christian Gmeiner <christian.gmeiner@gmail.com>,
David Airlie <airlied@gmail.com>,
Simona Vetter <simona@ffwll.ch>
Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 6/7] drm/etnaviv: add shared context support for iommuv2
Date: Tue, 02 Sep 2025 23:40:02 +0800 [thread overview]
Message-ID: <05ef7c0df0a2235277030b9e33f34082e8938faa.camel@icenowy.me> (raw)
In-Reply-To: <20250816074757.2559055-7-uwu@icenowy.me>
在 2025-08-16星期六的 15:47 +0800,Icenowy Zheng写道:
> Unfortunately the GC620 GPU seems to have broken PTA capibility, and
> switching page table ID in command stream after it's running won't
> work.
> As directly switching mtlb isn't working either, there will be no
> reliable way to switch page table in the command stream, and a shared
> context, like iommuv1, is needed.
>
> Add support for this shared context situation. Shared context is set
> when the broken PTA is known, and the context allocation code will be
> made short circuit when a shared context is set.
>
> Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
> ---
> drivers/gpu/drm/etnaviv/etnaviv_iommu_v2.c | 8 ++++++++
> drivers/gpu/drm/etnaviv/etnaviv_mmu.c | 1 +
> drivers/gpu/drm/etnaviv/etnaviv_mmu.h | 2 ++
> 3 files changed, 11 insertions(+)
>
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_iommu_v2.c
> b/drivers/gpu/drm/etnaviv/etnaviv_iommu_v2.c
> index 5654a604c70cf..960ba3d659dc5 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_iommu_v2.c
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_iommu_v2.c
Well, I forgot to clean shared_context in etnaviv_iommuv2_free() when
the shared context is torn down...
> @@ -273,6 +273,12 @@ etnaviv_iommuv2_context_alloc(struct
> etnaviv_iommu_global *global)
> struct etnaviv_iommu_context *context;
>
> mutex_lock(&global->lock);
> + if (global->shared_context) {
> + context = global->shared_context;
> + etnaviv_iommu_context_get(context);
> + mutex_unlock(&global->lock);
> + return context;
> + }
>
> v2_context = vzalloc(sizeof(*v2_context));
> if (!v2_context)
> @@ -301,6 +307,8 @@ etnaviv_iommuv2_context_alloc(struct
> etnaviv_iommu_global *global)
> mutex_init(&context->lock);
> INIT_LIST_HEAD(&context->mappings);
> drm_mm_init(&context->mm, SZ_4K, (u64)SZ_1G * 4 - SZ_4K);
> + if (global->v2.broken_pta)
> + global->shared_context = context;
>
> mutex_unlock(&global->lock);
> return context;
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_mmu.c
> b/drivers/gpu/drm/etnaviv/etnaviv_mmu.c
> index df5192083b201..a0f9c950504e0 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_mmu.c
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_mmu.c
> @@ -504,6 +504,7 @@ int etnaviv_iommu_global_init(struct etnaviv_gpu
> *gpu)
> memset32(global->bad_page_cpu, 0xdead55aa, SZ_4K /
> sizeof(u32));
>
> if (version == ETNAVIV_IOMMU_V2) {
> + global->v2.broken_pta = gpu->identity.model ==
> chipModel_GC620;
> global->v2.pta_cpu = dma_alloc_wc(dev,
> ETNAVIV_PTA_SIZE,
> &global->v2.pta_dma,
> GFP_KERNEL);
> if (!global->v2.pta_cpu)
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_mmu.h
> b/drivers/gpu/drm/etnaviv/etnaviv_mmu.h
> index 2ec4acda02bc6..5627d2a0d0237 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_mmu.h
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_mmu.h
> @@ -55,6 +55,8 @@ struct etnaviv_iommu_global {
> u64 *pta_cpu;
> dma_addr_t pta_dma;
> DECLARE_BITMAP(pta_alloc, ETNAVIV_PTA_ENTRIES);
> + /* Whether runtime switching page table ID will fail
> */
> + bool broken_pta;
> } v2;
> };
>
next prev parent reply other threads:[~2025-09-02 15:40 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-16 7:47 [PATCH 0/7] drm/etnaviv: add support for GC620 on T-Head TH1520 Icenowy Zheng
2025-08-16 7:47 ` [PATCH 1/7] drm/etnaviv: add HWDB entry for GC620 r5552 c20b Icenowy Zheng
2025-08-16 7:47 ` [PATCH 2/7] drm/etnaviv: add handle for GPUs with only SECURITY_AHB flag Icenowy Zheng
2025-08-16 7:47 ` [PATCH 3/7] drm/etnaviv: setup DEC400EX on GC620 r5552 Icenowy Zheng
2025-08-16 7:47 ` [PATCH 4/7] drm/etnaviv: protect whole iommuv2 ctx alloc func under global mutex Icenowy Zheng
2025-08-16 7:47 ` [PATCH 5/7] drm/etnaviv: prepare for shared_context support for iommuv2 Icenowy Zheng
2025-08-16 7:47 ` [PATCH 6/7] drm/etnaviv: add shared context " Icenowy Zheng
2025-09-02 15:40 ` Icenowy Zheng [this message]
2025-08-16 7:47 ` [PATCH 7/7] [NOT FOR UPSTREAM] riscv: dts: thead: enable GC620 G2D on TH1520 Icenowy Zheng
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=05ef7c0df0a2235277030b9e33f34082e8938faa.camel@icenowy.me \
--to=uwu@icenowy.me \
--cc=airlied@gmail.com \
--cc=christian.gmeiner@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=etnaviv@lists.freedesktop.org \
--cc=fustini@kernel.org \
--cc=guoren@kernel.org \
--cc=l.stach@pengutronix.de \
--cc=linux+etnaviv@armlinux.org.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=simona@ffwll.ch \
--cc=wefu@redhat.com \
/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;
as well as URLs for NNTP newsgroup(s).