Skip to content
Draft
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
42 changes: 16 additions & 26 deletions drivers/iommu/apple-dart-cio.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,51 +393,41 @@ int apple_dart_cio_finish(struct apple_dart_cio *s)
EXPORT_SYMBOL_GPL(apple_dart_cio_finish);

/*
* T6050 (J714s): the ACIO DART and the PCIe-C DART of a USB4 port go away with the port when
* its ACIO stops: a cable removed, or a dock given up after a sleep. While bit 4 of a DART's
* PS_PROT slice is set, the slice guards a power-state register of the DART's power domain.
* apple_dart_cio_on() sets the bit again after every sleep that saved the DART, as macOS does
* right after the domain's power-up, but nothing cleared it before apple_cio_stop() dropped the
* ACIO's domain links: genpd then gated ATC's CIO and PCIe-C domains from the runtime suspend
* of the ACIO's domain devices, with the guard on, and the CPU that wrote the PMGR took an
* SError. macOS clears the bit once the DART's streams are disabled and its TLB flushed, then
* gates the domain; it never gates one with the bit set. Clear it here in that order:
* apple_dart_remove() has just reset the DART, or its port clock went with its port and its
* requesters stopped first (its commands are gated). A slice still on is said, since the
* domain's power-off would fault.
* The ACIO DART and the PCIe-C DART of a USB4 port go away with the port when its ACIO stops: a
* cable removed, or a dock given up after a sleep. While bit 4 of a DART's PS_PROT slice is set,
* the slice guards a power-state register of the DART's power domain. apple_dart_cio_on() sets
* the bit again after every sleep that saved the DART, as macOS does right after the domain's
* power-up, but nothing cleared it before apple_cio_stop() dropped the ACIO's domain links:
* genpd then gated ATC's CIO and PCIe-C domains from the runtime suspend of the ACIO's domain
* devices, with the guard on. On a T6050 (J714s) the CPU that wrote the PMGR took an SError; a
* T8132 (J713) hung without one. macOS clears the bit once the DART's streams are disabled and
* its TLB flushed, then gates the domain; it never gates one with the bit set. Clear it here in
* that order: apple_dart_remove() has just reset the DART, or its port clock went with its port
* and its requesters stopped first (its commands are gated). A slice still on is said, since the
* domain's power-off would not complete.
*/
static bool apple_dart_cio_atc_port(struct apple_dart *dart)
{
struct device_node *parent = dart->dev->of_node->parent;

return parent && (of_machine_is_compatible("apple,j714s") ||
of_machine_is_compatible("apple,j716c")) &&
(of_device_is_compatible(parent, "apple,t6050-usb4-acio") ||
of_node_name_prefix(parent, "pcie-tunnel-"));
}

static void apple_dart_cio_release(struct apple_dart *dart)
{
struct apple_dart_cio *s = dart->cio;
u32 before = 0, after = 0;
int ret;

if (!s || !apple_dart_cio_atc_port(dart))
if (!s)
return;
ret = regmap_read(s->gapf, APPLE_PS_PROT_SLICE(s->slice), &before);
if (ret || !(before & APPLE_PS_PROT_SLICE_ON)) {
dev_info(dart->dev, "T6050: removed, PS_PROT slice %u %#x: nothing to clear (%d)\n",
dev_info(dart->dev, "CIO DART removed, PS_PROT slice %u %#x: nothing to clear (%d)\n",
s->slice, before, ret);
return;
}
ret = apple_dart_cio_gapf(s, false);
regmap_read(s->gapf, APPLE_PS_PROT_SLICE(s->slice), &after);
if (ret)
dev_err(dart->dev,
"T6050: removed with PS_PROT slice %u still on (%#x -> %#x, %d): its domain's power-off will fault\n",
"CIO DART removed with PS_PROT slice %u still on (%#x -> %#x, %d): its domain's power-off will not complete\n",
s->slice, before, after, ret);
else
dev_info(dart->dev,
"T6050: removed, PS_PROT slice %u %#x -> %#x before its domain goes off\n",
"CIO DART removed, PS_PROT slice %u %#x -> %#x before its domain goes off\n",
s->slice, before, after);
}
33 changes: 33 additions & 0 deletions drivers/iommu/apple-dart-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,38 @@ static u32 apple_dart_test_slice(struct apple_dart *dart)
return value;
}

/*
* A CIO DART removed by its host, which then powers its domain down: the clock
* protection a wake set is cleared, one that is off stays off.
*/
static void apple_dart_test_cio_release(struct kunit *test)
{
struct apple_dart *dart = apple_dart_test_host_dart(test);
struct apple_dart_cio *s;

/* No slice of its own to release. */
apple_dart_cio_release(dart);
KUNIT_EXPECT_EQ(test, apple_dart_test_slice(dart), 0x12U);

s = kunit_kzalloc(test, sizeof(*s), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, s);
s->dart = dart;
s->gapf = dart->ps_prot;
s->slice = APPLE_DART_TEST_PS_SLICE;
dart->cio = s;

/* Off, as before the first sleep: left alone. */
regmap_write(dart->ps_prot, APPLE_PS_PROT_SLICE(s->slice), 0x2);
apple_dart_cio_release(dart);
KUNIT_EXPECT_EQ(test, apple_dart_test_slice(dart), 0x2U);

/* On, as a wake leaves it. */
KUNIT_ASSERT_EQ(test, apple_dart_cio_gapf(s, true), 0);
KUNIT_EXPECT_EQ(test, apple_dart_test_slice(dart), 0x12U);
apple_dart_cio_release(dart);
KUNIT_EXPECT_EQ(test, apple_dart_test_slice(dart), 0x2U);
}

static void apple_dart_test_host_power_cycle(struct kunit *test)
{
struct apple_dart *dart = apple_dart_test_host_dart(test);
Expand Down Expand Up @@ -2261,6 +2293,7 @@ static struct kunit_case apple_dart_test_cases[] = {
KUNIT_CASE(apple_dart_test_resume_retained_bypass_t8103),
KUNIT_CASE(apple_dart_test_resume_retained_bypass_t8110),
#if IS_ENABLED(CONFIG_APPLE_DART_J713_DCP)
KUNIT_CASE(apple_dart_test_cio_release),
KUNIT_CASE(apple_dart_test_host_power_cycle),
KUNIT_CASE(apple_dart_test_host_power_lost),
KUNIT_CASE(apple_dart_test_host_power_refused),
Expand Down
Loading