diff --git a/drivers/iommu/apple-dart-cio.c b/drivers/iommu/apple-dart-cio.c index f10dea827172d..0c7fa7d7f5af3 100644 --- a/drivers/iommu/apple-dart-cio.c +++ b/drivers/iommu/apple-dart-cio.c @@ -393,40 +393,30 @@ 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; } @@ -434,10 +424,10 @@ static void apple_dart_cio_release(struct apple_dart *dart) 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); } diff --git a/drivers/iommu/apple-dart-test.c b/drivers/iommu/apple-dart-test.c index f0b6e68023214..32222dbf50d56 100644 --- a/drivers/iommu/apple-dart-test.c +++ b/drivers/iommu/apple-dart-test.c @@ -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); @@ -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),