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: 15880 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp797262wru; Fri, 4 Nov 2022 21:23:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6kMbofcRfBUWfUcK2Bm6KU8mmA9sSItQjQuhhZDbBjpeImaocfdea1dKnmLk84nrbNR+D3 X-Received: by 2002:aa7:8e89:0:b0:56c:636a:fa37 with SMTP id a9-20020aa78e89000000b0056c636afa37mr38963462pfr.83.1667622226522; Fri, 04 Nov 2022 21:23:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667622226; cv=none; d=google.com; s=arc-20160816; b=WPYfWbYhlii7810h5XSPDHPbttw83yLUf2UE5DCg+zGatJt+cHxpx3PNIb9s+7Jfhb 09C8Mj59HbvxX8Hkw7BTltesjwcBglHJ2KJM012XMUJccUakVLUl3JnmnzT2Pl9S4h9q 3EKTL+lW5M8BUDE+v/cfLIJqE/dEg3BXRqIULz//IgLeczPBi7v06XNZPfw5WiSVTtwe xQMeIzg3yLh2RDVyRFwf5vaKzxUQKQswtqdyjrsMqijVIMj4WlIUrh0pQBB17ZYXwpyv lujjYQfamL2tpc/q3mHMLRbm1iiNGypCHhbKzP95kv5vY+ZvM/9OkN0IzNFB+H7DAmd/ PPdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=aaEk4TRvaFFk7lgTP6mz7WtSHiVY82CogmSErBHUhaI=; b=wb2/cSE7JRpB3a2pV8vnKXflsEprjs9xUc1NLSiN+UzlYCavuxqklCcqEcvukcLOiO /HFcg5z0MMGrlhBWfTec3md/hO8ADVtlWyXIsAroHdnKCRgcM7jh37uGdQdMuBwlDiD+ YlReAxdRy0hefIcWQadENH65HxFq6HrTLHtWY8kIc69bJBfPrmjdIKS6TlCSnc9CAs9S zInGi8ae5wJoIdoBlbhok4VdjJz8nXRYeNkn2hQyRQgD9zC3WSFqNNtDCO+BAVzn5l6R NXSNRGg0gMsBHOHa90Txh78fF9iTwglwZulXNieToxR7uFMqXnMDtj+vByj/L3LmIeZz Xanw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bo6VOOrK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t7-20020a632247000000b0046fcf7aca3dsi1739274pgm.675.2022.11.04.21.23.33; Fri, 04 Nov 2022 21:23:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bo6VOOrK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229549AbiKEDsH (ORCPT + 99 others); Fri, 4 Nov 2022 23:48:07 -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 X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748628644144657880?= X-GMAIL-MSGID: =?utf-8?q?1748628644144657880?= 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; }