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
8 changes: 4 additions & 4 deletions drivers/iommu/apple-dart-v27-late.inc
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ int apple_dart_v27_claim(struct device *dev, struct device *owner,
return -EBUSY;
}
if (dev->driver != &apple_dart_driver.driver || !(d = dev_get_drvdata(dev)) ||
!d->v27_provider || !mutex_trylock(&d->v27_lifecycle)) {
!d->v27_provider || down_trylock(&d->v27_lifecycle)) {
device_unlock(dev);
return -ENODEV;
}
if (!try_module_get(THIS_MODULE)) {
mutex_unlock(&d->v27_lifecycle);
up(&d->v27_lifecycle);
device_unlock(dev);
return -ENODEV;
}
Expand Down Expand Up @@ -340,7 +340,7 @@ free:
unlock:
module_put(THIS_MODULE);
put_device(dev);
mutex_unlock(&d->v27_lifecycle);
up(&d->v27_lifecycle);
return ret;
}
EXPORT_SYMBOL_GPL(apple_dart_v27_claim);
Expand Down Expand Up @@ -459,7 +459,7 @@ int apple_dart_v27_finish(struct apple_dart_v27_lease *l, bool stopped)
WRITE_ONCE(d->m5_sleep_owner, NULL);
WRITE_ONCE(d->v27_restoring, false);
pm_runtime_put_noidle(d->dev);
mutex_unlock(&d->v27_lifecycle);
up(&d->v27_lifecycle);
module_put(l->module);
put_device(provider);
kfree(l);
Expand Down
21 changes: 14 additions & 7 deletions drivers/iommu/apple-dart.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/pm_wakeup.h>
#include <linux/semaphore.h>
#include <linux/slab.h>
#include <linux/soc/apple/tunable.h>
#include <linux/string.h>
Expand Down Expand Up @@ -385,7 +386,11 @@ struct apple_dart {
u32 m5_disp_streams; /* the display pipe's streams before its domain went off */
bool m5_released, m5_changed, m5_display, m5_failed;
/* Optional cached evidence; never a sleep-ownership grant. */
struct mutex v27_lifecycle;
/*
* Held for as long as a sleep lease lasts: taken by the suspend that claims the lease and
* released by the resume that finishes it, in another task. So a semaphore, not a mutex.
*/
struct semaphore v27_lifecycle;
struct list_head v27_clients;
atomic_t v27_ops;
bool v27_provider, v27_lost, v27_noirq_skip, v27_restoring;
Expand Down Expand Up @@ -5795,7 +5800,7 @@ static int apple_dart_probe(struct platform_device *pdev)
}
}
spin_lock_init(&dart->lock);
mutex_init(&dart->v27_lifecycle);
sema_init(&dart->v27_lifecycle, 1);
INIT_LIST_HEAD(&dart->v27_clients);
atomic_set(&dart->v27_ops, 0);
dart->v27_provider = res && apple_dart_v27_provider(dev, res->start);
Expand Down Expand Up @@ -6535,10 +6540,12 @@ int apple_dart_restore_tunnel_state(struct device *dev)
}
EXPORT_SYMBOL_GPL(apple_dart_restore_tunnel_state);

DEFINE_GUARD(apple_dart_v27_lifecycle, struct semaphore *, down(_T), up(_T))

static void apple_dart_remove(struct platform_device *pdev)
{
struct apple_dart *dart = platform_get_drvdata(pdev);
guard(mutex)(&dart->v27_lifecycle);
guard(apple_dart_v27_lifecycle)(&dart->v27_lifecycle);

if (dart->cold_ane) {
dev_warn(&pdev->dev, "cold ANE DART retained until reset\n");
Expand Down Expand Up @@ -6593,11 +6600,11 @@ static void apple_dart_shutdown(struct platform_device *pdev)
struct apple_dart *dart = platform_get_drvdata(pdev);

/*
* A sleep lease that lost its retained state keeps this mutex for good, so that nothing
* A sleep lease that lost its retained state keeps this semaphore for good, so that nothing
* reuses the DART before the platform reset. The reset is what follows here: waiting for
* the mutex would hang the shutdown.
* it would hang the shutdown.
*/
if (!mutex_trylock(&dart->v27_lifecycle)) {
if (down_trylock(&dart->v27_lifecycle)) {
dev_info(&pdev->dev, "shutdown: left as its sleep lease pinned it\n");
return;
}
Expand All @@ -6609,7 +6616,7 @@ static void apple_dart_shutdown(struct platform_device *pdev)
*/
if (apple_dart_has_borrowed(dart))
apple_dart_fail_borrowed(dart, "shutdown");
mutex_unlock(&dart->v27_lifecycle);
up(&dart->v27_lifecycle);
}

static const struct apple_dart_hw apple_dart_hw_t8103 = {
Expand Down
18 changes: 13 additions & 5 deletions drivers/soc/apple/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <linux/cpu.h>
#include <linux/cpumask.h>
#include <linux/completion.h>
#include <linux/cpuidle.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/err.h>
Expand Down Expand Up @@ -6027,14 +6028,21 @@ static int apple_sleep_enter_prepare(struct apple_sleep *s)
static int apple_sleep_enter_saved(unsigned long unused)
{
struct apple_sleep *s = apple_sleep;
int ret = s->soc->ops->cpu_prepare(s->mbox->boot_mpidr);
int ret;

/*
* cpu_suspend() calls its finisher with RCU not watching. Up to the commit this one
* takes locks, logs and looks at work items: RCU watches until then.
*/
ct_cpuidle_exit();
ret = s->soc->ops->cpu_prepare(s->mbox->boot_mpidr);
if (!ret)
ret = apple_sleep_enter_prepare(s);
if (!ret)
pm_set_resume_via_firmware();
ct_cpuidle_enter();
if (ret)
return ret;
ret = apple_sleep_enter_prepare(s);
if (ret)
return ret;
pm_set_resume_via_firmware();
/* cpu_suspend has already saved boot context. Commit never returns. */
return apple_sleep_commit(0);
}
Expand Down
Loading