From patchwork Wed Nov 7 20:43:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot for Kobe Wu X-Patchwork-Id: 10673059 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A694114D6 for ; Wed, 7 Nov 2018 20:44:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9289C2CE52 for ; Wed, 7 Nov 2018 20:44:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8595A2CF07; Wed, 7 Nov 2018 20:44:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,URIBL_SBL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF4DD2CE52 for ; Wed, 7 Nov 2018 20:44:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727059AbeKHGQd (ORCPT ); Thu, 8 Nov 2018 01:16:33 -0500 Received: from terminus.zytor.com ([198.137.202.136]:33125 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726517AbeKHGQc (ORCPT ); Thu, 8 Nov 2018 01:16:32 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id wA7KhTPA1606141 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 7 Nov 2018 12:43:29 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id wA7KhTMr1606137; Wed, 7 Nov 2018 12:43:29 -0800 Date: Wed, 7 Nov 2018 12:43:29 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: "tip-bot for Woods, Brian" Message-ID: Cc: tglx@linutronix.de, hpa@zytor.com, linux-pci@vger.kernel.org, bhelgaas@google.com, linux-hwmon@vger.kernel.org, qianyue.zj@alibaba-inc.com, linux-kernel@vger.kernel.org, mingo@kernel.org, x86@kernel.org, clemens@ladisch.de, jdelvare@suse.com, mingo@redhat.com, linux@roeck-us.net, brian.woods@amd.com, puwen@hygon.cn, Brian.Woods@amd.com, bp@suse.de Reply-To: bp@suse.de, Brian.Woods@amd.com, puwen@hygon.cn, brian.woods@amd.com, linux@roeck-us.net, mingo@redhat.com, jdelvare@suse.com, clemens@ladisch.de, x86@kernel.org, mingo@kernel.org, linux-kernel@vger.kernel.org, qianyue.zj@alibaba-inc.com, linux-hwmon@vger.kernel.org, bhelgaas@google.com, hpa@zytor.com, linux-pci@vger.kernel.org, tglx@linutronix.de In-Reply-To: <20181106200754.60722-3-brian.woods@amd.com> References: <20181106200754.60722-3-brian.woods@amd.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/amd-nb] x86/amd_nb: Add support for newer PCI topologies Git-Commit-ID: 556e4c62baffa71e2045a298379db7e57dd47f3d X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Disposition: inline Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Commit-ID: 556e4c62baffa71e2045a298379db7e57dd47f3d Gitweb: https://git.kernel.org/tip/556e4c62baffa71e2045a298379db7e57dd47f3d Author: Woods, Brian AuthorDate: Tue, 6 Nov 2018 20:08:16 +0000 Committer: Borislav Petkov CommitDate: Wed, 7 Nov 2018 21:28:29 +0100 x86/amd_nb: Add support for newer PCI topologies Add support for new processors which have multiple PCI root complexes per data fabric/system management network interface. If there are (N) multiple PCI roots per DF/SMN interface, then the PCI roots are redundant (as far as SMN/DF access goes). For each DF/SMN interface: map to the first available PCI root and skip the next N-1 PCI roots so the following DF/SMN interface get mapped to a correct PCI root. Ex: DF/SMN 0 -> 60 40 20 00 DF/SMN 1 -> e0 c0 a0 80 Signed-off-by: Brian Woods Signed-off-by: Borislav Petkov CC: Bjorn Helgaas CC: Clemens Ladisch CC: Guenter Roeck CC: "H. Peter Anvin" CC: Ingo Molnar CC: Jean Delvare CC: Jia Zhang CC: CC: CC: Pu Wen CC: Thomas Gleixner CC: x86-ml Link: http://lkml.kernel.org/r/20181106200754.60722-3-brian.woods@amd.com --- arch/x86/kernel/amd_nb.c | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c index 19d489ee2b1e..cc34266e3c62 100644 --- a/arch/x86/kernel/amd_nb.c +++ b/arch/x86/kernel/amd_nb.c @@ -213,7 +213,10 @@ int amd_cache_northbridges(void) const struct pci_device_id *root_ids = amd_root_ids; struct pci_dev *root, *misc, *link; struct amd_northbridge *nb; - u16 i = 0; + u16 roots_per_misc = 0; + u16 misc_count = 0; + u16 root_count = 0; + u16 i, j; if (amd_northbridges.num) return 0; @@ -226,26 +229,55 @@ int amd_cache_northbridges(void) misc = NULL; while ((misc = next_northbridge(misc, misc_ids)) != NULL) - i++; + misc_count++; - if (!i) + if (!misc_count) return -ENODEV; - nb = kcalloc(i, sizeof(struct amd_northbridge), GFP_KERNEL); + root = NULL; + while ((root = next_northbridge(root, root_ids)) != NULL) + root_count++; + + if (root_count) { + roots_per_misc = root_count / misc_count; + + /* + * There should be _exactly_ N roots for each DF/SMN + * interface. + */ + if (!roots_per_misc || (root_count % roots_per_misc)) { + pr_info("Unsupported AMD DF/PCI configuration found\n"); + return -ENODEV; + } + } + + nb = kcalloc(misc_count, sizeof(struct amd_northbridge), GFP_KERNEL); if (!nb) return -ENOMEM; amd_northbridges.nb = nb; - amd_northbridges.num = i; + amd_northbridges.num = misc_count; link = misc = root = NULL; - for (i = 0; i != amd_northbridges.num; i++) { + for (i = 0; i < amd_northbridges.num; i++) { node_to_amd_nb(i)->root = root = next_northbridge(root, root_ids); node_to_amd_nb(i)->misc = misc = next_northbridge(misc, misc_ids); node_to_amd_nb(i)->link = link = next_northbridge(link, link_ids); + + /* + * If there are more PCI root devices than data fabric/ + * system management network interfaces, then the (N) + * PCI roots per DF/SMN interface are functionally the + * same (for DF/SMN access) and N-1 are redundant. N-1 + * PCI roots should be skipped per DF/SMN interface so + * the following DF/SMN interfaces get mapped to + * correct PCI roots. + */ + for (j = 1; j < roots_per_misc; j++) + root = next_northbridge(root, root_ids); } if (amd_gart_present())