Message ID | 20230802101933.968971205@linutronix.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp410670vqx; Wed, 2 Aug 2023 05:15:06 -0700 (PDT) X-Google-Smtp-Source: APBJJlHZZ5wFrs5RCiOzOb7++Us/aH38YKjfbxnyQsEFIvEBHPIGt6ajxWk9mwzavqRPniZYJ4fQ X-Received: by 2002:a17:902:d4cb:b0:1b3:f5c7:4e75 with SMTP id o11-20020a170902d4cb00b001b3f5c74e75mr16740581plg.58.1690978506334; Wed, 02 Aug 2023 05:15:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690978506; cv=none; d=google.com; s=arc-20160816; b=Puc4TPyyREdma5NHiwcp3EqYn5Qx/BcV6172Ck078Ruovw4MAJGHXuj2CZaos4HF95 V8PrpgeCUVymdx9IzGUnvPTCyTsClEXzoiIiZPBBmP93fWK+rCNQ/xOoY74lMLdNH4uo LjZK8mmwJn1QiCGJB4b9gDey8V5jxZYlZFXtDiOVrrhAsNAcBlI7EsFJR8gJibgwmkp3 kiMXcWECL+p3pM5dLSIi/oAETGBfS4U4YQ/22ekxb4hF+28gB76De2u42Fc87BE4GVIb nkwFnyb5x7Pe1OHQYPWJbNc1aZkeES0lB3SXPBRKDCaAF7qp6Cz/Gq1NmUUc+gWn7duy A8Yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=RMPH9HSrX/vWRmKrh1k0g9K+DpbMWcgkkNBWT1U3b5k=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=v15fc38dxgDez+J7MxtfB/HmEEGlJIwT/008fR5v5yLsVTH5ST3OR4xYN0RzuS534B Cg/L3vUHi1FchtRCWhflHSJFCpBnRa+FgcQBOnCbg/ZT08Rdt7a7kn2/OD28N9v+o87X wBfTF3WEj+pez2kSsHlSteW1mJyh+p83rW0/umeUUjRghLOVJynEIpT3mlSoXiqixRKL vUzgAHcf5wk9Ui2rjKcdAx5ewlg5cgY66pu18ESNYnvDLTIe0wzt7IwOitxK4y1gFvpn 7AlihDzef7PcqwFwJugl/sBZJne7T2Cg3mUMuKY+47ZH4cvTtUiunQBCIO994X0ll8iO x1gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=R9NttLjM; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p17-20020a170902e35100b001bbcf3bc9d3si10282352plc.384.2023.08.02.05.14.51; Wed, 02 Aug 2023 05:15:06 -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=@linutronix.de header.s=2020 header.b=R9NttLjM; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233982AbjHBKXi (ORCPT <rfc822;maxi.paulin@gmail.com> + 99 others); Wed, 2 Aug 2023 06:23:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234218AbjHBKXA (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 2 Aug 2023 06:23:00 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C098422B for <linux-kernel@vger.kernel.org>; Wed, 2 Aug 2023 03:21:45 -0700 (PDT) Message-ID: <20230802101933.968971205@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971692; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=RMPH9HSrX/vWRmKrh1k0g9K+DpbMWcgkkNBWT1U3b5k=; b=R9NttLjMcnAJ8p2lO24QRYY9kpfuGK/BTdKHAjpxVUzHiuqKFwqWl4QOB6y9PfyRdeQnwI MtEdu4I7E8j4ORYanITmbdi5dU25hNuozYkGReZGEf8qHN5nZ6xy2eUj8ZUVcLhLxRrtZH e9LJoBQYbhRPMMT8HZ+CpQSuWLKaSXRWDUQyghmC7hEJwmqvISjr3j2X76OE79UoInooHI p+74RrhxxZQp9E2ZxKu27JYlwgpTgh3hD8LD5I/5J0fbTwoimW7kksiQnHziQQRgdPwqM9 o5523rpWXSUcWzDFJDQAJIodAICgD9nr4NKwts0zCOz/AdUobvWNiEzoGNkLvA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971692; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=RMPH9HSrX/vWRmKrh1k0g9K+DpbMWcgkkNBWT1U3b5k=; b=itBmo4u5rRN3f8Sjomd8pTktY24hZ4kn85GxAM7rphcVRzIMNn5WcYkM6xpsINx803Ljld RsbDQK9r8GBa43AA== From: Thomas Gleixner <tglx@linutronix.de> To: LKML <linux-kernel@vger.kernel.org> Cc: x86@kernel.org, Tom Lendacky <thomas.lendacky@amd.com>, Andrew Cooper <andrew.cooper3@citrix.com>, Arjan van de Ven <arjan@linux.intel.com>, Huang Rui <ray.huang@amd.com>, Juergen Gross <jgross@suse.com>, Dimitri Sivanich <dimitri.sivanich@hpe.com>, Michael Kelley <mikelley@microsoft.com>, Wei Liu <wei.liu@kernel.org> Subject: [patch V3 22/40] x86/cpu: Provide cpuid_read() et al. References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Wed, 2 Aug 2023 12:21:32 +0200 (CEST) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773119478692402009 X-GMAIL-MSGID: 1773119478692402009 |
Series |
x86/cpu: Rework the topology evaluation
|
|
Commit Message
Thomas Gleixner
Aug. 2, 2023, 10:21 a.m. UTC
Provide a few helper functions to read CPUID leafs or individual registers
into a data structure without requiring unions.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
arch/x86/include/asm/cpuid.h | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
--- a/arch/x86/include/asm/cpuid.h +++ b/arch/x86/include/asm/cpuid.h @@ -127,6 +127,42 @@ static inline unsigned int cpuid_edx(uns return edx; } +static inline void __cpuid_read(unsigned int leaf, unsigned int subleaf, u32 *regs) +{ + regs[CPUID_EAX] = leaf; + regs[CPUID_ECX] = subleaf; + __cpuid(regs, regs + 1, regs + 2, regs + 3); +} + +#define cpuid_subleaf(leaf, subleaf, regs) { \ + BUILD_BUG_ON(sizeof(*(regs)) != 16); \ + __cpuid_read(leaf, subleaf, (u32 *)(regs)); \ +} + +#define cpuid_leaf(leaf, regs) { \ + BUILD_BUG_ON(sizeof(*(regs)) != 16); \ + __cpuid_read(leaf, 0, (u32 *)(regs)); \ +} + +static inline void __cpuid_read_reg(unsigned int leaf, unsigned int subleaf, + enum cpuid_regs_idx regidx, u32 *reg) +{ + u32 regs[4]; + + __cpuid_read(leaf, subleaf, regs); + *reg = regs[regidx]; +} + +#define cpuid_subleaf_reg(leaf, subleaf, regidx, reg) { \ + BUILD_BUG_ON(sizeof(*(reg)) != 4); \ + __cpuid_read_reg(leaf, subleaf, regidx, (u32 *)(reg)); \ +} + +#define cpuid_leaf_reg(leaf, regidx, reg) { \ + BUILD_BUG_ON(sizeof(*(reg)) != 4); \ + __cpuid_read_reg(leaf, 0, regidx, (u32 *)(reg)); \ +} + static __always_inline bool cpuid_function_is_indexed(u32 function) { switch (function) {