Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
3 changes: 3 additions & 0 deletions arch/arm64/boot/dts/apple/t8103-pmgr.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@
#power-domain-cells = <0>;
#reset-cells = <0>;
label = "fpwm0";
power-domains = <&ps_sio>;
};

ps_fpwm1: power-controller@1e0 {
Expand All @@ -251,6 +252,7 @@
#power-domain-cells = <0>;
#reset-cells = <0>;
label = "fpwm1";
power-domains = <&ps_sio>;
};

ps_fpwm2: power-controller@1e8 {
Expand All @@ -259,6 +261,7 @@
#power-domain-cells = <0>;
#reset-cells = <0>;
label = "fpwm2";
power-domains = <&ps_sio>;
};

ps_i2c0: power-controller@1f0 {
Expand Down
169 changes: 169 additions & 0 deletions drivers/dma/apple-sio-boot-test.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-only OR MIT
/* Included by apple-sio.c: exercise protocol-9 publication and ACK failures. */
#include <kunit/device.h>
#include <kunit/test.h>

struct sio_boot_test {
Expand Down Expand Up @@ -196,6 +197,7 @@ static void sio_sleep_busy_test(struct kunit *test)
KUNIT_ASSERT_NOT_NULL(test, chan);
KUNIT_ASSERT_NOT_NULL(test, tx);
spin_lock_init(&chan->vc.lock);
INIT_LIST_HEAD(&chan->vc.desc_issued);

KUNIT_EXPECT_FALSE(test, sio_chan_busy(chan));
chan->current_tx = tx;
Expand All @@ -207,6 +209,171 @@ static void sio_sleep_busy_test(struct kunit *test)
chan->ring = true;
KUNIT_EXPECT_TRUE(test, sio_chan_busy(chan));
chan->ring = false;
chan->tx_rpm_held = true;
KUNIT_EXPECT_TRUE(test, sio_chan_busy(chan));
chan->tx_rpm_held = false;
list_add_tail(&tx->vd.node, &chan->vc.desc_issued);
KUNIT_EXPECT_TRUE(test, sio_chan_busy(chan));
list_del_init(&tx->vd.node);
KUNIT_EXPECT_FALSE(test, sio_chan_busy(chan));
}

static void sio_test_noop_desc_free(struct virt_dma_desc *vd)
{
}

static void sio_test_pm_runtime_disable(void *dev)
{
pm_runtime_disable(dev);
}

/*
* Issuing a descriptor after SIO runtime-suspends must not publish to stopped
* firmware; it stays queued until resume, and terminate/synchronize drains it
* and releases any held transfer runtime PM reference.
*/
static void sio_issue_pending_after_autosuspend_test(struct kunit *test)
{
struct device *dev = kunit_device_register(test, "apple-sio-rpm-test");
struct sio_data *sio;
struct sio_chan *chan;
struct sio_tx *tx, *idle_tx;

KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
sio = kunit_kzalloc(test, struct_size(sio, channels, 1), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, sio);
tx = kunit_kzalloc(test, sizeof(*tx), GFP_KERNEL);
idle_tx = kunit_kzalloc(test, sizeof(*idle_tx), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, tx);
KUNIT_ASSERT_NOT_NULL(test, idle_tx);

sio->dev = dev;
sio->nchannels = 1;
WRITE_ONCE(sio->rpm_stopped, true);
INIT_LIST_HEAD(&sio->dma.channels);

chan = &sio->channels[0];
chan->host = sio;
chan->no = 0;
chan->configured = true;
chan->vc.desc_free = sio_test_noop_desc_free;
tx->vd.tx.chan = &chan->vc.chan;
idle_tx->vd.tx.chan = &chan->vc.chan;
INIT_WORK(&chan->issue_wq, sio_issue_work);
INIT_WORK(&chan->terminate_wq, sio_terminate_work);
INIT_LIST_HEAD(&chan->retired);
INIT_LIST_HEAD(&chan->dead);
init_waitqueue_head(&chan->drained);
mutex_init(&chan->sync_lock);
init_waitqueue_head(&chan->sync_wait);
vchan_init(&chan->vc, &sio->dma);

pm_runtime_set_suspended(dev);
pm_runtime_enable(dev);
KUNIT_ASSERT_EQ(test,
kunit_add_action_or_reset(test, sio_test_pm_runtime_disable, dev),
0);

/* Queue a submitted descriptor and issue while firmware is stopped. */
list_add_tail(&tx->vd.node, &chan->vc.desc_submitted);
sio_issue_pending(&chan->vc.chan);
flush_work(&chan->issue_wq);

KUNIT_EXPECT_NULL(test, chan->current_tx);
KUNIT_EXPECT_FALSE(test, chan->tx_rpm_held);
KUNIT_EXPECT_TRUE(test, sio_chan_busy(chan));
KUNIT_EXPECT_TRUE(test, bitmap_empty(sio->tags.allocated, SIO_NTAGS));
KUNIT_EXPECT_EQ(test, atomic_read(&dev->power.usage_count), 0);

/* Terminating drains the deferred descriptor cleanly. */
KUNIT_EXPECT_EQ(test, sio_terminate_all(&chan->vc.chan), 0);
sio_synchronize(&chan->vc.chan);
KUNIT_EXPECT_FALSE(test, sio_chan_busy(chan));
KUNIT_EXPECT_EQ(test, atomic_read(&dev->power.usage_count), 0);

/* Ring handover to an idle transfer releases the active transfer PM ref. */
pm_runtime_get_noresume(dev);
chan->ring = true;
chan->idle = idle_tx;
chan->current_tx = tx;
chan->tx_rpm_held = true;
tx->vd.tx.cookie = DMA_MIN_COOKIE;
tx->terminated = false;
KUNIT_EXPECT_EQ(test, sio_terminate_all(&chan->vc.chan), 0);
KUNIT_EXPECT_NULL(test, chan->current_tx);
KUNIT_EXPECT_FALSE(test, chan->tx_rpm_held);
KUNIT_EXPECT_EQ(test, atomic_read(&dev->power.usage_count), 0);
chan->idle = NULL;
chan->ring = false;
INIT_LIST_HEAD(&chan->dead);
INIT_LIST_HEAD(&chan->retired);
}

/*
* When SIO is marked unavailable (e.g. after runtime suspend stop and immediate
* return both fail) while runtime PM remains RPM_ACTIVE, new cyclic prep is
* refused and already-submitted descriptors are aborted rather than issued.
*/
static void sio_rtk_unavailable_rejects_issue_test(struct kunit *test)
{
struct device *dev = kunit_device_register(test, "apple-sio-unavail-test");
struct sio_data *sio;
struct sio_chan *chan;
struct sio_tx *tx;
struct dma_tx_state txstate = { 0 };

KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
sio = kunit_kzalloc(test, struct_size(sio, channels, 1), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, sio);
tx = kunit_kzalloc(test, sizeof(*tx), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, tx);

sio->dev = dev;
sio->nchannels = 1;
WRITE_ONCE(sio->rtk_unavailable, true);
INIT_LIST_HEAD(&sio->dma.channels);

chan = &sio->channels[0];
chan->host = sio;
chan->no = 0;
chan->configured = true;
chan->vc.desc_free = sio_test_noop_desc_free;
tx->vd.tx.chan = &chan->vc.chan;
tx->vd.tx.cookie = DMA_MIN_COOKIE;
tx->period_len = 0x1000;
tx->nperiods = 2;
chan->vc.chan.cookie = DMA_MIN_COOKIE;
INIT_WORK(&chan->issue_wq, sio_issue_work);
INIT_WORK(&chan->terminate_wq, sio_terminate_work);
INIT_LIST_HEAD(&chan->retired);
INIT_LIST_HEAD(&chan->dead);
init_waitqueue_head(&chan->drained);
mutex_init(&chan->sync_lock);
init_waitqueue_head(&chan->sync_wait);
vchan_init(&chan->vc, &sio->dma);

pm_runtime_set_active(dev);
pm_runtime_enable(dev);
KUNIT_ASSERT_EQ(test,
kunit_add_action_or_reset(test, sio_test_pm_runtime_disable, dev),
0);

KUNIT_EXPECT_NULL(test, sio_prep_dma_cyclic(&chan->vc.chan, 0x10000, 0x2000,
0x1000, DMA_MEM_TO_DEV, 0));
list_add_tail(&tx->vd.node, &chan->vc.desc_submitted);
sio_issue_pending(&chan->vc.chan);
flush_work(&chan->issue_wq);

KUNIT_EXPECT_NULL(test, chan->current_tx);
KUNIT_EXPECT_FALSE(test, chan->tx_rpm_held);
KUNIT_EXPECT_FALSE(test, sio_chan_busy(chan));
KUNIT_EXPECT_TRUE(test, list_empty(&chan->vc.desc_issued));
KUNIT_EXPECT_EQ(test, atomic_read(&dev->power.usage_count), 0);
KUNIT_EXPECT_EQ(test, sio_tx_status(&chan->vc.chan, DMA_MIN_COOKIE, &txstate),
DMA_ERROR);
KUNIT_EXPECT_EQ(test, txstate.residue, 0x2000U);

sio_synchronize(&chan->vc.chan);
KUNIT_EXPECT_FALSE(test, sio_chan_busy(chan));
}

Expand All @@ -217,6 +384,8 @@ static struct kunit_case sio_boot_test_cases[] = {
KUNIT_CASE(sio_boot_control_ack_failure_test),
KUNIT_CASE(sio_boot_dma_arrays_test),
KUNIT_CASE(sio_sleep_busy_test),
KUNIT_CASE(sio_issue_pending_after_autosuspend_test),
KUNIT_CASE(sio_rtk_unavailable_rejects_issue_test),
{}
};

Expand Down
14 changes: 14 additions & 0 deletions drivers/dma/apple-sio-msg-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ static void sio_test_ack_callback(struct sio_chan *chan, void *cookie, bool ok)
ack->calls++;
}

/* Undoes sio_test_alloc()'s runtime PM: the hold it took, then the enable. */
static void sio_test_rpm_release(void *dev)
{
pm_runtime_disable(dev);
pm_runtime_put_noidle(dev);
pm_runtime_set_suspended(dev);
}

static struct sio_data *sio_test_alloc(struct kunit *test, int nchannels)
{
struct sio_data *sio;
Expand All @@ -86,6 +94,11 @@ static struct sio_data *sio_test_alloc(struct kunit *test, int nchannels)
sio->dev = dev;
sio->nchannels = nchannels;
sio_init_tags(sio);
/* As probe leaves a running SIO: runtime-active, and held while in use. */
pm_runtime_get_noresume(dev);
pm_runtime_set_active(dev);
pm_runtime_enable(dev);
KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test, sio_test_rpm_release, dev), 0);
for (i = 0; i < nchannels; i++) {
struct sio_chan *chan = &sio->channels[i];

Expand All @@ -97,6 +110,7 @@ static struct sio_data *sio_test_alloc(struct kunit *test, int nchannels)
init_waitqueue_head(&chan->drained);
mutex_init(&chan->sync_lock);
init_waitqueue_head(&chan->sync_wait);
INIT_WORK(&chan->issue_wq, sio_issue_work);
INIT_WORK(&chan->terminate_wq, sio_terminate_work);
}
return sio;
Expand Down
Loading
Loading