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
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ select:
properties:
compatible: true

apple,wake-latched-sources:
$ref: /schemas/types.yaml#/definitions/uint32-array
description:
Interrupt indices of the sources that a wake from system sleep latches. Such a line is
raised once by the wake and stays asserted until the next sleep. The assertion after a
wake is counted rather than reported, until the line is seen to clear.

allOf:
- if:
properties:
Expand Down Expand Up @@ -159,6 +166,8 @@ allOf:
- apple,t8152-event-log
- const: apple,soc-event-log

apple,wake-latched-sources: true

power-domains:
maxItems: 1
description: Power domain needed for the associated error-source registers.
Expand Down
2 changes: 2 additions & 0 deletions arch/arm64/boot/dts/apple/t8112-peripherals.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@

m2_event_log_handler: event-log@23b700000 {
compatible = "apple,t8112-event-log", "apple,soc-event-log";
/* The PMGR clock-mux block's source: its first access after a wake latches it. */
apple,wake-latched-sources = <2>;
reg = <0x2 0x3b700000 0x0 0xcc000>,
<0x2 0x3d280000 0x0 0x7c000>,
<0x2 0x3b000000 0x0 0x70000>,
Expand Down
6 changes: 6 additions & 0 deletions drivers/edac/apple_soc_edac-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ struct apple_soc_edac_irq {
unsigned int backoff_ms;
unsigned long armed_jiffies;
struct delayed_work rearm;
/* The DT lists this source as latched by a wake from system sleep. */
bool wake_latched;
/* Since the last wake, until the line is found to have cleared. */
bool wake_window;
unsigned int wake_events;
};

struct apple_soc_edac {
Expand All @@ -82,6 +87,7 @@ bool apple_soc_edac_t6041_status(struct apple_soc_edac_irq *irq_data,
bool apple_soc_edac_ni_status(struct apple_soc_edac_irq *irq_data,
bool *cleared);
void apple_soc_edac_rearm(struct work_struct *work);
void apple_soc_edac_open_wake_windows(struct apple_soc_edac *edac);
irqreturn_t apple_soc_edac_irq_thread(int irq, void *data);
extern const struct of_device_id apple_soc_edac_of_match[];
#endif
Expand Down
70 changes: 70 additions & 0 deletions drivers/edac/apple_soc_edac-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,73 @@ static void edac_test_irq_backoff_reset(struct kunit *test)
KUNIT_EXPECT_EQ(test, ctx->irq.retries, 2U);
}

/* A wake-latched source: counted, not reported, inside the wake window. */
static void edac_test_irq_wake_window(struct kunit *test)
{
const struct apple_soc_edac_hw *hw =
edac_test_hw(test, "apple,t8112-event-log");
struct edac_test_ctx *ctx = edac_test_line(test, hw, 2);

ctx->irq.wake_latched = true;
ctx->edac.hw = hw;
/* Before any wake, the source reports. */
edac_test_fire(test, ctx, APPLE_SOC_EDAC_BACKOFF_MS);
KUNIT_EXPECT_EQ(test, edac_test_ue(ctx), 1U);

/* Each re-arm after the wake finds it still asserted: counted only. */
ctx->irq.wake_window = true;
ctx->irq.armed_jiffies = jiffies;
edac_test_fire(test, ctx, 2 * APPLE_SOC_EDAC_BACKOFF_MS);
ctx->irq.armed_jiffies = jiffies;
edac_test_fire(test, ctx, 4 * APPLE_SOC_EDAC_BACKOFF_MS);
KUNIT_EXPECT_EQ(test, edac_test_ue(ctx), 1U);
KUNIT_EXPECT_EQ(test, ctx->irq.wake_events, 2U);
KUNIT_EXPECT_TRUE(test, ctx->irq.wake_window);
}

/* A wake-latched line that had cleared and fires again is a new event. */
static void edac_test_irq_wake_window_closes(struct kunit *test)
{
const struct apple_soc_edac_hw *hw =
edac_test_hw(test, "apple,t8112-event-log");
struct edac_test_ctx *ctx = edac_test_line(test, hw, 2);

ctx->irq.wake_latched = true;
ctx->irq.wake_window = true;
ctx->irq.armed_jiffies = jiffies -
msecs_to_jiffies(APPLE_SOC_EDAC_BACKOFF_MAX_MS) - 1;
edac_test_fire(test, ctx, APPLE_SOC_EDAC_BACKOFF_MS);
KUNIT_EXPECT_EQ(test, edac_test_ue(ctx), 1U);
KUNIT_EXPECT_EQ(test, ctx->irq.wake_events, 0U);
KUNIT_EXPECT_FALSE(test, ctx->irq.wake_window);
}

/* A wake opens the window on the latched sources only. */
static void edac_test_open_wake_windows(struct kunit *test)
{
const struct apple_soc_edac_hw *hw =
edac_test_hw(test, "apple,t8112-event-log");
struct edac_test_ctx *ctx = edac_test_line(test, hw, 2);
struct apple_soc_edac_irq irqs[16] = {};
struct apple_soc_edac edac = { .hw = hw, .irqs = irqs };
unsigned long before;

KUNIT_ASSERT_GE(test, ARRAY_SIZE(irqs), hw->num_irqs);
irqs[2].source = "event-log";
irqs[2].wake_latched = true;
irqs[3].source = "event-log";
irqs[5].wake_latched = true; /* not claimed: no source */
/* Last unmasked long before the sleep: the window is timed from the wake. */
irqs[2].armed_jiffies = jiffies - 10 * msecs_to_jiffies(APPLE_SOC_EDAC_BACKOFF_MAX_MS);
before = jiffies;
apple_soc_edac_open_wake_windows(&edac);
KUNIT_EXPECT_TRUE(test, irqs[2].wake_window);
KUNIT_EXPECT_GE(test, irqs[2].armed_jiffies, before);
KUNIT_EXPECT_FALSE(test, irqs[3].wake_window);
KUNIT_EXPECT_FALSE(test, irqs[5].wake_window);
KUNIT_EXPECT_NOT_NULL(test, ctx);
}

/* The rearm work unmasks and restarts the quiet-period clock. */
static void edac_test_rearm(struct kunit *test)
{
Expand All @@ -791,6 +858,9 @@ static void edac_test_rearm(struct kunit *test)

static struct kunit_case apple_soc_edac_test_cases[] = {
KUNIT_CASE(edac_test_source_t6041),
KUNIT_CASE(edac_test_irq_wake_window),
KUNIT_CASE(edac_test_irq_wake_window_closes),
KUNIT_CASE(edac_test_open_wake_windows),
KUNIT_CASE(edac_test_source_edges),
KUNIT_CASE(edac_test_tables),
KUNIT_CASE(edac_test_t6041_status_lines),
Expand Down
67 changes: 64 additions & 3 deletions drivers/edac/apple_soc_edac.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/pm.h>
#include <linux/workqueue.h>

#include "edac_module.h"
Expand Down Expand Up @@ -268,11 +269,33 @@ VISIBLE_IF_KUNIT void apple_soc_edac_rearm(struct work_struct *work)
}
EXPORT_SYMBOL_IF_KUNIT(apple_soc_edac_rearm);

/*
* A wake from system sleep latches some sources (the DT's apple,wake-latched-sources): the line
* is raised once by the wake and stays asserted until the next sleep. Each wake opens a window
* for them in which that assertion is expected and counted, not reported. The window closes once
* the line has stayed quiet for a minute, timed from the wake: the last unmask may have been long
* before the sleep.
*/
VISIBLE_IF_KUNIT void apple_soc_edac_open_wake_windows(struct apple_soc_edac *edac)
{
unsigned int i;

for (i = 0; i < edac->hw->num_irqs; i++) {
struct apple_soc_edac_irq *irq_data = &edac->irqs[i];

if (!irq_data->source || !irq_data->wake_latched)
continue;
irq_data->armed_jiffies = jiffies;
WRITE_ONCE(irq_data->wake_window, true);
}
}
EXPORT_SYMBOL_IF_KUNIT(apple_soc_edac_open_wake_windows);

VISIBLE_IF_KUNIT irqreturn_t apple_soc_edac_irq_thread(int irq, void *data)
{
struct apple_soc_edac_irq *irq_data = data;
struct apple_soc_edac *edac = irq_data->edac;
bool error, cleared;
bool error, cleared, expected;
char msg[64];

snprintf(msg, sizeof(msg), "%s source %u", irq_data->source,
Expand Down Expand Up @@ -310,7 +333,22 @@ VISIBLE_IF_KUNIT irqreturn_t apple_soc_edac_irq_thread(int irq, void *data)
/* No status was pending, or this source has no clear contract. */
disable_irq_nosync(irq);

if (!irq_data->ni && (!edac->hw->num_status_regs || irq_data->index < 45)) {
/*
* A wake-latched line inside its window is the wake's own assertion. One that had stayed
* quiet for a minute after its last unmask had cleared, so this is a new event: the
* window closes and it reports.
*/
expected = READ_ONCE(irq_data->wake_window);
if (expected && time_after(jiffies, irq_data->armed_jiffies +
msecs_to_jiffies(APPLE_SOC_EDAC_BACKOFF_MAX_MS))) {
WRITE_ONCE(irq_data->wake_window, false);
expected = false;
}
if (expected) {
irq_data->wake_events++;
dev_dbg(edac->dev, "%s asserted since the wake (%u), not reported\n", msg,
irq_data->wake_events);
} else if (!irq_data->ni && (!edac->hw->num_status_regs || irq_data->index < 45)) {
edac_device_handle_ue(edac->dci, 0, 0, msg);
dev_err_ratelimited(edac->dev,
"hardware error: %s (IRQ %d)\n", msg, irq);
Expand Down Expand Up @@ -366,7 +404,7 @@ static int apple_soc_edac_probe(struct platform_device *pdev)
struct apple_soc_edac *edac;
unsigned int requested = 0;
unsigned int i;
int ret;
int ret, n;

hw = device_get_match_data(&pdev->dev);
if (!hw)
Expand Down Expand Up @@ -451,6 +489,17 @@ static int apple_soc_edac_probe(struct platform_device *pdev)
requested++;
}

n = of_property_count_u32_elems(pdev->dev.of_node, "apple,wake-latched-sources");
for (i = 0; n > 0 && i < n; i++) {
u32 idx;

if (of_property_read_u32_index(pdev->dev.of_node, "apple,wake-latched-sources",
i, &idx) || idx >= hw->num_irqs ||
!edac->irqs[idx].source)
continue;
edac->irqs[idx].wake_latched = true;
}

for (i = 0; i < hw->num_irqs; i++) {
if (edac->irqs[i].source)
enable_irq(edac->irqs[i].irq);
Expand Down Expand Up @@ -499,11 +548,23 @@ VISIBLE_IF_KUNIT const struct of_device_id apple_soc_edac_of_match[] = {
EXPORT_SYMBOL_IF_KUNIT(apple_soc_edac_of_match);
MODULE_DEVICE_TABLE(of, apple_soc_edac_of_match);

/* Before the lines are unmasked again at the wake, so the wake's own assertion lands inside. */
static int apple_soc_edac_resume_noirq(struct device *dev)
{
apple_soc_edac_open_wake_windows(dev_get_drvdata(dev));
return 0;
}

static const struct dev_pm_ops apple_soc_edac_pm_ops = {
NOIRQ_SYSTEM_SLEEP_PM_OPS(NULL, apple_soc_edac_resume_noirq)
};

static struct platform_driver apple_soc_edac_driver = {
.probe = apple_soc_edac_probe,
.remove = apple_soc_edac_remove,
.driver = {
.name = APPLE_SOC_EDAC_NAME,
.pm = pm_sleep_ptr(&apple_soc_edac_pm_ops),
.of_match_table = apple_soc_edac_of_match,
},
};
Expand Down
Loading