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
66 changes: 63 additions & 3 deletions drivers/iommu/apple-dart-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ static void apple_dart_test_consumer_window(struct kunit *test)
dev->of_node = &node;

/*
* J613's common scanout alias survives both DART defaults, but only
* inside each stream's own window: the external DART excludes its top
* 64 KiB, so the shared aperture must too.
* On a 36-bit DART the 1 TiB scanout alias lies above the translated
* bits. It survives both DART defaults, but only inside each stream's
* own window: the second DART excludes its top 64 KiB, so the shared
* aperture must too.
*/
for (i = 0; i < 2; i++) {
dart->dma_min = i ? 0 : 0x10000000000;
Expand Down Expand Up @@ -155,6 +156,64 @@ static void apple_dart_test_consumer_window(struct kunit *test)
KUNIT_EXPECT_EQ(test, dma_max, (dma_addr_t)0xffffeffff);
}

/*
* The T8122 display DARTs translate 42 bits, so the 1 TiB scanout window is no
* alias there: it is disjoint from a low window on the DART, and a DART that
* serves both must have none, with each consumer naming its own.
*/
static void apple_dart_test_t8122_consumer_window(struct kunit *test)
{
static const struct {
u64 dart_min, dart_max, base, size;
int ret;
u64 min, max;
} windows[] = {
/* Scanout: the panel's DART, the external one with a low window. */
{ 0x10000000000, 0x10fffffffff, 0x10000000000, 0x1000000000,
0, 0x10000000000, 0x10fffffffff },
{ 0, 0xffffeffff, 0x10000000000, 0x1000000000, -EINVAL },
/* The external DART without one: scanout, then PIODMA. */
{ 0, DMA_BIT_MASK(42), 0x10000000000, 0x1000000000,
0, 0x10000000000, 0x10fffffffff },
{ 0, DMA_BIT_MASK(42), 0, 0xfffff0000, 0, 0, 0xffffeffff },
};
__be64 value[2];
struct property property = {
.name = "apple,dma-range",
.length = sizeof(value),
.value = value,
};
struct device_node node = { .properties = &property };
struct of_phandle_args args = { .args_count = 1 };
struct apple_dart *dart;
struct device *dev;
dma_addr_t dma_min, dma_max;
int i;

dev = kunit_device_register(test, "apple-dart-t8122-window-test");
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
dart = kunit_kzalloc(test, sizeof(*dart), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, dart);
dart->ias = 42;
dart->pgsize = SZ_16K;
dev->of_node = &node;

for (i = 0; i < ARRAY_SIZE(windows); i++) {
value[0] = cpu_to_be64(windows[i].base);
value[1] = cpu_to_be64(windows[i].size);
dart->dma_min = windows[i].dart_min;
dart->dma_max = windows[i].dart_max;
KUNIT_EXPECT_EQ_MSG(test, apple_dart_parse_dma_window(dev, dart, &args, &dma_min,
&dma_max),
windows[i].ret, "window %d", i);
if (windows[i].ret)
continue;
KUNIT_EXPECT_EQ_MSG(test, dma_min, (dma_addr_t)windows[i].min, "window %d", i);
KUNIT_EXPECT_EQ_MSG(test, dma_max, (dma_addr_t)windows[i].max, "window %d", i);
}
dev->of_node = NULL;
}

static void apple_dart_test_disjoint_consumer_window(struct kunit *test)
{
/* 2 GiB at the 1 TiB alias; its low bits start at 2 GiB. */
Expand Down Expand Up @@ -2341,6 +2400,7 @@ static struct kunit_case apple_dart_test_cases[] = {
KUNIT_CASE(apple_dart_test_topology),
KUNIT_CASE(apple_dart_test_iommu_specifiers),
KUNIT_CASE(apple_dart_test_consumer_window),
KUNIT_CASE(apple_dart_test_t8122_consumer_window),
KUNIT_CASE(apple_dart_test_disjoint_consumer_window),
KUNIT_CASE(apple_dart_test_invalid_consumer_window),
KUNIT_CASE(apple_dart_test_independent_remap_roots),
Expand Down
54 changes: 52 additions & 2 deletions drivers/soc/apple/display-gate-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -832,12 +832,24 @@ static void __init gt_expect_window(struct kunit *test, const char *path, const
KUNIT_EXPECT_EQ_MSG(test, window[1], want[1], "%s size", path);
}

/*
* On 14.7 the external display DART keeps no window of its own: it is the
* PIODMA stream's alone, so scanout at the panel's is not disjoint from it.
*/
static void __init gt_expect_piodma_window(struct kunit *test, const u64 want[2])
{
KUNIT_EXPECT_FALSE(test, of_property_present(gt_node(test, GT_T8122_DISPEXT_DART),
"apple,dma-range"));
gt_expect_window(test, GT_T8122_DCPEXT "/piodma", want);
}

/*
* The panel as gt_expect_enabled() checks it, and the dcpext enabled or not
* with all it needs. When enabled, @shared says whether its scanout DART joins
* the display subsystem's domain (disabling fbdma) or stays out (leaving fbdma
* available for framebuffer mirroring). @window: the window both dcpext DARTs
* must have, NULL for the device tree's own.
* must have, NULL for the device tree's own (the display DART's moved to the
* PIODMA stream when enabled).
*/
static void __init gt_expect_dcpext_mode(struct kunit *test, bool enabled, bool shared,
const u64 *window)
Expand Down Expand Up @@ -869,7 +881,14 @@ static void __init gt_expect_dcpext_mode(struct kunit *test, bool enabled, bool
KUNIT_EXPECT_EQ(test, gt_okay(test, GT_T8122_DCPEXT "/fbdma"), !shared);
}
gt_expect_window(test, GT_T8122_DCPEXT_DART, window ?: gt_t8122_dcpext_window);
gt_expect_window(test, GT_T8122_DISPEXT_DART, window ?: gt_t8122_dispext_window);
if (enabled && !window) {
gt_expect_piodma_window(test, gt_t8122_dispext_window);
} else {
gt_expect_window(test, GT_T8122_DISPEXT_DART, window ?: gt_t8122_dispext_window);
KUNIT_EXPECT_FALSE(test, of_property_present(gt_node(test,
GT_T8122_DCPEXT "/piodma"),
"apple,dma-range"));
}
/* The panel's own window stays as it is. */
gt_expect_window(test, "/t8122-soc/iommu@28d30c000", gt_t8122_panel_window);
}
Expand All @@ -887,6 +906,36 @@ static void __init gate_t8122_dcpext_not_ready(struct kunit *test)
gt_expect_dcpext(test, false, NULL);
}

/*
* gate_t8122_dcpext_piodma_window() alone: a window the PIODMA stream already
* has stays, and a display DART without one changes nothing.
*/
static void __init gate_t8122_dcpext_piodma_own_window(struct kunit *test)
{
struct device_node *piodma = gt_node(test, GT_T8122_DCPEXT "/piodma");
struct device_node *disp_dart = gt_node(test, GT_T8122_DISPEXT_DART);
static const u32 own[4] __initconst = { 0x8, 0x0, 0x7, 0xffff0000 };
struct gate_test *t = test->priv;
struct of_changeset cs, none;

gt_set_u32_array(test, GT_T8122_DCPEXT "/piodma", "apple,dma-range",
own, ARRAY_SIZE(own));
KUNIT_ASSERT_EQ(test, of_changeset_apply(&t->cs), 0);
of_changeset_init(&cs);
KUNIT_ASSERT_EQ(test, gate_t8122_dcpext_piodma_window(&cs, piodma, disp_dart), 0);
KUNIT_ASSERT_EQ(test, of_changeset_apply(&cs), 0);
gt_expect_piodma_window(test, gt_t8122_dcpext_window);

of_changeset_init(&none);
KUNIT_EXPECT_EQ(test, gate_t8122_dcpext_piodma_window(&none, piodma, disp_dart), 0);
KUNIT_EXPECT_TRUE(test, list_empty(&none.entries));
of_changeset_destroy(&none);

KUNIT_EXPECT_EQ(test, of_changeset_revert(&cs), 0);
of_changeset_destroy(&cs);
gt_expect_window(test, GT_T8122_DISPEXT_DART, gt_t8122_dispext_window);
}

/* On 14.7.0 it starts with the device tree's windows. */
static void __init gate_t8122_dcpext_v14_7(struct kunit *test)
{
Expand Down Expand Up @@ -1111,6 +1160,7 @@ static struct kunit_case gate_t8122_cases[] __refdata = {
KUNIT_CASE(gate_t8122_not_inherited_on),
KUNIT_CASE(gate_t8122_dcpext_not_ready),
KUNIT_CASE(gate_t8122_dcpext_v14_7),
KUNIT_CASE(gate_t8122_dcpext_piodma_own_window),
KUNIT_CASE(gate_t8122_dcpext_loader_default_marker),
KUNIT_CASE(gate_t8122_dcpext_other_marker),
KUNIT_CASE(gate_t8122_dcpext_board_mirrors),
Expand Down
71 changes: 51 additions & 20 deletions drivers/soc/apple/display-gate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1900,6 +1900,28 @@ static bool __init gate_node_in(struct device_node *const *nodes, int n,
return false;
}

/* Give @np the DMA window @window, in @cs. */
static int __init gate_set_window(struct of_changeset *cs, struct device_node *np,
const struct property *window)
{
/* Kept for good: the live tree refers to it once applied. */
struct property *prop = kzalloc_obj(*prop);
void *value = kmemdup(window->value, window->length, GFP_KERNEL);
int ret = -ENOMEM;

if (prop && value) {
prop->name = "apple,dma-range";
prop->length = window->length;
prop->value = value;
ret = of_changeset_update_property(cs, np, prop);
}
if (ret) {
kfree(prop);
kfree(value);
}
return ret;
}

/*
* On the 27.2 image the T8122 external processor and its scanout use the
* panel's DMA window (the 1 TiB alias): the display subsystem takes the
Expand All @@ -1926,30 +1948,37 @@ static int __init gate_t8122_dcpext_alias(struct of_changeset *cs,
return -ENODEV;
}

for (i = 0; i < ARRAY_SIZE(targets) && !ret; i++) {
/* Kept for good: the live tree refers to it once applied. */
struct property *prop = kzalloc_obj(*prop);
void *value = kmemdup(window->value, window->length, GFP_KERNEL);

if (!prop || !value) {
kfree(prop);
kfree(value);
ret = -ENOMEM;
break;
}
prop->name = "apple,dma-range";
prop->length = window->length;
prop->value = value;
ret = of_changeset_update_property(cs, targets[i], prop);
if (ret) {
kfree(prop);
kfree(value);
}
}
for (i = 0; i < ARRAY_SIZE(targets) && !ret; i++)
ret = gate_set_window(cs, targets[i], window);
of_node_put(panel_dart);
return ret;
}

/*
* On 14.7 the device tree's window of @disp_dart (from 0) is the one its
* PIODMA stream uses. Scanout reads framebuffers through another stream of
* that DART, at the panel's window (the 1 TiB alias). The DART translates 42
* bits, so the two windows are disjoint, and the DART driver refuses a
* consumer whose window its DART's excludes: the display subsystem, or fbdma
* on a board that keeps the DART out of it, would get no IOMMU domain. Move
* the window to @piodma, so that it binds that stream alone.
*/
static int __init gate_t8122_dcpext_piodma_window(struct of_changeset *cs,
struct device_node *piodma,
struct device_node *disp_dart)
{
struct property *window = of_find_property(disp_dart, "apple,dma-range", NULL);
int ret = 0;

if (!window)
return 0;
if (!of_property_present(piodma, "apple,dma-range"))
ret = gate_set_window(cs, piodma, window);
if (!ret)
ret = of_changeset_remove_property(cs, disp_dart, window);
return ret;
}

/*
* Does @np's display DART go into the display subsystem's domain? 1 or 0,
* or -ENODEV on a board that forbids it and has no @fbdma child to mirror
Expand Down Expand Up @@ -2077,6 +2106,8 @@ static void __init gate_t8122_dcpext_one(struct device_node *np)
ret = gate_add_bool(cs, entry, "apple,defer-startup-ack");
if (!ret && apple_t8122_dcpext_v27_2(np))
ret = gate_t8122_dcpext_alias(cs, dart, disp_dart);
else if (!ret)
ret = gate_t8122_dcpext_piodma_window(cs, piodma, disp_dart);
if (!ret)
ret = of_changeset_update_prop_string(cs, dart, "status", "okay");
if (!ret)
Expand Down
Loading