From: Michael J. Ruhl Date: Sun, 13 Jul 2025 17:29:40 +0000 (-0400) Subject: platform/x86/intel/pmt: add register access helpers X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f57b32cb4adb28b62f61c4729f7b85f55518cb2b;p=thirdparty%2Fkernel%2Fstable.git platform/x86/intel/pmt: add register access helpers The control register is used in a read/modify/write pattern. The status register is used in a read/check bit pattern. Add helpers to eliminate common code. Signed-off-by: Michael J. Ruhl Link: https://lore.kernel.org/r/20250713172943.7335-11-michael.j.ruhl@intel.com Reviewed-by: Ilpo Järvinen Signed-off-by: Ilpo Järvinen --- diff --git a/drivers/platform/x86/intel/pmt/crashlog.c b/drivers/platform/x86/intel/pmt/crashlog.c index 23b3971da40ac..ed781548e59d2 100644 --- a/drivers/platform/x86/intel/pmt/crashlog.c +++ b/drivers/platform/x86/intel/pmt/crashlog.c @@ -64,20 +64,40 @@ struct pmt_crashlog_priv { /* * I/O */ -static bool pmt_crashlog_complete(struct intel_pmt_entry *entry) + +/* Read, modify, write the control register, setting or clearing @bit based on @set */ +static void pmt_crashlog_rmw(struct intel_pmt_entry *entry, u32 bit, bool set) { - u32 control = readl(entry->disc_table + CONTROL_OFFSET); + u32 reg = readl(entry->disc_table + CONTROL_OFFSET); + + reg &= ~CRASHLOG_FLAG_TRIGGER_MASK; + + if (set) + reg |= bit; + else + reg &= ~bit; + + writel(reg, entry->disc_table + CONTROL_OFFSET); +} + +/* Read the status register and see if the specified @bit is set */ +static bool pmt_crashlog_rc(struct intel_pmt_entry *entry, u32 bit) +{ + u32 reg = readl(entry->disc_table + CONTROL_OFFSET); + + return !!(reg & bit); +} +static bool pmt_crashlog_complete(struct intel_pmt_entry *entry) +{ /* return current value of the crashlog complete flag */ - return !!(control & CRASHLOG_FLAG_TRIGGER_COMPLETE); + return pmt_crashlog_rc(entry, CRASHLOG_FLAG_TRIGGER_COMPLETE); } static bool pmt_crashlog_disabled(struct intel_pmt_entry *entry) { - u32 control = readl(entry->disc_table + CONTROL_OFFSET); - /* return current value of the crashlog disabled flag */ - return !!(control & CRASHLOG_FLAG_DISABLE); + return pmt_crashlog_rc(entry, CRASHLOG_FLAG_DISABLE); } static bool pmt_crashlog_supported(struct intel_pmt_entry *entry) @@ -98,37 +118,17 @@ static bool pmt_crashlog_supported(struct intel_pmt_entry *entry) static void pmt_crashlog_set_disable(struct intel_pmt_entry *entry, bool disable) { - u32 control = readl(entry->disc_table + CONTROL_OFFSET); - - /* clear trigger bits so we are only modifying disable flag */ - control &= ~CRASHLOG_FLAG_TRIGGER_MASK; - - if (disable) - control |= CRASHLOG_FLAG_DISABLE; - else - control &= ~CRASHLOG_FLAG_DISABLE; - - writel(control, entry->disc_table + CONTROL_OFFSET); + pmt_crashlog_rmw(entry, CRASHLOG_FLAG_DISABLE, disable); } static void pmt_crashlog_set_clear(struct intel_pmt_entry *entry) { - u32 control = readl(entry->disc_table + CONTROL_OFFSET); - - control &= ~CRASHLOG_FLAG_TRIGGER_MASK; - control |= CRASHLOG_FLAG_TRIGGER_CLEAR; - - writel(control, entry->disc_table + CONTROL_OFFSET); + pmt_crashlog_rmw(entry, CRASHLOG_FLAG_TRIGGER_CLEAR, true); } static void pmt_crashlog_set_execute(struct intel_pmt_entry *entry) { - u32 control = readl(entry->disc_table + CONTROL_OFFSET); - - control &= ~CRASHLOG_FLAG_TRIGGER_MASK; - control |= CRASHLOG_FLAG_TRIGGER_EXECUTE; - - writel(control, entry->disc_table + CONTROL_OFFSET); + pmt_crashlog_rmw(entry, CRASHLOG_FLAG_TRIGGER_EXECUTE, true); } /*