From nobody Fri Sep 25 14:31:21 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4F983443C11 for ; Fri, 11 Sep 2026 11:40:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789126832; cv=none; b=ix1RugsLXrXV2S9O/cPaR/vn7Owr9kNCqYjDW5TFzwG8hwLit2DpCKaiARMtXz4hNw05Yp1vHJRMN60fFeNATuEDFK759onnYaNa8CaGxGucn22FsE+XOfPL9Ruhr4ZDTU85BqhjKs4ZnZS3PKean2ZE4NTnjeB2oQfLA+hynO4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789126832; c=relaxed/simple; bh=SwCssg1TtHWQq2cdAinXB1qI41TqJtYDamzkLDOC6fA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OTGdCAX0CvuqAvaUfP1f/fXzKpQUwef4kPRUUN1HE/Qi+ThRJcT96TW1cWoXqCS3BZ2z4alZlbpAKaanrd0ukIVEddOkciNZZkVIfCV85IYZ+Q/aEpk0wrFp990sAbhz59vnY8XwvXGOZkiKEI7dg9xGZ/NekoOiTpwY5ztBIsU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=jW6DUbGm; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="jW6DUbGm" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id ECCD716F2; Fri, 11 Sep 2026 04:40:26 -0700 (PDT) Received: from e120398-lin.trondheim.arm.com (e120398-lin.trondheim.arm.com [10.42.46.160]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A7AF73F59E; Fri, 11 Sep 2026 04:40:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789126830; bh=SwCssg1TtHWQq2cdAinXB1qI41TqJtYDamzkLDOC6fA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jW6DUbGmhij6XMz24QUwYq3FjGlypfcofBDt+ftQQY/Uyqip087RB1gQK209E3NIl x2g6eXlI1MIq7bZQt7lxz9d6mJd+MxOWFkfNGycNFsUEax2b3C5N6qHt2FyePta85S 8B23QRCsoYzGKDeROk9tvxX6WWRAlkEqOYrkEx1A= From: Ketil Johnsen To: Boris Brezillon , Steven Price , Liviu Dudau , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Daniel Almeida , Alice Ryhl Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Ketil Johnsen Subject: [PATCH v3 1/6] drm/panthor: De-duplicate FW memory section sync Date: Fri, 11 Sep 2026 13:40:09 +0200 Message-ID: <20260911114014.79139-2-ketil.johnsen@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260911114014.79139-1-ketil.johnsen@arm.com> References: <20260911114014.79139-1-ketil.johnsen@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Handle the sync to device of FW memory sections inside panthor_fw_init_section_mem() so that the callers do not have to. This small improvement is also critical for protected FW sections, so we avoid issuing memory transactions to protected memory from CPU running in normal mode. Signed-off-by: Ketil Johnsen Reviewed-by: Boris Brezillon Reviewed-by: Liviu Dudau Reviewed-by: Steven Price --- drivers/gpu/drm/panthor/panthor_fw.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor= /panthor_fw.c index 4f1fab66a13bf..5f9f7a92c56a8 100644 --- a/drivers/gpu/drm/panthor/panthor_fw.c +++ b/drivers/gpu/drm/panthor/panthor_fw.c @@ -449,6 +449,7 @@ static void panthor_fw_init_section_mem(struct panthor_= device *ptdev, struct panthor_fw_section *section) { bool was_mapped =3D !!section->mem->kmap; + struct sg_table *sgt; int ret; =20 if (!section->data.size && @@ -467,6 +468,12 @@ static void panthor_fw_init_section_mem(struct panthor= _device *ptdev, =20 if (!was_mapped) panthor_kernel_bo_vunmap(section->mem); + + /* An sgt should have been requested when the kernel BO was GPU-mapped. */ + sgt =3D to_panthor_bo(section->mem->obj)->dmap.sgt; + if (!drm_WARN_ON_ONCE(&ptdev->base, !sgt)) + dma_sync_sgtable_for_device(ptdev->base.dev, sgt, + DMA_TO_DEVICE); } =20 /** @@ -639,7 +646,6 @@ static int panthor_fw_load_section_entry(struct panthor= _device *ptdev, =20 if (section_size) { u32 cache_mode =3D hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_MASK; - struct panthor_gem_object *bo; u32 vm_map_flags =3D 0; u64 va =3D hdr.va.start; =20 @@ -676,14 +682,6 @@ static int panthor_fw_load_section_entry(struct pantho= r_device *ptdev, } =20 panthor_fw_init_section_mem(ptdev, section); - - bo =3D to_panthor_bo(section->mem->obj); - - /* An sgt should have been requested when the kernel BO was GPU-mapped. = */ - if (drm_WARN_ON_ONCE(&ptdev->base, !bo->dmap.sgt)) - return -EINVAL; - - dma_sync_sgtable_for_device(ptdev->base.dev, bo->dmap.sgt, DMA_TO_DEVICE= ); } =20 if (hdr.va.start =3D=3D CSF_MCU_SHARED_REGION_START) @@ -738,17 +736,10 @@ panthor_reload_fw_sections(struct panthor_device *ptd= ev, bool full_reload) struct panthor_fw_section *section; =20 list_for_each_entry(section, &ptdev->fw->sections, node) { - struct sg_table *sgt; - if (!full_reload && !(section->flags & CSF_FW_BINARY_IFACE_ENTRY_WR)) continue; =20 panthor_fw_init_section_mem(ptdev, section); - - /* An sgt should have been requested when the kernel BO was GPU-mapped. = */ - sgt =3D to_panthor_bo(section->mem->obj)->dmap.sgt; - if (!drm_WARN_ON_ONCE(&ptdev->base, !sgt)) - dma_sync_sgtable_for_device(ptdev->base.dev, sgt, DMA_TO_DEVICE); } } =20 --=20 2.43.0 From nobody Fri Sep 25 14:31:21 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D88C543B3F9 for ; Fri, 11 Sep 2026 11:40:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789126836; cv=none; b=m5JjwBRC/Yaa9blgCoZBQHhKwDL3amHOoVjxEikuYjzpoAkwUMSzlXXXUNNBRMgF1as2/FrG9lsAVrHAgQBBrEdF5T/bf0DaDvDaWWSY0bjErUt1d9wApx6laCzyNNR/AX+4czVpGyUGndqWZlwrceV5TaW8KsnhARcjSERH3lU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789126836; c=relaxed/simple; bh=Bs7d472wVIf8U87LmcqeCV1HWKQs2v6gRqh4Jgrsd08=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FAkmigKOZygTjCI0tD3TEmO0bBufZd68mWT/Bf6dvL76dquHAEABRFYCiXeEJ9CYCkAsSyVjIIAum1kdpsQj/Y5VO0IpkQLnXwVr9wl2xsfpj7c4C8g1A0Clg0jQRPUCpkILyRi9q7m4SYCzKZjs6hhoE1BZnSWP5uRKo93SvZw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=krjKSBI7; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="krjKSBI7" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 74A0516A3; Fri, 11 Sep 2026 04:40:30 -0700 (PDT) Received: from e120398-lin.trondheim.arm.com (e120398-lin.trondheim.arm.com [10.42.46.160]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F3F673F59E; Fri, 11 Sep 2026 04:40:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789126834; bh=Bs7d472wVIf8U87LmcqeCV1HWKQs2v6gRqh4Jgrsd08=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=krjKSBI7JIjl6j84BxcGBDMQJ+Xjy5+1I1282tQNe5JZMWehTZQpDhpDjsaODCJGB CWl/cMcJgtycU+iPh5is5UV46a+VKcahytzwlWoPhtcfXVTBDZujufE+tKOGHEoLb6 fmcgbOEWW72b/f3dGOS12TqpbocnGtZ5Mny+Mr+Q= From: Ketil Johnsen To: Boris Brezillon , Steven Price , Liviu Dudau , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Daniel Almeida , Alice Ryhl Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Florent Tomasin , Ketil Johnsen Subject: [PATCH v3 2/6] drm/panthor: Minor scheduler refactoring Date: Fri, 11 Sep 2026 13:40:10 +0200 Message-ID: <20260911114014.79139-3-ketil.johnsen@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260911114014.79139-1-ketil.johnsen@arm.com> References: <20260911114014.79139-1-ketil.johnsen@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Florent Tomasin Refactor parts of the group scheduling logic into new helper functions. This will simplify addition of the protected mode feature. Remove redundant assignments of csg_slot. Signed-off-by: Florent Tomasin Co-developed-by: Ketil Johnsen Signed-off-by: Ketil Johnsen Reviewed-by: Boris Brezillon --- v3: - Use panthor_fw_csg_endpoint_req_update() (was rebase mistake) - Function rename to tick_ctx_update_group_prio() v2: - Moved option to ding only the CSG doorbell to later patch --- drivers/gpu/drm/panthor/panthor_sched.c | 131 ++++++++++++++---------- 1 file changed, 79 insertions(+), 52 deletions(-) diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/pant= hor/panthor_sched.c index 60b2417deb81b..1123cf36a7bca 100644 --- a/drivers/gpu/drm/panthor/panthor_sched.c +++ b/drivers/gpu/drm/panthor/panthor_sched.c @@ -2344,12 +2344,81 @@ tick_ctx_cleanup(struct panthor_scheduler *sched, } } =20 +static void +tick_ctx_evict_group(struct panthor_scheduler *sched, + struct panthor_csg_slots_upd_ctx *upd_ctx, + struct panthor_group *group) +{ + struct panthor_device *ptdev =3D sched->ptdev; + + if (drm_WARN_ON(&ptdev->base, group->csg_id < 0)) + return; + + csgs_upd_ctx_queue_reqs(ptdev, upd_ctx, group->csg_id, + group_can_run(group) ? + CSG_STATE_SUSPEND : CSG_STATE_TERMINATE, + CSG_STATE_MASK); +} + +static void +tick_ctx_update_group_prio(struct panthor_scheduler *sched, + struct panthor_csg_slots_upd_ctx *upd_ctx, + struct panthor_group *group, + int new_csg_prio) +{ + struct panthor_device *ptdev =3D sched->ptdev; + struct panthor_fw_csg_iface *csg_iface; + struct panthor_csg_slot *csg_slot; + + if (group->csg_id < 0) + return; + + csg_iface =3D panthor_fw_get_csg_iface(ptdev, group->csg_id); + csg_slot =3D &sched->csg_slots[group->csg_id]; + + if (csg_slot->priority !=3D new_csg_prio) { + panthor_fw_csg_endpoint_req_update(ptdev, csg_iface, + CSG_EP_REQ_PRIORITY(new_csg_prio), + CSG_EP_REQ_PRIORITY_MASK); + csgs_upd_ctx_queue_reqs(ptdev, upd_ctx, group->csg_id, + csg_iface->output->ack ^ CSG_ENDPOINT_CONFIG, + CSG_ENDPOINT_CONFIG); + } +} + +static int +tick_ctx_schedule_group(struct panthor_scheduler *sched, + struct panthor_csg_slots_upd_ctx *upd_ctx, + struct panthor_group *group, + int csg_id, int csg_prio) +{ + struct panthor_device *ptdev =3D sched->ptdev; + struct panthor_fw_csg_iface *csg_iface =3D + panthor_fw_get_csg_iface(ptdev, csg_id); + int ret; + + ret =3D group_bind_locked(group, csg_id); + if (ret) + return ret; + + csg_slot_prog_locked(ptdev, csg_id, csg_prio); + + csgs_upd_ctx_queue_reqs(ptdev, upd_ctx, csg_id, + group->state =3D=3D PANTHOR_CS_GROUP_SUSPENDED ? + CSG_STATE_RESUME : CSG_STATE_START, + CSG_STATE_MASK); + csgs_upd_ctx_queue_reqs(ptdev, upd_ctx, csg_id, + csg_iface->output->ack ^ CSG_ENDPOINT_CONFIG, + CSG_ENDPOINT_CONFIG); + + return 0; +} + static void tick_ctx_apply(struct panthor_scheduler *sched, struct panthor_sched_tick_= ctx *ctx) { struct panthor_group *group, *tmp; struct panthor_device *ptdev =3D sched->ptdev; - struct panthor_csg_slot *csg_slot; int prio, new_csg_prio =3D MAX_CSG_PRIO, i; u32 free_csg_slots =3D 0; struct panthor_csg_slots_upd_ctx upd_ctx; @@ -2359,44 +2428,13 @@ tick_ctx_apply(struct panthor_scheduler *sched, str= uct panthor_sched_tick_ctx *c =20 for (prio =3D PANTHOR_CSG_PRIORITY_COUNT - 1; prio >=3D 0; prio--) { /* Suspend or terminate evicted groups. */ - list_for_each_entry(group, &ctx->old_groups[prio], run_node) { - bool term =3D !group_can_run(group); - int csg_id =3D group->csg_id; - - if (drm_WARN_ON(&ptdev->base, csg_id < 0)) - continue; - - csg_slot =3D &sched->csg_slots[csg_id]; - csgs_upd_ctx_queue_reqs(ptdev, &upd_ctx, csg_id, - term ? CSG_STATE_TERMINATE : CSG_STATE_SUSPEND, - CSG_STATE_MASK); - } + list_for_each_entry(group, &ctx->old_groups[prio], run_node) + tick_ctx_evict_group(sched, &upd_ctx, group); =20 /* Update priorities on already running groups. */ - list_for_each_entry(group, &ctx->groups[prio], run_node) { - struct panthor_fw_csg_iface *csg_iface; - int csg_id =3D group->csg_id; - - if (csg_id < 0) { - new_csg_prio--; - continue; - } - - csg_slot =3D &sched->csg_slots[csg_id]; - csg_iface =3D panthor_fw_get_csg_iface(ptdev, csg_id); - if (csg_slot->priority =3D=3D new_csg_prio) { - new_csg_prio--; - continue; - } - - panthor_fw_csg_endpoint_req_update(ptdev, csg_iface, - CSG_EP_REQ_PRIORITY(new_csg_prio), - CSG_EP_REQ_PRIORITY_MASK); - csgs_upd_ctx_queue_reqs(ptdev, &upd_ctx, csg_id, - csg_iface->output->ack ^ CSG_ENDPOINT_CONFIG, - CSG_ENDPOINT_CONFIG); - new_csg_prio--; - } + list_for_each_entry(group, &ctx->groups[prio], run_node) + tick_ctx_update_group_prio(sched, &upd_ctx, group, + new_csg_prio--); } =20 ret =3D csgs_upd_ctx_apply_locked(ptdev, &upd_ctx); @@ -2424,34 +2462,23 @@ tick_ctx_apply(struct panthor_scheduler *sched, str= uct panthor_sched_tick_ctx *c for (prio =3D PANTHOR_CSG_PRIORITY_COUNT - 1; prio >=3D 0; prio--) { list_for_each_entry(group, &ctx->groups[prio], run_node) { int csg_id =3D group->csg_id; - struct panthor_fw_csg_iface *csg_iface; + int csg_prio =3D new_csg_prio--; =20 - if (csg_id >=3D 0) { - new_csg_prio--; + if (csg_id >=3D 0) continue; - } =20 csg_id =3D ffs(free_csg_slots) - 1; if (drm_WARN_ON(&ptdev->base, csg_id < 0)) break; =20 - csg_iface =3D panthor_fw_get_csg_iface(ptdev, csg_id); - csg_slot =3D &sched->csg_slots[csg_id]; - ret =3D group_bind_locked(group, csg_id); + ret =3D tick_ctx_schedule_group(sched, &upd_ctx, group, + csg_id, csg_prio); if (ret) { panthor_device_schedule_reset(ptdev); ctx->csg_upd_failed_mask |=3D BIT(csg_id); return; } =20 - csg_slot_prog_locked(ptdev, csg_id, new_csg_prio--); - csgs_upd_ctx_queue_reqs(ptdev, &upd_ctx, csg_id, - group->state =3D=3D PANTHOR_CS_GROUP_SUSPENDED ? - CSG_STATE_RESUME : CSG_STATE_START, - CSG_STATE_MASK); - csgs_upd_ctx_queue_reqs(ptdev, &upd_ctx, csg_id, - csg_iface->output->ack ^ CSG_ENDPOINT_CONFIG, - CSG_ENDPOINT_CONFIG); free_csg_slots &=3D ~BIT(csg_id); } } --=20 2.43.0 From nobody Fri Sep 25 14:31:21 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 604C9282F2A for ; Fri, 11 Sep 2026 11:40:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789126840; cv=none; b=WtogvmdxW3tKYJw1PieNlzxCNGKFj7m24cgjWATqfPgUFm8AuSAcrKrakABWp7LK/5ecCmMiDSwJuQ7aPUi6gm/rgJyrTmGUV5jIJzdUIv1IJzVqsw/QJ/qDP464hHhm/TNPHjXvavKsuWKdqM1Qu2wRC7+EfcTgSL9JLBTGRsU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789126840; c=relaxed/simple; bh=VotY5yVk2kEF+6syW15FI6fV9p/yKv/256/aV84IF+Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ItjKAWQMS5DgiBT+to90K1DSOxb01CaIEirAvZnfQ20nYhLiJitweUXTqRt68s2xYtn7EhxcQQdMazDuebbFyoDQATp/IZ5tE0ya3IG3TkvM//Y5+4qVDnqmqv3rpMSmfpaB2gdlifeTz6DPs9KlP7pywpvTwTOhQae7mfm9sXU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=G+eD4Hwj; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="G+eD4Hwj" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EFC621655; Fri, 11 Sep 2026 04:40:33 -0700 (PDT) Received: from e120398-lin.trondheim.arm.com (e120398-lin.trondheim.arm.com [10.42.46.160]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7B29B3F59E; Fri, 11 Sep 2026 04:40:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789126837; bh=VotY5yVk2kEF+6syW15FI6fV9p/yKv/256/aV84IF+Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G+eD4HwjrJ2wk8Ei4E8Key++sqqDCqKvTVboon//AkI533zytn7nhKpPodJ5Ky+dD HiN8bXqKI2VPY1lvO42frCfX5ziDcAUjK54vbOiaEh8LdVhTUkWU09EPXrwx1AYu+l vKFw3ji2ffspdS+kM2E3XFXgIRYpZ7mXc6FCK97U= From: Ketil Johnsen To: Boris Brezillon , Steven Price , Liviu Dudau , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Daniel Almeida , Alice Ryhl Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Ketil Johnsen Subject: [PATCH v3 3/6] drm/panthor: Pass drm_file instead of panthor_file Date: Fri, 11 Sep 2026 13:40:11 +0200 Message-ID: <20260911114014.79139-4-ketil.johnsen@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260911114014.79139-1-ketil.johnsen@arm.com> References: <20260911114014.79139-1-ketil.johnsen@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Boris Brezillon Some sched helpers need info that are part of drm_file, and we will soon need to call drm_gem_object_lookup() from panthor_group_create(). Let's prepare for that by passing a drm_file instead of panthor_file to all current helpers taking a panthor_file, so we keep things consistent. Signed-off-by: Boris Brezillon Co-developed-by: Ketil Johnsen Signed-off-by: Ketil Johnsen --- v3: - Fixed incorrect parameter passed to panthor_gpu_show_fdinfo() v2: - First introduction of this patch in this patch set --- drivers/gpu/drm/panthor/panthor_drv.c | 38 +++++++++++-------------- drivers/gpu/drm/panthor/panthor_mmu.c | 11 ++++--- drivers/gpu/drm/panthor/panthor_mmu.h | 6 ++-- drivers/gpu/drm/panthor/panthor_sched.c | 37 ++++++++++++++---------- drivers/gpu/drm/panthor/panthor_sched.h | 23 +++++++-------- 5 files changed, 59 insertions(+), 56 deletions(-) diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/pantho= r/panthor_drv.c index 46a3080b0b206..51eb77633602f 100644 --- a/drivers/gpu/drm/panthor/panthor_drv.c +++ b/drivers/gpu/drm/panthor/panthor_drv.c @@ -1111,7 +1111,6 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_de= vice *ddev, void *data, static int panthor_ioctl_group_submit(struct drm_device *ddev, void *data, struct drm_file *file) { - struct panthor_file *pfile =3D file->driver_priv; struct drm_panthor_group_submit *args =3D data; struct drm_panthor_queue_submit *jobs_args; struct panthor_submit_ctx ctx; @@ -1136,8 +1135,7 @@ static int panthor_ioctl_group_submit(struct drm_devi= ce *ddev, void *data, const struct drm_panthor_queue_submit *qsubmit =3D &jobs_args[i]; struct drm_sched_job *job; =20 - job =3D panthor_job_create(pfile, args->group_handle, qsubmit, - file->client_id); + job =3D panthor_job_create(file, args->group_handle, qsubmit); if (IS_ERR(job)) { ret =3D PTR_ERR(job); goto out_cleanup_submit_ctx; @@ -1217,19 +1215,17 @@ static int panthor_ioctl_group_submit(struct drm_de= vice *ddev, void *data, static int panthor_ioctl_group_destroy(struct drm_device *ddev, void *data, struct drm_file *file) { - struct panthor_file *pfile =3D file->driver_priv; struct drm_panthor_group_destroy *args =3D data; =20 if (args->pad) return -EINVAL; =20 - return panthor_group_destroy(pfile, args->group_handle); + return panthor_group_destroy(file, args->group_handle); } =20 static int panthor_ioctl_group_create(struct drm_device *ddev, void *data, struct drm_file *file) { - struct panthor_file *pfile =3D file->driver_priv; struct drm_panthor_group_create *args =3D data; struct drm_panthor_queue_create *queue_args; int ret; @@ -1245,7 +1241,7 @@ static int panthor_ioctl_group_create(struct drm_devi= ce *ddev, void *data, if (ret) goto out; =20 - ret =3D panthor_group_create(pfile, args, queue_args, file->client_id); + ret =3D panthor_group_create(file, args, queue_args); if (ret < 0) goto out; args->group_handle =3D ret; @@ -1259,10 +1255,9 @@ static int panthor_ioctl_group_create(struct drm_dev= ice *ddev, void *data, static int panthor_ioctl_group_get_state(struct drm_device *ddev, void *da= ta, struct drm_file *file) { - struct panthor_file *pfile =3D file->driver_priv; struct drm_panthor_group_get_state *args =3D data; =20 - return panthor_group_get_state(pfile, args); + return panthor_group_get_state(file, args); } =20 static int panthor_ioctl_tiler_heap_create(struct drm_device *ddev, void *= data, @@ -1605,6 +1600,7 @@ panthor_open(struct drm_device *ddev, struct drm_file= *file) if (!pfile) return -ENOMEM; =20 + file->driver_priv =3D pfile; pfile->ptdev =3D ptdev; pfile->user_mmio.offset =3D DRM_PANTHOR_USER_MMIO_OFFSET; =20 @@ -1619,19 +1615,18 @@ panthor_open(struct drm_device *ddev, struct drm_fi= le *file) #endif =20 =20 - ret =3D panthor_vm_pool_create(pfile); + ret =3D panthor_vm_pool_create(file); if (ret) goto err_free_file; =20 - ret =3D panthor_group_pool_create(pfile); + ret =3D panthor_group_pool_create(file); if (ret) goto err_destroy_vm_pool; =20 - file->driver_priv =3D pfile; return 0; =20 err_destroy_vm_pool: - panthor_vm_pool_destroy(pfile); + panthor_vm_pool_destroy(file); =20 err_free_file: kfree(pfile); @@ -1643,8 +1638,8 @@ panthor_postclose(struct drm_device *ddev, struct drm= _file *file) { struct panthor_file *pfile =3D file->driver_priv; =20 - panthor_group_pool_destroy(pfile); - panthor_vm_pool_destroy(pfile); + panthor_group_pool_destroy(file); + panthor_vm_pool_destroy(file); =20 kfree(pfile); } @@ -1704,11 +1699,13 @@ static int panthor_mmap(struct file *filp, struct v= m_area_struct *vma) } =20 static void panthor_gpu_show_fdinfo(struct panthor_device *ptdev, - struct panthor_file *pfile, + struct drm_file *file, struct drm_printer *p) { + struct panthor_file *pfile =3D file->driver_priv; + if (ptdev->profile_mask & PANTHOR_DEVICE_PROFILING_ALL) - panthor_fdinfo_gather_group_samples(pfile); + panthor_fdinfo_gather_group_samples(file); =20 if (ptdev->profile_mask & PANTHOR_DEVICE_PROFILING_TIMESTAMP) { #ifdef CONFIG_ARM_ARCH_TIMER @@ -1728,11 +1725,10 @@ static void panthor_gpu_show_fdinfo(struct panthor_= device *ptdev, static void panthor_show_internal_memory_stats(struct drm_printer *p, stru= ct drm_file *file) { char *drv_name =3D file->minor->dev->driver->name; - struct panthor_file *pfile =3D file->driver_priv; struct drm_memory_stats stats =3D {0}; =20 - panthor_fdinfo_gather_group_mem_info(pfile, &stats); - panthor_vm_heaps_sizes(pfile, &stats); + panthor_fdinfo_gather_group_mem_info(file, &stats); + panthor_vm_heaps_sizes(file, &stats); =20 drm_fdinfo_print_size(p, drv_name, "resident", "memory", stats.resident); drm_fdinfo_print_size(p, drv_name, "active", "memory", stats.active); @@ -1743,7 +1739,7 @@ static void panthor_show_fdinfo(struct drm_printer *p= , struct drm_file *file) struct drm_device *dev =3D file->minor->dev; struct panthor_device *ptdev =3D container_of(dev, struct panthor_device,= base); =20 - panthor_gpu_show_fdinfo(ptdev, file->driver_priv, p); + panthor_gpu_show_fdinfo(ptdev, file, p); panthor_show_internal_memory_stats(p, file); =20 drm_show_memory_stats(p, file); diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/pantho= r/panthor_mmu.c index d75d575473da4..3e5f20768d545 100644 --- a/drivers/gpu/drm/panthor/panthor_mmu.c +++ b/drivers/gpu/drm/panthor/panthor_mmu.c @@ -1692,8 +1692,9 @@ panthor_vm_pool_get_vm(struct panthor_vm_pool *pool, = u32 handle) * Note that VMs can outlive the pool they were created from if other * objects hold a reference to there VMs. */ -void panthor_vm_pool_destroy(struct panthor_file *pfile) +void panthor_vm_pool_destroy(struct drm_file *file) { + struct panthor_file *pfile =3D file->driver_priv; struct panthor_vm *vm; unsigned long i; =20 @@ -1715,8 +1716,9 @@ void panthor_vm_pool_destroy(struct panthor_file *pfi= le) * * Return: 0 on success, a negative error code otherwise. */ -int panthor_vm_pool_create(struct panthor_file *pfile) +int panthor_vm_pool_create(struct drm_file *file) { + struct panthor_file *pfile =3D file->driver_priv; struct panthor_gem_object *dummy; int ret; =20 @@ -1737,7 +1739,7 @@ int panthor_vm_pool_create(struct panthor_file *pfile) return 0; =20 err_destroy_vm_pool: - panthor_vm_pool_destroy(pfile); + panthor_vm_pool_destroy(file); return ret; } =20 @@ -2157,8 +2159,9 @@ struct panthor_heap_pool *panthor_vm_get_heap_pool(st= ruct panthor_vm *vm, bool c * Calculate all heap chunk sizes in all heap pools bound to a VM. If the = VM * is active, record the size as active as well. */ -void panthor_vm_heaps_sizes(struct panthor_file *pfile, struct drm_memory_= stats *stats) +void panthor_vm_heaps_sizes(struct drm_file *file, struct drm_memory_stats= *stats) { + struct panthor_file *pfile =3D file->driver_priv; struct panthor_vm *vm; unsigned long i; =20 diff --git a/drivers/gpu/drm/panthor/panthor_mmu.h b/drivers/gpu/drm/pantho= r/panthor_mmu.h index abc36e7204be0..e262fe2303f6c 100644 --- a/drivers/gpu/drm/panthor/panthor_mmu.h +++ b/drivers/gpu/drm/panthor/panthor_mmu.h @@ -38,7 +38,7 @@ int panthor_vm_as(struct panthor_vm *vm); struct panthor_heap_pool * panthor_vm_get_heap_pool(struct panthor_vm *vm, bool create); =20 -void panthor_vm_heaps_sizes(struct panthor_file *pfile, struct drm_memory_= stats *stats); +void panthor_vm_heaps_sizes(struct drm_file *file, struct drm_memory_stats= *stats); =20 struct panthor_vm *panthor_vm_get(struct panthor_vm *vm); void panthor_vm_put(struct panthor_vm *vm); @@ -64,8 +64,8 @@ void panthor_vm_add_job_fence_to_bos_resvs(struct panthor= _vm *vm, struct dma_resv *panthor_vm_resv(struct panthor_vm *vm); struct drm_gem_object *panthor_vm_root_gem(struct panthor_vm *vm); =20 -void panthor_vm_pool_destroy(struct panthor_file *pfile); -int panthor_vm_pool_create(struct panthor_file *pfile); +void panthor_vm_pool_destroy(struct drm_file *file); +int panthor_vm_pool_create(struct drm_file *file); 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/panthor_sched.c b/drivers/gpu/drm/pant= hor/panthor_sched.c index 1123cf36a7bca..e02062e8443ec 100644 --- a/drivers/gpu/drm/panthor/panthor_sched.c +++ b/drivers/gpu/drm/panthor/panthor_sched.c @@ -3112,8 +3112,9 @@ void panthor_sched_post_reset(struct panthor_device *= ptdev, bool reset_failed) } } =20 -void panthor_fdinfo_gather_group_samples(struct panthor_file *pfile) +void panthor_fdinfo_gather_group_samples(struct drm_file *file) { + struct panthor_file *pfile =3D file->driver_priv; struct panthor_group_pool *gpool =3D pfile->groups; struct panthor_group *group; unsigned long i; @@ -3649,11 +3650,11 @@ static void add_group_kbo_sizes(struct panthor_devi= ce *ptdev, =20 #define MAX_GROUPS_PER_POOL 128 =20 -int panthor_group_create(struct panthor_file *pfile, +int panthor_group_create(struct drm_file *file, const struct drm_panthor_group_create *group_args, - const struct drm_panthor_queue_create *queue_args, - u64 drm_client_id) + const struct drm_panthor_queue_create *queue_args) { + struct panthor_file *pfile =3D file->driver_priv; struct panthor_device *ptdev =3D pfile->ptdev; struct panthor_group_pool *gpool =3D pfile->groups; struct panthor_scheduler *sched =3D ptdev->scheduler; @@ -3748,7 +3749,8 @@ int panthor_group_create(struct panthor_file *pfile, goto err_put_group; =20 for (i =3D 0; i < group_args->queues.count; i++) { - group->queues[i] =3D group_create_queue(group, &queue_args[i], drm_clien= t_id, gid, i); + group->queues[i] =3D group_create_queue(group, &queue_args[i], + file->client_id, gid, i); if (IS_ERR(group->queues[i])) { ret =3D PTR_ERR(group->queues[i]); group->queues[i] =3D NULL; @@ -3788,8 +3790,9 @@ int panthor_group_create(struct panthor_file *pfile, return ret; } =20 -int panthor_group_destroy(struct panthor_file *pfile, u32 group_handle) +int panthor_group_destroy(struct drm_file *file, u32 group_handle) { + struct panthor_file *pfile =3D file->driver_priv; struct panthor_group_pool *gpool =3D pfile->groups; struct panthor_device *ptdev =3D pfile->ptdev; struct panthor_scheduler *sched =3D ptdev->scheduler; @@ -3834,9 +3837,10 @@ static struct panthor_group *group_from_handle(struc= t panthor_group_pool *pool, return group; } =20 -int panthor_group_get_state(struct panthor_file *pfile, +int panthor_group_get_state(struct drm_file *file, struct drm_panthor_group_get_state *get_state) { + struct panthor_file *pfile =3D file->driver_priv; struct panthor_group_pool *gpool =3D pfile->groups; struct panthor_device *ptdev =3D pfile->ptdev; struct panthor_scheduler *sched =3D ptdev->scheduler; @@ -3867,8 +3871,9 @@ int panthor_group_get_state(struct panthor_file *pfil= e, return 0; } =20 -int panthor_group_pool_create(struct panthor_file *pfile) +int panthor_group_pool_create(struct drm_file *file) { + struct panthor_file *pfile =3D file->driver_priv; struct panthor_group_pool *gpool; =20 gpool =3D kzalloc_obj(*gpool); @@ -3880,8 +3885,9 @@ int panthor_group_pool_create(struct panthor_file *pf= ile) return 0; } =20 -void panthor_group_pool_destroy(struct panthor_file *pfile) +void panthor_group_pool_destroy(struct drm_file *file) { + struct panthor_file *pfile =3D file->driver_priv; struct panthor_group_pool *gpool =3D pfile->groups; struct panthor_group *group; unsigned long i; @@ -3890,7 +3896,7 @@ void panthor_group_pool_destroy(struct panthor_file *= pfile) return; =20 xa_for_each(&gpool->xa, i, group) - panthor_group_destroy(pfile, i); + panthor_group_destroy(file, i); =20 xa_destroy(&gpool->xa); kfree(gpool); @@ -3905,9 +3911,10 @@ void panthor_group_pool_destroy(struct panthor_file = *pfile) * */ void -panthor_fdinfo_gather_group_mem_info(struct panthor_file *pfile, +panthor_fdinfo_gather_group_mem_info(struct drm_file *file, struct drm_memory_stats *stats) { + struct panthor_file *pfile =3D file->driver_priv; struct panthor_group_pool *gpool =3D pfile->groups; struct panthor_group *group; unsigned long i; @@ -3970,11 +3977,11 @@ struct panthor_vm *panthor_job_vm(struct drm_sched_= job *sched_job) } =20 struct drm_sched_job * -panthor_job_create(struct panthor_file *pfile, +panthor_job_create(struct drm_file *file, u16 group_handle, - const struct drm_panthor_queue_submit *qsubmit, - u64 drm_client_id) + const struct drm_panthor_queue_submit *qsubmit) { + struct panthor_file *pfile =3D file->driver_priv; struct panthor_group_pool *gpool =3D pfile->groups; struct panthor_job *job; u32 credits; @@ -4045,7 +4052,7 @@ panthor_job_create(struct panthor_file *pfile, =20 ret =3D drm_sched_job_init(&job->base, &job->group->queues[job->queue_idx]->entity, - credits, job->group, drm_client_id); + credits, job->group, file->client_id); if (ret) goto err_put_job; =20 diff --git a/drivers/gpu/drm/panthor/panthor_sched.h b/drivers/gpu/drm/pant= hor/panthor_sched.h index 9a8692de8aded..be7e1c8b4f563 100644 --- a/drivers/gpu/drm/panthor/panthor_sched.h +++ b/drivers/gpu/drm/panthor/panthor_sched.h @@ -15,31 +15,28 @@ struct drm_panthor_queue_create; struct drm_panthor_group_get_state; struct drm_panthor_queue_submit; struct panthor_device; -struct panthor_file; struct panthor_group_pool; struct panthor_job; =20 -int panthor_group_create(struct panthor_file *pfile, +int panthor_group_create(struct drm_file *file, const struct drm_panthor_group_create *group_args, - const struct drm_panthor_queue_create *queue_args, - u64 drm_client_id); -int panthor_group_destroy(struct panthor_file *pfile, u32 group_handle); -int panthor_group_get_state(struct panthor_file *pfile, + const struct drm_panthor_queue_create *queue_args); +int panthor_group_destroy(struct drm_file *file, u32 group_handle); +int panthor_group_get_state(struct drm_file *file, struct drm_panthor_group_get_state *get_state); =20 struct drm_sched_job * -panthor_job_create(struct panthor_file *pfile, +panthor_job_create(struct drm_file *file, u16 group_handle, - const struct drm_panthor_queue_submit *qsubmit, - u64 drm_client_id); + const struct drm_panthor_queue_submit *qsubmit); struct drm_sched_job *panthor_job_get(struct drm_sched_job *job); 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); =20 -int panthor_group_pool_create(struct panthor_file *pfile); -void panthor_group_pool_destroy(struct panthor_file *pfile); -void panthor_fdinfo_gather_group_mem_info(struct panthor_file *pfile, +int panthor_group_pool_create(struct drm_file *file); +void panthor_group_pool_destroy(struct drm_file *file); +void panthor_fdinfo_gather_group_mem_info(struct drm_file *pfile, struct drm_memory_stats *stats); =20 int panthor_sched_init(struct panthor_device *ptdev); @@ -53,6 +50,6 @@ void panthor_sched_report_mmu_fault(struct panthor_device= *ptdev); void panthor_sched_prepare_for_vm_destruction(struct panthor_device *ptdev= ); void panthor_sched_report_fw_events(struct panthor_device *ptdev, u32 even= ts); =20 -void panthor_fdinfo_gather_group_samples(struct panthor_file *pfile); +void panthor_fdinfo_gather_group_samples(struct drm_file *file); =20 #endif --=20 2.43.0 From nobody Fri Sep 25 14:31:21 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 87415443C2C for ; Fri, 11 Sep 2026 11:40:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789126843; cv=none; b=DXSHhgnumTXZuZNc19oqGyO+zlY7b9EFjPrx4u7HM7zfUON7R5dQdgr9Xt55EEEwmyzoOycMa7Kl32gqWyhQB5APfXssZjeF/ZuQyFityWWUATUjXQdSHfTHGT2HRBUryR86NhQGp42zlmeku5pbn+FWDahtyUtGVCO3jZcLZ1s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789126843; c=relaxed/simple; bh=X6S/11y57oqtbjM71ajaTOSiWRdLx/vpH6BjAYqx7OI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tSU/2n5kH+izP7VjfmKB29D5AkJQPLQlJrxMVRfaqRZkz+J6Z9aBUtLHeeDl+ZR6Fra/1wcOPcctX42QT8PpOX9wbh5uQIokZNI9/+7t2164cVVNrIBAIdpC1g+gcGaOYMwTQervRuFGmQ8JitSX+BbPWK78wpeqC2zYI4Gn3KM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=IAfqIuVP; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="IAfqIuVP" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4657E16F2; Fri, 11 Sep 2026 04:40:37 -0700 (PDT) Received: from e120398-lin.trondheim.arm.com (e120398-lin.trondheim.arm.com [10.42.46.160]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 014CA3F59E; Fri, 11 Sep 2026 04:40:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789126840; bh=X6S/11y57oqtbjM71ajaTOSiWRdLx/vpH6BjAYqx7OI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IAfqIuVPw2zieMK3EAKVai13jx1z6G4/fGJxXZdHWKyrMmw7/9g84oZl1cHLvXzbg +ObH8uItDpAy8MSwy3Y1Ll6xpVGUUvtkU6C5VyQkaviWt0iLqxbwah5ZfcLSxKEBIA lQbvjTcXz2mcCjoHkcoNr2YiVRupJ9X6kUtgVfZs= From: Ketil Johnsen To: Boris Brezillon , Steven Price , Liviu Dudau , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Daniel Almeida , Alice Ryhl Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Ketil Johnsen Subject: [PATCH v3 4/6] drm/panthor: Don't allocate protm_suspend_buf Date: Fri, 11 Sep 2026 13:40:12 +0200 Message-ID: <20260911114014.79139-5-ketil.johnsen@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260911114014.79139-1-ketil.johnsen@arm.com> References: <20260911114014.79139-1-ketil.johnsen@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The PROTM suspend buffer is only needed if the group is going to use PROTM in the first place, so let's not assume we need one until we're being asked to. Reviewed-by: Boris Brezillon Reviewed-by: Steven Price Reviewed-by: Liviu Dudau Signed-off-by: Ketil Johnsen --- drivers/gpu/drm/panthor/panthor_sched.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/pant= hor/panthor_sched.c index e02062e8443ec..0c8ea07fc7b9d 100644 --- a/drivers/gpu/drm/panthor/panthor_sched.c +++ b/drivers/gpu/drm/panthor/panthor_sched.c @@ -3636,9 +3636,11 @@ static void add_group_kbo_sizes(struct panthor_devic= e *ptdev, if (drm_WARN_ON(&ptdev->base, ptdev !=3D group->ptdev)) return; =20 - group->fdinfo.kbo_sizes +=3D group->suspend_buf->obj->size; - group->fdinfo.kbo_sizes +=3D group->protm_suspend_buf->obj->size; group->fdinfo.kbo_sizes +=3D group->syncobjs->obj->size; + group->fdinfo.kbo_sizes +=3D group->suspend_buf->obj->size; + + if (group->protm_suspend_buf) + group->fdinfo.kbo_sizes +=3D group->protm_suspend_buf->obj->size; =20 for (i =3D 0; i < group->queue_count; i++) { queue =3D group->queues[i]; @@ -3716,14 +3718,6 @@ int panthor_group_create(struct drm_file *file, goto err_put_group; } =20 - suspend_size =3D csg_iface->control->protm_suspend_size; - group->protm_suspend_buf =3D panthor_fw_alloc_suspend_buf_mem(ptdev, susp= end_size); - if (IS_ERR(group->protm_suspend_buf)) { - ret =3D PTR_ERR(group->protm_suspend_buf); - group->protm_suspend_buf =3D NULL; - goto err_put_group; - } - group->syncobjs =3D panthor_kernel_bo_create(ptdev, group->vm, group_args->queues.count * sizeof(struct panthor_syncobj_64b), --=20 2.43.0 From nobody Fri Sep 25 14:31:21 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 98D52468C07 for ; Fri, 11 Sep 2026 11:40:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789126848; cv=none; b=lwCkYqOnxhZq9KHunUIco1o4LwZwro9NTaHmHOgLyYW6Of6DScaYwtXdTSVQzfgRtW+tLGfwuN9aXzgFybxfMjbCUq228kdavESnTkTudMXnE8fdyX+n0N4t2k+dNeq80B6paOwy2W+MJ3CcPw+ox/otcG/Lqdj4LQfKRVfbs+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789126848; c=relaxed/simple; bh=TnOmt3K1qTraKX6HLPhVaaYc0aQNiV5Lzudv8VcOZYg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mwfeD+gsU9rnGEzZTe2IoRXbqRdFqbH0BaRCudw5+5PZm2ucSQMK2C//aXKzIJ86mxGx3uR9H6pB5ieNV2nPMbQQRFEcne6zWIwP7v6FW5bjLztltbUlXz1nEnVAXE95xnnBC1b8E6eSoAAQ8bZKLTb9CTDyDshJgb7awy+2Yn4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=SYi4RtFZ; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="SYi4RtFZ" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5E76916A3; Fri, 11 Sep 2026 04:40:41 -0700 (PDT) Received: from e120398-lin.trondheim.arm.com (e120398-lin.trondheim.arm.com [10.42.46.160]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4F8403F59E; Fri, 11 Sep 2026 04:40:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789126844; bh=TnOmt3K1qTraKX6HLPhVaaYc0aQNiV5Lzudv8VcOZYg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SYi4RtFZsNAjADmmS5RaD/dT2civ/7Qn3NNLKk38NC64VLkpA2JSYbBqOKn4hpEEK PH291uMHq9Ek5Ld3gzINZqFr4jwqsmObttExv2eSpoaqtpXVx2BoSpkFcslFFL8JR9 n+eKwLzXAJtn2eTEep+k06aUYj8opalmv/KvDwkw= From: Ketil Johnsen To: Boris Brezillon , Steven Price , Liviu Dudau , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Daniel Almeida , Alice Ryhl Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Florent Tomasin , Paul Toadere , Samuel Percival , Ketil Johnsen Subject: [PATCH v3 5/6] drm/panthor: Add support for entering and exiting protected mode Date: Fri, 11 Sep 2026 13:40:13 +0200 Message-ID: <20260911114014.79139-6-ketil.johnsen@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260911114014.79139-1-ketil.johnsen@arm.com> References: <20260911114014.79139-1-ketil.johnsen@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Florent Tomasin This patch modifies the Panthor driver code to allow handling of the GPU HW protected mode enter and exit. The logic added by this patch includes: - the mechanisms needed for entering and exiting protected mode. - the handling of protected mode IRQs and FW interactions. - the scheduler changes needed to decide when to enter protected mode based on CSG scheduling. - GPU fault handling during protected mode execution. Note that the submission of a protected mode jobs are done from the user space. The following is a summary of how protected mode is entered and exited: - When the GPU detects a protected mode job needs to be executed, an IRQ is sent to the CPU to notify the kernel driver that the job is blocked until the GPU has entered protected mode. The entering of protected mode is controlled by the kernel driver. - The Mali Panthor CSF driver will schedule a tick and evaluate which CS in the CSG to schedule on slot needs protected mode. If the priority of the CSG is not sufficiently high, the protected mode job will not progress until the CSG is scheduled at top priority. - The Panthor scheduler notifies the GPU that the blocked protected jobs will soon be able to progress. - Once all CSG and CS slots are updated, the scheduler requests the GPU to enter protected mode and waits for it to be acknowledged. - If successful, all protected mode jobs will resume execution while normal mode jobs block until the GPU exits protected mode, or the kernel driver rotates the CSGs and forces the GPU to exit protected mode. - If unsuccessful, the scheduler will request a GPU reset. - Faults during protected mode are reported GPU wide, and not as CSG/CS errors. We allow only one CSG to run in protected mode at a time so we know which CSG to blame for the fault. - All faults during protected mode are handled with a GPU reset. - When a protected mode job is suspended as a result of the CSGs rotation, the GPU will send an IRQ to the CPU to notify that the protected mode job needs to resume. This sequence will continue so long the user space is submitting protected mode jobs. Signed-off-by: Florent Tomasin Co-developed-by: Paul Toadere Signed-off-by: Paul Toadere Co-developed-by: Samuel Percival Signed-off-by: Samuel Percival Co-developed-by: Ketil Johnsen Signed-off-by: Ketil Johnsen --- v3: - Rebase - Required changes due to new IRQ handling (events_lock). - Required changes due to memory reclaim (more places to sync with protm). - Count number of enter and exits to and from protected mode. - Added helper function wait_protm_enter() to check protm enter condition, = using the counters mentioned above. - Tweaks to timeouts. - Removed disable/enable of GPU_IRQ_PROTM_FAULT. No longer recall what issu= e it was supposed to fix. - protm_fault changed to atomic. - Moved sync with protm out from panthor_vm_lock_region() and panthor_vm_unlock_region(). - Avoids special dealing with as.slots_lock and GPU reset. - Block and unblock of protm in same function, so easier to see. - We no longer need to add panthor_vm_expand_locked_region() (different p= atch). - The downside is that we might block protm mode more than necessary. - Added panthor_sched_protm_try_block() used by memory reclaim case. - protm_pending_queues made atomic (following the same change for fatal_que= ues). - Only clear bits from protm_pending_queues when we ACK CS_PROTM_PENDING. - Clear any pending CS_PROTM_PENDING on slot reset. - Ack all CS_PROTM_PENDING in tick_ctx_handle_protm_group(), no matter the = value of protm_pending_queues. - Inlined helper function panthor_sched_protm_enter(). v2: - Heavily reworked, although conceptually similar to v1. --- drivers/gpu/drm/panthor/panthor_device.c | 1 + drivers/gpu/drm/panthor/panthor_device.h | 31 ++ drivers/gpu/drm/panthor/panthor_fw.c | 92 +++++- drivers/gpu/drm/panthor/panthor_fw.h | 4 + drivers/gpu/drm/panthor/panthor_gpu.c | 47 ++- drivers/gpu/drm/panthor/panthor_gpu.h | 4 + drivers/gpu/drm/panthor/panthor_mmu.c | 24 +- drivers/gpu/drm/panthor/panthor_sched.c | 350 +++++++++++++++++++++-- drivers/gpu/drm/panthor/panthor_sched.h | 4 + 9 files changed, 533 insertions(+), 24 deletions(-) diff --git a/drivers/gpu/drm/panthor/panthor_device.c b/drivers/gpu/drm/pan= thor/panthor_device.c index 9687c59de3505..0a41f69c473c3 100644 --- a/drivers/gpu/drm/panthor/panthor_device.c +++ b/drivers/gpu/drm/panthor/panthor_device.c @@ -172,6 +172,7 @@ int panthor_device_init(struct panthor_device *ptdev) =20 ptdev->soc_data =3D of_device_get_match_data(ptdev->base.dev); =20 + init_rwsem(&ptdev->protm.lock); init_completion(&ptdev->unplug.done); ret =3D drmm_mutex_init(&ptdev->base, &ptdev->unplug.lock); if (ret) diff --git a/drivers/gpu/drm/panthor/panthor_device.h b/drivers/gpu/drm/pan= thor/panthor_device.h index b55a3f9edd414..f1b7f51f5ae1e 100644 --- a/drivers/gpu/drm/panthor/panthor_device.h +++ b/drivers/gpu/drm/panthor/panthor_device.h @@ -336,6 +336,37 @@ struct panthor_device { struct list_head node; } gems; #endif + /** @protm: Protected mode related data. */ + struct { + /** + * @lock: Lock to prevent MMU operations during protected mode. + * + * The MMU HW will silently ignore commands issued when the + * GPU is in protected mode. It is important that we handle this + * for some of the MMU HW interactions. + * + * Code which interacts with the MMU, typically by calling + * panthor_vm_lock_region(), should therefore ensure the + * scheduler is not in and will not enter protected mode first. + * This is done by calling either + * - panthor_sched_protm_block(), or + * - panthor_sched_protm_try_block() + * + * Once the MMU operations have completed, call + * panthor_sched_protm_unblock() to tell the scheduler that + * it is safe to enter protected mode again. + * + * The block/unblock for MMU operations take this as reader. + * The scheduler holds this as writer when switching into protm. + */ + struct rw_semaphore lock; + + /** @protm_enter_count: Number of times entered protm. */ + atomic64_t protm_enter_count; + + /** @protm_exit_count: Number of times exited protm. */ + atomic64_t protm_exit_count; + } protm; }; =20 struct panthor_gpu_usage { diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor= /panthor_fw.c index 5f9f7a92c56a8..96770ce34da84 100644 --- a/drivers/gpu/drm/panthor/panthor_fw.c +++ b/drivers/gpu/drm/panthor/panthor_fw.c @@ -1067,7 +1067,9 @@ static void panthor_fw_init_global_iface(struct panth= or_device *ptdev) GLB_CFG_PROGRESS_TIMER | GLB_CFG_POWEROFF_TIMER | GLB_IDLE_EN | - GLB_IDLE; + GLB_IDLE | + GLB_PROTM_ENTER | + GLB_PROTM_EXIT; =20 if (panthor_fw_has_glb_state(ptdev)) glb_iface->input->ack_irq_mask |=3D GLB_STATE_MASK; @@ -1281,6 +1283,9 @@ int panthor_fw_post_reset(struct panthor_device *ptde= v) return ret; } =20 + atomic64_set(&ptdev->protm.protm_enter_count, 0); + atomic64_set(&ptdev->protm.protm_exit_count, 0); + /* We must re-initialize the global interface even on fast-reset. */ panthor_fw_init_global_iface(ptdev); return 0; @@ -1476,6 +1481,91 @@ static void panthor_fw_ping_work(struct work_struct = *work) } } =20 +static bool wait_protm_enter(struct panthor_device *ptdev, + long long enter_count) +{ + return (panthor_gpu_status(ptdev) & GPU_STATUS_PROTM_ACTIVE) || + (atomic64_read(&ptdev->protm.protm_exit_count) >=3D enter_count); +} + +int panthor_fw_protm_enter(struct panthor_device *ptdev) +{ + struct panthor_fw_global_iface *glb_iface =3D + panthor_fw_get_glb_iface(ptdev); + u32 acked; + int ret; + long long enter_count; + + /* Restart the watchdog timer, so it doesn't hit immediately + * after entering protected mode, since this will cause GPU + * to exit protected mode to respond to the ping request. + */ + mod_delayed_work(ptdev->reset.wq, &ptdev->fw->watchdog.ping_work, + msecs_to_jiffies(PING_INTERVAL_MS)); + + panthor_fw_toggle_reqs(glb_iface, req, ack, GLB_PROTM_ENTER); + panthor_fw_ring_doorbell(ptdev, CSF_GLB_DOORBELL_ID); + + ret =3D panthor_fw_glb_wait_acks(ptdev, GLB_PROTM_ENTER, &acked, 250); + if (ret) { + drm_err(&ptdev->base, + "Wait for FW protected mode acknowledge timed out"); + return ret; + } + + enter_count =3D atomic64_inc_return(&ptdev->protm.protm_enter_count); + + /* Poll for the entry of protected mode. + * It is possible that GPU_STATUS_PROTM_ACTIVE is set and cleared + * before we check it below, so we must also check for GLB_PROTM_EXIT. + * GLB_PROTM_EXIT can not be checked directly, because this could also + * be handled and clear before we check below. We count number of + * protm enters and exits to safely handle that case. + */ + ret =3D wait_event_timeout(ptdev->fw->req_waitqueue, + wait_protm_enter(ptdev, enter_count), + msecs_to_jiffies(500)); + if (!ret) { + drm_err(&ptdev->base, + "Wait for GPU protected mode enter timed out"); + return -ETIMEDOUT; + } + + return 0; +} + +int panthor_fw_protm_exit_wait(struct panthor_device *ptdev, u32 timeout_m= s) +{ + int ret; + + ret =3D wait_event_timeout(ptdev->fw->req_waitqueue, + !(panthor_gpu_status(ptdev) & + GPU_STATUS_PROTM_ACTIVE), + msecs_to_jiffies(timeout_ms)); + if (!ret) + return -ETIMEDOUT; + + return 0; +} + +int panthor_fw_protm_exit(struct panthor_device *ptdev, u32 timeout_ms) +{ + struct panthor_fw_global_iface *glb_iface =3D + panthor_fw_get_glb_iface(ptdev); + int ret; + + /* Send PING request to force an exit */ + panthor_fw_toggle_reqs(glb_iface, req, ack, GLB_PING); + panthor_fw_ring_doorbell(ptdev, CSF_GLB_DOORBELL_ID); + + ret =3D panthor_fw_protm_exit_wait(ptdev, timeout_ms); + if (ret) + drm_err(&ptdev->base, + "Wait for GPU protected mode exit timed out"); + + return ret; +} + /** * panthor_fw_init() - Initialize FW related data. * @ptdev: Device. diff --git a/drivers/gpu/drm/panthor/panthor_fw.h b/drivers/gpu/drm/panthor= /panthor_fw.h index a99a9b6f4825c..4eda8f8e714c1 100644 --- a/drivers/gpu/drm/panthor/panthor_fw.h +++ b/drivers/gpu/drm/panthor/panthor_fw.h @@ -529,4 +529,8 @@ static inline int panthor_fw_resume(struct panthor_devi= ce *ptdev) int panthor_fw_init(struct panthor_device *ptdev); void panthor_fw_unplug(struct panthor_device *ptdev); =20 +int panthor_fw_protm_enter(struct panthor_device *ptdev); +int panthor_fw_protm_exit(struct panthor_device *ptdev, u32 timeout_ms); +int panthor_fw_protm_exit_wait(struct panthor_device *ptdev, u32 timeout_m= s); + #endif diff --git a/drivers/gpu/drm/panthor/panthor_gpu.c b/drivers/gpu/drm/pantho= r/panthor_gpu.c index a383b04f101ed..27617f3a72394 100644 --- a/drivers/gpu/drm/panthor/panthor_gpu.c +++ b/drivers/gpu/drm/panthor/panthor_gpu.c @@ -46,6 +46,9 @@ struct panthor_gpu { =20 /** @cache_flush_lock: Lock to serialize cache flushes */ struct mutex cache_flush_lock; + + /** @protm_fault: True if a GPU_IRQ_PROTM_FAULT has been raised */ + atomic_t protm_fault; }; =20 #define GPU_INTERRUPTS_MASK \ @@ -91,6 +94,34 @@ static void panthor_gpu_irq_handler(struct panthor_irq *= pirq, u32 status) struct panthor_device *ptdev =3D pirq->ptdev; struct panthor_gpu *gpu =3D ptdev->gpu; =20 + if (status & GPU_IRQ_PROTM_FAULT) { + /* Make a note of this fault before we clear the interrupt. + * This ensures panthor_gpu_protm_fault_pending() can always + * give an accurate answer. + * + * There is a race we need to handle between two interrupts, + * this GPU_IRQ_PROTM_FAULT and JOB_INT_GLOBAL_IF with the + * GLB_PROTM_EXIT event. + * + * Although GPU_IRQ_PROTM_FAULT is always raised first, + * processing of GLB_PROTM_EXIT could still execute first. + * The handling of GLB_PROTM_EXIT MUST know if a + * GPU_IRQ_PROTM_FAULT has been raised or not, otherwise it + * could incorrectly think everything is fine and resume + * with normal scheduling to early. + * + * We still need to do fault handling (reset) here as well, + * because some failures during protected mode do not + * automatically exit protected mode (no GLB_PROTM_EXIT). + * This means there is a slim chance we do two GPU resets + * instead of just one. This is not ideal, but should be safe. + */ + atomic_set(&gpu->protm_fault, 1); + + drm_warn(&ptdev->base, "GPU Fault in protected mode\n"); + panthor_device_schedule_reset(ptdev); + } + gpu_write(gpu->irq.iomem, INT_CLEAR, status); =20 if (tracepoint_enabled(gpu_power_status) && (status & GPU_POWER_INTERRUPT= S_MASK)) @@ -107,8 +138,6 @@ static void panthor_gpu_irq_handler(struct panthor_irq = *pirq, u32 status) fault_status, panthor_exception_name(ptdev, fault_status & 0xFF), address); } - if (status & GPU_IRQ_PROTM_FAULT) - drm_warn(&ptdev->base, "GPU Fault in protected mode\n"); =20 spin_lock(&ptdev->gpu->reqs_lock); if (status & ptdev->gpu->pending_reqs) { @@ -123,6 +152,13 @@ static irqreturn_t panthor_gpu_irq_threaded_handler(in= t irq, void *data) return panthor_irq_default_threaded_handler(data, panthor_gpu_irq_handler= ); } =20 +bool panthor_gpu_protm_fault_pending(struct panthor_device *ptdev) +{ + return atomic_read(&ptdev->gpu->protm_fault) || + gpu_read(ptdev->gpu->irq.iomem, INT_RAWSTAT) & + GPU_IRQ_PROTM_FAULT; +} + /** * panthor_gpu_unplug() - Called when the GPU is unplugged. * @ptdev: Device to unplug. @@ -404,6 +440,8 @@ int panthor_gpu_soft_reset(struct panthor_device *ptdev) struct panthor_gpu *gpu =3D ptdev->gpu; bool timedout =3D false; =20 + atomic_set(&ptdev->gpu->protm_fault, 0); + scoped_guard(spinlock, &ptdev->gpu->reqs_lock) { if (!drm_WARN_ON(&ptdev->base, ptdev->gpu->pending_reqs & GPU_IRQ_RESET_COMPLETED)) { @@ -508,3 +546,8 @@ int panthor_gpu_coherency_init(struct panthor_device *p= tdev) drm_err(&ptdev->base, "Coherency not supported by the device"); return -ENOTSUPP; } + +u32 panthor_gpu_status(struct panthor_device *ptdev) +{ + return gpu_read(ptdev->gpu->iomem, GPU_STATUS); +} diff --git a/drivers/gpu/drm/panthor/panthor_gpu.h b/drivers/gpu/drm/pantho= r/panthor_gpu.h index f615feb056094..00ec9a8c5d7fd 100644 --- a/drivers/gpu/drm/panthor/panthor_gpu.h +++ b/drivers/gpu/drm/panthor/panthor_gpu.h @@ -60,4 +60,8 @@ u64 panthor_gpu_get_cycle_count(struct panthor_device *pt= dev); =20 int panthor_gpu_coherency_init(struct panthor_device *ptdev); =20 +u32 panthor_gpu_status(struct panthor_device *ptdev); + +bool panthor_gpu_protm_fault_pending(struct panthor_device *ptdev); + #endif diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/pantho= r/panthor_mmu.c index 3e5f20768d545..1e1a158aa12ed 100644 --- a/drivers/gpu/drm/panthor/panthor_mmu.c +++ b/drivers/gpu/drm/panthor/panthor_mmu.c @@ -2505,6 +2505,11 @@ int panthor_vm_evict_bo_mappings_locked(struct panth= or_gem_object *bo) if (!mutex_trylock(&vm->op_lock)) return -EDEADLK; =20 + if (panthor_sched_protm_try_block(vm->ptdev)) { + mutex_unlock(&vm->op_lock); + return -EDEADLK; + } + /* It can be that the vm_bo was already evicted but a new * mapping pointing to this BO got created in the meantime, * thus turning the vm_bo in partially evicted state. In that case @@ -2540,6 +2545,7 @@ int panthor_vm_evict_bo_mappings_locked(struct pantho= r_gem_object *bo) vma->evicted =3D true; } =20 + panthor_sched_protm_unblock(vm->ptdev); mutex_unlock(&vm->op_lock); =20 if (ret) @@ -2612,6 +2618,10 @@ static int remap_evicted_vma(struct drm_gpuvm_bo *vm= _bo, } =20 if (found) { + ret =3D panthor_sched_protm_block(vm->ptdev); + if (ret) + goto out_unlock; + vm->op_ctx =3D op_ctx; ret =3D panthor_vm_lock_region(vm, evicted_vma->base.va.addr, evicted_vma->base.va.range); @@ -2633,9 +2643,12 @@ static int remap_evicted_vma(struct drm_gpuvm_bo *vm= _bo, panthor_vm_unlock_region(vm); } =20 + panthor_sched_protm_unblock(vm->ptdev); + vm->op_ctx =3D NULL; } =20 +out_unlock: mutex_unlock(&vm->op_lock); =20 out_cleanup: @@ -2726,9 +2739,13 @@ panthor_vm_exec_op(struct panthor_vm *vm, struct pan= thor_vm_op_ctx *op, mutex_lock(&vm->op_lock); vm->op_ctx =3D op; =20 + ret =3D panthor_sched_protm_block(vm->ptdev); + if (ret) + goto out_unlock; + ret =3D panthor_vm_lock_region(vm, op->va.addr, op->va.range); if (ret) - goto out; + goto out_unblock; =20 switch (op_type) { case DRM_PANTHOR_VM_BIND_OP_TYPE_MAP: { @@ -2759,10 +2776,13 @@ panthor_vm_exec_op(struct panthor_vm *vm, struct pa= nthor_vm_op_ctx *op, =20 panthor_vm_unlock_region(vm); =20 -out: +out_unblock: + panthor_sched_protm_unblock(vm->ptdev); + if (ret && flag_vm_unusable_on_failure) panthor_vm_declare_unusable(vm); =20 +out_unlock: vm->op_ctx =3D NULL; mutex_unlock(&vm->op_lock); =20 diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/pant= hor/panthor_sched.c index 0c8ea07fc7b9d..1fe77e5c41995 100644 --- a/drivers/gpu/drm/panthor/panthor_sched.c +++ b/drivers/gpu/drm/panthor/panthor_sched.c @@ -306,6 +306,17 @@ struct panthor_scheduler { */ struct list_head stopped_groups; } reset; + + /** @protm: Protected mode related fields. */ + struct { + /** + * @active_group: The active protected group. + * + * We only allow one protected group to run at the same time, + * as it makes it easier to handle faults in protected mode. + */ + struct panthor_group *active_group; + } protm; }; =20 /** @@ -570,6 +581,16 @@ struct panthor_group { */ atomic_t fatal_queues; =20 + /** + * @protm_pending_queues: Bitmask reflecting the queues that have raised + * a CS_PROTM_PENDING. + * + * The GPU will set the bit associated to the queue pending protected + * mode when a PROT_REGION command is executing or when trying to resume + * previously suspended protected mode jobs. + */ + atomic_t protm_pending_queues; + /** @tiler_oom: Mask of queues that have a tiler OOM event to process. */ atomic_t tiler_oom; =20 @@ -1149,12 +1170,14 @@ cs_slot_reset_locked(struct panthor_device *ptdev, = u32 csg_id, u32 cs_id) struct panthor_fw_cs_iface *cs_iface =3D panthor_fw_get_cs_iface(ptdev, c= sg_id, cs_id); struct panthor_group *group =3D ptdev->scheduler->csg_slots[csg_id].group; struct panthor_queue *queue =3D group->queues[cs_id]; + u32 val, mask; =20 lockdep_assert_held(&ptdev->scheduler->lock); =20 - panthor_fw_update_reqs(cs_iface, req, - CS_STATE_STOP, - CS_STATE_MASK); + val =3D CS_STATE_STOP | (cs_iface->output->ack & CS_PROTM_PENDING); + mask =3D CS_STATE_MASK | CS_PROTM_PENDING; + + panthor_fw_update_reqs(cs_iface, req, val, mask); =20 queue_suspend_timeout(queue); =20 @@ -1393,6 +1416,27 @@ csg_slot_prog_locked(struct panthor_device *ptdev, u= 32 csg_id, u32 priority) return 0; } =20 +static void +cs_slot_process_protm_pending_event_locked(struct panthor_device *ptdev, + u32 csg_id, u32 cs_id) +{ + struct panthor_scheduler *sched =3D ptdev->scheduler; + struct panthor_csg_slot *csg_slot =3D &sched->csg_slots[csg_id]; + struct panthor_group *group =3D csg_slot->group; + + lockdep_assert_held(&sched->events_lock); + + if (!group) + return; + + /* Do not allow user space work to switch into protected mode, as we + * do not fully support this quite yet. + */ + atomic_or(BIT(cs_id), &group->fatal_queues); + + sched_queue_delayed_work(sched, tick, 0); +} + static void cs_slot_process_fatal_event_locked(struct panthor_device *ptdev, u32 csg_id, u32 cs_id) @@ -1641,6 +1685,10 @@ static bool cs_slot_process_irq_locked(struct pantho= r_device *ptdev, if (events & CS_TILER_OOM) cs_slot_process_tiler_oom_event_locked(ptdev, csg_id, cs_id); =20 + if (events & CS_PROTM_PENDING) + cs_slot_process_protm_pending_event_locked(ptdev, csg_id, + cs_id); + /* We don't acknowledge the TILER_OOM event since its handling is * deferred to a separate work. */ @@ -1855,6 +1903,38 @@ static void sched_process_idle_event_locked(struct p= anthor_device *ptdev) sched_queue_delayed_work(ptdev->scheduler, tick, 0); } =20 +static void sched_process_protm_exit_event_locked(struct panthor_device *p= tdev) +{ + struct panthor_fw_global_iface *glb_iface =3D + panthor_fw_get_glb_iface(ptdev); + struct panthor_scheduler *sched =3D ptdev->scheduler; + + lockdep_assert_held(&sched->events_lock); + + atomic64_inc(&ptdev->protm.protm_exit_count); + + /* Acknowledge the protm exit */ + panthor_fw_update_reqs(glb_iface, req, glb_iface->output->ack, + GLB_PROTM_EXIT); + + /* If there are pending fault from protected mode execution, then early + * out here. The GPU_IRQ_PROTM_FAULT handling will trigger the propper + * error recovery via a GPU reset. + */ + if (panthor_gpu_protm_fault_pending(ptdev)) + return; + + /* Protected mode exited successfully. Clear protm.active_group so that + * tick_work() is unblocked to schedule new work. + */ + if (sched->protm.active_group) { + group_put(sched->protm.active_group); + sched->protm.active_group =3D NULL; + } + + sched_queue_delayed_work(sched, tick, 0); +} + /** * sched_process_global_irq_locked() - Process the scheduling part of a gl= obal IRQ * @ptdev: Device. @@ -1870,6 +1950,9 @@ static void sched_process_global_irq_locked(struct pa= nthor_device *ptdev) ack =3D READ_ONCE(glb_iface->output->ack); evts =3D (req ^ ack) & GLB_EVT_MASK; =20 + if (evts & GLB_PROTM_EXIT) + sched_process_protm_exit_event_locked(ptdev); + if (evts & GLB_IDLE) sched_process_idle_event_locked(ptdev); } @@ -1881,22 +1964,22 @@ static void sched_process_global_irq_locked(struct = panthor_device *ptdev) */ void panthor_sched_report_fw_events(struct panthor_device *ptdev, u32 even= ts) { + u32 csg_events =3D events & ~JOB_INT_GLOBAL_IF; + if (!ptdev->scheduler) return; =20 guard(spinlock)(&ptdev->scheduler->events_lock); =20 - if (events & JOB_INT_GLOBAL_IF) { - sched_process_global_irq_locked(ptdev); - events &=3D ~JOB_INT_GLOBAL_IF; - } - - while (events) { - u32 csg_id =3D ffs(events) - 1; + while (csg_events) { + u32 csg_id =3D ffs(csg_events) - 1; =20 sched_process_csg_irq_locked(ptdev, csg_id); - events &=3D ~BIT(csg_id); + csg_events &=3D ~BIT(csg_id); } + + if (events & JOB_INT_GLOBAL_IF) + sched_process_global_irq_locked(ptdev); } =20 /** @@ -1982,6 +2065,69 @@ group_unbind_locked(struct panthor_group *group) return 0; } =20 +static void handle_protm_fault(struct panthor_device *ptdev) +{ + struct panthor_scheduler *sched =3D ptdev->scheduler; + u32 csg_id; + struct panthor_group *protm_group; + + guard(mutex)(&sched->lock); + + protm_group =3D sched->protm.active_group; + + if (!protm_group || !panthor_gpu_protm_fault_pending(ptdev)) + return; + + atomic_set(&protm_group->fatal_queues, + GENMASK(protm_group->queue_count - 1, 0)); + + /* Different kinds of faults during protected mode can give different + * behavior/state. + * Case 1) The fault keeps the GPU in protected mode. + * In this case, the request to exit protected mode below will + * fail and we need to take some further action. + * Case 2) The fault do not keep the GPU in protected mode. + * In this case, the request to exit protected + * mode below will succeed, and we don't need to take any + * further action right here. + */ + if (!panthor_fw_protm_exit(ptdev, 500)) + return; + + /* GPU failed to exit protected mode. + * Mark all CSGs as suspended and unbind them, so that they are + * unaffected by the GPU reset itself. + * We can not suspend the groups in this case, because we are stuck + * in protected mode. That is also the reason it is safe to unbind + * without suspending first (the groups are already "suspended"). + * The failing protected group will be scheduled for termination. + */ + + for (csg_id =3D 0; csg_id < sched->csg_slot_count; csg_id++) { + struct panthor_group *group =3D sched->csg_slots[csg_id].group; + + if (!group) + continue; + + group_get(group); + + group->state =3D PANTHOR_CS_GROUP_SUSPENDED; + group_unbind_locked(group); + + drm_WARN_ON(&group->ptdev->base, !list_empty(&group->run_node)); + + if (group_can_run(group)) { + list_add(&group->run_node, + &sched->groups.idle[group->priority]); + } else { + list_del_init(&group->wait_node); + group_queue_work(group, term); + } + + group_put(group); + } +} + static const char *fence_get_driver_name(struct dma_fence *fence) { return "panthor"; @@ -2011,6 +2157,12 @@ static void csgs_upd_ctx_init(struct panthor_csg_slo= ts_upd_ctx *ctx) memset(ctx, 0, sizeof(*ctx)); } =20 +static void csgs_upd_ctx_ring_doorbell(struct panthor_csg_slots_upd_ctx *c= tx, + u32 csg_id) +{ + ctx->update_mask |=3D BIT(csg_id); +} + static void csgs_upd_ctx_queue_reqs(struct panthor_device *ptdev, struct panthor_csg_slots_upd_ctx *ctx, u32 csg_id, u32 value, u32 mask) @@ -2021,7 +2173,8 @@ static void csgs_upd_ctx_queue_reqs(struct panthor_de= vice *ptdev, =20 ctx->requests[csg_id].value =3D (ctx->requests[csg_id].value & ~mask) | (= value & mask); ctx->requests[csg_id].mask |=3D mask; - ctx->update_mask |=3D BIT(csg_id); + + csgs_upd_ctx_ring_doorbell(ctx, csg_id); } =20 static int csgs_upd_ctx_apply_locked(struct panthor_device *ptdev, @@ -2038,8 +2191,12 @@ static int csgs_upd_ctx_apply_locked(struct panthor_= device *ptdev, while (update_slots) { struct panthor_fw_csg_iface *csg_iface; u32 csg_id =3D ffs(update_slots) - 1; + u32 req_mask =3D ctx->requests[csg_id].mask; =20 update_slots &=3D ~BIT(csg_id); + if (!req_mask) + continue; + csg_iface =3D panthor_fw_get_csg_iface(ptdev, csg_id); panthor_fw_update_reqs(csg_iface, req, ctx->requests[csg_id].value, @@ -2056,6 +2213,9 @@ static int csgs_upd_ctx_apply_locked(struct panthor_d= evice *ptdev, int ret; =20 update_slots &=3D ~BIT(csg_id); + if (!req_mask) + continue; + csg_iface =3D panthor_fw_get_csg_iface(ptdev, csg_id); =20 ret =3D panthor_fw_csg_wait_acks(ptdev, csg_id, req_mask, &acked, 100); @@ -2092,6 +2252,7 @@ struct panthor_sched_tick_ctx { bool immediate_tick; bool stop_tick; u32 csg_upd_failed_mask; + struct panthor_group *protm_group; }; =20 static bool @@ -2133,6 +2294,11 @@ tick_ctx_pick_groups_from_list(const struct panthor_= scheduler *sched, if (!owned_by_tick_ctx) group_get(group); =20 + /* Only the first pick is allowed to request switch to protm */ + if (ctx->group_count =3D=3D 0 && + atomic_read(&group->protm_pending_queues)) + ctx->protm_group =3D group; + ctx->group_count++; =20 /* If we have more than one active group with the same priority, @@ -2291,6 +2457,48 @@ static void group_term_work(struct work_struct *work) group_put(group); } =20 +int panthor_sched_protm_block(struct panthor_device *ptdev) +{ + int ret; + + down_read(&ptdev->protm.lock); + + /* First, wait a little bit for FW to exit protected mode on its own. + * Only if that fails do we request a protected mode exit. + */ + + ret =3D panthor_fw_protm_exit_wait(ptdev, 5); + if (ret) { + ret =3D panthor_fw_protm_exit(ptdev, 2000); + if (ret) + up_read(&ptdev->protm.lock); + } + + return ret; +} + +int panthor_sched_protm_try_block(struct panthor_device *ptdev) +{ + int ret; + + ret =3D down_read_trylock(&ptdev->protm.lock); + if (ret) { + if (panthor_gpu_status(ptdev) & GPU_STATUS_PROTM_ACTIVE) { + up_read(&ptdev->protm.lock); + return -EAGAIN; + } + + return 0; + } + + return -EAGAIN; +} + +void panthor_sched_protm_unblock(struct panthor_device *ptdev) +{ + up_read(&ptdev->protm.lock); +} + static void tick_ctx_cleanup(struct panthor_scheduler *sched, struct panthor_sched_tick_ctx *ctx) @@ -2414,6 +2622,46 @@ tick_ctx_schedule_group(struct panthor_scheduler *sc= hed, return 0; } =20 +static void +tick_ctx_handle_protm_group(struct panthor_scheduler *sched, + struct panthor_csg_slots_upd_ctx *upd_ctx, + struct panthor_group *group) +{ + struct panthor_device *ptdev =3D sched->ptdev; + struct panthor_fw_csg_iface *csg_iface =3D + panthor_fw_get_csg_iface(ptdev, group->csg_id); + u32 q; + u32 cs_acked =3D 0; + + if (drm_WARN_ON(&ptdev->base, group->csg_id < 0)) + return; + + for (q =3D 0; q < group->queue_count; q++) { + struct panthor_fw_cs_iface *cs_iface =3D + panthor_fw_get_cs_iface(ptdev, group->csg_id, q); + + /* Ack any pending CS_PROTM_PENDING so it can run in protm */ + if ((cs_iface->output->ack ^ cs_iface->input->req) & + CS_PROTM_PENDING) { + drm_WARN_ON( + &ptdev->base, + !(atomic_read(&group->protm_pending_queues) & + BIT(q))); + + panthor_fw_update_reqs(cs_iface, req, + cs_iface->output->ack, + CS_PROTM_PENDING); + cs_acked |=3D BIT(q); + } + } + + /* Clear only the ones we acked */ + atomic_andnot(cs_acked, &group->protm_pending_queues); + + panthor_fw_toggle_reqs(csg_iface, doorbell_req, doorbell_ack, cs_acked); + csgs_upd_ctx_ring_doorbell(upd_ctx, group->csg_id); +} + static void tick_ctx_apply(struct panthor_scheduler *sched, struct panthor_sched_tick_= ctx *ctx) { @@ -2483,6 +2731,9 @@ tick_ctx_apply(struct panthor_scheduler *sched, struc= t panthor_sched_tick_ctx *c } } =20 + if (ctx->protm_group) + tick_ctx_handle_protm_group(sched, &upd_ctx, ctx->protm_group); + ret =3D csgs_upd_ctx_apply_locked(ptdev, &upd_ctx); if (ret) { panthor_device_schedule_reset(ptdev); @@ -2490,6 +2741,24 @@ tick_ctx_apply(struct panthor_scheduler *sched, stru= ct panthor_sched_tick_ctx *c return; } =20 + if (ctx->protm_group) { + if (drm_WARN_ON(&ptdev->base, sched->protm.active_group)) + group_put(sched->protm.active_group); + + sched->protm.active_group =3D ctx->protm_group; + group_get(sched->protm.active_group); + + down_write(&ptdev->protm.lock); + + ret =3D panthor_fw_protm_enter(ptdev); + if (ret) { + panthor_device_schedule_reset(ptdev); + ctx->csg_upd_failed_mask =3D U32_MAX; + } + + up_write(&ptdev->protm.lock); + } + for (prio =3D PANTHOR_CSG_PRIORITY_COUNT - 1; prio >=3D 0; prio--) { list_for_each_entry_safe(group, tmp, &ctx->groups[prio], run_node) { list_del_init(&group->run_node); @@ -2579,6 +2848,23 @@ static void tick_work(struct work_struct *work) if (panthor_device_reset_is_pending(sched->ptdev)) goto out_unlock; =20 + if (sched->protm.active_group) { + bool rt_groups_waiting =3D !list_empty( + &sched->groups.runnable[PANTHOR_CSG_PRIORITY_RT]); + + if (full_tick || rt_groups_waiting) { + /* We allow preemption in this case, but we must + * ensure we are fully out of protected mode first. + * We rely on the GLB_PROTM_EXIT (or error recovery) + * to get a new tick. + */ + if (panthor_fw_protm_exit(ptdev, 500)) + panthor_device_schedule_reset(ptdev); + } + + goto out_unlock; + } + tick_ctx_init(sched, &ctx); if (ctx.csg_upd_failed_mask) goto out_cleanup_ctx; @@ -2631,13 +2917,32 @@ static void tick_work(struct work_struct *work) } =20 /* If we have free CSG slots left, pick idle groups */ - for (prio =3D PANTHOR_CSG_PRIORITY_COUNT - 1; - prio >=3D 0 && !tick_ctx_is_full(sched, &ctx); - prio--) { - /* Check the old_group queue first to avoid reprogramming the slots */ - tick_ctx_pick_groups_from_list(sched, &ctx, &ctx.old_groups[prio], false= , true); - tick_ctx_pick_groups_from_list(sched, &ctx, &sched->groups.idle[prio], - false, false); + if (ctx.protm_group) { + /* Pick only idle groups with equal or lower priority than the + * group triggering protected mode. Do not bother picking + * unscheduled idle groups. + */ + for (prio =3D ctx.protm_group->priority; + prio >=3D 0 && !tick_ctx_is_full(sched, &ctx); prio--) + tick_ctx_pick_groups_from_list(sched, &ctx, + &ctx.old_groups[prio], + false, true); + } else { + /* No switch to protected, just pick any idle group according + * to priority + */ + for (prio =3D PANTHOR_CSG_PRIORITY_COUNT - 1; + prio >=3D 0 && !tick_ctx_is_full(sched, &ctx); prio--) { + /* Check the old_group queue first to avoid + * reprogramming the slots + */ + tick_ctx_pick_groups_from_list(sched, &ctx, + &ctx.old_groups[prio], + false, true); + tick_ctx_pick_groups_from_list(sched, &ctx, + &sched->groups.idle[prio], + false, false); + } } =20 tick_ctx_apply(sched, &ctx); @@ -3064,6 +3369,8 @@ void panthor_sched_pre_reset(struct panthor_device *p= tdev) cancel_work_sync(&sched->sync_upd_work); cancel_delayed_work_sync(&sched->tick_work); =20 + handle_protm_fault(ptdev); + panthor_sched_suspend(ptdev); =20 /* Stop all groups that might still accept jobs, so we don't get passed @@ -3089,6 +3396,11 @@ void panthor_sched_post_reset(struct panthor_device = *ptdev, bool reset_failed) =20 mutex_lock(&sched->reset.lock); =20 + if (sched->protm.active_group) { + group_put(sched->protm.active_group); + sched->protm.active_group =3D NULL; + } + list_for_each_entry_safe(group, group_tmp, &sched->reset.stopped_groups, = run_node) { /* Consider all previously running group as terminated if the * reset failed. diff --git a/drivers/gpu/drm/panthor/panthor_sched.h b/drivers/gpu/drm/pant= hor/panthor_sched.h index be7e1c8b4f563..1082c4d977c5e 100644 --- a/drivers/gpu/drm/panthor/panthor_sched.h +++ b/drivers/gpu/drm/panthor/panthor_sched.h @@ -52,4 +52,8 @@ void panthor_sched_report_fw_events(struct panthor_device= *ptdev, u32 events); =20 void panthor_fdinfo_gather_group_samples(struct drm_file *file); =20 +int panthor_sched_protm_block(struct panthor_device *ptdev); +int panthor_sched_protm_try_block(struct panthor_device *ptdev); +void panthor_sched_protm_unblock(struct panthor_device *ptdev); + #endif --=20 2.43.0 From nobody Fri Sep 25 14:31:21 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1EA6D39658D for ; Fri, 11 Sep 2026 11:40:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789126851; cv=none; b=N34/yD6JDB92CNqU7Jo7lqup54MEP7QwktcdqxVtrIRldlEI3au0BrwUZn4nj1UNDfRHLzkFywNkpRiXdVBspEyKad+jNSQZfvsNXuTBM7VtwA7VLpkF+HlYtnlSvNiXENvHgo8Fe1bOrlFHtyqkVd8wHYxA6Khz5nwjLwGKvPw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789126851; c=relaxed/simple; bh=pIY+WqEDy4/+Hp5LAAO3D5YEFvq2syVutRRW3FgFVSA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MhrPFc77dRiLH3B/Ew+RjKMGBzUEVRcQ3K+qX97A25fXYdGf8sJUmlWa6CF4DyaY1lrI3rG3qHVKaltji0IEPy0xlUpOMjvaA6ag4AIrJXBD0q/yglByP0CZEobnxM0ODihWaQgg17JB2MOtzm1oHcayWBJXeXNYmPOrg1k6UZM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=RTCBhqvM; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="RTCBhqvM" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DC9271655; Fri, 11 Sep 2026 04:40:44 -0700 (PDT) Received: from e120398-lin.trondheim.arm.com (e120398-lin.trondheim.arm.com [10.42.46.160]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 65A453F59E; Fri, 11 Sep 2026 04:40:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789126848; bh=pIY+WqEDy4/+Hp5LAAO3D5YEFvq2syVutRRW3FgFVSA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RTCBhqvMgW0QIKN6eARLpM8uEzT50dU8WWfyyipMzKLxY4hHo7iNiC6Ipjn3/oeWk aXuielZF6HlMiKBj+wYw2Cn+51LiKBzj3GLN2uTJwu2XQRYMI2xL/80fDzt146Y0WP h2NT55cE80y9qRrRkT8CoCloU1ZLXCaYt2HMSVx8= From: Ketil Johnsen To: Boris Brezillon , Steven Price , Liviu Dudau , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Daniel Almeida , Alice Ryhl Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Ketil Johnsen Subject: [PATCH v3 6/6] drm/panthor: Expose protected rendering features Date: Fri, 11 Sep 2026 13:40:14 +0200 Message-ID: <20260911114014.79139-7-ketil.johnsen@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260911114014.79139-1-ketil.johnsen@arm.com> References: <20260911114014.79139-1-ketil.johnsen@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Boris Brezillon Extensions to Panthor uAPI: - New IOCTL for user space to provide protected FW memory. - New query for checking protected rendering availability/status and requirements. - Extends group creation to allow user space to provide a protected suspend buffer. The Mali GPU FW needs some protected memory when executing in protected mode. This FW memory section is assigned a VA during device init. A user space process with the needed privileges (CAP_SYS_MODULE) must provide a suitable memory buffer before the Mali GPU is capable of executing in protected mode. Processes who want to execute in protected mode must also ensure they pass a protected suspend buffer during group creation. Added panthor_kernel_bo_import() to allow user provided buffers. Refactor panthor_kernel_bo_create() to allow shared code with the new import variant. Signed-off-by: Boris Brezillon Co-developed-by: Ketil Johnsen Signed-off-by: Ketil Johnsen --- v3: - Formating - Rebase changed - Keep local section_size var, needed for early out. - Access fatal_queues and protm_pending_queues as atomics. v2: - First version of this change in this patch set. --- drivers/gpu/drm/panthor/panthor_device.h | 3 + drivers/gpu/drm/panthor/panthor_drv.c | 23 +++- drivers/gpu/drm/panthor/panthor_fw.c | 159 +++++++++++++++++++---- drivers/gpu/drm/panthor/panthor_fw.h | 2 + drivers/gpu/drm/panthor/panthor_gem.c | 106 ++++++++++----- drivers/gpu/drm/panthor/panthor_gem.h | 7 +- drivers/gpu/drm/panthor/panthor_sched.c | 45 ++++++- include/uapi/drm/panthor_drm.h | 85 +++++++++++- 8 files changed, 356 insertions(+), 74 deletions(-) diff --git a/drivers/gpu/drm/panthor/panthor_device.h b/drivers/gpu/drm/pan= thor/panthor_device.h index f1b7f51f5ae1e..241550964b04c 100644 --- a/drivers/gpu/drm/panthor/panthor_device.h +++ b/drivers/gpu/drm/panthor/panthor_device.h @@ -366,6 +366,9 @@ struct panthor_device { =20 /** @protm_exit_count: Number of times exited protm. */ atomic64_t protm_exit_count; + + /** @info: Protected mode info. */ + struct drm_panthor_protm_info info; } protm; }; =20 diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/pantho= r/panthor_drv.c index 51eb77633602f..875c5ef3e2748 100644 --- a/drivers/gpu/drm/panthor/panthor_drv.c +++ b/drivers/gpu/drm/panthor/panthor_drv.c @@ -178,11 +178,13 @@ panthor_get_uobj_array(const struct drm_panthor_obj_a= rray *in, u32 min_stride, PANTHOR_UOBJ_DECL(struct drm_panthor_mmu_info, page_size_bitmap), \ PANTHOR_UOBJ_DECL(struct drm_panthor_timestamp_info, current_timestamp)= , \ PANTHOR_UOBJ_DECL(struct drm_panthor_group_priorities_info, pad), \ + PANTHOR_UOBJ_DECL(struct drm_panthor_protm_info, pad), \ PANTHOR_UOBJ_DECL(struct drm_panthor_sync_op, timeline_value), \ PANTHOR_UOBJ_DECL(struct drm_panthor_queue_submit, syncs), \ PANTHOR_UOBJ_DECL(struct drm_panthor_queue_create, ringbuf_size), \ PANTHOR_UOBJ_DECL(struct drm_panthor_vm_bind_op, syncs), \ - PANTHOR_UOBJ_DECL(struct drm_panthor_bo_sync_op, size)) + PANTHOR_UOBJ_DECL(struct drm_panthor_bo_sync_op, size), \ + PANTHOR_UOBJ_DECL(struct drm_panthor_protm_init, pad)) =20 /** * PANTHOR_UOBJ_SET() - Copy a kernel object to a user object. @@ -959,6 +961,10 @@ static int panthor_ioctl_dev_query(struct drm_device *= ddev, void *data, struct d args->size =3D sizeof(ptdev->mmu_info); return 0; =20 + case DRM_PANTHOR_DEV_QUERY_PROTM_INFO: + args->size =3D sizeof(ptdev->protm.info); + return 0; + default: return -EINVAL; } @@ -992,6 +998,9 @@ static int panthor_ioctl_dev_query(struct drm_device *d= dev, void *data, struct d case DRM_PANTHOR_DEV_QUERY_MMU_INFO: return PANTHOR_UOBJ_SET(args->pointer, args->size, ptdev->mmu_info); =20 + case DRM_PANTHOR_DEV_QUERY_PROTM_INFO: + return PANTHOR_UOBJ_SET(args->pointer, args->size, ptdev->protm.info); + default: return -EINVAL; } @@ -1589,6 +1598,12 @@ static int panthor_ioctl_bo_query_info(struct drm_de= vice *ddev, void *data, return 0; } =20 +static int panthor_ioctl_protm_init(struct drm_device *ddev, void *data, + struct drm_file *file) +{ + return panthor_fw_protm_init(file, data); +} + static int panthor_open(struct drm_device *ddev, struct drm_file *file) { @@ -1665,6 +1680,7 @@ static const struct drm_ioctl_desc panthor_drm_driver= _ioctls[] =3D { PANTHOR_IOCTL(SET_USER_MMIO_OFFSET, set_user_mmio_offset, DRM_RENDER_ALLO= W), PANTHOR_IOCTL(BO_SYNC, bo_sync, DRM_RENDER_ALLOW), PANTHOR_IOCTL(BO_QUERY_INFO, bo_query_info, DRM_RENDER_ALLOW), + PANTHOR_IOCTL(PROTM_INIT, protm_init, DRM_RENDER_ALLOW), }; =20 static int panthor_mmap(struct file *filp, struct vm_area_struct *vma) @@ -1785,6 +1801,9 @@ static void panthor_debugfs_init(struct drm_minor *mi= nor) * - 1.8 - extends DEV_QUERY_TIMESTAMP_INFO with flags * - 1.9 - adds DRM_PANTHOR_DEV_QUERY_MMU_INFO query * - adds DRM_PANTHOR_VM_BIND_OP_MAP_SPARSE flag + * - 1.10 - adds DRM_IOCTL_PANTHOR_PROTM_INIT ioctl + * - adds DRM_PANTHOR_DEV_QUERY_PROTM_INFO query + * - adds drm_panthor_group_create::protected_suspend_bo_handle */ static const struct drm_driver panthor_drm_driver =3D { .driver_features =3D DRIVER_RENDER | DRIVER_GEM | DRIVER_SYNCOBJ | @@ -1798,7 +1817,7 @@ static const struct drm_driver panthor_drm_driver =3D= { .name =3D "panthor", .desc =3D "Panthor DRM driver", .major =3D 1, - .minor =3D 9, + .minor =3D 10, =20 .gem_prime_import_sg_table =3D panthor_gem_prime_import_sg_table, .gem_prime_import =3D panthor_gem_prime_import, diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor= /panthor_fw.c index 96770ce34da84..4b44baf82a037 100644 --- a/drivers/gpu/drm/panthor/panthor_fw.c +++ b/drivers/gpu/drm/panthor/panthor_fw.c @@ -13,8 +13,10 @@ #include #include #include +#include =20 #include +#include #include #include =20 @@ -198,6 +200,12 @@ struct panthor_fw_section { /** @size: Size of @buf in bytes. */ size_t size; } data; + + /** @size: Section size. */ + size_t size; + + /** @va: Section VA. */ + u32 va; }; =20 #define CSF_MCU_SHARED_REGION_START 0x04000000ULL @@ -246,6 +254,9 @@ struct panthor_fw { /** @shared_section: The section containing the FW interfaces. */ struct panthor_fw_section *shared_section; =20 + /** @protm_section: The protected mode section. */ + struct panthor_fw_section *protm_section; + /** @iface: FW interfaces. */ struct panthor_fw_iface iface; =20 @@ -255,6 +266,9 @@ struct panthor_fw { struct delayed_work ping_work; } watchdog; =20 + /** @protm_init_lock: Used to serialize protm initialization. */ + struct mutex protm_init_lock; + /** * @req_waitqueue: FW request waitqueue. * @@ -543,6 +557,31 @@ panthor_fw_alloc_suspend_buf_mem(struct panthor_device= *ptdev, size_t size) "FW suspend buffer"); } =20 +static u32 section_vm_map_flags(const struct panthor_fw_section *section) +{ + u32 cache_mode =3D section->flags & + CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_MASK; + u32 vm_map_flags =3D 0; + + if (!(section->flags & CSF_FW_BINARY_IFACE_ENTRY_WR)) + vm_map_flags |=3D DRM_PANTHOR_VM_BIND_OP_MAP_READONLY; + + if (!(section->flags & CSF_FW_BINARY_IFACE_ENTRY_EX)) + vm_map_flags |=3D DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC; + + /* TODO: CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_*_COHERENT are mapped to + * non-cacheable for now. We might want to introduce a new + * IOMMU_xxx flag (or abuse IOMMU_MMIO, which maps to device + * memory and is currently not used by our driver) for + * AS_MEMATTR_AARCH64_SHARED memory, so we can take benefit + * of IO-coherent systems. + */ + if (cache_mode !=3D CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_CACHED) + vm_map_flags |=3D DRM_PANTHOR_VM_BIND_OP_MAP_UNCACHED; + + return vm_map_flags; +} + static int panthor_fw_load_section_entry(struct panthor_device *ptdev, const struct firmware *fw, struct panthor_fw_binary_iter *iter, @@ -590,12 +629,6 @@ static int panthor_fw_load_section_entry(struct pantho= r_device *ptdev, return -EINVAL; } =20 - if (hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_PROT) { - drm_warn(&ptdev->base, - "Firmware protected mode entry is not supported, ignoring"); - return 0; - } - if (hdr.va.start =3D=3D CSF_MCU_SHARED_REGION_START && !(hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_SHARED)) { drm_err(&ptdev->base, @@ -644,35 +677,36 @@ static int panthor_fw_load_section_entry(struct panth= or_device *ptdev, section->name =3D name; } =20 - if (section_size) { - u32 cache_mode =3D hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_MASK; - u32 vm_map_flags =3D 0; - u64 va =3D hdr.va.start; + section->size =3D section_size; + section->va =3D hdr.va.start; =20 - if (!(hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_WR)) - vm_map_flags |=3D DRM_PANTHOR_VM_BIND_OP_MAP_READONLY; + if (hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_PROT) { + if (ptdev->fw->protm_section) { + drm_err(&ptdev->base, + "Only one protected section supported\n"); + return -EINVAL; + } =20 - if (!(hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_EX)) - vm_map_flags |=3D DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC; + ptdev->protm.info.fw_protected_sections_size =3D + ALIGN(section->size, vm_pgsz); + ptdev->fw->protm_section =3D section; + } =20 - /* TODO: CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_*_COHERENT are mapped to - * non-cacheable for now. We might want to introduce a new - * IOMMU_xxx flag (or abuse IOMMU_MMIO, which maps to device - * memory and is currently not used by our driver) for - * AS_MEMATTR_AARCH64_SHARED memory, so we can take benefit - * of IO-coherent systems. - */ - if (cache_mode !=3D CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_CACHED) - vm_map_flags |=3D DRM_PANTHOR_VM_BIND_OP_MAP_UNCACHED; + /* Defer the section->mem creation if this is a protected entry. + * This will be populated when DRM_IOCTL_PANTHOR_PROTM_INIT is called. + */ + if (section->size && !(hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_PROT)) { + u32 vm_map_flags =3D section_vm_map_flags(section); =20 - section->mem =3D panthor_kernel_bo_create(ptdev, panthor_fw_vm(ptdev), - section_size, - DRM_PANTHOR_BO_NO_MMAP, - vm_map_flags, va, "FW section"); + section->mem =3D panthor_kernel_bo_create( + ptdev, panthor_fw_vm(ptdev), section->size, + DRM_PANTHOR_BO_NO_MMAP, vm_map_flags, section->va, + "FW section"); if (IS_ERR(section->mem)) return PTR_ERR(section->mem); =20 - if (drm_WARN_ON(&ptdev->base, section->mem->va_node.start !=3D hdr.va.st= art)) + if (drm_WARN_ON(&ptdev->base, + section->mem->va_node.start !=3D section->va)) return -EINVAL; =20 if (section->flags & CSF_FW_BINARY_IFACE_ENTRY_SHARED) { @@ -968,6 +1002,11 @@ static int panthor_init_csg_iface(struct panthor_devi= ce *ptdev, return -EINVAL; } =20 + if (!csg_idx) { + ptdev->protm.info.group_protected_suspend_buf_size =3D + csg_iface->control->protm_suspend_size; + } + if (csg_idx > 0) { struct panthor_fw_csg_iface *first_csg_iface =3D panthor_fw_get_csg_iface(ptdev, 0); @@ -1566,6 +1605,66 @@ int panthor_fw_protm_exit(struct panthor_device *ptd= ev, u32 timeout_ms) return ret; } =20 +int panthor_fw_protm_init(struct drm_file *file, + struct drm_panthor_protm_init *args) +{ + struct panthor_file *pfile =3D file->driver_priv; + struct panthor_device *ptdev =3D pfile->ptdev; + struct panthor_fw_section *protm_section =3D ptdev->fw->protm_section; + struct drm_gem_object *obj; + u32 vm_map_flags; + int cookie, ret =3D 0; + + if (!capable(CAP_SYS_MODULE)) + return -EPERM; + + if (args->pad) + return -EINVAL; + + if (!protm_section || !protm_section->size) + return -EINVAL; + + guard(mutex)(&ptdev->fw->protm_init_lock); + + if (ptdev->protm.info.state & DRM_PANTHOR_PROTM_INITIALIZED) + return 0; + + if (!drm_dev_enter(&ptdev->base, &cookie)) + return -ENODEV; + + obj =3D drm_gem_object_lookup(file, + args->fw_protected_sections_bo_handle); + if (!obj) { + ret =3D -ENOENT; + goto out_dev_exit; + } + + if (obj->size < ptdev->protm.info.fw_protected_sections_size) { + ret =3D -EINVAL; + goto out_gem_put; + } + + vm_map_flags =3D section_vm_map_flags(protm_section); + + protm_section->mem =3D panthor_kernel_bo_import( + ptdev, panthor_fw_vm(ptdev), to_panthor_bo(obj), vm_map_flags, + protm_section->va, protm_section->size); + if (IS_ERR(protm_section->mem)) { + ret =3D PTR_ERR(protm_section->mem); + protm_section->mem =3D NULL; + goto out_gem_put; + } + + ptdev->protm.info.state |=3D DRM_PANTHOR_PROTM_INITIALIZED; + +out_gem_put: + drm_gem_object_put(obj); + +out_dev_exit: + drm_dev_exit(cookie); + return ret; +} + /** * panthor_fw_init() - Initialize FW related data. * @ptdev: Device. @@ -1587,6 +1686,10 @@ int panthor_fw_init(struct panthor_device *ptdev) INIT_LIST_HEAD(&fw->sections); INIT_DELAYED_WORK(&fw->watchdog.ping_work, panthor_fw_ping_work); =20 + ret =3D drmm_mutex_init(&ptdev->base, &fw->protm_init_lock); + if (ret) + return ret; + irq =3D platform_get_irq_byname(to_platform_device(ptdev->base.dev), "job= "); if (irq <=3D 0) return -ENODEV; diff --git a/drivers/gpu/drm/panthor/panthor_fw.h b/drivers/gpu/drm/panthor= /panthor_fw.h index 4eda8f8e714c1..34bc9dc82314c 100644 --- a/drivers/gpu/drm/panthor/panthor_fw.h +++ b/drivers/gpu/drm/panthor/panthor_fw.h @@ -529,6 +529,8 @@ static inline int panthor_fw_resume(struct panthor_devi= ce *ptdev) int panthor_fw_init(struct panthor_device *ptdev); void panthor_fw_unplug(struct panthor_device *ptdev); =20 +int panthor_fw_protm_init(struct drm_file *file, + struct drm_panthor_protm_init *args); int panthor_fw_protm_enter(struct panthor_device *ptdev); int panthor_fw_protm_exit(struct panthor_device *ptdev, u32 timeout_ms); int panthor_fw_protm_exit_wait(struct panthor_device *ptdev, u32 timeout_m= s); diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/pantho= r/panthor_gem.c index c07a44057e426..9f9f68582ccf1 100644 --- a/drivers/gpu/drm/panthor/panthor_gem.c +++ b/drivers/gpu/drm/panthor/panthor_gem.c @@ -74,14 +74,16 @@ static void panthor_gem_debugfs_bo_rm(struct panthor_ge= m_object *bo) mutex_unlock(&ptdev->gems.lock); } =20 -static void panthor_gem_debugfs_set_usage_flags(struct panthor_gem_object = *bo, u32 usage_flags) +static void panthor_gem_debugfs_add_usage_flags(struct panthor_gem_object = *bo, + u32 usage_flags) { - bo->debugfs.flags =3D usage_flags; - panthor_gem_debugfs_bo_add(bo); + atomic_or(usage_flags, &bo->debugfs.flags); } #else +static void panthor_gem_debugfs_bo_add(struct panthor_gem_object *bo) {} static void panthor_gem_debugfs_bo_rm(struct panthor_gem_object *bo) {} -static void panthor_gem_debugfs_set_usage_flags(struct panthor_gem_object = *bo, u32 usage_flags) {} +static void panthor_gem_debugfs_add_usage_flags(struct panthor_gem_object = *bo, + u32 usage_flags) {} static void panthor_gem_debugfs_bo_init(struct panthor_gem_object *bo) {} #endif =20 @@ -1031,7 +1033,7 @@ panthor_gem_create(struct drm_device *dev, size_t siz= e, uint32_t flags, bo->base.resv =3D bo->exclusive_vm_root_gem->resv; } =20 - panthor_gem_debugfs_set_usage_flags(bo, usage_flags); + panthor_gem_debugfs_bo_add(bo); return bo; =20 err_put: @@ -1257,7 +1259,9 @@ void panthor_kernel_bo_destroy(struct panthor_kernel_= bo *bo) panthor_kernel_bo_vunmap(bo); =20 drm_WARN_ON(bo->obj->dev, - to_panthor_bo(bo->obj)->exclusive_vm_root_gem !=3D panthor_vm_root_g= em(vm)); + to_panthor_bo(bo->obj)->exclusive_vm_root_gem && + (to_panthor_bo(bo->obj)->exclusive_vm_root_gem !=3D + panthor_vm_root_gem(vm))); panthor_vm_unmap_range(vm, bo->va_node.start, bo->va_node.size); panthor_vm_free_va(vm, &bo->va_node); if (vm =3D=3D panthor_fw_vm(ptdev)) @@ -1268,46 +1272,32 @@ void panthor_kernel_bo_destroy(struct panthor_kerne= l_bo *bo) } =20 /** - * panthor_kernel_bo_create() - Create and map a GEM object to a VM + * panthor_kernel_bo_import() - Create a kernel BO from an existing GEM ob= ject * @ptdev: Device. * @vm: VM to map the GEM to. - * @size: Size of the buffer object. - * @bo_flags: Combination of drm_panthor_bo_flags flags. + * @bo: BO to use for our kernel BO. * @vm_map_flags: Combination of drm_panthor_vm_bind_op_flags (only those * that are related to map operations). * @gpu_va: GPU address assigned when mapping to the VM. * If gpu_va =3D=3D PANTHOR_VM_KERNEL_AUTO_VA, the virtual address will be * automatically allocated. - * @name: Descriptive label of the BO's contents + * @vm_map_size: Size of the BO to map to the VM. * * Return: A valid pointer in case of success, an ERR_PTR() otherwise. */ struct panthor_kernel_bo * -panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *= vm, - size_t size, u32 bo_flags, u32 vm_map_flags, - u64 gpu_va, const char *name) +panthor_kernel_bo_import(struct panthor_device *ptdev, struct panthor_vm *= vm, + struct panthor_gem_object *bo, u32 vm_map_flags, + u64 gpu_va, u32 vm_map_size) { struct panthor_kernel_bo *kbo; - struct panthor_gem_object *bo; - u32 debug_flags =3D PANTHOR_DEBUGFS_GEM_USAGE_FLAG_KERNEL; int ret; =20 - if (drm_WARN_ON(&ptdev->base, !vm)) - return ERR_PTR(-EINVAL); - kbo =3D kzalloc_obj(*kbo); if (!kbo) return ERR_PTR(-ENOMEM); =20 - if (vm =3D=3D panthor_fw_vm(ptdev)) - debug_flags |=3D PANTHOR_DEBUGFS_GEM_USAGE_FLAG_FW_MAPPED; - - bo =3D panthor_gem_create(&ptdev->base, size, bo_flags, vm, debug_flags); - if (IS_ERR(bo)) { - ret =3D PTR_ERR(bo); - goto err_free_kbo; - } - + drm_gem_object_get(&bo->base); kbo->obj =3D &bo->base; =20 if (vm =3D=3D panthor_fw_vm(ptdev)) { @@ -1316,24 +1306,27 @@ panthor_kernel_bo_create(struct panthor_device *ptd= ev, struct panthor_vm *vm, goto err_put_obj; } =20 - panthor_gem_kernel_bo_set_label(kbo, name); - /* The system and GPU MMU page size might differ, which becomes a * problem for FW sections that need to be mapped at explicit address * since our PAGE_SIZE alignment might cover a VA range that's * expected to be used for another section. * Make sure we never map more than we need. */ - size =3D ALIGN(size, panthor_vm_page_size(vm)); - ret =3D panthor_vm_alloc_va(vm, gpu_va, size, &kbo->va_node); + vm_map_size =3D ALIGN(vm_map_size, panthor_vm_page_size(vm)); + ret =3D panthor_vm_alloc_va(vm, gpu_va, vm_map_size, &kbo->va_node); if (ret) goto err_unpin; =20 - ret =3D panthor_vm_map_bo_range(vm, bo, 0, size, kbo->va_node.start, vm_m= ap_flags); + ret =3D panthor_vm_map_bo_range(vm, bo, 0, vm_map_size, + kbo->va_node.start, vm_map_flags); if (ret) goto err_free_va; =20 kbo->vm =3D panthor_vm_get(vm); + if (vm =3D=3D panthor_fw_vm(ptdev)) + panthor_gem_debugfs_add_usage_flags( + bo, PANTHOR_DEBUGFS_GEM_USAGE_FLAG_FW_MAPPED); + return kbo; =20 err_free_va: @@ -1345,12 +1338,55 @@ panthor_kernel_bo_create(struct panthor_device *ptd= ev, struct panthor_vm *vm, =20 err_put_obj: drm_gem_object_put(&bo->base); - -err_free_kbo: kfree(kbo); return ERR_PTR(ret); } =20 +/** + * panthor_kernel_bo_create() - Create and map a GEM object to a VM + * @ptdev: Device. + * @vm: VM to map the GEM to. + * @size: Size of the buffer object. + * @bo_flags: Combination of drm_panthor_bo_flags flags. + * @vm_map_flags: Combination of drm_panthor_vm_bind_op_flags (only those + * that are related to map operations). + * @gpu_va: GPU address assigned when mapping to the VM. + * If gpu_va =3D=3D PANTHOR_VM_KERNEL_AUTO_VA, the virtual address will be + * automatically allocated. + * @name: Descriptive label of the BO's contents + * + * Return: A valid pointer in case of success, an ERR_PTR() otherwise. + */ +struct panthor_kernel_bo * +panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *= vm, + size_t size, u32 bo_flags, u32 vm_map_flags, + u64 gpu_va, const char *name) +{ + struct panthor_kernel_bo *kbo; + struct panthor_gem_object *bo; + + if (drm_WARN_ON(&ptdev->base, !vm)) + return ERR_PTR(-EINVAL); + + bo =3D panthor_gem_create(&ptdev->base, size, bo_flags, vm, 0); + if (IS_ERR(bo)) + return ERR_CAST(bo); + + kbo =3D panthor_kernel_bo_import(ptdev, vm, bo, vm_map_flags, gpu_va, + size); + if (!IS_ERR(kbo)) { + panthor_gem_debugfs_add_usage_flags( + bo, PANTHOR_DEBUGFS_GEM_USAGE_FLAG_KERNEL); + panthor_gem_kernel_bo_set_label(kbo, name); + } + + /* panthor_kernel_bo_import() acquires a GEM ref if the import succeeds, = so + * we can release it unconditionally here. + */ + drm_gem_object_put(&bo->base); + return kbo; +} + /** * panthor_dummy_bo_create() - Create a Panthor BO meant to back sparse bi= ndings. * @ptdev: Device. @@ -1644,9 +1680,9 @@ static void panthor_gem_debugfs_bo_print(struct panth= or_gem_object *bo, enum panthor_gem_reclaim_state reclaim_state =3D bo->reclaim_state; unsigned int refcount =3D kref_read(&bo->base.refcount); int reclaimed_count =3D atomic_read(&bo->reclaimed_count); + u32 gem_usage_flags =3D atomic_read(&bo->debugfs.flags); char creator_info[32] =3D {}; size_t resident_size; - u32 gem_usage_flags =3D bo->debugfs.flags; u32 gem_state_flags =3D 0; =20 /* Skip BOs being destroyed. */ diff --git a/drivers/gpu/drm/panthor/panthor_gem.h b/drivers/gpu/drm/pantho= r/panthor_gem.h index 5ae37d0d3646f..7e88f5dcbff54 100644 --- a/drivers/gpu/drm/panthor/panthor_gem.h +++ b/drivers/gpu/drm/panthor/panthor_gem.h @@ -62,7 +62,7 @@ struct panthor_gem_debugfs { } creator; =20 /** @flags: Combination of panthor_debugfs_gem_usage_flags flags */ - u32 flags; + atomic_t flags; }; =20 /** @@ -318,6 +318,11 @@ panthor_kernel_bo_vunmap(struct panthor_kernel_bo *bo) } } =20 +struct panthor_kernel_bo * +panthor_kernel_bo_import(struct panthor_device *ptdev, struct panthor_vm *= vm, + struct panthor_gem_object *bo, + u32 vm_map_flags, u64 gpu_va, u32 vm_map_size); + struct panthor_kernel_bo * panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *= vm, size_t size, u32 bo_flags, u32 vm_map_flags, diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/pant= hor/panthor_sched.c index 1fe77e5c41995..d73fc2f6633a6 100644 --- a/drivers/gpu/drm/panthor/panthor_sched.c +++ b/drivers/gpu/drm/panthor/panthor_sched.c @@ -1429,10 +1429,15 @@ cs_slot_process_protm_pending_event_locked(struct p= anthor_device *ptdev, if (!group) return; =20 - /* Do not allow user space work to switch into protected mode, as we - * do not fully support this quite yet. + /* Do not allow user space work to switch into protected mode if we + * do not support protected mode on this device. + * User space should query (and init) this support before attempting + * to use such GPU instructions. */ - atomic_or(BIT(cs_id), &group->fatal_queues); + if (!(ptdev->protm.info.state & DRM_PANTHOR_PROTM_INITIALIZED)) + atomic_or(BIT(cs_id), &group->fatal_queues); + else + atomic_or(BIT(cs_id), &group->protm_pending_queues); =20 sched_queue_delayed_work(sched, tick, 0); } @@ -3963,6 +3968,7 @@ static void add_group_kbo_sizes(struct panthor_device= *ptdev, } =20 #define MAX_GROUPS_PER_POOL 128 +#define GROUP_CREATE_FLAGS DRM_PANTHOR_GROUP_CREATE_PROTECTED =20 int panthor_group_create(struct drm_file *file, const struct drm_panthor_group_create *group_args, @@ -3977,9 +3983,6 @@ int panthor_group_create(struct drm_file *file, u32 gid, i, suspend_size; int ret; =20 - if (group_args->pad) - return -EINVAL; - if (group_args->priority >=3D PANTHOR_CSG_PRIORITY_COUNT) return -EINVAL; =20 @@ -4030,6 +4033,36 @@ int panthor_group_create(struct drm_file *file, goto err_put_group; } =20 + if (group_args->protected_suspend_bo_handle) { + struct drm_gem_object *obj; + + obj =3D drm_gem_object_lookup(file, group_args->protected_suspend_bo_han= dle); + if (!obj) { + ret =3D -ENOENT; + goto err_put_group; + } + + if (obj->size < ptdev->protm.info.group_protected_suspend_buf_size) { + drm_gem_object_put(obj); + ret =3D -EINVAL; + goto err_put_group; + } + + suspend_size =3D csg_iface->control->protm_suspend_size; + group->protm_suspend_buf =3D + panthor_kernel_bo_import(ptdev, panthor_fw_vm(ptdev), + to_panthor_bo(obj), + DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC, + PANTHOR_VM_KERNEL_AUTO_VA, + suspend_size); + drm_gem_object_put(obj); + if (IS_ERR(group->protm_suspend_buf)) { + ret =3D PTR_ERR(group->protm_suspend_buf); + group->protm_suspend_buf =3D NULL; + goto err_put_group; + } + } + group->syncobjs =3D panthor_kernel_bo_create(ptdev, group->vm, group_args->queues.count * sizeof(struct panthor_syncobj_64b), diff --git a/include/uapi/drm/panthor_drm.h b/include/uapi/drm/panthor_drm.h index a2ff0f4ec6915..a0ed16041e178 100644 --- a/include/uapi/drm/panthor_drm.h +++ b/include/uapi/drm/panthor_drm.h @@ -154,6 +154,11 @@ enum drm_panthor_ioctl_id { * This is useful for imported BOs. */ DRM_PANTHOR_BO_QUERY_INFO, + + /** + * @DRM_PANTHOR_PROTM_INIT: Device-wide initialize of protected mode. + */ + DRM_PANTHOR_PROTM_INIT, }; =20 /** @@ -256,6 +261,11 @@ enum drm_panthor_dev_query_type { =20 /** @DRM_PANTHOR_DEV_QUERY_MMU_INFO: Query MMU information. */ DRM_PANTHOR_DEV_QUERY_MMU_INFO, + + /** + * @DRM_PANTHOR_DEV_QUERY_PROTM_INFO: Query supported protected rendering= information. + */ + DRM_PANTHOR_DEV_QUERY_PROTM_INFO, }; =20 /** @@ -517,6 +527,51 @@ struct drm_panthor_group_priorities_info { __u8 pad[3]; }; =20 +/** + * enum drm_panthor_protm_state_flags - Describes the state of the protect= ed mode feature. + * + * List of GPU states which can be used by the GPU to access protected mem= ory. + */ +enum drm_panthor_protm_state_flags { + /** + * @DRM_PANTHOR_PROTM_INITIALIZED: Device-wide initialization of the + * protected mode feature is done. + */ + DRM_PANTHOR_PROTM_INITIALIZED =3D 1 << 0, +}; + +/** + * struct drm_panthor_protm_info - Protected mode info. + * + * Structure grouping all queryable information relating to protected mode. + */ +struct drm_panthor_protm_info { + /** + * @state: Combination of enum drm_panthor_protm_state_flags flags. + */ + __u32 state; + + /** + * @fw_protected_sections_size: Size of all the protected FW sections. + * + * Size of the protected buffer to pass through + * DRM_IOCTL_PANTHOR_PROTM_INIT. + */ + __u32 fw_protected_sections_size; + + /** + * @group_protected_suspend_buf_size: Size of the group suspend buffer. + * + * This must be used to allocate a protected BO that's big enough to use + * as a protected suspend buffer when a group supports protected + * rendering. + */ + __u32 group_protected_suspend_buf_size; + + /** @pad: MBZ. */ + __u32 pad; +}; + /** * struct drm_panthor_dev_query - Arguments passed to DRM_PANTHOR_IOCTL_DE= V_QUERY */ @@ -901,8 +956,14 @@ struct drm_panthor_group_create { /** @priority: Group priority (see enum drm_panthor_group_priority). */ __u8 priority; =20 - /** @pad: Padding field, MBZ. */ - __u32 pad; + /** + * @protected_suspend_bo_handle: BO to use as a protected suspend buffer. + * + * This BO must have been allocated from a protected DMA-BUF heap and + * imported in panthor. It's size must be at least + * drm_panthor_protm_info::group_protected_suspend_buf_size. + */ + __u32 protected_suspend_bo_handle; =20 /** * @compute_core_mask: Mask encoding cores that can be used for compute j= obs. @@ -1270,6 +1331,24 @@ struct drm_panthor_bo_query_info { __u32 pad; }; =20 +/** + * struct drm_panthor_protm_init - Protected mode initialization arguments. + */ +struct drm_panthor_protm_init { + /** + * @fw_protected_sections_bo_handle: Handle of the BO to use for the FW p= rotected + * sections. + * + * This BO must have been allocated from a protected DMA-BUF heap and + * imported in panthor. It's size must be at least + * drm_panthor_protm_info::fw_protected_sections_size. + */ + __u32 fw_protected_sections_bo_handle; + + /** @pad: MBZ. */ + __u32 pad; +}; + /** * DRM_IOCTL_PANTHOR() - Build a Panthor IOCTL number * @__access: Access type. Must be R, W or RW. @@ -1320,6 +1399,8 @@ enum { DRM_IOCTL_PANTHOR(WR, BO_SYNC, bo_sync), DRM_IOCTL_PANTHOR_BO_QUERY_INFO =3D DRM_IOCTL_PANTHOR(WR, BO_QUERY_INFO, bo_query_info), + DRM_IOCTL_PANTHOR_PROTM_INIT =3D + DRM_IOCTL_PANTHOR(WR, PROTM_INIT, protm_init), }; =20 #if defined(__cplusplus) --=20 2.43.0