From 628ceb95daef2d996cabc1c6db46d1bab5c5aeb0 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Thu, 26 Nov 2026 14:39:43 -0500 Subject: [PATCH 1/3] iommu/apple-dart: allow runtime CIO DART power cycles apple_dart_cio_prepare() restricts CIO DART power cycles to PM_SUSPEND_MEM because existing callers only ran during deep sleep. External display processors that power down while idle at runtime need the same save/disable/restore/reopen lifecycle outside system suspend, while apple_dart_suspend() and apple_dart_resume() already skip DART MMIO whenever cio_active is set. Factor the shared preparation logic into apple_dart_cio_prepare_common() and export apple_dart_cio_prepare_runtime() for runtime power-gating consumers, keeping the PM_SUSPEND_MEM check on apple_dart_cio_prepare(). Signed-off-by: Erik Bourget --- drivers/iommu/apple-dart-cio.c | 19 ++++++++++++++++--- include/linux/soc/apple/dart-cio.h | 6 ++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/apple-dart-cio.c b/drivers/iommu/apple-dart-cio.c index 7e25682d7d113..f10dea827172d 100644 --- a/drivers/iommu/apple-dart-cio.c +++ b/drivers/iommu/apple-dart-cio.c @@ -111,14 +111,12 @@ int apple_dart_cio_check(struct apple_dart_cio *s, bool quiesced) } EXPORT_SYMBOL_GPL(apple_dart_cio_check); -int apple_dart_cio_prepare(struct apple_dart_cio *s) +static int apple_dart_cio_prepare_common(struct apple_dart_cio *s) { struct apple_dart *dart; unsigned long flags; int ret; - if (!s || !s->owner || pm_suspend_target_state != PM_SUSPEND_MEM) - return -EINVAL; dart = s->dart; ret = pm_runtime_resume_and_get(dart->dev); if (ret < 0) @@ -153,8 +151,23 @@ int apple_dart_cio_prepare(struct apple_dart_cio *s) pm_runtime_put(dart->dev); return ret; } + +int apple_dart_cio_prepare(struct apple_dart_cio *s) +{ + if (!s || !s->owner || pm_suspend_target_state != PM_SUSPEND_MEM) + return -EINVAL; + return apple_dart_cio_prepare_common(s); +} EXPORT_SYMBOL_GPL(apple_dart_cio_prepare); +int apple_dart_cio_prepare_runtime(struct apple_dart_cio *s) +{ + if (!s || !s->owner) + return -EINVAL; + return apple_dart_cio_prepare_common(s); +} +EXPORT_SYMBOL_GPL(apple_dart_cio_prepare_runtime); + static int apple_dart_cio_gapf(struct apple_dart_cio *s, bool on) { u32 value; diff --git a/include/linux/soc/apple/dart-cio.h b/include/linux/soc/apple/dart-cio.h index b1f4b32e6cdc7..760eb8156cdb0 100644 --- a/include/linux/soc/apple/dart-cio.h +++ b/include/linux/soc/apple/dart-cio.h @@ -23,6 +23,7 @@ struct apple_dart_cio; int apple_dart_cio_bind(struct device *owner, struct device *provider, struct apple_dart_cio **state); int apple_dart_cio_prepare(struct apple_dart_cio *state); +int apple_dart_cio_prepare_runtime(struct apple_dart_cio *state); int apple_dart_cio_check(struct apple_dart_cio *state, bool quiesced); int apple_dart_cio_off(struct apple_dart_cio *state); int apple_dart_cio_on(struct apple_dart_cio *state); @@ -39,6 +40,11 @@ static inline int apple_dart_cio_prepare(struct apple_dart_cio *s) return -EOPNOTSUPP; } +static inline int apple_dart_cio_prepare_runtime(struct apple_dart_cio *s) +{ + return -EOPNOTSUPP; +} + static inline int apple_dart_cio_check(struct apple_dart_cio *s, bool quiesced) { return -EOPNOTSUPP; From 50257ff52fd45eaf714e8019f3769ac4b30141e7 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Thu, 26 Nov 2026 21:15:44 -0500 Subject: [PATCH 2/3] tools/asahi: update dart-cio-owner-tests for apple_dart_cio_prepare_common Signed-off-by: Erik Bourget --- tools/asahi/dart-cio-owner-tests.c | 9 +++++++++ tools/asahi/dart-cio-owner-tests.py | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/asahi/dart-cio-owner-tests.c b/tools/asahi/dart-cio-owner-tests.c index aed55d6640a8d..5a9e44b2f0dc9 100644 --- a/tools/asahi/dart-cio-owner-tests.c +++ b/tools/asahi/dart-cio-owner-tests.c @@ -405,5 +405,14 @@ int main(void) assert(!apple_dart_cio_finish(&state) && !provider.refs); cases++; } + /* Runtime prepare works outside PM_SUSPEND_MEM while sleep prepare refuses. */ + reset_owner(5, false); + pm_suspend_target_state = 0; + assert(apple_dart_cio_prepare(&state) == -EINVAL && !dart.cio_active && !provider.refs); + assert(!apple_dart_cio_prepare_runtime(&state) && !apple_dart_cio_off(&state)); + lose_power(); + assert(!apple_dart_cio_on(&state) && !apple_dart_cio_finish(&state) && !provider.refs); + pm_suspend_target_state = PM_SUSPEND_MEM; + cases++; printf("PASS %u CIO DART ownership cases\n", cases); } diff --git a/tools/asahi/dart-cio-owner-tests.py b/tools/asahi/dart-cio-owner-tests.py index 04b5e6725de16..da51c4b22fcfc 100644 --- a/tools/asahi/dart-cio-owner-tests.py +++ b/tools/asahi/dart-cio-owner-tests.py @@ -32,8 +32,10 @@ def main(): struct = re.search(r'^struct apple_dart_cio \{.*?\n\};', sources[paths[4]], re.M | re.S).group() names = ['apple_dart_cio_bank', 'apple_dart_cio_check', - 'apple_dart_cio_prepare', 'apple_dart_cio_gapf', 'apple_dart_cio_reopen', - 'apple_dart_cio_off', 'apple_dart_cio_on', 'apple_dart_cio_finish'] + 'apple_dart_cio_prepare_common', 'apple_dart_cio_prepare', + 'apple_dart_cio_prepare_runtime', 'apple_dart_cio_gapf', + 'apple_dart_cio_reopen', 'apple_dart_cio_off', + 'apple_dart_cio_on', 'apple_dart_cio_finish'] methods = '\n'.join(function(owner, n) for n in names) gate = '\n'.join(function(sources[paths[3]], n) for n in [ 'apple_dart_sleep_writer_get', 'apple_dart_sleep_writer_put', 'apple_dart_sleep_close']) From 36a97130f2c5ff696fb6f6bc96fae9b7a907735f Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Fri, 27 Nov 2026 13:45:33 -0500 Subject: [PATCH 3/3] soc: apple: dart-cio: document runtime prepare obligations Document the caller's serialization and cleanup obligations on apple_dart_cio_prepare_runtime(). Signed-off-by: Erik Bourget --- include/linux/soc/apple/dart-cio.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/linux/soc/apple/dart-cio.h b/include/linux/soc/apple/dart-cio.h index 760eb8156cdb0..f801f537f44e0 100644 --- a/include/linux/soc/apple/dart-cio.h +++ b/include/linux/soc/apple/dart-cio.h @@ -23,6 +23,12 @@ struct apple_dart_cio; int apple_dart_cio_bind(struct device *owner, struct device *provider, struct apple_dart_cio **state); int apple_dart_cio_prepare(struct apple_dart_cio *state); +/* + * Runtime variant of apple_dart_cio_prepare(): drops the PM_SUSPEND_MEM check + * and leaves a successful transaction active until apple_dart_cio_finish(). + * Callers must serialize the transaction against their device's suspend and + * removal paths and finish it on every exit. + */ int apple_dart_cio_prepare_runtime(struct apple_dart_cio *state); int apple_dart_cio_check(struct apple_dart_cio *state, bool quiesced); int apple_dart_cio_off(struct apple_dart_cio *state);