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..f801f537f44e0 100644 --- a/include/linux/soc/apple/dart-cio.h +++ b/include/linux/soc/apple/dart-cio.h @@ -23,6 +23,13 @@ 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); int apple_dart_cio_on(struct apple_dart_cio *state); @@ -39,6 +46,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; 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'])