platform/x86/intel/pmt: Sapphire Rapids PMT errata fix

commit bcdfa1f77e upstream.

On Sapphire Rapids, due to a hardware issue affecting the PUNIT telemetry
region, reads that are not done in QWORD quantities and alignment may
return incorrect data. Use a custom 64-bit copy for this region.

Intel-SIG: commit bcdfa1f77e platform/x86/intel/pmt: Sapphire Rapids PMT errata fix
Backport for PMT important fix

Signed-off-by: David E. Box <david.e.box@linux.intel.com>
Link: https://lore.kernel.org/r/20221105034228.1376677-1-david.e.box@linux.intel.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
[ yingbao jia: amend commit log ]
Signed-off-by: yingbao jia <yingbao.jia@intel.com>
This commit is contained in:
David E. Box 2022-11-04 20:42:28 -07:00 committed by Jianping Liu
parent 1443dc5a69
commit 7c09555dea
1 changed files with 30 additions and 1 deletions

View File

@ -9,6 +9,7 @@
*/
#include <linux/kernel.h>
#include <linux/io-64-nonatomic-lo-hi.h>
#include <linux/module.h>
#include <linux/mm.h>
#include <linux/pci.h>
@ -18,6 +19,7 @@
#define PMT_XA_START 0
#define PMT_XA_MAX INT_MAX
#define PMT_XA_LIMIT XA_LIMIT(PMT_XA_START, PMT_XA_MAX)
#define GUID_SPR_PUNIT 0x9956f43f
/*
* Early implementations of PMT on client platforms have some
@ -41,6 +43,29 @@ bool intel_pmt_is_early_client_hw(struct device *dev)
}
EXPORT_SYMBOL_GPL(intel_pmt_is_early_client_hw);
static inline int
pmt_memcpy64_fromio(void *to, const u64 __iomem *from, size_t count)
{
int i, remain;
u64 *buf = to;
if (!IS_ALIGNED((unsigned long)from, 8))
return -EFAULT;
for (i = 0; i < count/8; i++)
buf[i] = readq(&from[i]);
/* Copy any remaining bytes */
remain = count % 8;
if (remain) {
u64 tmp = readq(&from[i]);
memcpy(&buf[i], &tmp, remain);
}
return count;
}
/*
* sysfs
*/
@ -62,6 +87,10 @@ intel_pmt_read(struct file *filp, struct kobject *kobj,
if (count > entry->size - off)
count = entry->size - off;
if (entry->guid == GUID_SPR_PUNIT)
/* PUNIT on SPR only supports aligned 64-bit read */
count = pmt_memcpy64_fromio(buf, entry->base + off, count);
else
memcpy_fromio(buf, entry->base + off, count);
return count;