Host1x/VIC support on Tegra264
Subsystems (6)
Mikko Perttunen
maintainerv2 cover Host1x/VIC support on Tegra264
Hello everyone,
this series adds support for Host1x and VIC on Tegra264 SoCs. The Host1x side is not very interesting, just adding the usual register definitions and other information. One thing of note is that multimedia engines apart from VIC have moved away from Host1x on this generation.
On the VIC side, there is a bit more of a change, as the VIC Falcon is now RISC-V based. Unlike NVDEC, VIC is still "externally booted", so the boot sequence is very similar to before.
host1x uapi-test[1] has been updated for Tegra264. Necessary headers for constructing VIC jobs have been added to open-gpu-doc[2].
Patches 1 and 2 add new compatible strings to Host1x and VIC device tree bindings.
Patch 3 fixes the context device device tree parsing code to handle iommu-map entries with length more than 1.
Patch 4 adds Tegra264 support to the Host1x driver.
Patches 5 and 6 add Tegra264 support to the VIC driver.
Patch 7 adds Host1x and VIC nodes to the Tegra264 device tree.
Thank you,
Mikko
[1] https://github.com/cyndis/uapi-test
[2] https://github.com/NVIDIA/open-gpu-doc/blob/master/classes/video/clceb6.h
https://github.com/NVIDIA/open-gpu-doc/blob/master/classes/video/vic_ceb6_types.h
---
Changes in v2:
- Updated dt-bindings changes to be chip-specific
- Link to v1: https://patch.msgid.link/[email protected]
---
Mikko Perttunen (6):
dt-bindings: display: tegra: Changes to support Tegra264
dt-bindings: display: tegra: Add Tegra264 compatible for VIC
gpu: host1x: Correctly parse linear ranges of context devices drm/tegra: falcon: Add support for RISC-V external boot drm/tegra: vic: Add Tegra264 support
arm64: tegra: Add Host1x and VIC on Tegra264
Santosh BS (1):
gpu: host1x: Add Tegra264 support
.../display/tegra/nvidia,tegra124-vic.yaml | 1 + .../display/tegra/nvidia,tegra20-host1x.yaml | 20 ++- arch/arm64/boot/dts/nvidia/tegra264.dtsi | 63 +++++++ drivers/gpu/drm/tegra/drm.c | 1 + drivers/gpu/drm/tegra/falcon.c | 66 ++++++-- drivers/gpu/drm/tegra/falcon.h | 23 +++ drivers/gpu/drm/tegra/vic.c | 95 ++++++++--- drivers/gpu/drm/tegra/vic.h | 9 +- drivers/gpu/host1x/Makefile | 3 +- drivers/gpu/host1x/context.c | 13 +- drivers/gpu/host1x/dev.c | 41 +++++ drivers/gpu/host1x/hw/cdma_hw.c | 12 +- drivers/gpu/host1x/hw/host1x10.c | 33 ++++ drivers/gpu/host1x/hw/host1x10.h | 15 ++ drivers/gpu/host1x/hw/host1x10_hardware.h | 21 +++ drivers/gpu/host1x/hw/hw_host1x10_common.h | 6 + drivers/gpu/host1x/hw/hw_host1x10_hypervisor.h | 10 ++ drivers/gpu/host1x/hw/hw_host1x10_uclass.h | 181 +++++++++++++++++++++ drivers/gpu/host1x/hw/hw_host1x10_vm.h | 36 ++++ 19 files changed, 601 insertions(+), 48 deletions(-)
---
base-commit: 4549871118cf616eecdd2d939f78e3b9e1dddc48
change-id: 20260313-t264-host1x-c97171fdde77
Mikko Perttunen
maintainerPATCH v2 1/7 dt-bindings: display: tegra: Changes to support Tegra264
Add nvidia,tegra264-host1x compatible string. The Tegra264 host1x is similar to Tegra234, but with a different set of engines and layout.
The engine register range is no longer continuous, so two range entries are also needed.
--- .../display/tegra/nvidia,tegra20-host1x.yaml | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/display/tegra/nvidia,tegra20-host1x.yaml +19 -1
@@ -25,6 +25,7 @@ properties: - nvidia,tegra186-host1x - nvidia,tegra194-host1x - nvidia,tegra234-host1x + - nvidia,tegra264-host1x - items: - const: nvidia,tegra132-host1x
@@ -57,7 +58,8 @@ properties: enum: [1, 2] ranges: - maxItems: 1 + minItems: 1 + maxItems: 2 clocks: description: Must contain one entry, for the module clock. See
@@ -192,6 +194,7 @@ allOf: contains: enum: - nvidia,tegra234-host1x + - nvidia,tegra264-host1x then: properties: reg-names:
@@ -239,6 +242,21 @@ allOf: required: - reg-names + - if: + properties: + compatible: + contains: + enum: + - nvidia,tegra264-host1x + then: + properties: + ranges: + minItems: 2 + maxItems: 2 + else: + properties: + ranges: + maxItems: 1 examples: - |
Signature · 1 line
2.53.0
Re: [PATCH v2 1/7] dt-bindings: display: tegra: Changes to support Tegra264
Quoted 11 lines · Mikko Perttunen
Add nvidia,tegra264-host1x compatible string. The Tegra264 host1x is similar to Tegra234, but with a different set of engines and layout.
The engine register range is no longer continuous, so two range entries are also needed.
Signed-off-by Mikko Perttunen <[email protected]>--- .../display/tegra/nvidia,tegra20-host1x.yaml | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
Mikko Perttunen
maintainerPATCH v2 2/7 dt-bindings: display: tegra: Add Tegra264 compatible for VIC
In reply to Mikko PerttunenAdd nvidia,tegra264-vic compatible string for the VIC on Tegra264. VIC on Tegra264 has a new RISC-V based microcontroller and improved image processing capabilities.
--- Documentation/devicetree/bindings/display/tegra/nvidia,tegra124-vic.yaml | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/display/tegra/nvidia,tegra124-vic.yaml +1 -0
@@ -22,6 +22,7 @@ properties: - nvidia,tegra186-vic - nvidia,tegra194-vic - nvidia,tegra234-vic + - nvidia,tegra264-vic - items: - const: nvidia,tegra132-vic
Signature · 1 line
2.53.0
Mikko Perttunen
maintainerPATCH v2 3/7 gpu: host1x: Correctly parse linear ranges of context devices
In reply to Mikko PerttunenThe previous parsing of the iommu-map property assumed each context device has its own one-length entry in the device tree. This has worked fine so far, but on Tegra264 larger numbers of context devices are usable, so it's better to support linear ranges as well.
--- drivers/gpu/host1x/context.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/gpu/host1x/context.c +11 -2
@@ -23,7 +23,7 @@ int host1x_memory_context_list_init(struct host1x *host1x)struct host1x_memory_context_list *cdl = &host1x->context_list;struct device_node *node = host1x->dev->of_node;struct host1x_memory_context *ctx; -unsigned int i; +unsigned int devs, i;int err; cdl->devs =NULL ;
@@ -34,7 +34,16 @@ int host1x_memory_context_list_init(struct host1x *host1x)if (err <0 )return 0 ; - cdl->len = err /4 ; + devs =0 ; + +for (i =0 ; i < err /4 ; i++) { +u32 length; + +of_property_read_u32_index (node,"iommu-map" , i *4 +3 , &length); + devs += length; + } + + cdl->len = devs; cdl->devs =kzalloc_objs (*cdl->devs, cdl->len);if (!cdl->devs)return -ENOMEM ;
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v2 3/7] gpu: host1x: Correctly parse linear ranges of context devices
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The struct device objects embedded in host1x_memory_context are allocated as a contiguous array and freed synchronously via kfree(cdl->devs) on error paths and teardown, violating device lifecycle rules. --
commit a5e361c6f75f05af608f6d934522d035e2ecb31b
Author: Mikko Perttunen <[email protected]>
gpu: host1x: Correctly parse linear ranges of context devices
The previous parsing of the iommu-map property assumed each context device has its own one-length entry in the device tree. This patch updates the logic to support linear ranges by properly summing the lengths.
Quoted 4 lines
drivers/gpu/host1x/context.c +0
-0
[ ... ]
Quoted 6 lines
drivers/gpu/host1x/context.c +1
-1@@ -34,7 +34,16 @@ int host1x_memory_context_list_init(struct host1x *host1x)if (err <0 )return 0 ; - cdl->len = err /4 ; + devs =0 ;
drivers/gpu/host1x/context.c int host1x_memory_context_list_init(struct host1x *host1x) · line 47
Quoted 10 lines
drivers/gpu/host1x/context.c +9
-0+ +for (i =0 ; i < err /4 ; i++) { +u32 length; + +of_property_read_u32_index (node,"iommu-map" , i *4 +3 , &length); + devs += length; + } + + cdl->len = devs; cdl->devs =kzalloc_objs (*cdl->devs, cdl->len);
[Severity: High]
This is a pre-existing issue, but allocating struct device objects as a contiguous array and synchronously freeing them can lead to a use-after-free.
When host1x_memory_context_list_init() fails later on, it jumps to the unreg_devices label:
unreg_devices:
while (i--)
device_unregister(&cdl->devs[i].dev);
kfree(cdl->devs);Calling device_unregister() drops a reference, but does not guarantee the reference count drops to zero immediately. If another subsystem or userspace holds an asynchronous reference, kfree() will prematurely free the entire array while those references are still active.
Later, when the final reference is dropped, the kernel will attempt to invoke the host1x_memory_context_release() callback on the already freed memory.
Can the individual context devices be allocated separately to allow them to have independent lifecycles managed by their respective release callbacks?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Mikko Perttunen
maintainerPATCH v2 4/7 gpu: host1x: Add Tegra264 support
In reply to Mikko PerttunenFrom: Santosh BS <[email protected]>
Add device data and chip headers for Tegra264.
--- drivers/gpu/host1x/Makefile | 3 +- drivers/gpu/host1x/dev.c | 41 ++++++ drivers/gpu/host1x/hw/cdma_hw.c | 12 +- drivers/gpu/host1x/hw/host1x10.c | 33 +++++ drivers/gpu/host1x/hw/host1x10.h | 15 ++ drivers/gpu/host1x/hw/host1x10_hardware.h | 21 +++ drivers/gpu/host1x/hw/hw_host1x10_common.h | 6 + drivers/gpu/host1x/hw/hw_host1x10_hypervisor.h | 10 ++ drivers/gpu/host1x/hw/hw_host1x10_uclass.h | 181 +++++++++++++++++++++++++ drivers/gpu/host1x/hw/hw_host1x10_vm.h | 36 +++++ 10 files changed, 352 insertions(+), 6 deletions(-)
drivers/gpu/host1x/Makefile +2 -1
@@ -17,7 +17,8 @@ host1x-y = \ hw/host1x05.o \ hw/host1x06.o \ hw/host1x07.o \ - hw/host1x08.o + hw/host1x08.o \ + hw/host1x10.o host1x-$(CONFIG_IOMMU_API) += \ context.o
drivers/gpu/host1x/dev.c +41 -0
54 lines not on this page · raw message
drivers/gpu/host1x/hw/cdma_hw.c +7 -5
@@ -246,23 +246,24 @@ static void timeout_release_mlock(struct host1x_cdma *cdma)* so it turns out that if we don't /actually/ need MLOCKs, we can just * ignore them. * -* As such, for now just implement this on Tegra234 where things are -* stricter but also easy to implement. +* As such, for now just implement this on Tegra234 and above where things +* are stricter but also easy to implement. */ struct host1x_channel *ch =cdma_to_channel (cdma);struct host1x *host1x =cdma_to_host1x (cdma);u32 offset;switch (ch->client->class) { +case HOST1X_CLASS_VIC : + offset =HOST1X_COMMON_VIC_MLOCK ; +break ; +#if HOST1X_HW ==8 case HOST1X_CLASS_NVJPG1 : offset =HOST1X_COMMON_NVJPG1_MLOCK ;break ;case HOST1X_CLASS_NVENC : offset =HOST1X_COMMON_NVENC_MLOCK ;break ; -case HOST1X_CLASS_VIC : - offset =HOST1X_COMMON_VIC_MLOCK ; -break ;case HOST1X_CLASS_NVJPG : offset =HOST1X_COMMON_NVJPG_MLOCK ;break ;
@@ -272,6 +273,7 @@ static void timeout_release_mlock(struct host1x_cdma *cdma)case HOST1X_CLASS_OFA : offset =HOST1X_COMMON_OFA_MLOCK ;break ; +#endif default :WARN (1 ,"%s was not updated for class %u" , __func__, ch->client->class);return ;
drivers/gpu/host1x/hw/host1x10.c new file +33 -0
@@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Host1x init for Tegra264 SoCs +* +* Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +*/ + +/* include hw specification */ +#include "host1x10.h" +#include "host1x10_hardware.h" + +/* include code */ +#define HOST1X_HW 10 + +#include "cdma_hw.c" +#include "channel_hw.c" +#include "debug_hw.c" +#include "intr_hw.c" +#include "syncpt_hw.c" + +#include "../dev.h" + +int host1x10_init (struct host1x *host) +{ + host->channel_op = &host1x_channel_ops; + host->cdma_op = &host1x_cdma_ops; + host->cdma_pb_op = &host1x_pushbuffer_ops; + host->syncpt_op = &host1x_syncpt_ops; + host->intr_op = &host1x_intr_ops; + host->debug_op = &host1x_debug_ops; + +return 0 ; +}
drivers/gpu/host1x/hw/host1x10.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Host1x init for Tegra264 SoCs +* +* Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +*/ + +#ifndef HOST1X_HOST1X10_H +#define HOST1X_HOST1X10_H + +struct host1x ; + +int host1x10_init (struct host1x *host); + +#endif
drivers/gpu/host1x/hw/host1x10_hardware.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Tegra host1x Register Offsets for Tegra264 +* +* Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +*/ + +#ifndef __HOST1X_HOST1X10_HARDWARE_H +#define __HOST1X_HOST1X10_HARDWARE_H + +#include <linux/types.h> +#include <linux/bitops.h> + +#include "hw_host1x10_uclass.h" +#include "hw_host1x10_vm.h" +#include "hw_host1x10_hypervisor.h" +#include "hw_host1x10_common.h" + +#include "opcodes.h" + +#endif
drivers/gpu/host1x/hw/hw_host1x10_common.h new file +6 -0
@@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +*/ + +#define HOST1X_COMMON_VIC_MLOCK 0x4060
drivers/gpu/host1x/hw/hw_host1x10_hypervisor.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +*/ + +#define HOST1X_HV_SYNCPT_PROT_EN 0x172c +#define HOST1X_HV_SYNCPT_PROT_EN_CH_EN BIT(1) +#define HOST1X_HV_CH_MLOCK_EN (x) (0x1708 + (x * 4)) +#define HOST1X_HV_CH_KERNEL_FILTER_GBUFFER (x) (0x1718 + (x * 4)) +#define HOST1X_HV_SYNCPT_VM (x) (0x0 + 4 * (x))
drivers/gpu/host1x/hw/hw_host1x10_uclass.h new file +181 -0
181 lines not on this page · raw message
drivers/gpu/host1x/hw/hw_host1x10_vm.h new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +*/ + +#define HOST1X_CHANNEL_DMASTART 0x0000 +#define HOST1X_CHANNEL_DMASTART_HI 0x0004 +#define HOST1X_CHANNEL_DMAPUT 0x0008 +#define HOST1X_CHANNEL_DMAPUT_HI 0x000c +#define HOST1X_CHANNEL_DMAGET 0x0010 +#define HOST1X_CHANNEL_DMAGET_HI 0x0014 +#define HOST1X_CHANNEL_DMAEND 0x0018 +#define HOST1X_CHANNEL_DMAEND_HI 0x001c +#define HOST1X_CHANNEL_DMACTRL 0x0020 +#define HOST1X_CHANNEL_DMACTRL_DMASTOP BIT(0) +#define HOST1X_CHANNEL_DMACTRL_DMAGETRST BIT(1) +#define HOST1X_CHANNEL_DMACTRL_DMAINITGET BIT(2) +#define HOST1X_CHANNEL_CMDFIFO_STAT 0x0024 +#define HOST1X_CHANNEL_CMDFIFO_STAT_EMPTY BIT(13) +#define HOST1X_CHANNEL_CMDFIFO_RDATA 0x0028 +#define HOST1X_CHANNEL_CMDP_OFFSET 0x0030 +#define HOST1X_CHANNEL_CMDP_CLASS 0x0034 +#define HOST1X_CHANNEL_CHANNELSTAT 0x0038 +#define HOST1X_CHANNEL_CMDPROC_STOP 0x0048 +#define HOST1X_CHANNEL_TEARDOWN 0x004c +#define HOST1X_CHANNEL_SMMU_STREAMID 0x0084 + +#define HOST1X_SYNC_SYNCPT_CPU_INCR (x) (0x6400 + 4 * (x)) +#define HOST1X_SYNC_SYNCPT_THRESH_CPU0_INT_STATUS (x) (0x6600 + 4 * (x)) +#define HOST1X_SYNC_SYNCPT_INTR_DEST (x) (0x6684 + 4 * (x)) +#define HOST1X_SYNC_SYNCPT_THRESH_INT_ENABLE_CPU0 (x) (0x770c + 4 * (x)) +#define HOST1X_SYNC_SYNCPT_THRESH_INT_DISABLE (x) (0x7790 + 4 * (x)) +#define HOST1X_SYNC_SYNCPT (x) (0x8080 + 4 * (x)) +#define HOST1X_SYNC_SYNCPT_INT_THRESH (x) (0xa088 + 4 * (x)) +#define HOST1X_SYNC_SYNCPT_CH_APP (x) (0xb090 + 4 * (x)) +#define HOST1X_SYNC_SYNCPT_CH_APP_CH (v) (((v) & 0x3f) << 8)
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v2 4/7] gpu: host1x: Add Tegra264 support
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] In `hw_host1x10_uclass.h`, the macro definition following `host1x_uclass_indoff_rwn_read_v`…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] In hw_host1x10_uclass.h, the macro definition following host1x_uclass_indoff_rwn_read_v incorrectly redefines HOST1X_UCLASS_INDOFF_INDROFFSET_F instead of defining HOST1X_UCLASS_INDOFF_RWN_READ_V. --
commit 6528bd5a94c6539553c675b4b4c0ced0e30024a6
Author: Santosh BS <[email protected]>
gpu: host1x: Add Tegra264 support
This commit adds device data and chip headers for Tegra264.
Quoted 5 lines
drivers/gpu/host1x/hw/hw_host1x10_uclass.h new file +0
-0
[ ... ]
drivers/gpu/host1x/hw/hw_host1x10_uclass.h line 167
Quoted 12 lines
drivers/gpu/host1x/hw/hw_host1x10_uclass.h new file +12
-0+static inline u32 host1x_uclass_indoff_indroffset_f (u32 v) +{ +return (v &0xffff ) <<2 ; +} +#define HOST1X_UCLASS_INDOFF_INDROFFSET_F (v) \ + host1x_uclass_indoff_indroffset_f(v) +static inline u32 host1x_uclass_indoff_rwn_read_v (void ) +{ +return 1 ; +} +#define HOST1X_UCLASS_INDOFF_INDROFFSET_F (v) \ + host1x_uclass_indoff_indroffset_f(v)
[Severity: Low]
Does this code accidentally redefine HOST1X_UCLASS_INDOFF_INDROFFSET_F?
It looks like this might be a copy-paste error where HOST1X_UCLASS_INDOFF_RWN_READ_V should have been defined instead, calling host1x_uclass_indoff_rwn_read_v().
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Mikko Perttunen
maintainerPATCH v2 5/7 drm/tegra: falcon: Add support for RISC-V external boot
In reply to Mikko PerttunenAdd support for loading and booting RISC-V firmwares on Falcons with RISC-V hardware. The flow is mostly the same as for traditional Falcons, with a few different registers and different firmware layout.
--- drivers/gpu/drm/tegra/falcon.c | 66 +++++++++++++++++++++++++++++++++++------- drivers/gpu/drm/tegra/falcon.h | 23 +++++++++++++++ 2 files changed, 79 insertions(+), 10 deletions(-)
drivers/gpu/drm/tegra/falcon.c +56 -10
@@ -26,8 +26,12 @@ int falcon_wait_idle(struct falcon *falcon) {u32 value; -return readl_poll_timeout (falcon->regs +FALCON_IDLESTATE , value, - (value ==0 ),10 ,100000 ); +if (falcon->riscv) +return readl_poll_timeout (falcon->regs +RISCV_CPUCTL , value, + (value &RISCV_CPUCTL_ACTIVE_STAT_ACTIVE ),10 ,100000 ); +else +return readl_poll_timeout (falcon->regs +FALCON_IDLESTATE , value, + (value ==0 ),10 ,100000 ); }static int falcon_dma_wait_not_full (struct falcon *falcon)
@@ -122,6 +126,17 @@ static int falcon_parse_firmware_image(struct falcon *falcon)return 0 ; } +static void falcon_parse_firmware_desc (struct falcon *falcon) +{ +struct falcon_fw_riscv_desc *desc = + (struct falcon_fw_riscv_desc *)falcon->firmware.desc_firmware->data; + + falcon->firmware.code.offset = desc->code_offset; + falcon->firmware.code.size = desc->code_size; + falcon->firmware.data.offset = desc->data_offset; + falcon->firmware.data.size = desc->data_size; +} +int falcon_read_firmware (struct falcon *falcon,const char *name) {int err;
@@ -133,7 +148,23 @@ int falcon_read_firmware(struct falcon *falcon, const char *name) falcon->firmware.size = falcon->firmware.firmware->size; +if (falcon->riscv) { +/* Load separate descriptor */ +char desc_name[128 ]; + +scnprintf (desc_name,sizeof (desc_name),"%s.desc" , name); + err =request_firmware (&falcon->firmware.desc_firmware, desc_name, falcon->dev); +if (err <0 ) + goto release_firmware; + } +return 0 ; + +release_firmware: +release_firmware (falcon->firmware.firmware); + falcon->firmware.firmware =NULL ; + +return err; }int falcon_load_firmware (struct falcon *falcon)
@@ -144,16 +175,22 @@ int falcon_load_firmware(struct falcon *falcon)/* copy firmware image into local area. this also ensures endianness */ falcon_copy_firmware_image (falcon, firmware); -/* parse the image data */ - err =falcon_parse_firmware_image (falcon); -if (err <0 ) { -dev_err (falcon->dev,"failed to parse firmware image\n" ); -return err; +if (falcon->riscv) { +falcon_parse_firmware_desc (falcon); + }else { + err =falcon_parse_firmware_image (falcon); +if (err <0 ) { +dev_err (falcon->dev,"failed to parse firmware image\n" ); +return err; + } }release_firmware (firmware); falcon->firmware.firmware =NULL ; +release_firmware (falcon->firmware.desc_firmware); + falcon->firmware.desc_firmware =NULL ; +return 0 ; }
@@ -168,6 +205,9 @@ void falcon_exit(struct falcon *falcon) {if (falcon->firmware.firmware)release_firmware (falcon->firmware.firmware); + +if (falcon->firmware.desc_firmware) +release_firmware (falcon->firmware.desc_firmware); }int falcon_boot (struct falcon *falcon)
@@ -229,9 +269,15 @@ int falcon_boot(struct falcon *falcon)FALCON_ITFEN_CTXEN , FALCON_ITFEN); -/* boot falcon */ -falcon_writel (falcon,0x00000000 ,FALCON_BOOTVEC ); -falcon_writel (falcon,FALCON_CPUCTL_STARTCPU ,FALCON_CPUCTL ); +if (falcon->riscv) { +falcon_writel (falcon,RISCV_BCR_CTRL_CORE_SELECT_RISCV ,RISCV_BCR_CTRL ); +falcon_writel (falcon,0x0 ,RISCV_BOOT_VECTOR_HI ); +falcon_writel (falcon,0x100000 ,RISCV_BOOT_VECTOR_LO ); +falcon_writel (falcon,RISCV_CPUCTL_STARTCPU ,RISCV_CPUCTL ); + }else { +falcon_writel (falcon,0x00000000 ,FALCON_BOOTVEC ); +falcon_writel (falcon,FALCON_CPUCTL_STARTCPU ,FALCON_CPUCTL ); + } err =falcon_wait_idle (falcon);if (err <0 ) {
drivers/gpu/drm/tegra/falcon.h +23 -0
@@ -55,6 +55,16 @@#define FALCON_DMATRFFBOFFS 0x0000111c +#define RISCV_BOOT_VECTOR_LO 0x00001780 +#define RISCV_BOOT_VECTOR_HI 0x00001784 + +#define RISCV_CPUCTL 0x00001788 +#define RISCV_CPUCTL_STARTCPU (1 << 0) +#define RISCV_CPUCTL_ACTIVE_STAT_ACTIVE (1 << 7) + +#define RISCV_BCR_CTRL 0x00001a68 +#define RISCV_BCR_CTRL_CORE_SELECT_RISCV (1 << 4) +struct falcon_fw_bin_header_v1 {u32 magic;/* 0x10de */ u32 version;/* version of bin format (1) */
@@ -76,6 +86,14 @@ struct falcon_fw_os_header_v1 {u32 data_size; }; +struct falcon_fw_riscv_desc { +u32 reserved[74 ]; +u32 data_offset; +u32 data_size; +u32 code_offset; +u32 code_size; +}; +struct falcon_firmware_section {unsigned long offset;size_t size;
@@ -84,6 +102,8 @@ struct falcon_firmware_section {struct falcon_firmware {/* Firmware after it is read but not loaded */ const struct firmware *firmware; +/* RISC-V firmware descriptor */ +const struct firmware *desc_firmware;/* Raw firmware data */ dma_addr_t iova;
@@ -102,6 +122,9 @@ struct falcon {struct device *dev;void __iomem *regs; +/* Peregrine falcon, external boot */ +bool riscv; +struct falcon_firmware firmware; };
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v2 5/7] drm/tegra: falcon: Add support for RISC-V external boot
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Missing bounds check, endianness conversion, and size validation of the RISC-V firmware descriptor…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Missing bounds check, endianness conversion, and size validation of the RISC-V firmware descriptor leads to out-of-bounds memory accesses and unbounded DMA. --
commit ce83e1285215f11b260dbf628363fe352ce09b78
Author: Mikko Perttunen <[email protected]>
drm/tegra: falcon: Add support for RISC-V external boot
Add support for loading and booting RISC-V firmwares on Falcons with RISC-V hardware.
Quoted 4 lines
drivers/gpu/drm/tegra/falcon.c +0
-0
[ ... ]
drivers/gpu/drm/tegra/falcon.c static int falcon_parse_firmware_image(struct falcon *falcon) · line 137
Quoted 13 lines
drivers/gpu/drm/tegra/falcon.c +9
-0@@ -122,6 +126,17 @@ static int falcon_parse_firmware_image(struct falcon *falcon)return 0 ; } +static void falcon_parse_firmware_desc (struct falcon *falcon) +{ +struct falcon_fw_riscv_desc *desc = + (struct falcon_fw_riscv_desc *)falcon->firmware.desc_firmware->data; + + falcon->firmware.code.offset = desc->code_offset; + falcon->firmware.code.size = desc->code_size; + falcon->firmware.data.offset = desc->data_offset; + falcon->firmware.data.size = desc->data_size;
[Severity: High]
Does this code need to validate the size of desc_firmware before casting its data to struct falcon_fw_riscv_desc? If the firmware file is smaller than the struct size, this could lead to an out-of-bounds read.
Also, do these fields need le32_to_cpu() conversion for big-endian systems, similar to how the main firmware is handled in falcon_copy_firmware_image()?
Finally, are the parsed sizes and offsets validated against the main firmware's size? If not, these unchecked values could cause out-of-bounds host memory accesses later in falcon_boot() when they are used in the falcon_copy_chunk() DMA loops:
for (offset = 0; offset < falcon->firmware.data.size; offset += 256)
falcon_copy_chunk(falcon,
falcon->firmware.data.offset + offset,
offset, FALCON_MEMORY_DATA);Quoted 4 lines
drivers/gpu/drm/tegra/falcon.c +2
-0+} +int falcon_read_firmware (struct falcon *falcon,const char *name) {
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Mikko Perttunen
maintainerPATCH v2 6/7 drm/tegra: vic: Add Tegra264 support
In reply to Mikko PerttunenAdd support for VIC on Tegra264. The Tegra264 VIC uses a RISC-V based Falcon microcontroller instead of the traditional Falcon previously, and has the TRANSCFG register in a different place.
The .version field is set to 0x264 rather than 0x26 to allow distinguishing between different VIC capabilities between minor version variations of some chips.
--- drivers/gpu/drm/tegra/drm.c | 1 + drivers/gpu/drm/tegra/vic.c | 95 +++++++++++++++++++++++++++++++++------------ drivers/gpu/drm/tegra/vic.h | 9 ++--- 3 files changed, 76 insertions(+), 29 deletions(-)
drivers/gpu/drm/tegra/drm.c +1 -0
@@ -1396,6 +1396,7 @@ static const struct of_device_id host1x_drm_subdevs[] = { { .compatible = "nvidia,tegra194-nvdec", }, { .compatible = "nvidia,tegra234-vic", }, { .compatible = "nvidia,tegra234-nvdec", }, + { .compatible = "nvidia,tegra264-vic", }, { /* sentinel */ } };
drivers/gpu/drm/tegra/vic.c +71 -24
179 lines not on this page · raw message
drivers/gpu/drm/tegra/vic.h +4 -5
@@ -21,11 +21,10 @@#define CG_IDLE_CG_EN (1 << 6)#define CG_WAKEUP_DLY_CNT (val) ((val & 0xf) << 16) -#define VIC_TFBIF_TRANSCFG 0x00002044 -#define TRANSCFG_ATT (i, v) (((v) & 0x3) << (i * 4)) -#define TRANSCFG_SID_HW 0 -#define TRANSCFG_SID_PHY 1 -#define TRANSCFG_SID_FALCON 2 +#define TRANSCFG_ATT (i, v) (((v) & 0x3) << (i * 4)) +#define TRANSCFG_SID_HW 0 +#define TRANSCFG_SID_PHY 1 +#define TRANSCFG_SID_FALCON 2/* Firmware offsets */
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v2 6/7] drm/tegra: vic: Add Tegra264 support
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Error paths in vic_load_firmware leave a dangling pointer in vic->falcon.firmware.virt, causing Use-After-Free and Double Free. --
commit c58aa87e57c2ab3ec5383df99d29ec8f6a79e162
Author: Mikko Perttunen <[email protected]>
Subject: drm/tegra: vic: Add Tegra264 support
Add support for VIC on Tegra264. The Tegra264 VIC uses a RISC-V based Falcon microcontroller instead of the traditional Falcon previously, and has the TRANSCFG register in a different place.
Quoted 4 lines
drivers/gpu/drm/tegra/vic.c +0
-0
[ ... ]
drivers/gpu/drm/tegra/vic.c static int vic_load_firmware(struct vic *vic) · line 332
Quoted 4 lines
drivers/gpu/drm/tegra/vic.c +0
-0@@ -302,7 +330,6 @@ static int vic_load_firmware(struct vic *vic)return err; }
[Severity: Critical]
This is a pre-existing issue, but I noticed a potential use-after-free and double-free in the error handling of vic_load_firmware().
When memory allocation succeeds, the pointers are assigned:
vic->falcon.firmware.virt = virt; vic->falcon.firmware.iova = iova;
If a subsequent step fails (such as falcon_load_firmware() or dma_map_single()), the code jumps to the cleanup label, frees the memory, but does not clear the pointer:
cleanup:
if (!client->group) dma_free_coherent(vic->dev, size, virt, iova); else tegra_drm_free(tegra, size, virt, iova); mutex_unlock(&lock); return err;
If vic_load_firmware() is called again (for example, during the next PM runtime resume), it sees the non-NULL pointer, assumes the firmware is loaded, and returns 0.
Will this cause the driver to program the hardware to DMA from the freed memory?
Furthermore, when the device is unbound, will the teardown path unconditionally free vic->falcon.firmware.virt again causing a double-free?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Mikko Perttunen
maintainerPATCH v2 7/7 arm64: tegra: Add Host1x and VIC on Tegra264
In reply to Mikko PerttunenTegra264 has a host1x instance with a VIC (video image compositor). Other multimedia engines have moved outside host1x. Stream IDs are now namespaced by device rather than being defined globally -- however, the only engine we have using context isolation is VIC so we only define VIC's range of context devices.
--- arch/arm64/boot/dts/nvidia/tegra264.dtsi | 63 ++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+)
arch/arm64/boot/dts/nvidia/tegra264.dtsi +63 -0
@@ -3807,6 +3807,69 @@ its: msi-controller@40000 { }; }; + /* VISION MMIO */ + bus@8180000000 { + compatible = "simple-bus"; + #address-cells = <2>; + #size-cells = <2>; + + ranges = <0x000 0x00000000 0x81 0x80000000 0x00 0x10000000>, /* MMIO (256 MiB) */ + <0x100 0x00000000 0x00 0x20000000 0x00 0x40000000>, /* non-prefetchable memory (32-bit) */ + <0x200 0x00000000 0xa8 0x80000000 0x57 0x80000000>; /* I/O, ECAM, prefetchable memory (64-bit) */ + + host1x@1200000 { + compatible = "nvidia,tegra264-host1x"; + reg = <0x0 0x1200000 0x0 0x10000>, + <0x0 0x1210000 0x0 0x10000>, + <0x0 0x1240000 0x0 0x10000>; + reg-names = "common", "hypervisor", "vm"; + interrupts = <GIC_SPI 327 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 328 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 329 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 330 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 331 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 332 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 333 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 334 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 325 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "syncpt0", "syncpt1", "syncpt2", "syncpt3", "syncpt4", + "syncpt5", "syncpt6", "syncpt7", "host1x"; + clocks = <&bpmp TEGRA264_CLK_HOST1X>; + clock-names = "host1x"; + + #address-cells = <2>; + #size-cells = <2>; + + ranges = <0x000 0x00000000 0x00 0x08000000 0x00 0x01000000>, + <0x000 0x02800000 0x00 0x0a800000 0x00 0x00800000>; + + interconnects = <&mc TEGRA264_MEMORY_CLIENT_HOST1XR &emc>; + interconnect-names = "dma-mem"; + iommus = <&smmu1 TEGRA264_SID_HOST1X>; + dma-coherent; + + /* Context isolation domains */ + iommu-map = <0 &smmu1 (TEGRA264_SID_VIC + 1) 16>; + + vic@50000 { + compatible = "nvidia,tegra264-vic"; + reg = <0x0 0x50000 0x0 0x40000>; + interrupts = <GIC_SPI 468 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&bpmp TEGRA264_CLK_VIC>; + clock-names = "vic"; + resets = <&bpmp TEGRA264_RESET_VIC>; + reset-names = "vic"; + power-domains = <&bpmp TEGRA264_POWER_DOMAIN_VIC>; + interconnects = <&mc TEGRA264_MEMORY_CLIENT_VICR &emc>, + <&mc TEGRA264_MEMORY_CLIENT_VICW &emc>; + interconnect-names = "dma-mem", "write"; + + iommus = <&smmu1 TEGRA264_SID_VIC>; + dma-coherent; + }; + }; + }; + /* DISP_USB MMIO */ bus@8800000000 { compatible = "simple-bus";
Signature · 1 line
2.53.0
Re: [PATCH v2 7/7] arm64: tegra: Add Host1x and VIC on Tegra264
Quoted 10 lines · Mikko Perttunen
Tegra264 has a host1x instance with a VIC (video image compositor). Other multimedia engines have moved outside host1x. Stream IDs are now namespaced by device rather than being defined globally -- however, the only engine we have using context isolation is VIC so we only define VIC's range of context devices.
Signed-off-by Mikko Perttunen <[email protected]>--- arch/arm64/boot/dts/nvidia/tegra264.dtsi | 63 ++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+)
Applied, thanks.
Thierry
Thierry Reding
maintainerQuoted 70 lines · Mikko Perttunen
Hello everyone,
this series adds support for Host1x and VIC on Tegra264 SoCs. The Host1x side is not very interesting, just adding the usual register definitions and other information. One thing of note is that multimedia engines apart from VIC have moved away from Host1x on this generation.
On the VIC side, there is a bit more of a change, as the VIC Falcon is now RISC-V based. Unlike NVDEC, VIC is still "externally booted", so the boot sequence is very similar to before.
host1x uapi-test[1] has been updated for Tegra264. Necessary headers for constructing VIC jobs have been added to open-gpu-doc[2].
Patches 1 and 2 add new compatible strings to Host1x and VIC device tree bindings.
Patch 3 fixes the context device device tree parsing code to handle iommu-map entries with length more than 1.
Patch 4 adds Tegra264 support to the Host1x driver.
Patches 5 and 6 add Tegra264 support to the VIC driver.
Patch 7 adds Host1x and VIC nodes to the Tegra264 device tree.
Thank you,
Mikko[1] https://github.com/cyndis/uapi-test
[2] https://github.com/NVIDIA/open-gpu-doc/blob/master/classes/video/clceb6.h
https://github.com/NVIDIA/open-gpu-doc/blob/master/classes/video/vic_ceb6_types.h---
Changes in v2:
- Updated dt-bindings changes to be chip-specific
- Link to v1: https://patch.msgid.link/[email protected]---
Mikko Perttunen (6):
dt-bindings: display: tegra: Changes to support Tegra264
dt-bindings: display: tegra: Add Tegra264 compatible for VIC
gpu: host1x: Correctly parse linear ranges of context devices drm/tegra: falcon: Add support for RISC-V external boot drm/tegra: vic: Add Tegra264 support
arm64: tegra: Add Host1x and VIC on Tegra264Santosh BS (1):
gpu: host1x: Add Tegra264 support.../display/tegra/nvidia,tegra124-vic.yaml | 1 + .../display/tegra/nvidia,tegra20-host1x.yaml | 20 ++- arch/arm64/boot/dts/nvidia/tegra264.dtsi | 63 +++++++ drivers/gpu/drm/tegra/drm.c | 1 + drivers/gpu/drm/tegra/falcon.c | 66 ++++++-- drivers/gpu/drm/tegra/falcon.h | 23 +++ drivers/gpu/drm/tegra/vic.c | 95 ++++++++--- drivers/gpu/drm/tegra/vic.h | 9 +- drivers/gpu/host1x/Makefile | 3 +- drivers/gpu/host1x/context.c | 13 +- drivers/gpu/host1x/dev.c | 41 +++++ drivers/gpu/host1x/hw/cdma_hw.c | 12 +- drivers/gpu/host1x/hw/host1x10.c | 33 ++++ drivers/gpu/host1x/hw/host1x10.h | 15 ++ drivers/gpu/host1x/hw/host1x10_hardware.h | 21 +++ drivers/gpu/host1x/hw/hw_host1x10_common.h | 6 + drivers/gpu/host1x/hw/hw_host1x10_hypervisor.h | 10 ++ drivers/gpu/host1x/hw/hw_host1x10_uclass.h | 181 +++++++++++++++++++++ drivers/gpu/host1x/hw/hw_host1x10_vm.h | 36 ++++ 19 files changed, 601 insertions(+), 48 deletions(-)
Quoted 3 lines
---
base-commit:4549871118cf616eecdd2d939f78e3b9e1dddc48
change-id: 20260313-t264-host1x-c97171fdde77
Patches 1-6 applied to drm-misc-next. I'll pick up patch 7 into the Tegra tree because it looks like there will be a conflict.
Thanks,
Thierry