From patchwork Sat Nov 5 03:42:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "David E. Box" X-Patchwork-Id: 13032826 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69E07C4332F for ; Sat, 5 Nov 2022 03:48:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229505AbiKEDsG (ORCPT ); Fri, 4 Nov 2022 23:48:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbiKEDsD (ORCPT ); Fri, 4 Nov 2022 23:48:03 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 952F430F57; Fri, 4 Nov 2022 20:48:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667620082; x=1699156082; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Ys34ez7ZeKmkHIVhh+N4ZKBlxYKVu++wIiRaYVAo3bw=; b=bo6VOOrKGvBG912t8A2FrbujQCvKcejzwy6yXWoVo9Sq0k85T839xD7b T8GUGrEhKzic7fGbxwrasnVn10H+Wku9LGjPxbqgFedSkL0ZLl8kzdlmh J/qMWSamQd2obESnwVMIheIRxQoEPUOuODQpe1V9CXdIxYDny5WC3ftTD LUjIyNCCE78BKdEDnvZ7+7DBhlfpVREUqwZp7v2/wfPTaU52HNDQpNjko yDcc0l86SngCCj4lU8RkAgt5AKQZK8CYjpFQE5YkX6D8X+YM1BU/UhmHY aPC687hl9Ss6DMfljE51aotYTM0xzN7RW4q2+7CdYwEPuENxsLTBYxlnU A==; X-IronPort-AV: E=McAfee;i="6500,9779,10521"; a="290515084" X-IronPort-AV: E=Sophos;i="5.96,139,1665471600"; d="scan'208";a="290515084" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2022 20:42:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10521"; a="586392680" X-IronPort-AV: E=Sophos;i="5.96,139,1665471600"; d="scan'208";a="586392680" Received: from linux.intel.com ([10.54.29.200]) by orsmga003.jf.intel.com with ESMTP; 04 Nov 2022 20:42:29 -0700 Received: from debox1-desk4.intel.com (unknown [10.212.242.20]) by linux.intel.com (Postfix) with ESMTP id 2CD08580BDB; Fri, 4 Nov 2022 20:42:29 -0700 (PDT) From: "David E. Box" To: david.e.box@linux.intel.com, hdegoede@redhat.com, markgross@kernel.org Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] platform/x86/intel/pmt: Sapphire Rapids PMT errata fix Date: Fri, 4 Nov 2022 20:42:28 -0700 Message-Id: <20221105034228.1376677-1-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org 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. Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmt/class.c | 31 +++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) base-commit: 225469d4acbcb873358d7618bad6e0203b67b964 diff --git a/drivers/platform/x86/intel/pmt/class.c b/drivers/platform/x86/intel/pmt/class.c index 53d7fd2943b4..46598dcb634a 100644 --- a/drivers/platform/x86/intel/pmt/class.c +++ b/drivers/platform/x86/intel/pmt/class.c @@ -9,6 +9,7 @@ */ #include +#include #include #include #include @@ -19,6 +20,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 bool intel_pmt_is_early_client_hw(struct device *dev) { @@ -33,6 +35,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 */ @@ -54,7 +79,11 @@ intel_pmt_read(struct file *filp, struct kobject *kobj, if (count > entry->size - off) count = entry->size - off; - memcpy_fromio(buf, entry->base + off, count); + 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; }