media: apple: add avd driver
v2 cover media: apple: add avd driver
Hi,
This series enables hardware video decoding on Apple Silicon M1, M2 and M3 SoCs. It adds support for all the codecs AVD (Apple Video Decoder) supports, which is H264, H265, VP9 and AV1 (only on M3+).
The AVD is a bit unique both as a video decoder and an IP block on Apple Silicon SoCs. Instead of following the normal "a register for each parameter", AVD is programmed through one single register. This means the order of the writes are important, but its also important to ensure we dont write faster than the hardware can process. To solve this, we use the included Cortex-M3 co-processor. The CM3 accepts unsigned code, which we take advantage off [1].
The driver prepares the instructions and writes them into segments, which are submitted to the CM3. The CM3 then programs the hardware and notifies the AP when the job is done or if an error occurred.
The driver implements the V4L2 M2M stateless decoder API. The driver's framework is based very heavy on rkvdecs driver. It therefore comes as no suprise that v4l2-compliance reports no errors:
Total for avd device /dev/video0: 49, Succeeded: 49, Failed: 0, Warnings: 0
The fluster scores are:
JVT-AVC_V1: 77/135
JVT-FR-EXT: 42/69
VP9-TEST-VECTORS: 216/305
VP9-TEST-VECTORS-HIGH: 1/6
JCT-VC-HEVC_V1: 143/147
AV1-TEST-VECTORS: 238/242
Since not all unsupported H264 streams are rejected, the scores depend on the reset working, this only works with a patch to the apple-dart driver so that the IOMMU attach/detach trick works.
All codecs support 4:2:2, 4:2:0, in 10 and 8 bit. By default, AVD outputs in NV12, NV16, P010 and P210. Support for 4:4:4 and 12 bit formats has not been added yet.
Internally the AVD uses an Apple specific compressed and tiled format called Interchange to store reference image data. This is stored after image data across all codecs. Apple Interchange is used for sharing buffers with other hardware blocks (GPU, display controller), support for this is on its way [2].
The V4L2 pixel formats have been added to help with calculating sizes.
This driver has been tested on most Apple Silicon SoCs in our downstream tree [3]. Its expected this driver will work on M4, M5, M6 and the Neo, with firmware already being written for all except the M6 SoCs [4].
The groundwork for this was laid many years ago by Jamie, R and Eileen, who through a combined effort managed to reverse engineer many core parts of the AVD block.
This driver would not have been possible without the work done by Eileen, who wrote initial support for H264, H265, VP9 and excellent tooling [5], allowing me to reverse engineer AV1 and make the driver conformant.
[1] https://github.com/sofus13/avd-fw/tree/avd-next-fw
[2] https://patch.msgid.link/[email protected]
[3] https://github.com/AsahiLinux/linux
[4] https://github.com/AsahiLinux/avd-fw
[5] https://github.com/eiln/avd/tree/main
---
Changes in v2:
- Patch order
- Fixed dt-bindings by constraining all properties
- Fixed dts, add interrupts, iommus and regs. Drop labels, fix names
- Add Apple Interchange format
- Add more av1 and vp9 validation to v4l2-ctrls
- Validate more codec parameters
- Use the new CM3 firmware (drop avd-hw, drop submission loops)
- Updated cover to reflect changes
- Link to v1: https://patch.msgid.link/[email protected]
To: Sven Peter <[email protected]>
To: Janne Grunau <[email protected]>
To: Neal Gompa <[email protected]>
To: Mauro Carvalho Chehab <[email protected]>
To: Rob Herring <[email protected]>
To: Krzysztof Kozlowski <[email protected]>
To: Conor Dooley <[email protected]>
To: Sofus Forstreuter <[email protected]>
To: Philipp Zabel <[email protected]>
To: Heiko Stuebner <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
Sofus Forstreuter (17):
dt-bindings: media: add apple,avd
media: v4l2: Add P210 pixel format
media: v4l2: Add Apple interchange pixel formats
media: v4l2-ctrls: validate av1 tile info
media: v4l2-ctrls: validate vp9 tile_rows_log2
media: apple: add avd driver
media: apple: avd: add h264 support
media: apple: avd: add vp9 support
media: apple: avd: add hevc support
media: apple: avd: add av1 support
arm64: dts: apple: t8103: add avd nodes
arm64: dts: apple: t8112: add avd nodes
arm64: dts: apple: t8122: add avd nodes
arm64: dts: apple: t600x: add avd nodes
arm64: dts: apple: t602x: add avd nodes
arm64: dts: apple: t6030: add avd nodes
arm64: dts: apple: t6031: add avd nodes
.../devicetree/bindings/media/apple,avd.yaml | 127 + .../userspace-api/media/v4l/pixfmt-yuv-planar.rst | 14 +- MAINTAINERS | 2 + arch/arm64/boot/dts/apple/t600x-dieX.dtsi | 32 + arch/arm64/boot/dts/apple/t602x-dieX.dtsi | 32 + arch/arm64/boot/dts/apple/t6030.dtsi | 32 + arch/arm64/boot/dts/apple/t6031-dieX.dtsi | 32 + arch/arm64/boot/dts/apple/t8103.dtsi | 32 + arch/arm64/boot/dts/apple/t8112.dtsi | 32 + arch/arm64/boot/dts/apple/t8122.dtsi | 32 + drivers/media/platform/Kconfig | 1 + drivers/media/platform/Makefile | 1 + drivers/media/platform/apple/Kconfig | 5 + drivers/media/platform/apple/Makefile | 3 + drivers/media/platform/apple/avd/Kconfig | 18 + drivers/media/platform/apple/avd/Makefile | 5 + .../media/platform/apple/avd/avd-av1-entropymode.c | 4698 ++++++++++++++++++++ .../media/platform/apple/avd/avd-av1-entropymode.h | 284 ++ drivers/media/platform/apple/avd/avd-av1.c | 1432 ++++++ drivers/media/platform/apple/avd/avd-drv.c | 776 ++++ drivers/media/platform/apple/avd/avd-h264.c | 862 ++++ drivers/media/platform/apple/avd/avd-hevc.c | 1340 ++++++ drivers/media/platform/apple/avd/avd-inst.h | 210 + drivers/media/platform/apple/avd/avd-v4l2.c | 992 +++++ drivers/media/platform/apple/avd/avd-vp9.c | 1054 +++++ drivers/media/platform/apple/avd/avd.h | 299 ++ drivers/media/v4l2-core/v4l2-common.c | 8 + drivers/media/v4l2-core/v4l2-ctrls-core.c | 17 +- drivers/media/v4l2-core/v4l2-ioctl.c | 7 + include/uapi/linux/v4l2-controls.h | 2 +- include/uapi/linux/videodev2.h | 9 + 31 files changed, 12386 insertions(+), 4 deletions(-)
---
base-commit: 4efa625593e1e9c76346232413997556dea1d89f
change-id: 20260917-avd-7ee5474b468c
Best regards,
Signature · 1 line
Sofus Forstreuter <[email protected]>
PATCH v2 1/17 dt-bindings: media: add apple,avd
Document the Apple Video Decoder. A hardware video decoder present on Apple hardware.
--- .../devicetree/bindings/media/apple,avd.yaml | 127 +++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 128 insertions(+)
Documentation/devicetree/bindings/media/apple,avd.yaml new file +127 -0
@@ -0,0 +1,127 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/apple,avd.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple Video Decoder (AVD) + +description: | + AVD is a stateless video decode IP block present on Apple devices. + Notably it includes an ARM Cortex-M3 and associated DMA controller. + AVD is capable of decoding H264, H265, VP9 and AV1 on newer SoCs. + + The IP does not change much, with changes being mostly the CM3 having more + memory and interrupts. + +maintainers: + - Sofus Forstreuter <[email protected]> + +properties: + compatible: + oneOf: + - items: + - enum: + - apple,t6030-avd + - apple,t6031-avd + - const: apple,t8122-avd + - enum: + - apple,t8103-avd + - apple,t8112-avd + - apple,t8122-avd + - apple,t6000-avd + - apple,t6020-avd + + reg: + items: + - description: DMA control + - description: Cortex-M3 code (unsigned) + - description: Cortex-M3 sram + - description: Mailbox + - description: Video decode control + + reg-names: + items: + - const: piodma + - const: code + - const: sram + - const: mbox + - const: ctrl + + iommus: + items: + - description: Decode related + - description: DMA controller + + power-domains: + maxItems: 1 + + resets: + maxItems: 1 + + interrupts: + items: + - description: mailbox 0 + - description: mailbox 1 + - description: mailbox 2 + - description: mailbox 3 + - description: flag 0 + - description: flag 1 + - description: DMA status + description: | + Notably there are no decode related interrupts. All decode related + interrupts are sent to the CM3. + + interrupt-names: + items: + - const: mbox0 + - const: mbox1 + - const: mbox2 + - const: mbox3 + - const: flag0 + - const: flag1 + - const: piodma + +required: + - compatible + - reg + - interrupts + - reg-names + - iommus + - power-domains + - resets + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/apple-aic.h> + #include <dt-bindings/interrupt-controller/irq.h> + + soc { + #address-cells = <2>; + #size-cells = <2>; + + video-codec@289070000 { + compatible = "apple,t8122-avd"; + reg = <0x2 0x89070000 0x0 0x4000>, + <0x2 0x89080000 0x0 0x10000>, + <0x2 0x89092000 0x0 0x14000>, + <0x2 0x890a4000 0x0 0x4000>, + <0x2 0x89100000 0x0 0x10000>; + reg-names = "piodma", "code", "sram", "mbox", "ctrl"; + interrupt-parent = <&aic>; + interrupts = <AIC_IRQ 679 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 680 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 681 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 682 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 683 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 684 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 685 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "mbox0", "mbox1", "mbox2", "mbox3", + "flag0", "flag1", "piodma"; + power-domains = <&ps_avd_sys>; + resets = <&ps_avd_sys>; + iommus = <&avd_dart 0>, <&avd_dart 1>; + }; + };
MAINTAINERS +1 -0
@@ -2643,6 +2643,7 @@ F: Documentation/devicetree/bindings/iommu/apple,dart.yaml F: Documentation/devicetree/bindings/iommu/apple,sart.yaml F: Documentation/devicetree/bindings/leds/backlight/apple,dwi-bl.yaml F: Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml +F: Documentation/devicetree/bindings/media/apple,avd.yaml F: Documentation/devicetree/bindings/mfd/apple,smc.yaml F: Documentation/devicetree/bindings/net/bluetooth/brcm,bcm4377-bluetooth.yaml F: Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml
Signature · 1 line
2.55.0
Re: [PATCH v2 01/17] dt-bindings: media: add apple,avd
Documentation/devicetree/bindings/media/apple,avd.yaml line 33
Quoted 13 lines · Sofus Forstreuter
Documentation/devicetree/bindings/media/apple,avd.yaml new file +13
-0+ compatible: + oneOf: + - items: + - enum: + - apple,t6030-avd + - apple,t6031-avd + - const: apple,t8122-avd + - enum: + - apple,t8103-avd + - apple,t8112-avd + - apple,t8122-avd + - apple,t6000-avd + - apple,t6020-avd
These are misordered. Order is alphabetical.
With this fixed:
Best regards,
Krzysztof
PATCH v2 2/17 media: v4l2: Add P210 pixel format
In reply to Sofus ForstreuterP210 is a YUV format with 10-bits per component with interleaved UV.
--- .../userspace-api/media/v4l/pixfmt-yuv-planar.rst | 14 ++++++++++++-- drivers/media/v4l2-core/v4l2-common.c | 1 + drivers/media/v4l2-core/v4l2-ioctl.c | 1 + include/uapi/linux/videodev2.h | 1 + 4 files changed, 15 insertions(+), 2 deletions(-)
Documentation/userspace-api/media/v4l/pixfmt-yuv-planar.rst +12 -2
@@ -138,6 +138,13 @@ All components are stored with the same number of bits per component. - Cb, Cr - No - Linear + * - V4L2_PIX_FMT_P210 + - 'P210' + - 10 + - 4:2:2 + - Cb, Cr + - Yes + - Linear * - V4L2_PIX_FMT_NV15 - 'NV15' - 10
@@ -834,12 +841,15 @@ number of lines as the luma plane. .. _V4L2_PIX_FMT_P010: .. _V4L2-PIX-FMT-P010-4L4: +.. _V4L2-PIX-FMT-P210: -P010 and tiled P010 -------------------- +P010, tiled P010 and P210 +------------------------- P010 is like NV12 with 10 bits per component, expanded to 16 bits. Data in the 10 high bits, zeros in the 6 low bits, arranged in little endian order. +P210 is the same as P010 but the chroma plane is only subsampled by 2 in the +horizontal direction. .. flat-table:: Sample 4x4 P010 Image :header-rows: 0
drivers/media/v4l2-core/v4l2-common.c +1 -0
@@ -325,6 +325,7 @@ const struct v4l2_format_info *v4l2_format_info(u32 format) { .format = V4L2_PIX_FMT_NV42, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_P010, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 2, 2, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 1 }, { .format = V4L2_PIX_FMT_P012, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 2, 4, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 2 }, + { .format = V4L2_PIX_FMT_P210, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 2, 4, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 1 }, { .format = V4L2_PIX_FMT_YUV410, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 3, .bpp = { 1, 1, 1, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 4, .vdiv = 4 }, { .format = V4L2_PIX_FMT_YVU410, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 3, .bpp = { 1, 1, 1, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 4, .vdiv = 4 },
drivers/media/v4l2-core/v4l2-ioctl.c +1 -0
@@ -1369,6 +1369,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)case V4L2_PIX_FMT_NV42 : descr ="Y/VU 4:4:4" ;break ;case V4L2_PIX_FMT_P010 : descr ="10-bit Y/UV 4:2:0" ;break ;case V4L2_PIX_FMT_P012 : descr ="12-bit Y/UV 4:2:0" ;break ; +case V4L2_PIX_FMT_P210 : descr ="10-bit Y/UV 4:2:2" ;break ;case V4L2_PIX_FMT_NV12_4L4 : descr ="Y/UV 4:2:0 (4x4 Linear)" ;break ;case V4L2_PIX_FMT_NV12_16L16 : descr ="Y/UV 4:2:0 (16x16 Linear)" ;break ;case V4L2_PIX_FMT_NV12_32L32 : descr ="Y/UV 4:2:0 (32x32 Linear)" ;break ;
include/uapi/linux/videodev2.h +1 -0
@@ -659,6 +659,7 @@ struct v4l2_pix_format {#define V4L2_PIX_FMT_NV42 v4l2_fourcc('N', 'V', '4', '2')/* 24 Y/CrCb 4:4:4 */ #define V4L2_PIX_FMT_P010 v4l2_fourcc('P', '0', '1', '0')/* 24 Y/CbCr 4:2:0 10-bit per component */ #define V4L2_PIX_FMT_P012 v4l2_fourcc('P', '0', '1', '2')/* 24 Y/CbCr 4:2:0 12-bit per component */ +#define V4L2_PIX_FMT_P210 v4l2_fourcc('P', '2', '1', '0')/* 32 Y/CbCr 4:2:2 10-bit per component */ /* two non contiguous planes - one Y, one Cr + Cb interleaved */ #define V4L2_PIX_FMT_NV12M v4l2_fourcc('N', 'M', '1', '2')/* 12 Y/CbCr 4:2:0 */
Signature · 1 line
2.55.0
PATCH v2 3/17 media: v4l2: Add Apple interchange pixel formats
In reply to Sofus ForstreuterApple Interchange is a compressed and tiled format modifier.
Its intended use is for sharing buffers between hardware blocks (GPU, display controller, video codecs) on Apple platforms.
Add it to the v4l2_format_info table to help with calculating sizes.
--- drivers/media/v4l2-core/v4l2-common.c | 7 +++++++ drivers/media/v4l2-core/v4l2-ioctl.c | 6 ++++++ include/uapi/linux/videodev2.h | 8 ++++++++ 3 files changed, 21 insertions(+)
drivers/media/v4l2-core/v4l2-common.c +7 -0
@@ -336,6 +336,13 @@ const struct v4l2_format_info *v4l2_format_info(u32 format) { .format = V4L2_PIX_FMT_GREY, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_Y12, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_IC12, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 2 }, + { .format = V4L2_PIX_FMT_IC16, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_IC24, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_IC03, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 5, 10, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 2, .vdiv = 2 }, + { .format = V4L2_PIX_FMT_IC23, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 5, 10, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 2, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_IC43, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 5, 10, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 1, .vdiv = 1 }, + /* Tiled YUV formats */ { .format = V4L2_PIX_FMT_NV12_4L4, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 2 }, { .format = V4L2_PIX_FMT_NV15_4L4, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 5, 10, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 2, .vdiv = 2,
drivers/media/v4l2-core/v4l2-ioctl.c +6 -0
@@ -1561,6 +1561,12 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)case V4L2_PIX_FMT_PISP_COMP2_GBRG : descr ="PiSP 8b GBGB/RGRG mode2 compr" ;break ;case V4L2_PIX_FMT_PISP_COMP2_BGGR : descr ="PiSP 8b BGBG/GRGR mode2 compr" ;break ;case V4L2_PIX_FMT_PISP_COMP2_MONO : descr ="PiSP 8b monochrome mode2 compr" ;break ; +case V4L2_PIX_FMT_IC12 : descr ="Interchange NV12" ;break ; +case V4L2_PIX_FMT_IC16 : descr ="Interchange NV16" ;break ; +case V4L2_PIX_FMT_IC24 : descr ="Interchange NV24" ;break ; +case V4L2_PIX_FMT_IC03 : descr ="Interchange P030" ;break ; +case V4L2_PIX_FMT_IC23 : descr ="Interchange P230" ;break ; +case V4L2_PIX_FMT_IC43 : descr ="Interchange P430" ;break ;default :if (fmt->description[0 ])return ;
include/uapi/linux/videodev2.h +8 -0
@@ -842,6 +842,14 @@ struct v4l2_pix_format {#define V4L2_PIX_FMT_PISP_COMP2_BGGR v4l2_fourcc('P', 'C', '2', 'B')/* PiSP 8-bit mode 2 compressed BGGR bayer */ #define V4L2_PIX_FMT_PISP_COMP2_MONO v4l2_fourcc('P', 'C', '2', 'M')/* PiSP 8-bit mode 2 compressed monochrome */ +/* Apple Interchange, compressed and tiled formats */ +#define V4L2_PIX_FMT_IC12 v4l2_fourcc('I', 'C', '1', '2')/* Interchange NV12 */ +#define V4L2_PIX_FMT_IC16 v4l2_fourcc('I', 'C', '1', '6')/* Interchange NV16 */ +#define V4L2_PIX_FMT_IC24 v4l2_fourcc('I', 'C', '2', '4')/* Interchange NV24 */ +#define V4L2_PIX_FMT_IC03 v4l2_fourcc('I', 'C', '0', '3')/* Interchange P030 */ +#define V4L2_PIX_FMT_IC23 v4l2_fourcc('I', 'C', '2', '3')/* Interchange P230 */ +#define V4L2_PIX_FMT_IC43 v4l2_fourcc('I', 'C', '4', '3')/* Interchange P430 */ +/* Renesas RZ/V2H CRU packed formats. 64-bit units with contiguous pixels */ #define V4L2_PIX_FMT_RAW_CRU10 v4l2_fourcc('C', 'R', '1', '0')#define V4L2_PIX_FMT_RAW_CRU12 v4l2_fourcc('C', 'R', '1', '2')
Signature · 1 line
2.55.0
PATCH v2 4/17 media: v4l2-ctrls: validate av1 tile info
In reply to Sofus ForstreuterMany drivers use tile_cols and/or tile_rows, so make sure they are valid.
Increase V4L2_AV1_MAX_TILE_COUNT to MAX_TILE_COLS * MAX_TILE_ROWS
--- drivers/media/v4l2-core/v4l2-ctrls-core.c | 15 +++++++++++++++ include/uapi/linux/v4l2-controls.h | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-ctrls-core.c +15 -0
@@ -800,10 +800,25 @@ static int validate_av1_film_grain(struct v4l2_ctrl_av1_film_grain *fg)return 0 ; } +static int validate_av1_tile_info (struct v4l2_av1_tile_info *ti) +{ +if (ti->tile_cols >V4L2_AV1_MAX_TILE_COLS || + ti->tile_rows >V4L2_AV1_MAX_TILE_ROWS ) +return -EINVAL ; + +if (ti->context_update_tile_id > ti->tile_cols * ti->tile_rows) +return -EINVAL ; + +return 0 ; +} +static int validate_av1_frame (struct v4l2_ctrl_av1_frame *f) {int ret =0 ; + ret =validate_av1_tile_info (&f->tile_info); +if (ret) +return ret; ret =validate_av1_quantization (&f->quantization);if (ret)return ret;
include/uapi/linux/v4l2-controls.h +1 -1
@@ -2939,7 +2939,7 @@ struct v4l2_ctrl_vp9_compressed_hdr {#define V4L2_AV1_MAX_NUM_PLANES 3#define V4L2_AV1_MAX_TILE_COLS 64#define V4L2_AV1_MAX_TILE_ROWS 64 -#define V4L2_AV1_MAX_TILE_COUNT 512 +#define V4L2_AV1_MAX_TILE_COUNT 4096#define V4L2_AV1_SEQUENCE_FLAG_STILL_PICTURE 0x00000001#define V4L2_AV1_SEQUENCE_FLAG_USE_128X128_SUPERBLOCK 0x00000002
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v2 04/17] media: v4l2-ctrls: validate av1 tile info
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] media: v4l2-ctrls: out-of-bounds context_update_tile_id due to incorrect validation --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] media: v4l2-ctrls: out-of-bounds context_update_tile_id due to incorrect validation --
commit e21c9b1dec9408bc9aafb56a531be7a72e6ad344
Author: Sofus Forstreuter <[email protected]>
media: v4l2-ctrls: validate av1 tile info
Many drivers use tile_cols and/or tile_rows, so make sure they are valid.
Quoted 5 lines
drivers/media/v4l2-core/v4l2-ctrls-core.c +0
-0
drivers/media/v4l2-core/v4l2-ctrls-core.c static int validate_av1_film_grain(struct v4l2_ctrl_av1_film_grain *fg) · line 809
Quoted 10 lines
drivers/media/v4l2-core/v4l2-ctrls-core.c +7
-0@@ -800,10 +800,25 @@ static int validate_av1_film_grain(struct v4l2_ctrl_av1_film_grain *fg)return 0 ; } +static int validate_av1_tile_info (struct v4l2_av1_tile_info *ti) +{ +if (ti->tile_cols >V4L2_AV1_MAX_TILE_COLS || + ti->tile_rows >V4L2_AV1_MAX_TILE_ROWS ) +return -EINVAL ; + +if (ti->context_update_tile_id > ti->tile_cols * ti->tile_rows)
[Severity: High]
Does this boundary check allow an out-of-bounds tile ID?
Since context_update_tile_id is a 0-based index, the valid IDs for a frame with N total tiles (where N is ti->tile_cols * ti->tile_rows) should range strictly from 0 to N-1.
Because this check uses the strictly greater than operator (>), a value exactly equal to the total number of tiles will pass validation. Downstream stateless decoder drivers (such as the Rockchip VPU driver) calculate and program this tile ID directly into hardware registers. Instructing the hardware to use an invalid, out-of-bounds tile index for CDF updates can lead to out-of-bounds DMA memory writes or VPU hangs.
Should this use greater than or equal to (>=) instead?
Quoted 5 lines
drivers/media/v4l2-core/v4l2-ctrls-core.c +5
-0+return -EINVAL ; + +return 0 ; +} +
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
PATCH v2 5/17 media: v4l2-ctrls: validate vp9 tile_rows_log2
In reply to Sofus Forstreuter--- drivers/media/v4l2-core/v4l2-ctrls-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-ctrls-core.c +1 -1
@@ -638,7 +638,7 @@ validate_vp9_frame(struct v4l2_ctrl_vp9_frame *frame)* According to the spec, tile_cols_log2 shall be less than or equal * to 6. */ -if (frame->tile_cols_log2 >6 ) +if (frame->tile_cols_log2 >6 || frame->tile_rows_log2 >2 )return -EINVAL ;if (frame->reference_mode >V4L2_VP9_REFERENCE_MODE_SELECT )
Signature · 1 line
2.55.0
PATCH v2 6/17 media: apple: add avd driver
In reply to Sofus ForstreuterAdd the AVD (Apple Video Decoder) driver with V4L2 M2M stateless support based largely on rockchips implementation.
--- MAINTAINERS | 1 + drivers/media/platform/Kconfig | 1 + drivers/media/platform/Makefile | 1 + drivers/media/platform/apple/Kconfig | 5 + drivers/media/platform/apple/Makefile | 3 + drivers/media/platform/apple/avd/Kconfig | 16 + drivers/media/platform/apple/avd/Makefile | 4 + drivers/media/platform/apple/avd/avd-drv.c | 776 +++++++++++++++++++++++++++ drivers/media/platform/apple/avd/avd-inst.h | 210 ++++++++ drivers/media/platform/apple/avd/avd-v4l2.c | 780 ++++++++++++++++++++++++++++ drivers/media/platform/apple/avd/avd.h | 267 ++++++++++ 11 files changed, 2064 insertions(+)
MAINTAINERS +1 -0
@@ -2676,6 +2676,7 @@ F: drivers/input/touchscreen/apple_z2.c F: drivers/iommu/apple-dart.c F: drivers/iommu/io-pgtable-dart.c F: drivers/irqchip/irq-apple-aic.c +F: drivers/media/platform/apple/* F: drivers/mfd/macsmc.c F: drivers/nvme/host/apple.c F: drivers/nvmem/apple-efuses.c
drivers/media/platform/Kconfig +1 -0
@@ -66,6 +66,7 @@ source "drivers/media/platform/allegro-dvt/Kconfig" source "drivers/media/platform/amd/Kconfig" source "drivers/media/platform/amlogic/Kconfig" source "drivers/media/platform/amphion/Kconfig" +source "drivers/media/platform/apple/Kconfig" source "drivers/media/platform/arm/Kconfig" source "drivers/media/platform/aspeed/Kconfig" source "drivers/media/platform/atmel/Kconfig"
drivers/media/platform/Makefile +1 -0
@@ -9,6 +9,7 @@ obj-y += allegro-dvt/ obj-y += amd/ obj-y += amlogic/ obj-y += amphion/ +obj-y += apple/ obj-y += arm/ obj-y += aspeed/ obj-y += atmel/
drivers/media/platform/apple/Kconfig new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-only + +comment "Apple media platform drivers" + +source "drivers/media/platform/apple/avd/Kconfig"
drivers/media/platform/apple/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-y += avd/
drivers/media/platform/apple/avd/Kconfig new file +16 -0
@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0 + +config VIDEO_APPLE_AVD + tristate "Apple Silicon Video Decoding driver" + depends on VIDEO_DEV + depends on MEDIA_CONTROLLER + depends on ARCH_APPLE || COMPILE_TEST + depends on OF_ADDRESS + depends on V4L_PLATFORM_DRIVERS + select V4L2_MEM2MEM_DEV + select VIDEOBUF2_DMA_CONTIG + help + Support for hardware video decoding on Apple Silicon devices using + the Apple Video Decoder (AVD). + To compile this driver as a module, choose M here: the module will + be called apple-avd.
drivers/media/platform/apple/avd/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-only + +apple-avd-y := avd-drv.o avd-v4l2.o +obj-$(CONFIG_VIDEO_APPLE_AVD) += apple-avd.o
drivers/media/platform/apple/avd/avd-drv.c new file +776 -0
776 lines not on this page · raw message
drivers/media/platform/apple/avd/avd-inst.h new file +210 -0
210 lines not on this page · raw message
drivers/media/platform/apple/avd/avd-v4l2.c new file +780 -0
780 lines not on this page · raw message
drivers/media/platform/apple/avd/avd.h new file +267 -0
267 lines not on this page · raw message
Signature · 1 line
2.55.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 13 potential issue(s) to consider: - [Critical] media: apple: avd: buffer overflow in push() due to missing bounds check - [High] media…
Thank you for your contribution! Sashiko AI review found 13 potential issue(s) to consider:
- [Critical] media: apple: avd: buffer overflow in push() due to missing bounds check
- [High] media: apple: avd: devm_kzalloc of video_device causes Use-After-Free
- [High] media: apple: avd: non-synchronous cancel_delayed_work() causes UAF and deadlock
- [High] media: apple: avd: missing error check in avd_init_job() causes NULL dereference
- [High] media: apple: avd: UAF of m2m_dev in threaded IRQ handler during unbind
- [High] media: apple: avd: off-by-one in AVD_PIODMA_CMD_SIZE causes OOB DMA read
- [High] media: apple: avd: VIDIOC_TRY_FMT mutates internal context state corrupting decodes
- [High] media: apple: avd: missing IS_ERR check on reset control causes panic
- [High] media: apple: avd: race between threaded IRQ and watchdog completes wrong job
- [High] media: apple: avd: avd_stop_streaming reclaims active buffers leading to DMA UAF
- [High] media: apple: avd: missing size validation in avd_boot causes OOB write
- [High] media: apple: avd: device left detached from IOMMU domain after reset
- [Medium] media: apple: avd: unsafe hardware register access in IRQ handler --
commit f9c8639c9bc75cad903911b0f8b6e86b0705207f
Author: Sofus Forstreuter <[email protected]>
media: apple: add avd driver
Add the AVD (Apple Video Decoder) driver with V4L2 M2M stateless support based largely on rockchips implementation.
Quoted 4 lines
drivers/media/platform/apple/avd/avd-drv.c new file +0
-0
[ ... ]
drivers/media/platform/apple/avd/avd-drv.c int avd_end_segment(struct avd_ctx *ctx, bool update_submit) · line 138
Quoted 7 lines
drivers/media/platform/apple/avd/avd-drv.c new file +0
-0@@ -133,14 +133,16 @@ int avd_end_segment(struct avd_ctx *ctx, bool update_submit)struct avd_job *job = &ctx->job;struct avd_segment *seg = &job->segments[job->num];/* avd_segment includes piodma_cmd which is not transferred */ seg->piodma_cmd =AVD_PIODMA_CMD_SIZE ((sizeof (struct avd_segment ) -8 ) /4 );
[Severity: High]
Does this calculation result in an off-by-one error for the command size? The macro AVD_PIODMA_CMD_SIZE appears to expect the transfer size in number of words minus one. Passing the exact word count (512) could cause the hardware to read one word past the end of the segment's instructions array, leading to an out-of-bounds DMA read.
Quoted 2 lines
drivers/media/platform/apple/avd/avd-drv.c new file +0
-0seg->piodma_cmd |=AVD_PIODMA_CMD_DEST (job->dest); seg->piodma_cmd |=AVD_PIODMA_CMD_CONST ;
[ ... ]
Quoted 4 lines
drivers/media/platform/apple/avd/avd-drv.c new file +0
-0@@ -148,15 +150,16 @@ int avd_init_job(struct avd_ctx *ctx, enum avd_codec codec, size_t segments) {int ret =0 ;struct avd_job *job = &ctx->job;
drivers/media/platform/apple/avd/avd-drv.c int avd_init_job(struct avd_ctx *ctx, enum avd_codec codec, size_t segments) · line 162
Quoted 10 lines
drivers/media/platform/apple/avd/avd-drv.c new file +0
-0job->codec = codec; job->dest =0x1000 ; job->num =0 ; job->num_submit =0 ; job->num_alloc = segments; ret =avd_buf_alloc (ctx->dev, &job->buf, job->num_alloc *sizeof (*job->segments)); job->segments = job->buf.cpu;memset (job->buf.cpu,0 , job->buf.size);
[Severity: High]
Can job->buf.cpu be NULL here if the allocation failed?
The return value of avd_buf_alloc is assigned to ret, but it isn't checked before the unconditional memset, which would lead to a NULL pointer dereference under memory pressure.
Quoted 2 lines
drivers/media/platform/apple/avd/avd-drv.c new file +0
-0return ret; }
[ ... ]
Quoted 6 lines
drivers/media/platform/apple/avd/avd-drv.c new file +0
-0@@ -195,30 +198,34 @@ static int avd_boot(struct avd_dev *avd) {u32 val;int ret;char version[64 ];
drivers/media/platform/apple/avd/avd-drv.c static int avd_boot(struct avd_dev *avd) · line 212
Quoted 10 lines
drivers/media/platform/apple/avd/avd-drv.c new file +0
-0if (avd->variant->revision !=3 )dev_info_once (avd->dev,"booting hw version: %04x" ,readl_relaxed (avd->ctrl));writel (avd->sram_start, avd->piodma +0x24 );dev_info_once (avd->dev,"piodma version: %04x base: %08x" ,readl_relaxed (avd->piodma +0xb4 ),readl_relaxed (avd->piodma +0x24 ));memcpy_toio (avd->code, avd->fw->data, avd->fw->size);
[Severity: High]
Is it possible for the firmware size to exceed the mapped IO memory region? Since avd->fw->size is not validated against the resource size of avd->code, an excessively large firmware image could cause an out-of-bounds MMIO write.
Quoted 2 lines
drivers/media/platform/apple/avd/avd-drv.c new file +0
-0writel_relaxed (AVD_MBOX_ENABLE , avd->mbox +AVD_REG_MBOX1_STATUS );
[ ... ]
Quoted 5 lines
drivers/media/platform/apple/avd/avd-drv.c new file +0
-0@@ -235,21 +242,23 @@ static void avd_shutdown(struct avd_dev *avd)static int avd_reset (struct avd_dev *avd) {int ret =0 ;
drivers/media/platform/apple/avd/avd-drv.c static void avd_shutdown(struct avd_dev *avd) · line 255
Quoted 10 lines
drivers/media/platform/apple/avd/avd-drv.c new file +0
-0ret =pm_runtime_resume_and_get (avd->dev);if (ret <0 )return ret; ret =reset_control_reset (avd->rstc);if (ret)dev_err (avd->dev,"reset: failed: %d" , ret);iommu_attach_device (avd->empty_domain, avd->dev);iommu_detach_device (avd->empty_domain, avd->dev);
[Severity: High]
Does this leave the device permanently detached from any functional IOMMU translation context?
By detaching the empty domain without subsequently attaching the working domain (avd->domain), it appears the device is left without an active domain, which could cause IOMMU faults on the next DMA operation.
Quoted 2 lines
drivers/media/platform/apple/avd/avd-drv.c new file +0
-0ret =avd_boot (avd);
[ ... ]
drivers/media/platform/apple/avd/avd-drv.c static void avd_watchdog_func(struct work_struct *work) · line 304
Quoted 9 lines
drivers/media/platform/apple/avd/avd-drv.c new file +0
-0@@ -288,27 +297,32 @@ static void avd_watchdog_func(struct work_struct *work)static irqreturn_t avd_irq_handler (int irq,void *data) {struct avd_dev *avd = data;struct avd_ctx *ctx =v4l2_m2m_get_curr_priv (avd->m2m_dev);enum vb2_buffer_state state;u32 status; status =readl (avd->mbox +AVD_REG_MBOX0_RETRIEVE );
[Severity: Medium]
Could this register read happen while the hardware is suspended? According to the power management guidelines, an IRQ handler shouldn't access hardware registers without first using pm_runtime_get_if_active() to ensure the device isn't in an RPM_SUSPENDED state, which could result in invalid data (0xffffffff) or bus errors during a spurious interrupt.
drivers/media/platform/apple/avd/avd-drv.c static void avd_watchdog_func(struct work_struct *work) · line 315
Quoted 11 lines
drivers/media/platform/apple/avd/avd-drv.c new file +0
-0writel (AVD_MBOX0_NOT_EMPTY , avd->mbox +AVD_REG_MBOX_IRQ_CLR );if (status &0x10000 ) {/* dbg */ dev_warn (avd->dev,"no handler for IRQ: %3d" , status & ~0x10000 );writel_relaxed (0 , avd->mbox +AVD_REG_MBOX_IRQ_ENABLE );return IRQ_HANDLED ; }if (!ctx)return IRQ_HANDLED ;
[Severity: High]
Is it safe to retrieve the context via v4l2_m2m_get_curr_priv(avd->m2m_dev) during teardown, or when a watchdog race occurs?
First, during module unbind (avd_remove), avd_v4l2_cleanup() is called which frees the m2m_dev before the devres-managed IRQ handler is disabled. If an interrupt fires in that window, wouldn't v4l2_m2m_get_curr_priv(avd->m2m_dev) trigger a use-after-free on m2m_dev?
Second, if the watchdog completes a timed-out job and the M2M framework dispatches a new job, a concurrent interrupt for the timed-out job could fetch the newly dispatched job's context here. Calling avd_job_finish(ctx, state) on this new context could prematurely complete it.
Quoted 2 lines
drivers/media/platform/apple/avd/avd-drv.c new file +0
-0if (status &0x1000 ) {
[ ... ]
drivers/media/platform/apple/avd/avd-drv.c static int avd_open(struct file *filp) · line 446
Quoted 6 lines
drivers/media/platform/apple/avd/avd-drv.c new file +0
-0@@ -428,21 +442,22 @@ static int avd_open(struct file *filp)static int avd_release (struct file *filp) {struct avd_ctx *ctx =file_to_ctx (filp);cancel_delayed_work (&ctx->watchdog_work);
[Severity: High]
Can a non-synchronous cancel_delayed_work() leave the watchdog executing while the context is freed?
If the watchdog is executing on another CPU, cancel_delayed_work() returns while the handler runs. The subsequent kfree(ctx) destroys the context, causing a use-after-free in avd_watchdog_func(). Moreover, if the watchdog is blocked from calling avd_job_finish(), v4l2_m2m_ctx_release() could block indefinitely resulting in a deadlock.
Quoted 12 lines
drivers/media/platform/apple/avd/avd-drv.c new file +0
-0v4l2_fh_del (&ctx->fh, filp);v4l2_m2m_ctx_release (ctx->fh.m2m_ctx);v4l2_ctrl_handler_free (&ctx->ctrl_hdl);v4l2_fh_exit (&ctx->fh);avd_buf_free (ctx->dev, &ctx->inst);avd_buf_free (ctx->dev, &ctx->pipe_state);avd_buf_free (ctx->dev, &ctx->job.buf);kfree (ctx);return 0 ; }
[ ... ]
drivers/media/platform/apple/avd/avd-drv.c static int avd_probe(struct platform_device *pdev) · line 525
Quoted 5 lines
drivers/media/platform/apple/avd/avd-drv.c new file +0
-0@@ -507,21 +522,23 @@ static int avd_probe(struct platform_device *pdev)struct avd_dev *avd;int ret, irq; avd =devm_kzalloc (&pdev->dev,sizeof (*avd),GFP_KERNEL );
[Severity: High]
Does allocating the avd structure with devm_kzalloc() create a use-after-free risk when tied to the V4L2 device lifecycle?
The avd structure contains the video_device (avd->vdev). Because it's managed by devres, it gets freed when avd_remove() completes. If a user keeps a file descriptor open, V4L2 core will access the freed video_device memory upon subsequent ioctls or closure.
drivers/media/platform/apple/avd/avd-drv.c static int avd_probe(struct platform_device *pdev) · line 537
Quoted 12 lines
drivers/media/platform/apple/avd/avd-drv.c new file +0
-0if (!avd)return -ENOMEM ;platform_set_drvdata (pdev, avd); avd->dev = &pdev->dev; avd->pdev = pdev;mutex_init (&avd->vdev_lock); avd->variant =of_device_get_match_data (&pdev->dev); avd->rstc =devm_reset_control_get_exclusive (avd->dev,NULL );
[Severity: High]
Could avd->rstc be an ERR_PTR if devm_reset_control_get_exclusive() fails? Without an IS_ERR check, a failure like -EPROBE_DEFER or -ENOMEM would store an ERR_PTR here, which would later cause a kernel panic when dereferenced by reset_control_reset(avd->rstc) in avd_reset().
Quoted 2 lines
drivers/media/platform/apple/avd/avd-drv.c new file +0
-0avd->piodma =devm_platform_ioremap_resource_byname (pdev,"piodma" );
[ ... ]
drivers/media/platform/apple/avd/avd-drv.c static int avd_probe(struct platform_device *pdev) · line 563
Quoted 7 lines
drivers/media/platform/apple/avd/avd-drv.c new file +0
-0@@ -541,20 +558,21 @@ static int avd_probe(struct platform_device *pdev) irq =platform_get_irq_byname (pdev,"mbox0" );if (irq <0 )return irq; ret =devm_request_threaded_irq (&pdev->dev, irq,NULL , avd_irq_handler,IRQF_ONESHOT ,dev_name (&pdev->dev), avd);
[Severity: High]
Does using devm_request_threaded_irq() keep the interrupt alive too long during teardown?
Because devres cleans this up after avd_remove() finishes, an interrupt can fire after avd_v4l2_cleanup() has manually freed m2m_dev, leading to the aforementioned use-after-free in avd_irq_handler().
Quoted 4 lines
drivers/media/platform/apple/avd/avd-drv.c new file +0
-0if (ret) {dev_err (avd->dev,"Could not request IRQ 0" );return ret; }
[ ... ]
drivers/media/platform/apple/avd/avd-drv.c static int avd_probe(struct platform_device *pdev) · line 609
Quoted 6 lines
drivers/media/platform/apple/avd/avd-drv.c new file +0
-0@@ -587,14 +605,15 @@ static int avd_probe(struct platform_device *pdev)static void avd_remove (struct platform_device *pdev) {struct avd_dev *avd =platform_get_drvdata (pdev);avd_v4l2_cleanup (avd);
[Severity: High]
Could this manual cleanup lead to a use-after-free due to the devm_kzalloc() of avd?
Once avd_v4l2_cleanup() and avd_remove() complete, devres reclaims the avd memory. This leaves V4L2 with a dangling pointer to the video_device if file descriptors are still open.
Quoted 7 lines
drivers/media/platform/apple/avd/avd-drv.c new file +0
-0iommu_domain_free (avd->empty_domain);drivers/media/platform/apple/avd/avd-inst.h new file +0
-0
[ ... ]
drivers/media/platform/apple/avd/avd-inst.h static inline void push(struct avd_ctx *ctx, u32 inst) · line 138
Quoted 6 lines
drivers/media/platform/apple/avd/avd-inst.h new file +0
-0@@ -134,14 +134,15 @@ static inline void push(struct avd_ctx *ctx, u32 inst) {struct avd_job *job = &ctx->job;struct avd_segment *seg = &job->segments[job->num]; seg->instructions[seg->num++] = inst;
[Severity: Critical]
Is seg->num bounded against overflowing the instructions array? Without checking if seg->num exceeds AVD_MAX_INST (512), a complex bitstream from userspace could cause an out-of-bounds write. This could overwrite memory like the piodma_cmd of the next segment, potentially injecting arbitrary DMA commands.
Quoted 7 lines
drivers/media/platform/apple/avd/avd-inst.h new file +0
-0}drivers/media/platform/apple/avd/avd-v4l2.c new file +0
-0
[ ... ]
drivers/media/platform/apple/avd/avd-v4l2.c static void avd_fill_decoded_pixfmt(struct avd_ctx *ctx, · line 130
Quoted 11 lines
drivers/media/platform/apple/avd/avd-v4l2.c new file +0
-0@@ -121,21 +121,23 @@ static void avd_fill_decoded_pixfmt(struct avd_ctx *ctx, struct v4l2_pix_format_mplane *pix_mp) {v4l2_fill_pixfmt_mp (pix_mp, pix_mp->pixelformat, pix_mp->width, pix_mp->height);if (is_interchange (pix_mp->pixelformat)) pix_mp->plane_fmt[0 ].sizeimage =0 ; ctx->comp.start_offset = pix_mp->plane_fmt[0 ].sizeimage;fill_comp (&ctx->comp, ctx->image_fmt, pix_mp->width, pix_mp->height);
[Severity: High]
Does this mutate the driver context state during VIDIOC_TRY_FMT? The V4L2 specification explicitly prohibits VIDIOC_TRY_FMT from modifying internal state. Since avd_try_capture_fmt calls this helper, untrusted userspace could probe formats during active streaming and silently corrupt the global ctx->comp state used by avd_run_preamble() for active decodes.
Quoted 1 line
drivers/media/platform/apple/avd/avd-v4l2.c new file +0
-0pix_mp->plane_fmt[0 ].sizeimage += ctx->comp.size;
[ ... ]
drivers/media/platform/apple/avd/avd-v4l2.c static int avd_v4l2_init(struct avd_dev *avd) · line 333
Quoted 12 lines
drivers/media/platform/apple/avd/avd-v4l2.c new file +0
-0@@ -321,18 +323,20 @@ static int avd_v4l2_init(struct avd_dev *avd) avd->mdev.dev = avd->dev;strscpy (avd->mdev.model,"avd" ,sizeof (avd->mdev.model));strscpy (avd->mdev.bus_info,"platform:avd" ,sizeof (avd->mdev.bus_info));media_device_init (&avd->mdev); avd->mdev.ops = &avd_media_ops; avd->v4l2_dev.mdev = &avd->mdev; avd->vdev.lock = &avd->vdev_lock; avd->vdev.v4l2_dev = &avd->v4l2_dev; avd->vdev.fops = &avd_fops; avd->vdev.release = video_device_release_empty;
[Severity: High]
Does setting release to video_device_release_empty bypass standard V4L2 cleanup? Opting out of the standard V4L2 release tracking prevents the core from safely deferring cleanup until the last file descriptor is closed, leading to the use-after-free since the video_device is part of the devm_kzalloc'd avd struct.
Quoted 1 line
drivers/media/platform/apple/avd/avd-v4l2.c new file +0
-0avd->vdev.vfl_dir =VFL_DIR_M2M ;
[ ... ]
Quoted 6 lines
drivers/media/platform/apple/avd/avd-v4l2.c new file +0
-0@@ -495,27 +499,32 @@ static void avd_queue_cleanup(struct vb2_queue *vq, u32 state)static void avd_stop_streaming (struct vb2_queue *q) {struct avd_ctx *ctx =vb2_get_drv_priv (q);if (V4L2_TYPE_IS_OUTPUT (q->type)) {
drivers/media/platform/apple/avd/avd-v4l2.c static void avd_queue_cleanup(struct vb2_queue *vq, u32 state) · line 513
Quoted 10 lines
drivers/media/platform/apple/avd/avd-v4l2.c new file +0
-0const struct avd_coded_fmt_desc *desc = ctx->coded_fmt_desc;if (WARN_ON (!desc))return ;if (desc->ops->stop) desc->ops->stop (ctx); }avd_queue_cleanup (q,VB2_BUF_STATE_ERROR );
[Severity: High]
Is it safe to unconditionally reclaim all buffers while hardware decoding could be active?
When VIDIOC_STREAMOFF invokes avd_stop_streaming(), avd_queue_cleanup() is called without synchronizing against the actively running hardware job. This causes the queues to be abruptly emptied, returning the buffers to vb2. The hardware could continue its DMA into these reclaimed buffers.
Quoted 8 lines
drivers/media/platform/apple/avd/avd-v4l2.c new file +0
-0}const struct vb2_ops avd_queue_ops = { .queue_setup = avd_queue_setup, .buf_prepare = avd_buf_prepare, .buf_queue = avd_buf_queue, .buf_out_validate = avd_buf_out_validate, .buf_request_complete = avd_buf_request_complete,
drivers/media/platform/apple/avd/avd-v4l2.c static void avd_queue_cleanup(struct vb2_queue *vq, u32 state)
Quoted 10 lines
drivers/media/platform/apple/avd/avd-v4l2.c new file +0
-0.start_streaming = avd_start_streaming, .stop_streaming = avd_stop_streaming, };void avd_job_finish_no_pm (struct avd_ctx *ctx,enum vb2_buffer_state result) {if (ctx->coded_fmt_desc->ops->done) {struct vb2_v4l2_buffer *src_buf, *dst_buf; src_buf =v4l2_m2m_next_src_buf (ctx->fh.m2m_ctx);
[Severity: High]
Could v4l2_m2m_next_src_buf() return NULL here if avd_stop_streaming() emptied the queue?
If a stream is closed while the hardware is still active, the queues are cleared by avd_queue_cleanup(). When the hardware job eventually finishes, this attempt to retrieve the source buffer will yield NULL, which will then be passed to desc->ops->done(), causing a NULL pointer dereference.
Quoted 3 lines
drivers/media/platform/apple/avd/avd-v4l2.c new file +0
-0dst_buf =v4l2_m2m_next_dst_buf (ctx->fh.m2m_ctx); ctx->coded_fmt_desc->ops->done (ctx, src_buf, dst_buf, result); }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
PATCH v2 7/17 media: apple: avd: add h264 support
In reply to Sofus ForstreuterThe fluster score is 77/135 for JVT-AVC_V1 and 42/69 for JVT-FR-EXT.
While there are no unexpected test cases. FM1_FT_E, SP1_BT_A and sp2_bt_b still have some unsupported features that are not rejected, which causes the hardware to fault.
--- drivers/media/platform/apple/avd/Kconfig | 1 + drivers/media/platform/apple/avd/Makefile | 2 +- drivers/media/platform/apple/avd/avd-h264.c | 862 ++++++++++++++++++++++++++++ drivers/media/platform/apple/avd/avd-v4l2.c | 72 ++- drivers/media/platform/apple/avd/avd.h | 2 + 5 files changed, 937 insertions(+), 2 deletions(-)
drivers/media/platform/apple/avd/Kconfig +1 -0
@@ -9,6 +9,7 @@ config VIDEO_APPLE_AVD depends on V4L_PLATFORM_DRIVERS select V4L2_MEM2MEM_DEV select VIDEOBUF2_DMA_CONTIG + select V4L2_H264 help Support for hardware video decoding on Apple Silicon devices using the Apple Video Decoder (AVD).
drivers/media/platform/apple/avd/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only -apple-avd-y := avd-drv.o avd-v4l2.o +apple-avd-y := avd-drv.o avd-v4l2.o avd-h264.o obj-$(CONFIG_VIDEO_APPLE_AVD) += apple-avd.o
drivers/media/platform/apple/avd/avd-h264.c new file +862 -0
862 lines not on this page · raw message
drivers/media/platform/apple/avd/avd-v4l2.c +71 -1
78 lines not on this page · raw message
drivers/media/platform/apple/avd/avd.h +2 -0
@@ -242,6 +242,8 @@ void avd_job_finish(struct avd_ctx *ctx, enum vb2_buffer_state result);void avd_run_preamble (struct avd_ctx *ctx,struct avd_run *run);void avd_run_postamble (struct avd_ctx *ctx,struct avd_run *run); +extern const struct avd_coded_fmt_ops avd_h264_fmt_ops; +extern const struct v4l2_ctrl_ops avd_ctrl_ops;extern const struct v4l2_ioctl_ops avd_ioctl_ops;extern const struct vb2_ops avd_queue_ops;
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v2 07/17] media: apple: avd: add h264 support
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [Critical] media: apple: avd: memory exhaustion and OOB write via HOLD_CAPTURE_BUF - [Critical] media…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [Critical] media: apple: avd: memory exhaustion and OOB write via HOLD_CAPTURE_BUF
- [Critical] media: apple: avd: heap buffer overflows due to flawed slice reallocation
- [High] media: apple: avd: integer underflow in slice payload size calculation
- [High] media: apple: avd: OOB read in decode->dpb via unvalidated user index --
commit 10d5fd4b6c8cc892d38453f03a1a8fcb406d63ac
Author: Sofus Forstreuter <[email protected]>
media: apple: avd: add h264 support
The fluster score is 77/135 for JVT-AVC_V1 and 42/69 for JVT-FR-EXT.
While there are no unexpected test cases. FM1_FT_E, SP1_BT_A and sp2_bt_b still have some unsupported features that are not rejected, which causes the hardware to fault.
Quoted 5 lines
drivers/media/platform/apple/avd/avd-h264.c new file +0
-0
[ ... ]
Quoted 2 lines
drivers/media/platform/apple/avd/avd-h264.c new file +2
-0+static void stream_slice (struct avd_ctx *ctx,struct avd_h264_run *run) +{
[ ... ]
drivers/media/platform/apple/avd/avd-h264.c line 404
Quoted 6 lines
drivers/media/platform/apple/avd/avd-h264.c new file +6
-0+u32 payload_len = h264_ctx->active_slice->size; +bool en_mode = (pps->flags &V4L2_H264_PPS_FLAG_ENTROPY_CODING_MODE ) == +0 ; +const u8 *data = h264_ctx->active_slice->cpu; +u32 min_off = (sl->header_bit_size + (en_mode ?0 :7 )) /8 ; +u32 off =2 ;
[Severity: High]
Does this code underflow when calculating the payload size?
The variable off is initialized to 2 here, implying the payload must be at least 2 bytes.
drivers/media/platform/apple/avd/avd-h264.c line 412
Quoted 8 lines
drivers/media/platform/apple/avd/avd-h264.c new file +8
-0+u32 num_ref_idx_active, bytes_read =2 ; +dma_addr_t coded_in, mv_color_addr; +struct avd_decoded_buffer *dst, *ref; + + dst =vb2_to_avd_decoded_buf (&run->base.bufs.dst->vb2_buf); + +if (payload_len < min_off) +return ;
If userspace submits a malformed slice payload with payload_len of 0 or 1, and min_off is 0, this check passes and the early return is bypassed.
[ ... ]
drivers/media/platform/apple/avd/avd-h264.c line 430
Quoted 9 lines
drivers/media/platform/apple/avd/avd-h264.c new file +9
-0+ coded_in = h264_ctx->active_slice->addr + off; + +push (AVD_OP_CODED_DATA | +AVD_OP_CODED_DATA_BIT_OFF ( + en_mode ? (sl->header_bit_size %8 ) :0 ) | +AVD_OP_CODED_IN_HI (coded_in), +"slc_a7c_cmd_set_coded_slice" ); +push (AVD_OP_CODED_IN_LO (coded_in),"slc_a84_slice_addr_low" ); +push (payload_len - off,"slc_a88_slice_hdr_size" );
If payload_len was less than off, payload_len - off would underflow yielding 0xFFFFFFFF, which is then pushed to the hardware ring.
Could this cause an arbitrarily large out-of-bounds DMA read by the hardware?
[ ... ]
drivers/media/platform/apple/avd/avd-h264.c line 505
Quoted 7 lines
drivers/media/platform/apple/avd/avd-h264.c new file +7
-0+if (sl->slice_type ==V4L2_H264_SLICE_TYPE_B ) { + +/* sl->ref_pic_list1[0].index < ARRAY_SIZE(decode->dpb) */ +/* bidirectional reference of previous mv */ + ref =avd_get_ref_buf ( + ctx, &dst->base.vb, + decode->dpb[sl->ref_pic_list1[0 ].index].reference_ts);
[Severity: High]
Does this allow out-of-bounds memory reads from the decode->dpb array?
If sl->ref_pic_list1[0].index comes from unvalidated user input, it might exceed the bounds of the decode->dpb array (size 16).
Could this potentially cause a crash or leak kernel state?
[ ... ]
Quoted 2 lines
drivers/media/platform/apple/avd/avd-h264.c new file +2
-0+static int avd_h264_realloc_slices (struct avd_ctx *ctx) +{
[ ... ]
drivers/media/platform/apple/avd/avd-h264.c line 687
Quoted 3 lines
drivers/media/platform/apple/avd/avd-h264.c new file +3
-0+ alloc_slice_num = (h264_ctx->alloc_slice_num *3 ) /2 ; + h264_ctx->slices = +kzalloc_objs (*h264_ctx->slices, alloc_slice_num,GFP_KERNEL );
[Severity: Critical]
Is it possible for the array growth calculation to fail to increase capacity?
If h264_ctx->alloc_slice_num is initially 1, (1 * 3) / 2 evaluates to 1, meaning the capacity never grows.
[ ... ]
drivers/media/platform/apple/avd/avd-h264.c line 712
Quoted 5 lines
drivers/media/platform/apple/avd/avd-h264.c new file +5
-0+ job->segments = tmp_buf.cpu; + job->num_alloc = (alloc_slice_num +1 ); +memset (tmp_buf.cpu,0 , tmp_buf.size); +memcpy (job->segments, job->buf.cpu, +sizeof (*job->segments) * (job->num +1 ));
Does this copy operation overflow the buffers?
If job->num is equal to the allocated capacity, job->num + 1 will exceed the allocated capacity, causing a read past the source buffer and a write past the destination buffer.
[ ... ]
Quoted 2 lines
drivers/media/platform/apple/avd/avd-h264.c new file +2
-0+static int avd_h264_run (struct avd_ctx *ctx) +{
[ ... ]
drivers/media/platform/apple/avd/avd-h264.c line 743
Quoted 6 lines
drivers/media/platform/apple/avd/avd-h264.c new file +6
-0+if (ctx->job.segments && + h264_ctx->slice_num >= h264_ctx->alloc_slice_num) { + ret =avd_h264_realloc_slices (ctx); +if (ret) + goto postamble; + }
[Severity: Critical]
Could this condition inadvertently skip reallocation and cause an out-of-bounds array access?
If userspace submits a slice with V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF, and avd_init_job is not called because is_new_frame evaluates to false, ctx->job.segments remains NULL.
The reallocation logic would then be silently skipped.
drivers/media/platform/apple/avd/avd-h264.c line 745
Quoted 2 lines
drivers/media/platform/apple/avd/avd-h264.c new file +2
-0+ + h264_ctx->active_slice = &h264_ctx->slices[h264_ctx->slice_num];
And then h264_ctx->slices is accessed unconditionally here, which would be out of bounds if reallocation was bypassed, or if the capacity failed to grow in avd_h264_realloc_slices.
[ ... ]
Quoted 5 lines
drivers/media/platform/apple/avd/avd-h264.c new file +5
-0+static void avd_h264_done (struct avd_ctx *ctx,struct vb2_v4l2_buffer *src_buf, +struct vb2_v4l2_buffer *dst_buf, +enum vb2_buffer_state result) +{ +struct avd_dev *avd = ctx->dev;
drivers/media/platform/apple/avd/avd-h264.c line 812
Quoted 10 lines
drivers/media/platform/apple/avd/avd-h264.c new file +10
-0+struct avd_h264_ctx *h264_ctx = ctx->priv; +int i; + +if (!(src_buf->flags &V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF )) { +for (i =0 ; i < h264_ctx->slice_num; i++) +avd_buf_free (avd, &h264_ctx->slices[i]); + h264_ctx->slice_num =0 ; + ctx->job.segments =NULL ; + } +}
Is it possible for abandoned frames to never get their slices freed?
If userspace repeatedly submits slices with the V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF flag, the cleanup here is bypassed.
Could this lead to memory exhaustion?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
PATCH v2 8/17 media: apple: avd: add vp9 support
In reply to Sofus ForstreuterThe fluster scores is 216/305 for VP9-TEST-VECTORS and 1/6 for VP9-TEST-VECTORS-HIGH.
--- drivers/media/platform/apple/avd/Kconfig | 1 + drivers/media/platform/apple/avd/Makefile | 2 +- drivers/media/platform/apple/avd/avd-v4l2.c | 37 + drivers/media/platform/apple/avd/avd-vp9.c | 1054 +++++++++++++++++++++++++++ drivers/media/platform/apple/avd/avd.h | 10 + 5 files changed, 1103 insertions(+), 1 deletion(-)
drivers/media/platform/apple/avd/Kconfig +1 -0
@@ -10,6 +10,7 @@ config VIDEO_APPLE_AVD select V4L2_MEM2MEM_DEV select VIDEOBUF2_DMA_CONTIG select V4L2_H264 + select V4L2_VP9 help Support for hardware video decoding on Apple Silicon devices using the Apple Video Decoder (AVD).
drivers/media/platform/apple/avd/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only -apple-avd-y := avd-drv.o avd-v4l2.o avd-h264.o +apple-avd-y := avd-drv.o avd-v4l2.o avd-h264.o avd-vp9.o obj-$(CONFIG_VIDEO_APPLE_AVD) += apple-avd.o
drivers/media/platform/apple/avd/avd-v4l2.c +37 -0
@@ -255,6 +255,29 @@ static const struct avd_ctrls avd_h264_ctrls = { .num_ctrls = ARRAY_SIZE(avd_h264_ctrl_descs), }; +static const struct avd_ctrl_desc avd_vp9_ctrl_descs[] = { + { + .cfg.id =V4L2_CID_STATELESS_VP9_FRAME , + .cfg.ops = &avd_ctrl_ops, + }, + { + .cfg.id =V4L2_CID_STATELESS_VP9_COMPRESSED_HDR , + }, + { + .cfg.id =V4L2_CID_MPEG_VIDEO_VP9_PROFILE , + .cfg.min =V4L2_MPEG_VIDEO_VP9_PROFILE_0 , + .cfg.max =V4L2_MPEG_VIDEO_VP9_PROFILE_2 , + .cfg.menu_skip_mask = +BIT (V4L2_MPEG_VIDEO_VP9_PROFILE_1 ), + .cfg.def =V4L2_MPEG_VIDEO_VP9_PROFILE_0 , + }, +}; + +static const struct avd_ctrls avd_vp9_ctrls = { + .ctrls = avd_vp9_ctrl_descs, + .num_ctrls =ARRAY_SIZE (avd_vp9_ctrl_descs), +}; +static const struct avd_coded_fmt_desc avd_coded_fmts[] = { { .fourcc =V4L2_PIX_FMT_H264_SLICE ,
@@ -271,6 +294,20 @@ static const struct avd_coded_fmt_desc avd_coded_fmts[] = { .subsystem_flags = VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF, .capability = AVD_CAPABILITY_H264, }, + { + .fourcc = V4L2_PIX_FMT_VP9_FRAME, + .frmsize = { + .min_width = 64, + .max_width = 16384, + .step_width = 64, + .min_height = 64, + .max_height = 16384, + .step_height = 16, + }, + .ctrls = &avd_vp9_ctrls, + .ops = &avd_vp9_fmt_ops, + .capability = AVD_CAPABILITY_VP9, + }, };static bool avd_is_capable (struct avd_ctx *ctx,unsigned int capability)
drivers/media/platform/apple/avd/avd-vp9.c new file +1054 -0
1,054 lines not on this page · raw message
drivers/media/platform/apple/avd/avd.h +10 -0
@@ -98,6 +98,12 @@ struct avd_ctrls {unsigned int num_ctrls; }; +struct avd_vp9_decoded_buffer_info { +unsigned short width; +unsigned short height; +unsigned int bit_depth :4 ; +}; +struct avd_comp {u32 size;/* offset to start of compressed data */
@@ -110,6 +116,9 @@ struct avd_decoded_buffer {/* Must be the first field in this struct. */ struct v4l2_m2m_buffer base;struct avd_comp comp; +union { +struct avd_vp9_decoded_buffer_info vp9; + }; }; static inline struct avd_decoded_buffer *
@@ -243,6 +252,7 @@ void avd_run_preamble(struct avd_ctx *ctx, struct avd_run *run);void avd_run_postamble (struct avd_ctx *ctx,struct avd_run *run);extern const struct avd_coded_fmt_ops avd_h264_fmt_ops; +extern const struct avd_coded_fmt_ops avd_vp9_fmt_ops;extern const struct v4l2_ctrl_ops avd_ctrl_ops;extern const struct v4l2_ioctl_ops avd_ioctl_ops;
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v2 08/17] media: apple: avd: add vp9 support
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Critical] media: apple: avd: integer underflow in set_tiles() leads to out-of-bounds DMA read --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] media: apple: avd: integer underflow in set_tiles() leads to out-of-bounds DMA read --
commit dea68a18dd2979fd1f45ba84519d873291b90e56
Author: Sofus Forstreuter <[email protected]>
media: apple: avd: add vp9 support
This commit introduces hardware VP9 decoding support for the Apple Video Decoder (AVD). It achieves a fluster score of 216/305 for VP9-TEST-VECTORS.
Quoted 5 lines
drivers/media/platform/apple/avd/avd-vp9.c new file +0
-0
[ ... ]
Quoted 16 lines
drivers/media/platform/apple/avd/avd-vp9.c new file +16
-0+static int set_tiles (struct avd_ctx *ctx,struct avd_vp9_run *run) +{ +const struct v4l2_ctrl_vp9_frame *frame = run->decode_params; +struct vb2_v4l2_buffer *src =v4l2_m2m_next_src_buf (ctx->fh.m2m_ctx); +const u8 *data =vb2_plane_vaddr (&src->vb2_buf,0 ); +unsigned long plane_payload =vb2_get_plane_payload (&src->vb2_buf,0 ); +u32 offset = + frame->uncompressed_header_size + frame->compressed_header_size; +u32 num_tile_rows =1 << frame->tile_rows_log2; +u32 num_tile_cols =1 << frame->tile_cols_log2; +u32 tile_size, size; +dma_addr_t coded_in; + +if (plane_payload < offset) +return -EINVAL ; + size = plane_payload - offset;
drivers/media/platform/apple/avd/avd-vp9.c line 478
Quoted 10 lines
drivers/media/platform/apple/avd/avd-vp9.c new file +10
-0+ +/* 6.2.6 Compute image size syntax */ +u32 sb_64_cols = (((frame->frame_width_minus_1 +8 ) >>3 ) +7 ) >>3 ; +u32 sb_64_rows = (((frame->frame_height_minus_1 +8 ) >>3 ) +7 ) >>3 ; + +for (int row =0 ; row < num_tile_rows; row++) +for (int col =0 ; col < num_tile_cols; col++) { +if (row == num_tile_rows -1 && + col == num_tile_cols -1 ) { + tile_size = size;
[Severity: Critical]
Could an underflowed size be assigned to tile_size here?
If size underflowed in a previous iteration, this assignment could result in a massive out-of-bounds DMA read by the VPU when tile_size is pushed to the hardware command buffer.
drivers/media/platform/apple/avd/avd-vp9.c line 483
Quoted 5 lines
drivers/media/platform/apple/avd/avd-vp9.c new file +5
-0+ }else { +if (offset > plane_payload) +return -EINVAL ; + tile_size =get_unaligned_be32 (&data[offset]); +if (tile_size > size -4 )
[Severity: Critical]
Does this code underflow size if the remaining payload is less than 4 bytes?
If a userspace caller provides a VP9 frame payload where plane_payload has only 1 to 3 bytes remaining after offset, the offset > plane_payload check evaluates to false. This allows get_unaligned_be32() to read out of bounds. The unsigned arithmetic size - 4 would then underflow to a large value, causing the size validation to incorrectly pass and permanently underflowing size for subsequent tile loops.
Quoted 4 lines
drivers/media/platform/apple/avd/avd-vp9.c new file +4
-0+return -EINVAL ; + offset +=4 ; + size -=4 ; + }
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
PATCH v2 9/17 media: apple: avd: add hevc support
In reply to Sofus ForstreuterThe fluster score is 143/147 for JCT-VC-HEVC_V1.
RPS_E_qualcomm_5, WPP_D_ericsson_MAIN_2 and WPP_D_ericsson_MAIN10_2 are failing, but should be supported.
--- drivers/media/platform/apple/avd/Makefile | 2 +- drivers/media/platform/apple/avd/avd-hevc.c | 1340 +++++++++++++++++++++++++++ drivers/media/platform/apple/avd/avd-v4l2.c | 72 ++ drivers/media/platform/apple/avd/avd.h | 6 + 4 files changed, 1419 insertions(+), 1 deletion(-)
drivers/media/platform/apple/avd/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only -apple-avd-y := avd-drv.o avd-v4l2.o avd-h264.o avd-vp9.o +apple-avd-y := avd-drv.o avd-v4l2.o avd-h264.o avd-vp9.o avd-hevc.o obj-$(CONFIG_VIDEO_APPLE_AVD) += apple-avd.o
drivers/media/platform/apple/avd/avd-hevc.c new file +1340 -0
1,340 lines not on this page · raw message
drivers/media/platform/apple/avd/avd-v4l2.c +72 -0
84 lines not on this page · raw message
drivers/media/platform/apple/avd/avd.h +6 -0
@@ -104,6 +104,10 @@ struct avd_vp9_decoded_buffer_info { unsigned int bit_depth : 4; }; +struct avd_hevc_decoded_buffer_info { +bool is_intra; +}; +struct avd_comp {u32 size;/* offset to start of compressed data */
@@ -118,6 +122,7 @@ struct avd_decoded_buffer {struct avd_comp comp;union {struct avd_vp9_decoded_buffer_info vp9; +struct avd_hevc_decoded_buffer_info hevc; }; };
@@ -252,6 +257,7 @@ void avd_run_preamble(struct avd_ctx *ctx, struct avd_run *run);void avd_run_postamble (struct avd_ctx *ctx,struct avd_run *run);extern const struct avd_coded_fmt_ops avd_h264_fmt_ops; +extern const struct avd_coded_fmt_ops avd_hevc_fmt_ops;extern const struct avd_coded_fmt_ops avd_vp9_fmt_ops;extern const struct v4l2_ctrl_ops avd_ctrl_ops;
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v2 09/17] media: apple: avd: add hevc support
Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider: - [Critical] avd: heap buffer overflow due to missing array bounds validation on pps->column_width_minus1…
Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider:
- [Critical] avd: heap buffer overflow due to missing array bounds validation on pps->column_width_minus1
- [High] avd: kernel panic and buffer overflow via unbounded sps->log2_diff shift
- [High] avd: kernel stack out-of-bounds read via unbounded pos variable in stream_slices
- [High] avd: double out-of-bounds array read in stream_slice_mv via sl->collocated_ref_idx
- [High] avd: heap out-of-bounds read via off-by-one check on slice_segment_addr
- [High] avd: arbitrary physical DMA read via integer underflow in slice size offset validation
- [High] avd: use-after-free and out-of-bounds read due to lockless dereference of V4L2 dynamic array pointers
- [High] avd: integer overflow in entry point offset validation allows heap out-of-bounds read
- [Medium] avd: hardware register corruption due to overlapping bitmasks for HEVC_TR_INTRA and HEVC_TR_INTER --
commit a7dbbf6a1924ee26ecce4f5c5b73414f86b42959
Author: Sofus Forstreuter <[email protected]>
media: apple: avd: add hevc support
The fluster score is 143/147 for JCT-VC-HEVC_V1.
RPS_E_qualcomm_5, WPP_D_ericsson_MAIN_2 and WPP_D_ericsson_MAIN10_2 are failing, but should be supported.
Quoted 6 lines
drivers/media/platform/apple/avd/avd-hevc.c new file +0
-0@@ -0,0 +1,1340 @@
[ ... ]
drivers/media/platform/apple/avd/avd-hevc.c line 28
Quoted 2 lines
drivers/media/platform/apple/avd/avd-hevc.c new file +2
-0+#define HEVC_TR_INTRA (v) FIELD_PREP(GENMASK(4, 1), v) +#define HEVC_TR_INTER (v) FIELD_PREP(GENMASK(7, 4), v)
[Severity: Medium]
Do these bitmasks overlap? It looks like both GENMASK(4, 1) and GENMASK(7, 4) include bit 4. When these are ORed together in set_header() like so:
HEVC_TR_INTER(sps->max_transform_hierarchy_depth_inter) | HEVC_TR_INTRA(sps->max_transform_hierarchy_depth_intra) |
could this clobber the overlapping bit and misconfigure the hardware decoder?
[ ... ]
Quoted 62 lines
drivers/media/platform/apple/avd/avd-hevc.c new file +62
-0+static void stream_slice_mv (struct avd_ctx *ctx,struct avd_hevc_run *run, +const struct v4l2_ctrl_hevc_slice_params *sl, +bool is_first) +{ +const struct v4l2_ctrl_hevc_decode_params *decode = run->decode; +struct avd_decoded_buffer *dst, *ref; +bool ref_valid; +const u8 *ref_list; +int ref_idx =0 ; + + ref_list = sl->slice_type ==V4L2_HEVC_SLICE_TYPE_P ? sl->ref_idx_l0 : + sl->flags &V4L2_HEVC_SLICE_PARAMS_FLAG_COLLOCATED_FROM_L0 ? + sl->ref_idx_l0 : + sl->ref_idx_l1; + +if (sl->slice_type ==V4L2_HEVC_SLICE_TYPE_I ) { +push (AVD_OP_SL_REF | +AVD_OP_SL_REF_SLICE_I (sl->slice_type == +V4L2_HEVC_SLICE_TYPE_I ), +"slc_a8c_cmd_ref_type" ); +return ; + } +/* bidirectional prediction */ +if (sl->collocated_ref_idx <V4L2_HEVC_DPB_ENTRIES_NUM_MAX && + ref_list[sl->collocated_ref_idx] <V4L2_HEVC_DPB_ENTRIES_NUM_MAX ) + ref_idx = ref_list[sl->collocated_ref_idx]; + + dst =vb2_to_avd_decoded_buf (&run->base.bufs.dst->vb2_buf); + ref =avd_get_ref_buf (ctx, &dst->base.vb, + decode->dpb[ref_idx].timestamp); + + ref_valid = !(sl->flags & +V4L2_HEVC_SLICE_PARAMS_FLAG_DEPENDENT_SLICE_SEGMENT ) && + (sl->flags & +V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_TEMPORAL_MVP_ENABLED ) && + is_first && !ref->hevc.is_intra; + +push (AVD_OP_SL_REF | +AVD_OP_SL_REF_MAX_MERGE ( +5 - sl->five_minus_max_num_merge_cand) | +AVD_OP_SL_REF_FLAG_CABAC ( + sl->flags & +V4L2_HEVC_SLICE_PARAMS_FLAG_CABAC_INIT ) | +AVD_OP_SL_REF_FLAG0 ( + (sl->flags & +V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_TEMPORAL_MVP_ENABLED ) && + !(sl->flags & +V4L2_HEVC_SLICE_PARAMS_FLAG_COLLOCATED_FROM_L0 )) | +AVD_OP_SL_REF_FLAG1 ( + !(sl->flags & +V4L2_HEVC_SLICE_PARAMS_FLAG_MVD_L1_ZERO )) | +AVD_OP_SL_REF_FLAG2 ( + (sl->flags & +V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_TEMPORAL_MVP_ENABLED ) || + (sl->flags & +V4L2_HEVC_SLICE_PARAMS_FLAG_DEPENDENT_SLICE_SEGMENT )) | +AVD_OP_SL_REF_NUM_L0 (sl->num_ref_idx_l0_active_minus1) | +AVD_OP_SL_REF_NUM_L1 (sl->num_ref_idx_l1_active_minus1) | +AVD_OP_SL_REF_SLICE_P (sl->slice_type == +V4L2_HEVC_SLICE_TYPE_P ) | +AVD_OP_SL_REF_SLICE_B (ref_valid), +"slc_a8c_cmd_ref_type" );
drivers/media/platform/apple/avd/avd-hevc.c line 626
Quoted 10 lines
drivers/media/platform/apple/avd/avd-hevc.c new file +10
-0+ +if (ref_valid) { +dma_addr_t mv_color_addr = +vb2_dma_contig_plane_dma_addr (&ref->base.vb.vb2_buf, +0 ) + + (ref->base.vb.planes[0 ].length - +mv_color_size (fmt_width (ctx),fmt_height (ctx))); +pusha (mv_color_addr,"slc_bd4_sps_tile_addr2_lsb8" , + decode->dpb[ref_list[sl->collocated_ref_idx]] + .pic_order_cnt_val);
[Severity: High]
Is it possible to have an out-of-bounds read here?
If sl->collocated_ref_idx (which is controlled by userspace) is >= 16 (V4L2_HEVC_DPB_ENTRIES_NUM_MAX), it seems to bypass the initial bounds check which updates ref_idx. Later, when pushing the command:
decode->dpb[ref_list[sl->collocated_ref_idx]]
could this read ref_list out-of-bounds, yielding a garbage index, and then subsequently use that to read out-of-bounds in decode->dpb, programming arbitrary memory values into the hardware?
Quoted 2 lines
drivers/media/platform/apple/avd/avd-hevc.c new file +2
-0+ } +}
[ ... ]
Quoted 21 lines
drivers/media/platform/apple/avd/avd-hevc.c new file +21
-0+static int submit_slice_segment (struct avd_ctx *ctx,struct avd_hevc_run *run, +const struct v4l2_ctrl_hevc_slice_params *sl, +int row,int col,u32 col_bd[23 ], +u32 row_bd[23 ],u32 pic_in_cts_width, +u32 pic_in_cts_height,bool first_slice, +bool hflip,bool vflip,u32 coded_flags, +u32 last_tile_block) +{ +const struct v4l2_ctrl_hevc_pps *pps = run->pps; +u32 tb_x, tb_y, tile_block, tile_boundary; + +if (coded_flags &NEW_SLICE ) { + tb_x = sl->slice_segment_addr % pic_in_cts_width; + tb_y = sl->slice_segment_addr / pic_in_cts_width; + + tile_block =AVD_OP_SL_LOC_Y (tb_y) |AVD_OP_SL_LOC_X (tb_x); + +if (!(sl->flags & +V4L2_HEVC_SLICE_PARAMS_FLAG_DEPENDENT_SLICE_SEGMENT )) + last_tile_block = tile_block; +
drivers/media/platform/apple/avd/avd-hevc.c line 672
Quoted 10 lines
drivers/media/platform/apple/avd/avd-hevc.c new file +10
-0+/* +* tile block start +* CABAC window +*/ +push (AVD_OP_SL_LOC | last_tile_block,"cm3_cmd_set_cabac_xy" ); + +stream_slice_dqtblk (ctx, run, sl); + }else { + tile_boundary =AVD_OP_SL_LOC_Y (row_bd[row]) | +AVD_OP_SL_LOC_X (col_bd[col]);
[Severity: High]
Can the 'row' index here exceed the bounds of the 45-element row_bd kernel stack array?
In stream_slices(), the row index is calculated from an unbounded 'pos' counter which increments for each entry point offset:
row = pos / num_cols; col = pos % num_cols;
Since there can be up to 1760 entry point offsets, 'row' is not bounded against 44. Could this result in an out-of-bounds stack read?
Quoted 1 line
drivers/media/platform/apple/avd/avd-hevc.c new file +1
-0+ }
[ ... ]
Quoted 6 lines
drivers/media/platform/apple/avd/avd-hevc.c new file +6
-0+static void compute_tiles_non_uniform (struct avd_hevc_run *run, +u16 log2_min_cb_size,u16 width, +u16 height,u32 pic_in_cts_width, +u32 pic_in_cts_height,u16 *column_width, +u16 *row_height) +{
drivers/media/platform/apple/avd/avd-hevc.c line 743
Quoted 10 lines
drivers/media/platform/apple/avd/avd-hevc.c new file +10
-0+const struct v4l2_ctrl_hevc_pps *pps = run->pps; +u32 sum =0 ; +int i; + +for (i =0 ; i < pps->num_tile_columns_minus1; i++) { + column_width[i] =MIN (pps->column_width_minus1[i] +1 , + pic_in_cts_width); + sum += column_width[i]; + } + column_width[i] = pic_in_cts_width - sum;
[Severity: Critical]
Does this code overflow column_width_minus1[] and also underflow column_width[i]?
The validation allows pps->num_tile_columns_minus1 up to 39, but the V4L2 payload array column_width_minus1 only has 20 elements. This could cause an out-of-bounds read of the struct.
Additionally, since sum is not validated, if sum exceeds pic_in_cts_width, does pic_in_cts_width - sum underflow into a huge unsigned 16-bit integer?
This huge dimension seems to propagate into compute_bd() and compute_tile_ids(), potentially causing thousands of out-of-bounds memory writes on the kernel heap when indexing ctb_addr_rs_to_ts and tile_ids.
Quoted 2 lines
drivers/media/platform/apple/avd/avd-hevc.c new file +2
-0+ + sum =0 ;
[ ... ]
Quoted 40 lines
drivers/media/platform/apple/avd/avd-hevc.c new file +40
-0+static void stream_slices (struct avd_ctx *ctx,struct avd_hevc_run *run) +{ +const struct v4l2_ctrl_hevc_sps *sps = run->sps; +const struct v4l2_ctrl_hevc_pps *pps = run->pps; +const struct v4l2_ctrl_hevc_slice_params *sl; +struct avd_hevc_tile_info *tile_info = &run->tile_info; +bool tiles_enabled, first_slice, first_segment; +bool hflip, vflip; +int slice_segment_offset, entry_point_idx =0 , pos =0 , offset =0 ; +int row, col, i, s, to; +int slice_flag, size, new_offset; +int tile_id, last_tile_id; +u16 log2_min_cb_size, width, height; +u32 max_cu_width, pic_in_ctbs_width, pic_in_ctbs_height; +u32 pic_in_ctbs_size, num_cols, last_tile_block =0 ; +struct sl_ctx last = { + .q1_col =-1 , + .q1_row =-1 , + }; + + width = sps->pic_width_in_luma_samples; + height = sps->pic_height_in_luma_samples; + + tiles_enabled = !!(pps->flags &V4L2_HEVC_PPS_FLAG_TILES_ENABLED ); + + log2_min_cb_size = sps->log2_min_luma_coding_block_size_minus3 +3 ; + + num_cols = pps->num_tile_columns_minus1 +1 ; + + max_cu_width =1 << (sps->log2_diff_max_min_luma_coding_block_size + + log2_min_cb_size); + pic_in_ctbs_width = (width + max_cu_width -1 ) / max_cu_width; + pic_in_ctbs_height = (height + max_cu_width -1 ) / max_cu_width; + pic_in_ctbs_size = pic_in_ctbs_width * pic_in_ctbs_height; + +for (s =0 ; s < run->num_slices; s++) { + sl = &(*run->sl)[s]; + slice_segment_offset =0 ; + +/* entry_points are not needed for WPP */
drivers/media/platform/apple/avd/avd-hevc.c line 871
Quoted 10 lines
drivers/media/platform/apple/avd/avd-hevc.c new file +10
-0+ to = tiles_enabled ? sl->num_entry_point_offsets +1 :1 ; + +for (i =0 ; i < to; i++) { + first_segment = i ==0 ; + first_slice = s ==0 ; + +if (tiles_enabled && to >1 ) { +if (i < sl->num_entry_point_offsets) { + size = (*run->entry_point_offsets) + [entry_point_idx++];
[Severity: High]
Is it safe to locklessly dereference the V4L2 dynamic array pointer here?
In avd_hevc_run_preamble(), the pointer to the dynamic array control is cached without acquiring the V4L2 state lock:
run->entry_point_offsets = ctrl ? (const u32 **)&ctrl->p_cur.p : NULL; ... run->sl = ctrl ? (const struct v4l2_ctrl_hevc_slice_params **)&ctrl->p_cur.p : NULL;
If a concurrent VIDIOC_S_EXT_CTRLS ioctl reallocates the array to a smaller size while the decoder is running, *run->entry_point_offsets will point to the new smaller array, but the cached bounds will remain large, leading to out-of-bounds heap reads here. Also, dereferencing p_cur.p concurrently while it is being freed could trigger a Use-After-Free.
[Severity: High]
Does this code allow an integer overflow during validation?
In avd_hevc_run_preamble(), the total number of entry points is accumulated into a signed 32-bit int:
for (i = 0; i < run->num_slices; i++) sum += (*run->sl)[i].num_entry_point_offsets;
If userspace provides extremely large num_entry_point_offsets, could this sum wrap around and exactly match run->num_entry_point_offsets to bypass the validation? If so, entry_point_idx could iterate out-of-bounds and read past the end of the allocated entry_point_offsets array here.
drivers/media/platform/apple/avd/avd-hevc.c line 883
Quoted 12 lines
drivers/media/platform/apple/avd/avd-hevc.c new file +12
-0+ new_offset = size; + }else { + size = sl->bit_size /8 - + sl->data_byte_offset - + slice_segment_offset; + new_offset = + size + sl->data_byte_offset; + } + }else { + size = (sl->bit_size) /8 - + sl->data_byte_offset; + new_offset = size + sl->data_byte_offset;
[Severity: High]
Can the subtraction here trigger an integer underflow?
Userspace could supply sl->data_byte_offset or entry point offsets such that they exceed sl->bit_size / 8. This would cause an underflow, resulting in a huge integer for 'size'.
When set_slice() is called:
dma_addr_t coded_in = run->base.coded_in + offset + sl->data_byte_offset;
this uncontrolled size, alongside an unvalidated memory address, is programmed into the hardware, potentially causing it to perform arbitrary DMA memory reads.
drivers/media/platform/apple/avd/avd-hevc.c line 891
Quoted 8 lines
drivers/media/platform/apple/avd/avd-hevc.c new file +8
-0+ } + +if (sl->slice_segment_addr > pic_in_ctbs_size) +return ; + + tile_id = tile_info->tile_ids + [tile_info->ctb_addr_rs_to_ts + [sl->slice_segment_addr]];
[Severity: High]
Does this validation allow an off-by-one error?
Because it checks for > rather than >=, could sl->slice_segment_addr exactly equal pic_in_ctbs_size, leading to a heap out-of-bounds read of ctb_addr_rs_to_ts? The resulting garbage value might then be used to read tile_ids out-of-bounds.
Quoted 1 line
drivers/media/platform/apple/avd/avd-hevc.c new file +1
-0+ last_tile_id =
[ ... ]
Quoted 8 lines
drivers/media/platform/apple/avd/avd-hevc.c new file +8
-0+static int avd_hevc_compute_tiles (struct avd_ctx *ctx,struct avd_hevc_run *run) +{ +const struct v4l2_ctrl_hevc_sps *sps = run->sps; +const struct v4l2_ctrl_hevc_pps *pps = run->pps; +bool tiles_enabled; +struct avd_hevc_tile_info *tile_info = &run->tile_info; +u16 log2_min_cb_size, width, height; + u32 max_cu_width, pic_in_ctbs_width, pic_in_ctbs_height,
drivers/media/platform/apple/avd/avd-hevc.c line 1151
Quoted 10 lines
drivers/media/platform/apple/avd/avd-hevc.c new file +10
-0+ pic_in_ctbs_size; + + width = sps->pic_width_in_luma_samples; + height = sps->pic_height_in_luma_samples; + + log2_min_cb_size = sps->log2_min_luma_coding_block_size_minus3 +3 ; + + max_cu_width =1 << (sps->log2_diff_max_min_luma_coding_block_size + + log2_min_cb_size); + pic_in_ctbs_width = (width + max_cu_width -1 ) / max_cu_width;
[Severity: High]
Does this code permit an unbounded bit shift?
Userspace provides sps->log2_diff_max_min_luma_coding_block_size and sps->log2_min_luma_coding_block_size_minus3 without bounds checking. If their sum exceeds 31, the shift will result in undefined behavior. This could yield 0, triggering a zero division on the very next line.
Alternatively, if it evaluates to a huge value (like 1 << 30), could this overflow the 32-bit math during scratch allocations in avd_hevc_alloc_scratch() like so:
ret = avd_buf_alloc(avd, &hevc_ctx->bufs.ip_above, ((max_col * max_cu_width) / 4) * bit_depth);
causing it to wrap around to a dangerously small size, leading to hardware memory corruption?
Quoted 2 lines
drivers/media/platform/apple/avd/avd-hevc.c new file +2
-0+ pic_in_ctbs_height = (height + max_cu_width -1 ) / max_cu_width; + pic_in_ctbs_size = pic_in_ctbs_height * pic_in_ctbs_width;
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
PATCH v2 10/17 media: apple: avd: add av1 support
In reply to Sofus ForstreuterAVD only supports decoding AV1 on newer SoCs, it does not support film grain.
The entropymode files are adapted from
commit c0d0e579db4e ("media: verisilicon: Add AV1 entropy helpers") with some extra tables being added and some tables being changed a bit.
The fluster score is 238/242 for AV1-TEST-VECTORS.
--- drivers/media/platform/apple/avd/Makefile | 3 +- .../media/platform/apple/avd/avd-av1-entropymode.c | 4698 ++++++++++++++++++++ .../media/platform/apple/avd/avd-av1-entropymode.h | 284 ++ drivers/media/platform/apple/avd/avd-av1.c | 1432 ++++++ drivers/media/platform/apple/avd/avd-v4l2.c | 33 + drivers/media/platform/apple/avd/avd.h | 14 + 6 files changed, 6463 insertions(+), 1 deletion(-)
drivers/media/platform/apple/avd/Makefile +2 -1
@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -apple-avd-y := avd-drv.o avd-v4l2.o avd-h264.o avd-vp9.o avd-hevc.o +apple-avd-y := avd-drv.o avd-v4l2.o avd-h264.o avd-vp9.o avd-hevc.o avd-av1.o \ + avd-av1-entropymode.o obj-$(CONFIG_VIDEO_APPLE_AVD) += apple-avd.o
drivers/media/platform/apple/avd/avd-av1-entropymode.c new file +4698 -0
2,994 lines not on this page · raw message
drivers/media/platform/apple/avd/avd-av1-entropymode.h new file +284 -0
284 lines not on this page · raw message
drivers/media/platform/apple/avd/avd-av1.c new file +1432 -0
1,432 lines not on this page · raw message
drivers/media/platform/apple/avd/avd-v4l2.c +33 -0
Lines of this file are not shown. View the raw message.
drivers/media/platform/apple/avd/avd.h +14 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.55.0
Part of the diff is not shown here. View the raw message.
[email protected]
AI reviewRe: [PATCH v2 10/17] media: apple: avd: add av1 support
Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider: - [Critical] media: avd: av1: Unvalidated frame dimensions lead to integer overflows and OOB DMA access…
Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider:
- [Critical] media: avd: av1: Unvalidated frame dimensions lead to integer overflows and OOB DMA access
- [High] media: avd: av1: AV1_LF_SHARPNESS bitmask overlaps with loop filter delta macros
- [High] media: avd: av1: Unvalidated ref_frame_idx causes OOB read from reference_frame_ts array
- [High] media: avd: av1: Missing tile_cols/tile_rows validation causes off-by-one OOB access and overflows
- [High] media: avd: av1: Hardware accesses physical address 0x0 for unallocated auxiliary buffers
- [High] media: avd: av1: NULL pointer dereference from unchecked vb2_plane_vaddr()
- [Medium] media: avd: av1: Fallback logic copies uninitialized CDF memory from the destination buffer
- [Medium] media: avd: av1: Incorrect global motion shear calculation rejects valid negative alpha parameters
- [Low] media: avd: av1: Lockless read of active V4L2 controls risks torn parameters
--
commit 803772d649afcd58e4fdefb6bd3047324fac968b
Author: Sofus Forstreuter <[email protected]>
media: apple: avd: add av1 support
This commit adds AV1 decoding support to the Apple Video Decoder (AVD) driver. It includes entropy mode helpers, V4L2 format definitions, and the main decoding flow for AV1 frames.
Quoted 6 lines
drivers/media/platform/apple/avd/avd-av1.c new file +0
-0@@ -0,0 +1,1432 @@
[ ... ]
drivers/media/platform/apple/avd/avd-av1.c line 158
Quoted 10 lines
drivers/media/platform/apple/avd/avd-av1.c new file +10
-0+#define AV1_LF_DELTA_ENABLED (v) FIELD_PREP(BIT(27), !!(v)) +#define AV1_LF_DELTA_MULTI (v) FIELD_PREP(BIT(28), !!(v)) +#define AV1_LF_DELTA_PRESENT (v) FIELD_PREP(BIT(31), !!(v)) +#define AV1_LF_DELTA_RES (v) FIELD_PREP(GENMASK(30, 29), v) +#define AV1_LF_LV3 (v) FIELD_PREP(GENMASK(5, 0), v) +#define AV1_LF_LV2 (v) FIELD_PREP(GENMASK(11, 6), v) +#define AV1_LF_LV1 (v) FIELD_PREP(GENMASK(17, 12), v) +#define AV1_LF_LV0 (v) FIELD_PREP(GENMASK(23, 18), v) + +#define AV1_LF_SHARPNESS (v) FIELD_PREP(GENMASK(31, 28), v)
[Severity: High]
Does this bitmask overlap with the loop filter delta macros? It looks like bits 28 through 31 are shared with AV1_LF_DELTA_MULTI, AV1_LF_DELTA_RES, and AV1_LF_DELTA_PRESENT, which could cause the hardware to be misconfigured when both are used in set_header().
[ ... ]
drivers/media/platform/apple/avd/avd-av1.c line 304
Quoted 11 lines
drivers/media/platform/apple/avd/avd-av1.c new file +11
-0+static void +avd_av1_dec_get_shear_params (const u32 *params,s64 *alpha, +s64 *beta,s64 *gamma,s64 *delta) +{ +const int *mat = params; +short shift; +short y; +long long gv, dv; + +if (mat[2 ] <=0 ) +return ;
[Severity: Medium]
Will this improperly reject valid negative alpha parameters? According to the AV1 specification, the transform calculation should only abort if the alpha coefficient (mat[2]) is exactly zero to avoid division by zero.
[ ... ]
drivers/media/platform/apple/avd/avd-av1.c line 582
Quoted 12 lines
drivers/media/platform/apple/avd/avd-av1.c new file +12
-0+static void set_ref_hdr (struct avd_ctx *ctx,struct avd_av1_run *run) +{ +const struct v4l2_ctrl_av1_frame *frame = run->frame; +u8 ref_slots[7 ] = {1 ,2 ,3 ,4 ,5 ,6 ,7 }; +int sign_bias =0 ; +int ref_slot =0 ; +int i, j; + +/* point to the first index where the frames equal */ +for (i =0 ; i <6 ; i++) { +for (j = i +1 ; j <7 ; j++) { + if (frame->reference_frame_ts[frame->ref_frame_idx[i]] ==
[Severity: High]
Can an unvalidated ref_frame_idx from userspace cause an out-of-bounds read here? The V4L2 framework does not natively bounds-check ref_frame_idx against V4L2_AV1_TOTAL_REFS_PER_FRAME (8), which might allow a payload to index out of the reference_frame_ts array.
[ ... ]
drivers/media/platform/apple/avd/avd-av1.c line 620
Quoted 11 lines
drivers/media/platform/apple/avd/avd-av1.c new file +11
-0+/* 7.16. Upscaling process */ +static void calc_upscale (int frame_width,int upscaled_width,int sub_x, +int *step_x,int *initial_subpel_x) +{ +int downscaled_plane_w, upscaled_plane_w, err; + + downscaled_plane_w =AV1_DIV_ROUND_UP_POW2 (frame_width, sub_x); + upscaled_plane_w =AV1_DIV_ROUND_UP_POW2 (upscaled_width, sub_x); + *step_x = ((downscaled_plane_w <<SUPERRES_SCALE_BITS ) + + (upscaled_plane_w /2 )) / + upscaled_plane_w;
[Severity: Critical]
Could a maliciously crafted frame with an upscaled_width of 0 result in a division by zero panic here? There doesn't appear to be a prior non-zero check on the upscaled dimensions.
[ ... ]
Quoted 2 lines
drivers/media/platform/apple/avd/avd-av1.c new file +2
-0+static void set_header (struct avd_ctx *ctx,struct avd_av1_run *run) +{
[ ... ]
drivers/media/platform/apple/avd/avd-av1.c line 817
Quoted 4 lines
drivers/media/platform/apple/avd/avd-av1.c new file +4
-0+pusha (run->addresses.probs_out,"probs_out" ,0 ); +pusha (av1_ctx->bufs.probs.addr,"probs" ,1 ); +pusha (av1_ctx->bufs.above_info.addr,"col" ,0 ); +pusha (av1_ctx->bufs.seg.addr,"seg" ,0 );
[Severity: High]
Is it possible for the hardware to access physical address 0x0 here? The bufs.seg buffer is only allocated in avd_av1_alloc_work_bufs() if V4L2_AV1_SEGMENTATION_FLAG_UPDATE_MAP is set. If segmentation is enabled but UPDATE_MAP is not set, this unconditionally pushes a 0 address to the hardware, which might cause an IOMMU fault.
[ ... ]
Quoted 14 lines
drivers/media/platform/apple/avd/avd-av1.c new file +14
-0+static int set_tiles (struct avd_ctx *ctx,struct avd_av1_run *run) +{ +const struct v4l2_ctrl_av1_frame *frame = run->frame; +const struct v4l2_ctrl_av1_sequence *seq = run->seq; +const struct v4l2_ctrl_av1_tile_group_entry *tile_group; +const struct v4l2_av1_tile_info *tile_info = &frame->tile_info; +dma_addr_t coded_in; +int row, col, sb_row, sb_col, tile_id, tile_row, tile_col; +int sb_shift = + seq->flags &V4L2_AV1_SEQUENCE_FLAG_USE_128X128_SUPERBLOCK ?5 : +4 ; + +for (row =0 ; row < tile_info->tile_rows; row++) { +for (col =0 ; col < tile_info->tile_cols; col++) {
drivers/media/platform/apple/avd/avd-av1.c line 1006
Quoted 10 lines
drivers/media/platform/apple/avd/avd-av1.c new file +10
-0+ tile_id = row * tile_info->tile_cols + col; + tile_group = &run->tile_group[tile_id]; + coded_in = run->base.coded_in + + tile_group->tile_offset; + tile_row = tile_group->tile_row; + tile_col = tile_group->tile_col; + +if (tile_col >V4L2_AV1_MAX_TILE_COLS || + tile_row >V4L2_AV1_MAX_TILE_ROWS ) +return -EINVAL ;
[Severity: High]
Does this strict greater-than check allow an off-by-one out-of-bounds access? If tile_col is exactly V4L2_AV1_MAX_TILE_COLS (64), it bypasses this check and would read exactly at the bounds of the width_in_sbs_minus_1 array below.
[ ... ]
Quoted 17 lines
drivers/media/platform/apple/avd/avd-av1.c new file +17
-0+push (AVD_SL_DIM_END_ROW ( + !(frame->flags & +V4L2_AV1_FRAME_FLAG_DISABLE_FRAME_END_UPDATE_CDF ) && + tile_id == + tile_info->context_update_tile_id ? +8 : +0 ) | +AVD_SL_DIM_END_COL (col) | +AVD_SL_DIM_END_Y ( + sb_row + + tile_info->height_in_sbs_minus_1 + [tile_row]) | +AVD_SL_DIM_END_X ( + sb_col + + tile_info->width_in_sbs_minus_1 + [tile_col]), +"tile_op_end" );
[ ... ]
Quoted 2 lines
drivers/media/platform/apple/avd/avd-av1.c new file +2
-0+static void avd_av1_set_prob (struct avd_ctx *ctx,struct avd_av1_run *run) +{
[ ... ]
Quoted 4 lines
drivers/media/platform/apple/avd/avd-av1.c new file +4
-0+if (error_resilient_mode || frame_is_intra || + run->frame->primary_ref_frame ==7 ) { +avd_av1_default_coeff_probs (run->frame->quantization.base_q_idx, + av1_ctx->bufs.probs.cpu);
drivers/media/platform/apple/avd/avd-av1.c line 1074
Quoted 10 lines
drivers/media/platform/apple/avd/avd-av1.c new file +10
-0+avd_av1_set_default_cdfs (av1_ctx->bufs.probs.cpu); + }else { + ref =avd_av1_get_ref_buf (ctx, run, + run->frame->primary_ref_frame); +memcpy (av1_ctx->bufs.probs.cpu, +vb2_plane_vaddr (&ref->base.vb.vb2_buf,0 ) + +AVD_AV1_CDFS_OFFSET ( + ref->base.vb.vb2_buf.planes[0 ].length, + ref->av1.color_size), +sizeof (struct avd_av1_cdfs ));
[Severity: High]
Is it safe to use vb2_plane_vaddr() without checking for a NULL return? If userspace provides a buffer via V4L2_MEMORY_DMABUF that cannot be mapped into the kernel virtual address space, this will result in a NULL pointer dereference.
[Severity: Medium]
If avd_av1_get_ref_buf() cannot find the reference and falls back to returning the destination buffer (dst), does this copy uninitialized CDF memory from the current uninitialized frame?
[Severity: Critical]
Because avd_color_size() lacks unvalidated dimension protection from avd_av1_try_ctrl(), could malicious frame dimensions cause an integer overflow, forcing the AVD_AV1_CDFS_OFFSET macro to underflow and generate an arbitrary DMA offset? This would result in out-of-bounds kernel memory corruption during the memcpy.
[ ... ]
drivers/media/platform/apple/avd/avd-av1.c line 1129
Quoted 11 lines
drivers/media/platform/apple/avd/avd-av1.c new file +11
-0+static int avd_av1_run_preamble (struct avd_ctx *ctx,struct avd_av1_run *run) +{ +struct v4l2_ctrl *ctrl; +int dst_len, tlb_len; + +avd_run_preamble (ctx, &run->base); + + ctrl =v4l2_ctrl_find (&ctx->ctrl_hdl,V4L2_CID_STATELESS_AV1_SEQUENCE ); +if (WARN_ON (!ctrl)) +return -EINVAL ; + run->seq = ctrl->p_cur.p;
[Severity: Low]
Could a lockless read of the active V4L2 control here lead to torn parameters if userspace concurrently modifies the control via VIDIOC_S_EXT_CTRLS while the decoder workqueue is running?
[ ... ]
Quoted 8 lines
drivers/media/platform/apple/avd/avd-av1.c new file +8
-0+static int avd_av1_alloc_work_bufs (struct avd_ctx *ctx,struct avd_av1_run *run) +{ +struct avd_dev *avd = ctx->dev; +struct avd_av1_ctx *av1_ctx = ctx->priv; +const struct v4l2_ctrl_av1_frame *frame = run->frame; +const struct v4l2_ctrl_av1_sequence *seq = run->seq; +const struct v4l2_av1_tile_info *tile_info = &frame->tile_info; + u32 ret, max_sb_col = 0, max_sb_row = 0, i, sb_cols1 = 0, sb_cols2 = 0,
drivers/media/platform/apple/avd/avd-av1.c line 1175
Quoted 10 lines
drivers/media/platform/apple/avd/avd-av1.c new file +10
-0+ sb; +u32 w = frame->frame_width_minus_1 +1 ; +u32 h = frame->frame_height_minus_1 +1 ; +u8 sb_shift = + seq->flags &V4L2_AV1_SEQUENCE_FLAG_USE_128X128_SUPERBLOCK ?1 : +0 ; +u8 bit_depth = seq->bit_depth; + +for (i =0 ; i < tile_info->tile_cols; i++) { + sb = tile_info->width_in_sbs_minus_1[i] +1 ;
[Severity: High]
Since tile_cols can be up to 256, does this read past the end of the 64-element width_in_sbs_minus_1 array? It seems this could result in out-of-bounds reads and drastically undersized work buffer allocations if it overflows.
[ ... ]
drivers/media/platform/apple/avd/avd-av1.c line 1423
Quoted 8 lines
drivers/media/platform/apple/avd/avd-av1.c new file +8
-0+static int avd_av1_try_ctrl (struct avd_ctx *ctx,struct v4l2_ctrl *ctrl) +{ +if (ctrl->id ==V4L2_CID_STATELESS_AV1_SEQUENCE ) +return avd_av1_validate_sequence (ctx, + ctrl->p_new.p_av1_sequence); +/* width should also be > 8 */ +return 0 ; +}
[Severity: Critical]
Should we validate the AV1 frame dimensions against the negotiated queue format here? Unvalidated dimensions lead to the integer overflows in calc_upscale() and avd_color_size() mentioned earlier, resulting in OOB DMA accesses.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
PATCH v2 11/17 arm64: dts: apple: t8103: add avd nodes
In reply to Sofus Forstreuter--- arch/arm64/boot/dts/apple/t8103.dtsi | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
arch/arm64/boot/dts/apple/t8103.dtsi +32 -0
@@ -984,6 +984,38 @@ pinctrl_aop: pinctrl@24a820000 { <AIC_IRQ 274 IRQ_TYPE_LEVEL_HIGH>; }; + avd_dart: iommu@269010000 { + compatible = "apple,t8103-dart"; + reg = <0x2 0x69010000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = <AIC_IRQ 547 IRQ_TYPE_LEVEL_HIGH>; + #iommu-cells = <1>; + power-domains = <&ps_avd_sys>; + }; + + video-codec@269070000 { + compatible = "apple,t8103-avd"; + reg = <0x2 0x69070000 0x0 0x4000>, + <0x2 0x69080000 0x0 0xc000>, + <0x2 0x6908c000 0x0 0xc000>, + <0x2 0x69098000 0x0 0x4000>, + <0x2 0x69100000 0x0 0x10000>; + reg-names = "piodma", "code", "sram", "mbox", "ctrl"; + interrupt-parent = <&aic>; + interrupts = <AIC_IRQ 540 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 541 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 542 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 543 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 544 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 545 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 546 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "mbox0", "mbox1", "mbox2", "mbox3", + "flag0", "flag1", "piodma"; + iommus = <&avd_dart 0>, <&avd_dart 1>; + power-domains = <&ps_avd_sys>; + resets = <&ps_avd_sys>; + }; + ans_mbox: mbox@277408000 { compatible = "apple,t8103-asc-mailbox", "apple,asc-mailbox-v4"; reg = <0x2 0x77408000 0x0 0x4000>;
Signature · 1 line
2.55.0
PATCH v2 12/17 arm64: dts: apple: t8112: add avd nodes
In reply to Sofus Forstreuter--- arch/arm64/boot/dts/apple/t8112.dtsi | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
arch/arm64/boot/dts/apple/t8112.dtsi +32 -0
@@ -987,6 +987,38 @@ pinctrl_aop: pinctrl@24a820000 { <AIC_IRQ 307 IRQ_TYPE_LEVEL_HIGH>; }; + avd_dart: iommu@269010000 { + compatible = "apple,t8110-dart"; + reg = <0x2 0x69010000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = <AIC_IRQ 674 IRQ_TYPE_LEVEL_HIGH>; + #iommu-cells = <1>; + power-domains = <&ps_avd_sys>; + }; + + video-codec@269070000 { + compatible = "apple,t8112-avd"; + reg = <0x2 0x69070000 0x0 0x4000>, + <0x2 0x69080000 0x0 0x10000>, + <0x2 0x69090000 0x0 0x10000>, + <0x2 0x690a0000 0x0 0x4000>, + <0x2 0x69100000 0x0 0x10000>; + reg-names = "piodma", "code", "sram", "mbox", "ctrl"; + interrupt-parent = <&aic>; + interrupts = <AIC_IRQ 667 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 668 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 669 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 670 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 671 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 672 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 673 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "mbox0", "mbox1", "mbox2", "mbox3", + "flag0", "flag1", "piodma"; + iommus = <&avd_dart 0>, <&avd_dart 1>; + power-domains = <&ps_avd_sys>; + resets = <&ps_avd_sys>; + }; + ans_mbox: mbox@277408000 { compatible = "apple,t8112-asc-mailbox", "apple,asc-mailbox-v4"; reg = <0x2 0x77408000 0x0 0x4000>;
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v2 12/17] arm64: dts: apple: t8112: add avd nodes
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] media: apple: null pointer dereference in avd_init_job() on allocation failure - [High] media…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] media: apple: null pointer dereference in avd_init_job() on allocation failure
- [High] media: apple: use-after-free of avd_ctx in avd_watchdog_func()
- [Low] media: v4l2: off-by-one error allows out-of-bounds context_update_tile_id
- [Low] dt-bindings: media: apple,avd: missing t8132 and t8140 compatible strings --
commit 55c4cd1f1e93f6dcc1e853c4ea8a083b87538669
Author: Sofus Forstreuter <[email protected]>
arm64: dts: apple: t8112: add avd nodes
This patch series adds the Apple Video Decoder (AVD) driver to support stateless video decoding on newer Apple SoCs.
Quoted 5 lines
Documentation/devicetree/bindings/media/apple,avd.yaml new file +0
-0
[ ... ]
Quoted 4 lines
Documentation/devicetree/bindings/media/apple,avd.yaml new file +4
-0+properties: + compatible: + oneOf: + - items:
Documentation/devicetree/bindings/media/apple,avd.yaml
Quoted 10 lines
Documentation/devicetree/bindings/media/apple,avd.yaml new file +10
-0+ - enum: + - apple,t6030-avd + - apple,t6031-avd + - const: apple,t8122-avd + - enum: + - apple,t8103-avd + - apple,t8112-avd + - apple,t8122-avd + - apple,t6000-avd + - apple,t6020-avd
[Severity: Low]
Do the dt-bindings miss the apple,t8132-avd and apple,t8140-avd compatible strings?
The AVD driver explicitly registers support for apple,t8132-avd and apple,t8140-avd via the avd_of_match array in avd-drv.c.
Because the device tree binding schema documentation omits these compatible strings, validating device trees that contain these hardware variants fails with a dt-schema validation error.
[ ... ]
Quoted 5 lines
drivers/media/platform/apple/avd/avd-drv.c new file +0
-0
[ ... ]
Quoted 4 lines
drivers/media/platform/apple/avd/avd-drv.c new file +4
-0+int avd_init_job (struct avd_ctx *ctx,enum avd_codec codec,size_t segments) +{ +int ret =0 ; +struct avd_job *job = &ctx->job;
drivers/media/platform/apple/avd/avd-drv.c
Quoted 10 lines
drivers/media/platform/apple/avd/avd-drv.c new file +10
-0+ + job->codec = codec; + job->dest =0x1000 ; + job->num =0 ; + job->num_submit =0 ; + job->num_alloc = segments; + ret =avd_buf_alloc (ctx->dev, &job->buf, + job->num_alloc *sizeof (*job->segments)); + job->segments = job->buf.cpu; +memset (job->buf.cpu,0 , job->buf.size);
[Severity: High]
Is there a risk of a null pointer dereference of job->buf.cpu on allocation failure?
If avd_buf_alloc() fails and returns -ENOMEM, it leaves job->buf.cpu as null. Since the return value assigned to ret is not checked, the subsequent memset() will unconditionally use the null pointer.
This path is reachable from userspace by submitting decode jobs, meaning memory pressure could induce a kernel panic.
Quoted 2 lines
drivers/media/platform/apple/avd/avd-drv.c new file +2
-0+return ret; +}
[ ... ]
drivers/media/platform/apple/avd/avd-drv.c
Quoted 12 lines
drivers/media/platform/apple/avd/avd-drv.c new file +12
-0+static void avd_watchdog_func (struct work_struct *work) +{ +struct avd_dev *avd; +struct avd_ctx *ctx; +int ret; + + ctx = container_of(to_delayed_work(work), struct avd_ctx, + watchdog_work); +if (!ctx) +return ; + + avd = ctx->dev;
[Severity: High]
Could this result in a use-after-free of ctx if it runs concurrently with avd_release()?
In avd_release(), cancel_delayed_work() is used to stop the watchdog timer, which doesn't block if the work is currently executing on another CPU. Following this, avd_release() frees the context:
avd-drv.c:avd_release() {
...
cancel_delayed_work(&ctx->watchdog_work);
...
kfree(ctx);
}If avd_watchdog_func() is running concurrently, won't it dereference the freed ctx pointer when accessing ctx->dev?
This race condition can be triggered by closing the video device while a decoding timeout occurs, resulting in memory corruption or a kernel panic.
[ ... ]
Quoted 17 lines
drivers/media/platform/apple/avd/avd-drv.c new file +17
-0+static int avd_release (struct file *filp) +{ +struct avd_ctx *ctx =file_to_ctx (filp); + +cancel_delayed_work (&ctx->watchdog_work); + +v4l2_fh_del (&ctx->fh, filp); +v4l2_m2m_ctx_release (ctx->fh.m2m_ctx); +v4l2_ctrl_handler_free (&ctx->ctrl_hdl); +v4l2_fh_exit (&ctx->fh); +avd_buf_free (ctx->dev, &ctx->inst); +avd_buf_free (ctx->dev, &ctx->pipe_state); +avd_buf_free (ctx->dev, &ctx->job.buf); +kfree (ctx); + +return 0 ; +}
[ ... ]
Quoted 4 lines
drivers/media/v4l2-core/v4l2-ctrls-core.c +0
-0
[ ... ]
drivers/media/v4l2-core/v4l2-ctrls-core.c static int validate_av1_film_grain(struct v4l2_ctrl_av1_film_grain *fg) · line 809
Quoted 11 lines
drivers/media/v4l2-core/v4l2-ctrls-core.c +7
-0@@ -800,10 +800,25 @@ static int validate_av1_film_grain(struct v4l2_ctrl_av1_film_grain *fg)return 0 ; } +static int validate_av1_tile_info (struct v4l2_av1_tile_info *ti) +{ +if (ti->tile_cols >V4L2_AV1_MAX_TILE_COLS || + ti->tile_rows >V4L2_AV1_MAX_TILE_ROWS ) +return -EINVAL ; + +if (ti->context_update_tile_id > ti->tile_cols * ti->tile_rows)
[Severity: Low]
Does this check allow an out-of-bounds context_update_tile_id to pass validation?
Since context_update_tile_id is a 0-based index for the tiles, an ID exactly equal to ti->tile_cols * ti->tile_rows is out-of-bounds.
Shouldn't this check use >= instead of > to properly enforce the AV1 bitstream specification, which mandates that context_update_tile_id must be strictly less than TileCols * TileRows?
This allows an invalid tile ID to be passed to hardware drivers, which could result in undefined logic or hardware state.
Quoted 4 lines
drivers/media/v4l2-core/v4l2-ctrls-core.c +4
-0+return -EINVAL ; + +return 0 ; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
PATCH v2 13/17 arm64: dts: apple: t8122: add avd nodes
In reply to Sofus Forstreuter--- arch/arm64/boot/dts/apple/t8122.dtsi | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
arch/arm64/boot/dts/apple/t8122.dtsi +32 -0
@@ -186,6 +186,38 @@ soc { /* Required to get >32-bit DMA via DARTs */ dma-ranges = <0 0 0 0 0xffffffff 0xffffc000>; + avd_dart: iommu@289010000 { + compatible = "apple,t8122-dart", "apple,t8110-dart"; + reg = <0x2 0x89010000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = <AIC_IRQ 686 IRQ_TYPE_LEVEL_HIGH>; + #iommu-cells = <1>; + power-domains = <&ps_avd_sys>; + }; + + video-codec@289070000 { + compatible = "apple,t8122-avd"; + reg = <0x2 0x89070000 0x0 0x4000>, + <0x2 0x89080000 0x0 0x10000>, + <0x2 0x89090000 0x0 0x14000>, + <0x2 0x890a4000 0x0 0x4000>, + <0x2 0x89100000 0x0 0x10000>; + reg-names = "piodma", "code", "sram", "mbox", "ctrl"; + interrupt-parent = <&aic>; + interrupts = <AIC_IRQ 679 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 680 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 681 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 682 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 683 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 684 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 685 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "mbox0", "mbox1", "mbox2", "mbox3", + "flag0", "flag1", "piodma"; + iommus = <&avd_dart 0>, <&avd_dart 1>; + power-domains = <&ps_avd_sys>; + resets = <&ps_avd_sys>; + }; + i2c0: i2c@2a1010000 { compatible = "apple,t8122-i2c", "apple,t8103-i2c"; reg = <0x2 0xa1010000 0x0 0x4000>;
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v2 13/17] arm64: dts: apple: t8122: add avd nodes
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Missing DT binding documentation for apple,t8122-dart --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Missing DT binding documentation for apple,t8122-dart
--
commit c017f32bf6e48954134742ab315013310a3424f7
Author: Sofus Forstreuter <[email protected]>
arm64: dts: apple: t8122: add avd nodes
This commit adds the AVD (Apple Video Decoder) and its associated DART IOMMU nodes to the t8122 device tree.
arch/arm64/boot/dts/apple/t8122.dtsi soc { · line 190
Quoted 10 lines
arch/arm64/boot/dts/apple/t8122.dtsi +2
-0@@ -186,6 +186,38 @@ soc { /* Required to get >32-bit DMA via DARTs */ dma-ranges = <0 0 0 0 0xffffffff 0xffffc000>; + avd_dart: iommu@289010000 { + compatible = "apple,t8122-dart", "apple,t8110-dart";
[Severity: Low]
Is this compatible string missing from the DT bindings schema?
Schema validation tools like dtbs_check will emit a warning because apple,t8122-dart is not defined. While this has no runtime effect since the kernel can safely match on the documented fallback string apple,t8110-dart, should this string be documented in the bindings?
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
PATCH v2 14/17 arm64: dts: apple: t600x: add avd nodes
In reply to Sofus Forstreuter--- arch/arm64/boot/dts/apple/t600x-dieX.dtsi | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
arch/arm64/boot/dts/apple/t600x-dieX.dtsi +32 -0
@@ -24,6 +24,38 @@ DIE_NODE(cpufreq_p1): cpufreq@212e20000 { #performance-domain-cells = <0>; }; + DIE_NODE(avd_dart): iommu@287010000 { + compatible = "apple,t8110-dart"; + reg = <0x2 0x87010000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = <AIC_IRQ DIE_NO 1018 IRQ_TYPE_LEVEL_HIGH>; + #iommu-cells = <1>; + power-domains = <&DIE_NODE(ps_avd_sys)>; + }; + + video-codec@287070000 { + compatible = "apple,t6000-avd"; + reg = <0x2 0x87070000 0x0 0x4000>, + <0x2 0x87080000 0x0 0x10000>, + <0x2 0x87090000 0x0 0x10000>, + <0x2 0x870a0000 0x0 0x4000>, + <0x2 0x87100000 0x0 0x10000>; + reg-names = "piodma", "code", "sram", "mbox", "ctrl"; + interrupt-parent = <&aic>; + interrupts = <AIC_IRQ DIE_NO 1011 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ DIE_NO 1012 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ DIE_NO 1013 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ DIE_NO 1014 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ DIE_NO 1015 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ DIE_NO 1016 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ DIE_NO 1017 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "mbox0", "mbox1", "mbox2", "mbox3", + "flag0", "flag1", "piodma"; + iommus = <&DIE_NODE(avd_dart) 0>, <&DIE_NODE(avd_dart) 1>; + power-domains = <&DIE_NODE(ps_avd_sys)>; + resets = <&DIE_NODE(ps_avd_sys)>; + }; + DIE_NODE(pmgr): power-management@28e080000 { compatible = "apple,t6000-pmgr", "apple,pmgr", "syscon", "simple-mfd"; #address-cells = <1>;
Signature · 1 line
2.55.0
PATCH v2 15/17 arm64: dts: apple: t602x: add avd nodes
In reply to Sofus Forstreuter--- arch/arm64/boot/dts/apple/t602x-dieX.dtsi | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
arch/arm64/boot/dts/apple/t602x-dieX.dtsi +32 -0
@@ -23,6 +23,38 @@ DIE_NODE(cpufreq_p1): cpufreq@212e20000 { #performance-domain-cells = <0>; }; + DIE_NODE(avd_dart): iommu@287010000 { + compatible = "apple,t6020-dart", "apple,t8110-dart"; + reg = <0x2 0x87010000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = <AIC_IRQ DIE_NO 1095 IRQ_TYPE_LEVEL_HIGH>; + #iommu-cells = <1>; + power-domains = <&DIE_NODE(ps_avd_sys)>; + }; + + video-codec@287070000 { + compatible = "apple,t6020-avd"; + reg = <0x2 0x87070000 0x0 0x4000>, + <0x2 0x87080000 0x0 0x10000>, + <0x2 0x87090000 0x0 0x10000>, + <0x2 0x870a0000 0x0 0x4000>, + <0x2 0x87100000 0x0 0x10000>; + reg-names = "piodma", "code", "sram", "mbox", "ctrl"; + interrupt-parent = <&aic>; + interrupts = <AIC_IRQ DIE_NO 1088 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ DIE_NO 1089 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ DIE_NO 1090 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ DIE_NO 1091 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ DIE_NO 1092 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ DIE_NO 1093 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ DIE_NO 1094 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "mbox0", "mbox1", "mbox2", "mbox3", + "flag0", "flag1", "piodma"; + iommus = <&DIE_NODE(avd_dart) 0>, <&DIE_NODE(avd_dart) 1>; + power-domains = <&DIE_NODE(ps_avd_sys)>; + resets = <&DIE_NODE(ps_avd_sys)>; + }; + DIE_NODE(pmgr): power-management@28e080000 { compatible = "apple,t6020-pmgr", "apple,t8103-pmgr", "syscon", "simple-mfd"; #address-cells = <1>;
Signature · 1 line
2.55.0
PATCH v2 16/17 arm64: dts: apple: t6030: add avd nodes
In reply to Sofus Forstreuter--- arch/arm64/boot/dts/apple/t6030.dtsi | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
arch/arm64/boot/dts/apple/t6030.dtsi +32 -0
@@ -361,6 +361,38 @@ pmgr_gfx: power-management@290e80000 { /* child nodes are added in t6030-pmgr.dtsi */ }; + avd_dart: iommu@30b010000 { + compatible = "apple,t6030-dart", "apple,t8110-dart"; + reg = <0x3 0x0b010000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = <AIC_IRQ 795 IRQ_TYPE_LEVEL_HIGH>; + #iommu-cells = <1>; + power-domains = <&ps_avd_sys>; + }; + + video-codec@30b070000 { + compatible = "apple,t6030-avd", "apple,t8122-avd"; + reg = <0x3 0x0b070000 0x0 0x4000>, + <0x3 0x0b080000 0x0 0x10000>, + <0x3 0x0b090000 0x0 0x14000>, + <0x3 0x0b0a4000 0x0 0x4000>, + <0x3 0x0b100000 0x0 0x10000>; + reg-names = "piodma", "code", "sram", "mbox", "ctrl"; + interrupt-parent = <&aic>; + interrupts = <AIC_IRQ 788 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 789 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 790 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 791 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 792 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 793 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ 794 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "mbox0", "mbox1", "mbox2", "mbox3", + "flag0", "flag1", "piodma"; + iommus = <&avd_dart 0>, <&avd_dart 1>; + power-domains = <&ps_avd_sys>; + resets = <&ps_avd_sys>; + }; + pinctrl_ap: pinctrl@347100000 { compatible = "apple,t6030-pinctrl", "apple,t8103-pinctrl"; reg = <0x3 0x47100000 0x0 0x4000>;
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v2 16/17] arm64: dts: apple: t6030: add avd nodes
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] dt-bindings: undocumented compatible string 'apple,t6030-dart' --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] dt-bindings: undocumented compatible string 'apple,t6030-dart'
--
commit a86b2ab51c200171749c5b4ddd9cf551f1bd6ec3
Author: Sofus Forstreuter <[email protected]>
arm64: dts: apple: t6030: add avd nodes
This commit adds the AVD DART and video codec nodes to the Apple T6030 devicetree.
arch/arm64/boot/dts/apple/t6030.dtsi pmgr_gfx: power-management@290e80000 { · line 365
Quoted 10 lines
arch/arm64/boot/dts/apple/t6030.dtsi +2
-0@@ -361,6 +361,38 @@ pmgr_gfx: power-management@290e80000 { /* child nodes are added in t6030-pmgr.dtsi */ }; + avd_dart: iommu@30b010000 { + compatible = "apple,t6030-dart", "apple,t8110-dart";
[Severity: Low]
Is this compatible string defined in the devicetree bindings?
The patch adds an IOMMU node with the compatible string 'apple,t6030-dart', but this string does not appear to be defined in Documentation/devicetree/bindings/iommu/apple,dart.yaml.
Will this omission leave the hardware interface undocumented and cause make dtbs_check validation to fail for the new devicetree?
Quoted 3 lines
arch/arm64/boot/dts/apple/t6030.dtsi +3
-0+ reg = <0x3 0x0b010000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = <AIC_IRQ 795 IRQ_TYPE_LEVEL_HIGH>;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=16
PATCH v2 17/17 arm64: dts: apple: t6031: add avd nodes
In reply to Sofus Forstreuter--- arch/arm64/boot/dts/apple/t6031-dieX.dtsi | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
arch/arm64/boot/dts/apple/t6031-dieX.dtsi +32 -0
@@ -73,6 +73,38 @@ DIE_NODE(pinctrl_aop): pinctrl@2a8824000 { <AIC_IRQ DIE_NO 601 IRQ_TYPE_LEVEL_HIGH>; }; + DIE_NODE(avd_dart): iommu@2cd010000 { + compatible = "apple,t6031-dart", "apple,t8110-dart"; + reg = <0x2 0xcd010000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = <AIC_IRQ DIE_NO 1192 IRQ_TYPE_LEVEL_HIGH>; + #iommu-cells = <1>; + power-domains = <&DIE_NODE(ps_avd_sys)>; + }; + + video-codec@2cd070000 { + compatible = "apple,t6031-avd", "apple,t8122-avd"; + reg = <0x2 0xcd070000 0x0 0x4000>, + <0x2 0xcd080000 0x0 0x10000>, + <0x2 0xcd090000 0x0 0x14000>, + <0x2 0xcd0a4000 0x0 0x4000>, + <0x2 0xcd100000 0x0 0x10000>; + reg-names = "piodma", "code", "sram", "mbox", "ctrl"; + interrupt-parent = <&aic>; + interrupts = <AIC_IRQ DIE_NO 1185 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ DIE_NO 1186 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ DIE_NO 1187 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ DIE_NO 1188 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ DIE_NO 1189 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ DIE_NO 1190 IRQ_TYPE_LEVEL_HIGH>, + <AIC_IRQ DIE_NO 1191 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "mbox0", "mbox1", "mbox2", "mbox3", + "flag0", "flag1", "piodma"; + iommus = <&DIE_NODE(avd_dart) 0>, <&DIE_NODE(avd_dart) 1>; + power-domains = <&DIE_NODE(ps_avd_sys)>; + resets = <&DIE_NODE(ps_avd_sys)>; + }; + DIE_NODE(pinctrl_ap): pinctrl@2b3000000 { compatible = "apple,t6031-pinctrl", "apple,t8103-pinctrl"; reg = <0x2 0xb3000000 0x0 0x4000>;
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v2 17/17] arm64: dts: apple: t6031: add avd nodes
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] dts: nodes sorted incorrectly by unit-address --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] dts: nodes sorted incorrectly by unit-address
--
commit fe4ebbc8c6f98e6f76243dbcfb7c2f83ad238d54
Author: Sofus Forstreuter <[email protected]>
arm64: dts: apple: t6031: add avd nodes
This commit adds device tree nodes for the avd dart (IOMMU) and video codec on the Apple T6031 SoC.
arch/arm64/boot/dts/apple/t6031-dieX.dtsi DIE_NODE(pinctrl_aop): pinctrl@2a8824000 { · line 76
Quoted 9 lines
arch/arm64/boot/dts/apple/t6031-dieX.dtsi +1
-0@@ -73,6 +73,38 @@ DIE_NODE(pinctrl_aop): pinctrl@2a8824000 { <AIC_IRQ DIE_NO 601 IRQ_TYPE_LEVEL_HIGH>; }; + DIE_NODE(avd_dart): iommu@2cd010000 {
[Severity: Low]
Are these new nodes inserted in the correct order? In kernel device tree files, nodes are conventionally sorted by unit-address.
The patch inserts iommu@2cd010000 and video-codec@2cd070000 between pinctrl@2a8824000 and pinctrl@2b3000000. Since 0x2cd010000 and 0x2cd070000 are numerically greater than 0x2b3000000, should these new nodes be placed after pinctrl@2b3000000 instead?
Quoted 2 lines
arch/arm64/boot/dts/apple/t6031-dieX.dtsi +2
-0+ compatible = "apple,t6031-dart", "apple,t8110-dart"; + reg = <0x2 0xcd010000 0x0 0x4000>;
[ ... ]
Quoted 2 lines
arch/arm64/boot/dts/apple/t6031-dieX.dtsi +2
-0+ video-codec@2cd070000 { + compatible = "apple,t6031-avd", "apple,t8122-avd";
[ ... ]
Quoted 3 lines
arch/arm64/boot/dts/apple/t6031-dieX.dtsi +0
-0DIE_NODE(pinctrl_ap): pinctrl@2b3000000 { compatible = "apple,t6031-pinctrl", "apple,t8103-pinctrl"; reg = <0x2 0xb3000000 0x0 0x4000>;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=17
Quoted 146 lines · Sofus Forstreuter
Hi,
This series enables hardware video decoding on Apple Silicon M1, M2 and M3 SoCs. It adds support for all the codecs AVD (Apple Video Decoder) supports, which is H264, H265, VP9 and AV1 (only on M3+).
The AVD is a bit unique both as a video decoder and an IP block on Apple Silicon SoCs. Instead of following the normal "a register for each parameter", AVD is programmed through one single register. This means the order of the writes are important, but its also important to ensure we dont write faster than the hardware can process. To solve this, we use the included Cortex-M3 co-processor. The CM3 accepts unsigned code, which we take advantage off [1].
The driver prepares the instructions and writes them into segments, which are submitted to the CM3. The CM3 then programs the hardware and notifies the AP when the job is done or if an error occurred.The driver implements the V4L2 M2M stateless decoder API. The driver's framework is based very heavy on rkvdecs driver. It therefore comes as no suprise that
v4l2-compliancereports no errors:
Total for avd device/dev/video0: 49, Succeeded: 49, Failed: 0, Warnings: 0The fluster scores are:
JVT-AVC_V1: 77/135
JVT-FR-EXT: 42/69
VP9-TEST-VECTORS: 216/305
VP9-TEST-VECTORS-HIGH: 1/6
JCT-VC-HEVC_V1: 143/147
AV1-TEST-VECTORS: 238/242Since not all unsupported H264 streams are rejected, the scores depend on the reset working, this only works with a patch to the apple-dart driver so that the IOMMU attach/detach trick works.
All codecs support 4:2:2, 4:2:0, in 10 and 8 bit. By default, AVD outputs in NV12, NV16, P010 and P210. Support for 4:4:4 and 12 bit formats has not been added yet.
Internally the AVD uses an Apple specific compressed and tiled format called Interchange to store reference image data. This is stored after image data across all codecs. Apple Interchange is used for sharing buffers with other hardware blocks (GPU, display controller), support for this is on its way [2].
The V4L2 pixel formats have been added to help with calculating sizes.This driver has been tested on most Apple Silicon SoCs in our downstream tree [3]. Its expected this driver will work on M4, M5, M6 and the Neo, with firmware already being written for all except the M6 SoCs [4].
The groundwork for this was laid many years ago by Jamie, R and Eileen, who through a combined effort managed to reverse engineer many core parts of the AVD block.
This driver would not have been possible without the work done by Eileen, who wrote initial support for H264, H265, VP9 and excellent tooling [5], allowing me to reverse engineer AV1 and make the driver conformant.[1] https://github.com/sofus13/avd-fw/tree/avd-next-fw
[2] https://patch.msgid.link/[email protected]
[3] https://github.com/AsahiLinux/linux
[4] https://github.com/AsahiLinux/avd-fw
[5] https://github.com/eiln/avd/tree/mainSigned-off-by Sofus Forstreuter <[email protected]>---
Changes in v2:
- Patch order
- Fixed dt-bindings by constraining all properties
- Fixed dts, add interrupts, iommus and regs. Drop labels, fix names
- Add Apple Interchange format
- Add more av1 and vp9 validation to v4l2-ctrls
- Validate more codec parameters
- Use the new CM3 firmware (drop avd-hw, drop submission loops)
- Updated cover to reflect changes
- Link to v1: https://patch.msgid.link/[email protected]To: Sven Peter <[email protected]>
To: Janne Grunau <[email protected]>
To: Neal Gompa <[email protected]>
To: Mauro Carvalho Chehab <[email protected]>
To: Rob Herring <[email protected]>
To: Krzysztof Kozlowski <[email protected]>
To: Conor Dooley <[email protected]>
To: Sofus Forstreuter <[email protected]>
To: Philipp Zabel <[email protected]>
To: Heiko Stuebner <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]---
Sofus Forstreuter (17):
dt-bindings: media: add apple,avd
media: v4l2: Add P210 pixel format
media: v4l2: Add Apple interchange pixel formats
media: v4l2-ctrls: validate av1 tile info
media: v4l2-ctrls: validate vp9tile_rows_log2
media: apple: add avd driver
media: apple: avd: add h264 support
media: apple: avd: add vp9 support
media: apple: avd: add hevc support
media: apple: avd: add av1 support
arm64: dts: apple: t8103: add avd nodes
arm64: dts: apple: t8112: add avd nodes
arm64: dts: apple: t8122: add avd nodes
arm64: dts: apple: t600x: add avd nodes
arm64: dts: apple: t602x: add avd nodes
arm64: dts: apple: t6030: add avd nodes
arm64: dts: apple: t6031: add avd nodes.../devicetree/bindings/media/apple,avd.yaml | 127 + .../userspace-api/media/v4l/pixfmt-yuv-planar.rst | 14 +- MAINTAINERS | 2 + arch/arm64/boot/dts/apple/t600x-dieX.dtsi | 32 + arch/arm64/boot/dts/apple/t602x-dieX.dtsi | 32 + arch/arm64/boot/dts/apple/t6030.dtsi | 32 + arch/arm64/boot/dts/apple/t6031-dieX.dtsi | 32 + arch/arm64/boot/dts/apple/t8103.dtsi | 32 + arch/arm64/boot/dts/apple/t8112.dtsi | 32 + arch/arm64/boot/dts/apple/t8122.dtsi | 32 + drivers/media/platform/Kconfig | 1 + drivers/media/platform/Makefile | 1 + drivers/media/platform/apple/Kconfig | 5 + drivers/media/platform/apple/Makefile | 3 + drivers/media/platform/apple/avd/Kconfig | 18 + drivers/media/platform/apple/avd/Makefile | 5 + .../media/platform/apple/avd/avd-av1-entropymode.c | 4698 ++++++++++++++++++++ .../media/platform/apple/avd/avd-av1-entropymode.h | 284 ++ drivers/media/platform/apple/avd/avd-av1.c | 1432 ++++++ drivers/media/platform/apple/avd/avd-drv.c | 776 ++++ drivers/media/platform/apple/avd/avd-h264.c | 862 ++++ drivers/media/platform/apple/avd/avd-hevc.c | 1340 ++++++ drivers/media/platform/apple/avd/avd-inst.h | 210 + drivers/media/platform/apple/avd/avd-v4l2.c | 992 +++++ drivers/media/platform/apple/avd/avd-vp9.c | 1054 +++++ drivers/media/platform/apple/avd/avd.h | 299 ++ drivers/media/v4l2-core/v4l2-common.c | 8 + drivers/media/v4l2-core/v4l2-ctrls-core.c | 17 +- drivers/media/v4l2-core/v4l2-ioctl.c | 7 + include/uapi/linux/v4l2-controls.h | 2 +- include/uapi/linux/videodev2.h | 9 + 31 files changed, 12386 insertions(+), 4 deletions(-)
Quoted 4 lines
---
base-commit:4efa625593e1e9c76346232413997556dea1d89f
change-id: 20260917-avd-7ee5474b468c
Series LGTM.
Signature · 1 line
真実はいつも一つ!/ Always, there's only one truth!