[RFC PATCH v2 2/5] x86/hygon: Add Family 0x18 node enumeration API header
From: Lin Wang
Date: Thu Apr 23 2026 - 02:10:09 EST
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@xxxxxxxxxxxxxx>
---
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@xxxxxxxx>
+M: Lin Wang <wanglin@xxxxxxxxxxxxxx>
L: linux-kernel@xxxxxxxxxxxxxxx
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