[PATCH v4 08/10] platform/x86/intel/pmt: add register access helpers
Ilpo Järvinen
ilpo.jarvinen at linux.intel.com
Wed Jun 11 10:52:24 UTC 2025
On Tue, 10 Jun 2025, Michael J. Ruhl wrote:
> 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 <michael.j.ruhl at intel.com>
> ---
> drivers/platform/x86/intel/pmt/crashlog.c | 58 +++++++++++------------
> 1 file changed, 29 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/platform/x86/intel/pmt/crashlog.c b/drivers/platform/x86/intel/pmt/crashlog.c
> index 99f0e85f2de6..e11865686f2a 100644
> --- a/drivers/platform/x86/intel/pmt/crashlog.c
> +++ b/drivers/platform/x86/intel/pmt/crashlog.c
> @@ -63,20 +63,40 @@ struct pmt_crashlog_priv {
> /*
> * I/O
> */
> -static bool pmt_crashlog_complete(struct intel_pmt_entry *entry)
> +#define SET true
> +#define CLEAR false
There's a risk of namespace collisions if using too generic names.
> +static void read_modify_write(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);
> +}
> +
> +static bool read_check(struct intel_pmt_entry *entry, u32 bit)
Despite being static, I'd prefer these to have prefixes. With the prefixes
reading the calling code, it's trivial to discern it's an driver internal
function whereas generic names likes will not convey the scope
information.
> +{
> + 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 read_check(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 read_check(entry, CRASHLOG_FLAG_DISABLE);
> }
>
> static bool pmt_crashlog_supported(struct intel_pmt_entry *entry)
> @@ -97,37 +117,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);
> + read_modify_write(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);
> + read_modify_write(entry, CRASHLOG_FLAG_TRIGGER_CLEAR, SET);
> }
>
> 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);
> + read_modify_write(entry, CRASHLOG_FLAG_TRIGGER_EXECUTE, SET);
> }
>
> /*
>
--
i.
More information about the Intel-xe
mailing list