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
19 changes: 16 additions & 3 deletions drivers/iommu/apple-dart-cio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions include/linux/soc/apple/dart-cio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions tools/asahi/dart-cio-owner-tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
6 changes: 4 additions & 2 deletions tools/asahi/dart-cio-owner-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
Loading