Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions Documentation/devicetree/bindings/iommu/apple,dart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ properties:
- apple,t8110-dart
- apple,t6000-dart
- apple,t8152-dart-gen3
- apple,t8152-avd-dart
- items:
- const: apple,t8140-ane-dart
- const: apple,t8140-dart
Expand Down Expand Up @@ -369,15 +370,19 @@ allOf:
properties:
compatible:
contains:
const: apple,t8152-dart-gen3
enum:
- apple,t8152-dart-gen3
- apple,t8152-avd-dart
then:
description:
The T8152 Gen3 DARTs in front of the display coprocessors and their
display pipes belong to the SPTM. The bootloader hands them over
locked, and the operating system only adds page table entries in
root slots that are empty at handoff. Their TLB command register
answers translation queries; a stream is invalidated through the
TLB invalidation aperture instead.
TLB invalidation aperture instead. The T8152 AVD instance uses the
same invalidation aperture, but starts unlocked with inactive streams
and is initialized by the operating system after its PSD domain is on.
properties:
reg:
minItems: 2
Expand All @@ -395,6 +400,17 @@ allOf:
- const: dart
- enum: [dapf, gapf, ps-wr-dis, auxiliary]

- if:
properties:
compatible:
contains:
const: apple,t8152-avd-dart
then:
required:
- power-domains
- apple,dma-range
- apple,tunable

additionalProperties: false

examples:
Expand Down
73 changes: 73 additions & 0 deletions Documentation/devicetree/bindings/media/apple,t8152-avd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/media/apple,t8152-avd.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

title: Apple T8152 Kopsia video decoder

maintainers:
- Thomas Glanzmann <thomas@glanzmann.de>

description:
Kopsia is the T8152 stateless video decoder. Its decoder, PIODMA and
auxiliary data streams share a Gen3 DART and a PSD power domain. The host
submits codec programs with the MCU halted and polls decoder status;
the PostOffice mailbox transport is not used by this implementation.

properties:
compatible:
const: apple,t8152-avd

reg:
items:
- description: MCU code memory
- description: MCU control registers
- description: Decoder control registers
- description: Decoder wrapper registers
- description: PIODMA registers

reg-names:
items:
- const: code
- const: mbox
- const: ctrl
- const: wrap
- const: dma

iommus:
items:
- description: Decoder stream
- description: PIODMA stream
- description: Auxiliary data stream

power-domains:
maxItems: 1

required:
- compatible
- reg
- reg-names
- iommus
- power-domains

additionalProperties: false

examples:
- |
soc {
#address-cells = <2>;
#size-cells = <2>;

video-codec@485400000 {
compatible = "apple,t8152-avd";
reg = <0x4 0x85400000 0x0 0x12000>,
<0x4 0x85500000 0x0 0x4000>,
<0x4 0x85100000 0x0 0x10000>,
<0x4 0x850c0000 0x0 0x4000>,
<0x4 0x85070000 0x0 0x4000>;
reg-names = "code", "mbox", "ctrl", "wrap", "dma";
iommus = <&avd_dart 0>, <&avd_dart 1>, <&avd_dart 2>;
power-domains = <&ps_avd>;
};
};
14 changes: 14 additions & 0 deletions arch/arm64/boot/dts/apple/t8152-j873-avd.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: GPL-2.0+ OR MIT
/* J873g: the Kopsia video decoder (described in t8152-peripherals.dtsi). */

&ps_avd {
status = "okay";
};

&avd_dart {
status = "okay";
};

&avd {
status = "okay";
};
1 change: 1 addition & 0 deletions arch/arm64/boot/dts/apple/t8152-j873g.dts
Original file line number Diff line number Diff line change
Expand Up @@ -503,3 +503,4 @@
#include "t8152-j873-ethernet.dtsi"
#include "t8152-j873-audio.dtsi"
#include "t8152-j873-dcp.dtsi"
#include "t8152-j873-avd.dtsi"
55 changes: 53 additions & 2 deletions arch/arm64/boot/dts/apple/t8152-peripherals.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,62 @@
status = "disabled";
};

/* Kopsia decoder: PSD service 50, Gen3 DART streams 0..2. */
ps_avd: power-controller@303a13200 {
compatible = "apple,t8152-psd";
reg = <0x3 0x03a13200 0x0 0x100>;
#power-domain-cells = <0>;
label = "avd";
status = "disabled";
};

avd_dart: iommu@485020000 {
compatible = "apple,t8152-dart", "apple,t8110-dart";
reg = <0x4 0x85020000 0x0 0x20000>;
compatible = "apple,t8152-avd-dart";
reg = <0x4 0x85020000 0x0 0x20000>, <0x2 0x300 0x0 0x10>;
reg-names = "dart", "tlbi";
interrupts = <AIC_IRQ 1257 IRQ_TYPE_LEVEL_HIGH>;
#iommu-cells = <1>;
power-domains = <&ps_avd>;
/* A 64-GiB window within the ADT's 1..4-TiB DMA aperture. */
apple,dma-range = <0x100 0x0 0x10 0x0>;
apple,tunable = <
0x20c 0x80000121 0x80000121
0x220 0xf0f 0xf0f
0x224 0xffff 0x909
0x300 0x1f31 0x1
0x308 0x3ffffffc 0x10000000
0x310 0x3ffffffc 0x3ffffffc
0x800 0xf007f 0x10000
0x804 0xf007f 0x20002
0x808 0xf007f 0x50006
0x80c 0xf007f 0x20026
0x810 0xf007f 0x3002a
0x814 0xf007f 0x40032
0x818 0xf007f 0x0
0x81c 0xf007f 0x0
0x820 0xf007f 0x0
0x824 0xf007f 0x0
0x828 0xf007f 0x0
0x82c 0xf007f 0x0
0x830 0xf007f 0x0
0x834 0xf007f 0x0
0x838 0xf007f 0x0
0x83c 0xf007f 0x0
0x4600 0x2 0x2
>;
status = "disabled";
};

avd: video-codec@485400000 {
compatible = "apple,t8152-avd";
reg = <0x4 0x85400000 0x0 0x12000>,
<0x4 0x85500000 0x0 0x4000>,
<0x4 0x85100000 0x0 0x10000>,
<0x4 0x850c0000 0x0 0x4000>,
<0x4 0x85070000 0x0 0x4000>;
reg-names = "code", "mbox", "ctrl", "wrap", "dma";
power-domains = <&ps_avd>;
iommus = <&avd_dart 0>, <&avd_dart 1>, <&avd_dart 2>;
status = "disabled";
};

Expand Down
83 changes: 57 additions & 26 deletions drivers/iommu/apple-dart.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ struct apple_dart_fw_tree {
#define APPLE_DART_GAPF_PROTECT BIT(4)

struct apple_dart {
bool cold_gen3;
struct device *dev;
const struct apple_dart_hw *hw;

Expand Down Expand Up @@ -2661,6 +2662,17 @@ static int apple_dart_hw_reset(struct apple_dart *dart)
struct apple_dart_stream_map stream_map;
int i;

if (dart->cold_gen3) {
stream_map.dart = dart;
bitmap_zero(stream_map.sidmap, DART_MAX_STREAMS);
bitmap_set(stream_map.sidmap, 0, 3);
apple_dart_hw_disable_dma(&stream_map);
apple_dart_hw_clear_all_ttbrs(&stream_map);
apple_dart_apply_own_tunables(dart);
apple_dart_writel(dart, 7, dart->hw->enable_streams);
return dart->hw->invalidate_tlb(&stream_map);
}

if (dart->isp_host)
return apple_dart_isp_host_reset(dart);
if (dart->managed_sids || dart->cold_ane)
Expand Down Expand Up @@ -3393,6 +3405,17 @@ static int __apple_dart_finalize_domain(struct apple_dart_domain *dart_domain,
.iommu_dev = dart->dev,
};

if (dart->cold_gen3) {
if ((dma_min ^ dma_max) & ~DMA_BIT_MASK(36)) {
ret = -ERANGE;
goto done;
}
/* Gen3 selects the high DMA window separately from its two-level
* 16K page-table indices, as with iBoot's display streams.
*/
pgtbl_cfg.ias = 36;
}

if (dart->locked) {
unsigned long *sidmap;
int sid;
Expand Down Expand Up @@ -5548,6 +5571,7 @@ static int apple_dart_probe(struct platform_device *pdev)
dart->dev = dev;
dart->hw = of_device_get_match_data(dev);
dart->tunneled = tunneled;
dart->cold_gen3 = of_device_is_compatible(dev->of_node, "apple,t8152-avd-dart");
dart->cold_ane = of_device_is_compatible(dev->of_node, "apple,t8140-ane-dart") ||
of_device_is_compatible(dev->of_node, "apple,t8142-ane-dart");
if (dart->cold_ane && !IS_BUILTIN(CONFIG_APPLE_DART))
Expand Down Expand Up @@ -5967,6 +5991,38 @@ static int apple_dart_probe(struct platform_device *pdev)
ret = -EBUSY;
goto err_clk_disable;
}
if (dart->hw->gen3) {
struct resource *tlbi;

/* Cold initialization is qualified only for the AVD instance. */
if (!dart->locked && !dart->cold_gen3) {
dev_err(dev, "Gen3 DART is not locked; cold setup is not supported\n");
ret = -ENODEV;
goto err_clk_disable;
}
if (dart->cold_gen3 && (dart->locked || dart->version != 0x300 ||
dart->num_streams != 16 || !dev->pm_domain || !dart->tunables ||
(apple_dart_readl(dart, dart->hw->enable_streams) & 7))) {
ret = -EINVAL;
goto err_clk_disable;
}
/* The aperture is shared by every Gen3 DART: map, do not claim. */
tlbi = platform_get_resource_byname(pdev, IORESOURCE_MEM, "tlbi");
if (!tlbi || resource_size(tlbi) < 16) {
dev_err(dev, "Gen3 DART needs its TLBI aperture\n");
ret = -EINVAL;
goto err_clk_disable;
}
dart->tlbi = devm_ioremap(dev, tlbi->start, resource_size(tlbi));
if (!dart->tlbi) {
ret = -ENOMEM;
goto err_clk_disable;
}
dart->tlbi_route = apple_dart_readl(dart, DART_GEN3_TLBI_ROUTE) & 0xf;
dev_info(dev, "Gen3 DART, version %#x, TLBI route %u\n",
dart->version, dart->tlbi_route);
}

apple_dart_parse_sleep_list(dart, res, "apple,sleep-prepare", &dart->sleep_prepare);
apple_dart_parse_sleep_list(dart, res, "apple,sleep-restore", &dart->sleep_restore);
apple_dart_parse_sleep_list(dart, res, "apple,sleep-restore-late",
Expand Down Expand Up @@ -6107,32 +6163,6 @@ static int apple_dart_probe(struct platform_device *pdev)
goto err_clk_disable;
}

if (dart->hw->gen3) {
struct resource *tlbi;

/* Only an iBoot-provisioned (locked) Gen3 stream is supported. */
if (!dart->locked) {
dev_err(dev, "Gen3 DART is not locked; cold setup is not supported\n");
ret = -ENODEV;
goto err_clk_disable;
}
/* The aperture is shared by every Gen3 DART: map, do not claim. */
tlbi = platform_get_resource_byname(pdev, IORESOURCE_MEM, "tlbi");
if (!tlbi || resource_size(tlbi) < 16) {
dev_err(dev, "Gen3 DART needs its TLBI aperture\n");
ret = -EINVAL;
goto err_clk_disable;
}
dart->tlbi = devm_ioremap(dev, tlbi->start, resource_size(tlbi));
if (!dart->tlbi) {
ret = -ENOMEM;
goto err_clk_disable;
}
dart->tlbi_route = apple_dart_readl(dart, DART_GEN3_TLBI_ROUTE) & 0xf;
dev_info(dev, "Gen3 DART, version %#x, TLBI route %u\n",
dart->version, dart->tlbi_route);
}

/* Borrowed display state: never acknowledge someone else's fault. */
if (dart->locked && !dart->preserve_display && !dart->hw->gen3)
apple_dart_drain_stale_exceptions(dart);
Expand Down Expand Up @@ -7394,6 +7424,7 @@ static const struct dev_pm_ops apple_dart_pm_ops = {

static const struct of_device_id apple_dart_of_match[] = {
{ .compatible = "apple,t8152-dart-gen3", .data = &apple_dart_hw_gen3 },
{ .compatible = "apple,t8152-avd-dart", .data = &apple_dart_hw_gen3 },
{ .compatible = "apple,t8103-dart", .data = &apple_dart_hw_t8103 },
{ .compatible = "apple,t8103-usb4-dart", .data = &apple_dart_hw_t8103_usb4 },
{ .compatible = "apple,t8110-dart", .data = &apple_dart_hw_t8110 },
Expand Down
4 changes: 3 additions & 1 deletion drivers/media/platform/apple/avd/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ config VIDEO_APPLE_AVD
help
Support the Apple Silicon stateless video decoder.

Build the decoder firmware from https://github.com/aurora-silicon/avd-fw
T8152 uses host submission and does not need a firmware image.

For earlier SoCs, build the decoder firmware from https://github.com/aurora-silicon/avd-fw
and install it under /lib/firmware/apple/. J700/T8140 uses the
avd-fw-v5-t0.bin image. Firmware is supplied separately from this driver.

Expand Down
2 changes: 1 addition & 1 deletion drivers/media/platform/apple/avd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

apple-avd-y := avd-drv.o avd-v4l2.o avd-hw.o avd-pm.o avd-h264.o avd-vp9.o \
avd-hevc.o avd-av1.o avd-av1-entropymode.o avd-queue.o avd-backend-open.o \
avd-backend-apple.o avd-backend-queue.o
avd-backend-apple.o avd-backend-queue.o avd-backend-kopsia.o
apple-avd-$(CONFIG_VIDEO_APPLE_AVD_KUNIT_TEST) += avd-h264-test.o avd-queue-test.o \
avd-pm-test.o
obj-$(CONFIG_VIDEO_APPLE_AVD) += apple-avd.o
Loading
Loading