Received: by 2002:a05:7412:b112:b0:f9:3106:f1c0 with SMTP id az18csp23535rdb; Sun, 17 Dec 2023 19:05:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IG7LsgYaMQ45RZNqTn9wI0J3qjJ0wImsx++B2QkeuCx3hDV7mwSDSALpshYGS64KNZNuD0m X-Received: by 2002:a92:cda4:0:b0:35f:addc:b2cd with SMTP id g4-20020a92cda4000000b0035faddcb2cdmr2666567ild.61.1702868699952; Sun, 17 Dec 2023 19:04:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702868699; cv=none; d=google.com; s=arc-20160816; b=KyrU31GzYNG9E9YXTlYj2sZa6MRs9tmu4oE9n/ECOcZ2nPZoMovZ0AoJr2szCjCr1o JCTOBZMsqkomJAd60QqkFa/S/R/R/6j/rZ23sxHWnT85mjeb2mqZDvBe14tI1akjgAPP RTWVPmG79lkpL8lCB0ibbeRnfgeKoR5gaLHt/ZjPfkG7lbk+B3H5FlZVtTGqqOyox+mH 7NOfoItAYV8Ss+lkIXK3jg7Xgf1B8e2KksPwN9HoUH+eq61uQaQYmYCTjPAbdvcKMUoe uUAl1r0bQ5dSOIkR1BdFxfvUQjYfsJHImIcmbcaYh7wEcBZiDz4Z1Em6H+pDGlHm9sv/ e4Uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=qf9NB7S2Uq7nnRkcSTWlC+ycFmkEToKsQT1UMUoKQUU=; fh=m78OHke778HCKRWBAKUmJlH7wnphMgZrmsNcQ/ZbGbw=; b=ToxwN1eYskdy3oSTkc+l9fw0hsldYMhS/t1/d+P0pIOqldPx4q7iH4ls+pqmQkVYBU OKlILyq73/8DOoBePWDgPtCC5D+y0+AqOI8SkW8Wh1HghwGIt+oSDqXom5nLyL9AQ4/E fiK3tqukJPfPxHR1aIpxx+SVIRsJzsIFVVVK5JXqFTSiwm+xIi/ZmRJDFZzXi8ZXHmSy DFJeWaOfwB+B9uM2/rq+Iex4EExsS+sr75jM1CQUqc4JA8QOR1PJomtYIKCnogdSGePk nO5lwWmSkjiUmBhxghYOoskF8bchBlS+BAgLcByXChhxDx+qjMP/bif9rjJb/+3OxTOX k/Wg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-2957-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2957-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id k10-20020a170902694a00b001d0be32b0c2si17186376plt.48.2023.12.17.19.04.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Dec 2023 19:04:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-2957-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-2957-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2957-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id D8611B20CCE for ; Mon, 18 Dec 2023 03:04:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 529EE440E; Mon, 18 Dec 2023 03:04:48 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mx2.zhaoxin.com (mx2.zhaoxin.com [203.110.167.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C4D2290D for ; Mon, 18 Dec 2023 03:04:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zhaoxin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zhaoxin.com X-ASG-Debug-ID: 1702868676-1eb14e538c375a0001-xx1T2L Received: from ZXSHMBX2.zhaoxin.com (ZXSHMBX2.zhaoxin.com [10.28.252.164]) by mx2.zhaoxin.com with ESMTP id W6OW1CkGYo5wxXUl (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Mon, 18 Dec 2023 11:04:36 +0800 (CST) X-Barracuda-Envelope-From: LeoLiu-oc@zhaoxin.com X-Barracuda-RBL-Trusted-Forwarder: 10.28.252.164 Received: from ZXBJMBX03.zhaoxin.com (10.29.252.7) by ZXSHMBX2.zhaoxin.com (10.28.252.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 18 Dec 2023 11:04:36 +0800 Received: from xin.lan (10.32.64.1) by ZXBJMBX03.zhaoxin.com (10.29.252.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 18 Dec 2023 11:04:34 +0800 X-Barracuda-RBL-Trusted-Forwarder: 10.28.252.164 From: LeoLiu-oc X-Barracuda-RBL-Trusted-Forwarder: 10.29.252.7 To: , , , , , , , , , , CC: , , , , LeoLiuoc Subject: [PATCH v2 1/3] ACPI/APEI: Add hest_parse_pcie_aer() Date: Mon, 18 Dec 2023 11:04:28 +0800 X-ASG-Orig-Subj: [PATCH v2 1/3] ACPI/APEI: Add hest_parse_pcie_aer() Message-ID: <20231218030430.783495-2-LeoLiu-oc@zhaoxin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231218030430.783495-1-LeoLiu-oc@zhaoxin.com> References: <20231115091612.580685-1-LeoLiu-oc@zhaoxin.com> <20231218030430.783495-1-LeoLiu-oc@zhaoxin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: zxbjmbx1.zhaoxin.com (10.29.252.163) To ZXBJMBX03.zhaoxin.com (10.29.252.7) X-Barracuda-Connect: ZXSHMBX2.zhaoxin.com[10.28.252.164] X-Barracuda-Start-Time: 1702868676 X-Barracuda-Encrypted: ECDHE-RSA-AES128-GCM-SHA256 X-Barracuda-URL: https://10.28.252.36:4443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at zhaoxin.com X-Barracuda-Scan-Msg-Size: 4147 X-Barracuda-BRTS-Status: 0 X-Barracuda-Bayes: INNOCENT GLOBAL 0.0000 1.0000 -2.0210 X-Barracuda-Spam-Score: -2.02 X-Barracuda-Spam-Status: No, SCORE=-2.02 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.118228 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- From: LeoLiuoc The purpose of the function apei_hest_parse_aer() is used to parse and extract register value from HEST PCIe AER structures. Signed-off-by: LeoLiuoc --- drivers/acpi/apei/hest.c | 69 ++++++++++++++++++++++++++++++++++++++-- include/acpi/apei.h | 17 ++++++++++ 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/apei/hest.c b/drivers/acpi/apei/hest.c index 6aef1ee5e1bd..7e7026c0001b 100644 --- a/drivers/acpi/apei/hest.c +++ b/drivers/acpi/apei/hest.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -86,9 +87,73 @@ static int hest_esrc_len(struct acpi_hest_header *hest_hdr) return len; }; -typedef int (*apei_hest_func_t)(struct acpi_hest_header *hest_hdr, void *data); +#ifdef CONFIG_ACPI_APEI +static bool hest_match_pci_devfn(struct acpi_hest_aer_common *p, struct pci_dev *dev) +{ + return ACPI_HEST_SEGMENT(p->bus) == pci_domain_nr(dev->bus) && + ACPI_HEST_BUS(p->bus) == dev->bus->number && + p->device == PCI_SLOT(dev->devfn) && + p->function == PCI_FUNC(dev->devfn); +} + +static bool hest_source_is_pcie_aer(struct acpi_hest_header *hest_hdr, struct pci_dev *dev) +{ + u16 hest_type = hest_hdr->type; + u8 pcie_type = pci_pcie_type(dev); + struct acpi_hest_aer_common *common; + + switch (hest_type) { + case ACPI_HEST_TYPE_AER_ROOT_PORT: + if (pcie_type != PCI_EXP_TYPE_ROOT_PORT) + return false; + break; + case ACPI_HEST_TYPE_AER_ENDPOINT: + if (pcie_type != PCI_EXP_TYPE_ENDPOINT) + return false; + break; + case ACPI_HEST_TYPE_AER_BRIDGE: + if (pcie_type != PCI_EXP_TYPE_PCI_BRIDGE && + pcie_type != PCI_EXP_TYPE_PCIE_BRIDGE) + return false; + break; + default: + return false; + } + + common = (struct acpi_hest_aer_common *)(hest_hdr + 1); + if (common->flags & ACPI_HEST_GLOBAL) + return true; + + if (hest_match_pci_devfn(common, dev)) + return true; + + return false; +} + +int hest_parse_pcie_aer(struct acpi_hest_header *hest_hdr, void *data) +{ + struct hest_parse_aer_info *info = data; + + if (!hest_source_is_pcie_aer(hest_hdr, info->pci_dev)) + return 0; + + switch (hest_hdr->type) { + case ACPI_HEST_TYPE_AER_ROOT_PORT: + info->hest_aer_root_port = (struct acpi_hest_aer_root *)hest_hdr; + return 1; + case ACPI_HEST_TYPE_AER_ENDPOINT: + info->hest_aer_endpoint = (struct acpi_hest_aer *)hest_hdr; + return 1; + case ACPI_HEST_TYPE_AER_BRIDGE: + info->hest_aer_bridge = (struct acpi_hest_aer_bridge *)hest_hdr; + return 1; + default: + return 0; + } +} +#endif -static int apei_hest_parse(apei_hest_func_t func, void *data) +int apei_hest_parse(apei_hest_func_t func, void *data) { struct acpi_hest_header *hest_hdr; int i, rc, len; diff --git a/include/acpi/apei.h b/include/acpi/apei.h index dc60f7db5524..82d3cdf53e22 100644 --- a/include/acpi/apei.h +++ b/include/acpi/apei.h @@ -23,6 +23,15 @@ enum hest_status { HEST_NOT_FOUND, }; +#ifdef CONFIG_ACPI_APEI +struct hest_parse_aer_info { + struct pci_dev *pci_dev; + struct acpi_hest_aer *hest_aer_endpoint; + struct acpi_hest_aer_root *hest_aer_root_port; + struct acpi_hest_aer_bridge *hest_aer_bridge; +}; +#endif + extern int hest_disable; extern int erst_disable; #ifdef CONFIG_ACPI_APEI_GHES @@ -33,10 +42,18 @@ void __init acpi_ghes_init(void); static inline void acpi_ghes_init(void) { } #endif +typedef int (*apei_hest_func_t)(struct acpi_hest_header *hest_hdr, void *data); +int apei_hest_parse(apei_hest_func_t func, void *data); + #ifdef CONFIG_ACPI_APEI void __init acpi_hest_init(void); +int hest_parse_pcie_aer(struct acpi_hest_header *hest_hdr, void *data); #else static inline void acpi_hest_init(void) { } +static inline int hest_parse_pcie_aer(struct acpi_hest_header *hest_hdr, void *data) +{ + return 0; +} #endif int erst_write(const struct cper_record_header *record); -- 2.34.1