mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lin Wang <wanglin@open-hieco.net>
To: yazen.ghannam@amd.com, mario.limonciello@amd.com,
	Borislav Petkov <bp@alien8.de>
Cc: tglx@kernel.org, mingo@redhat.com, x86@kernel.org,
	linux-kernel@vger.kernel.org
Subject: [RFC PATCH v2 2/5] x86/hygon: Add Family 0x18 node enumeration API header
Date: Thu, 23 Apr 2026 14:04:09 +0800	[thread overview]
Message-ID: <20260423060420.1785357-3-wanglin@open-hieco.net> (raw)
In-Reply-To: <20260423060420.1785357-1-wanglin@open-hieco.net>

Introduce asm/hygon/node.h, a Hygon-only header that provides the public
API for Hygon Family 0x18 Data Fabric node support.

Exported function prototypes (under CONFIG_HYGON_NODE):

  hygon_f18h_model()              model byte, 0 if not Hygon Fam18h
  hygon_cdd_num()                 compute die count for EDAC sizing
  hygon_get_dfid()                DF ID for a DF misc device
  hygon_cpu_to_df_node()          phys_node_id to dense DF node index

Inline model-range helper (usable regardless of CONFIG_HYGON_NODE):

  hygon_f18h_model_in_range()     true if model is within [first, last]

All functions have static inline stubs returning 0/NULL/-ENODEV when
CONFIG_HYGON_NODE=n, so consumers need no #ifdef guards.

Also add the MAINTAINERS entry for Hygon node support header.

Signed-off-by: Lin Wang <wanglin@open-hieco.net>
---
 MAINTAINERS                       |  2 +
 arch/x86/include/asm/hygon/node.h | 85 +++++++++++++++++++++++++++++++
 2 files changed, 87 insertions(+)
 create mode 100644 arch/x86/include/asm/hygon/node.h

diff --git a/MAINTAINERS b/MAINTAINERS
index c9b7b6f9828e..3d5ef8a344f3 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11941,8 +11941,10 @@ F:	drivers/input/touchscreen/hycon-hy46xx.c
 
 HYGON PROCESSOR SUPPORT
 M:	Pu Wen <puwen@hygon.cn>
+M:	Lin Wang <wanglin@open-hieco.net>
 L:	linux-kernel@vger.kernel.org
 S:	Maintained
+F:	arch/x86/include/asm/hygon/
 F:	arch/x86/kernel/cpu/hygon.c
 
 HYNIX HI556 SENSOR DRIVER
diff --git a/arch/x86/include/asm/hygon/node.h b/arch/x86/include/asm/hygon/node.h
new file mode 100644
index 000000000000..18c4c7a3ea6e
--- /dev/null
+++ b/arch/x86/include/asm/hygon/node.h
@@ -0,0 +1,85 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef _ASM_X86_HYGON_NODE_H
+#define _ASM_X86_HYGON_NODE_H
+
+#include <linux/errno.h>
+#include <linux/types.h>
+
+struct pci_dev;
+
+#define HYGON_MAX_SOCKETS	8
+
+#ifdef CONFIG_HYGON_NODE
+
+/**
+ * hygon_cdd_num() - number of compute dies (CDD)
+ *
+ * DF IDs >= 4 represent compute dies (CDD). DF IDs < 4 represent IO dies
+ * (IOD). EDAC instances must be sized by CDD count, not total node count,
+ * because IOD nodes have no UMC.
+ */
+u16 hygon_cdd_num(void);
+
+/**
+ * hygon_f18h_model() - return Hygon Fam18h model byte, or 0 if not Hygon Fam18h
+ */
+u8 hygon_f18h_model(void);
+
+/**
+ * hygon_get_dfid() - read DF ID for a Hygon DF misc device
+ * @misc: PCI dev for DF misc (function 3)
+ * @dfid: output DF ID
+ */
+int hygon_get_dfid(struct pci_dev *misc, u8 *dfid);
+
+/**
+ * hygon_cpu_to_df_node() - map CPU to dense DF node index (O(1))
+ * @cpu: CPU index
+ *
+ * Hygon Fam18h exposes sparse physical node IDs (CPUID 8000001E[7:0]).
+ * This function translates the per-CPU physical node ID into a contiguous
+ * DF node index (0..hygon_cdd_num()-1) that aligns with EDAC instance
+ * numbering and amd_nb[] indexing.
+ *
+ * Return: DF node index on success, negative errno on failure.
+ */
+int hygon_cpu_to_df_node(unsigned int cpu);
+
+#else /* !CONFIG_HYGON_NODE */
+
+static inline u16 hygon_cdd_num(void)
+{
+	return 0;
+}
+
+static inline u8 hygon_f18h_model(void)
+{
+	return 0;
+}
+
+static inline int hygon_get_dfid(struct pci_dev *misc, u8 *dfid)
+{
+	return -ENODEV;
+}
+
+static inline int hygon_cpu_to_df_node(unsigned int cpu)
+{
+	return -ENODEV;
+}
+#endif /* CONFIG_HYGON_NODE */
+
+/**
+ * hygon_f18h_model_in_range() - check if Hygon Fam18h model is within [first, last]
+ * @first: lower bound (inclusive)
+ * @last:  upper bound (inclusive)
+ *
+ * Returns false on non-Hygon-Fam18h systems (hygon_f18h_model() returns 0).
+ */
+static inline bool hygon_f18h_model_in_range(u8 first, u8 last)
+{
+	u8 m = hygon_f18h_model();
+
+	return m >= first && m <= last;
+}
+
+#endif /* _ASM_X86_HYGON_NODE_H */
-- 
2.43.0


  parent reply	other threads:[~2026-04-23  6:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-23  6:04 [RFC PATCH v2 0/5] x86/hygon: Add Family 0x18 node enumeration and SMN access Lin Wang
2026-04-23  6:04 ` [RFC PATCH v2 1/5] pci_ids: Add Hygon Family 0x18 DF device IDs Lin Wang
2026-04-23  6:04 ` Lin Wang [this message]
2026-04-23  6:04 ` [RFC PATCH v2 3/5] x86/amd_nb: Add amd_nb_set_cache() for external NB cache registration Lin Wang
2026-04-23  6:04 ` [RFC PATCH v2 4/5] x86/amd_node: Add smn_set_roots() and smn_activate() for external SMN registration Lin Wang
2026-04-23 19:12   ` Mario Limonciello
2026-04-24  1:43     ` Lin Wang
2026-04-23  6:04 ` [RFC PATCH v2 5/5] x86/hygon: Add Fam18h node enumeration, NB cache and SMN init Lin Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260423060420.1785357-3-wanglin@open-hieco.net \
    --to=wanglin@open-hieco.net \
    --cc=bp@alien8.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=mingo@redhat.com \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    --cc=yazen.ghannam@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®