Skip to contentSkip to conversation

Add support for Hygon Family 18h model 4h~8h processors

PATCH Superseded Fu Hao 4 participants 19 messages Mar 27 – Jun 5

Subsystems (8)
x86 Sound PCI perf events +4 more subsystems

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Fu Hao

author
#0 lore raw

cover Add support for Hygon Family 18h model 4h~8h processors

This patch series introduce support for the new-generation Hygon model 4h~8h processors, addressing five key areas:

1. CPU Topology Updates
The new processor introduces a revised CPU topology hierarchy compared to previous generations. This patch updates the kernel's topology detection logic to correctly identify core/socket relationships and cache sharing patterns.

2. L3 Performance Monitoring Updates
The L3 perf registers of model 6h differ from those of the previous processor.

3. Microcode loading
Add microcode loading support for Hygon processor.

4. Audio Controller Driver
Add initial support for the integrated HD-Audio controller.

5. New SB IOAPIC information support
The southbridge IOAPIC of Hygon's new-generation processors is located at 00:0b.0.

Fu Hao (8):
x86/cpu/hygon: Adjust the die_id and logical_die_id for Hygon model

    4h~8h

x86/cpu: Get LLC ID for Hygon family 18h model 4h x86/cpu/hygon: Remove Spectral Chicken for Hygon processors perf/x86/uncore: Add L3 PMU support for Hygon family 18h model 6h x86/microcode/hygon: Add microcode loading support for Hygon
processors
ALSA: hda: Add support for Hygon family 18h model 5h HD-Audio
ALSA: hda: Fix single byte writing issue for Hygon family 18h model 5h iommu/hygon: Add support for Hygon family 18h model 4h IOAPIC

 arch/x86/Kconfig                         |  2 +-
 arch/x86/events/amd/uncore.c             | 48 +++++++++++++++++-
 arch/x86/include/asm/perf_event.h        |  8 +++
 arch/x86/kernel/cpu/cacheinfo.c          | 22 +++++++--
 arch/x86/kernel/cpu/hygon.c              | 21 +++++---
 arch/x86/kernel/cpu/microcode/amd.c      | 63 ++++++++++++++++++------
 arch/x86/kernel/cpu/microcode/core.c     | 11 +++++
 arch/x86/kernel/cpu/microcode/internal.h | 12 +++++
 drivers/iommu/amd/init.c                 | 10 +++-
 include/linux/pci_ids.h                  |  1 +
 include/sound/hdaudio.h                  |  1 +
 sound/hda/controllers/intel.c            |  9 ++++
 sound/hda/core/controller.c              | 10 +++-
 sound/hda/core/stream.c                  | 42 ++++++++++++----
 14 files changed, 220 insertions(+), 40 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/8 x86/cpu/hygon: Adjust the die_id and logical_die_id for Hygon model 4h~8h

The die id should be get from the NodeId field of CPUID leaf 0x8000001e ecx for Hygon model 4h~8h processors.

---
 arch/x86/kernel/cpu/hygon.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
arch/x86/kernel/cpu/hygon.c +15 -0
index 7f95a74e4..f39d32a68 100644
@@ -168,6 +168,19 @@ static void early_init_hygon(struct cpuinfo_x86 *c)
 	set_cpu_cap(c, X86_FEATURE_VMMCALL);
 }
 
+/*
+ * Adjust the die_id and logical_die_id for Hygon model 4h~8h.
+ */
+static void cpu_topology_fixup_hygon(struct cpuinfo_x86 *c)
+{
+	if (c->x86_model >= 0x4 && c->x86_model <= 0x8) {
+		c->topo.die_id = cpuid_ecx(0x8000001e) & 0xff;
+		c->topo.logical_die_id = (c->topo.die_id >> 4) *
+					 topology_amd_nodes_per_pkg() +
+					 (c->topo.die_id & 0xf);
+	}
+}
+
 static void init_hygon(struct cpuinfo_x86 *c)
 {
 	u64 vm_cr;
@@ -191,6 +204,8 @@ static void init_hygon(struct cpuinfo_x86 *c)
 
 	init_hygon_cacheinfo(c);
 
+	cpu_topology_fixup_hygon(c);
+
 	if (cpu_has(c, X86_FEATURE_SVM)) {
 		rdmsrq(MSR_VM_CR, vm_cr);
 		if (vm_cr & SVM_VM_CR_SVM_DIS_MASK) {
Signature · 1 line
2.34.1
author
#6 lore raw

PATCH 2/8 x86/cpu: Get LLC ID for Hygon family 18h model 4h

In reply to Fu Hao

Add support to calculate LLC ID from the number of threads sharing the cache for Hygon family 18h model 4h processor.

---
 arch/x86/kernel/cpu/cacheinfo.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/cacheinfo.c +17 -5
index 51a95b078..98862afc4 100644
@@ -341,11 +341,23 @@ void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c)
 	if (!cpuid_amd_hygon_has_l3_cache())
 		return;
 
-	/*
-	 * Hygons are similar to AMD Family 17h up to 1F models: LLC is
-	 * at the core complex level.  Core complex ID is ApicId[3].
-	 */
-	c->topo.llc_id = c->topo.apicid >> 3;
+	if (c->x86_model >= 0x4) {
+		/*
+		 * From model 4h: LLC ID is calculated from the number
+		 * of threads sharing the L3 cache.
+		 */
+		u32 llc_index = find_num_cache_leaves(c) - 1;
+		struct _cpuid4_info id4 = {};
+
+		if (!amd_fill_cpuid4_info(llc_index, &id4))
+			c->topo.llc_id = get_cache_id(c->topo.apicid, &id4);
+	} else {
+		/*
+		 * The others are similar to AMD Family 17h up to 1F models: LLC is
+		 * at the core complex level.  Core complex ID is ApicId[3].
+		 */
+		c->topo.llc_id = c->topo.apicid >> 3;
+	}
 }
 
 void init_amd_cacheinfo(struct cpuinfo_x86 *c)
Signature · 1 line
2.34.1
author
#8 lore raw

PATCH 4/8 perf/x86/uncore: Add L3 PMU support for Hygon family 18h model 6h

In reply to Fu Hao

Adjust the L3 PMU slicemask and threadmask for Hygon family 18h model 6h processor.

---
 arch/x86/events/amd/uncore.c      | 48 ++++++++++++++++++++++++++++++-
 arch/x86/include/asm/perf_event.h |  8 ++++++
 2 files changed, 55 insertions(+), 1 deletion(-)
arch/x86/events/amd/uncore.c +47 -1
index dd956cfca..e71d9e784 100644
@@ -308,6 +308,14 @@ amd_f17h_uncore_is_visible(struct kobject *kobj, struct attribute *attr, int i)
 	       attr->mode : 0;
 }
 
+static umode_t
+hygon_f18h_m6h_uncore_is_visible(struct kobject *kobj, struct attribute *attr, int i)
+{
+	return boot_cpu_data.x86 == 0x18 &&
+	       boot_cpu_data.x86_model >= 0x6 && boot_cpu_data.x86_model <= 0xf	?
+	       attr->mode : 0;
+}
+
 static umode_t
 amd_f19h_uncore_is_visible(struct kobject *kobj, struct attribute *attr, int i)
 {
@@ -359,6 +367,8 @@ DEFINE_UNCORE_FORMAT_ATTR(enallslices,	enallslices,	"config:46");		   /* F19h L3
 DEFINE_UNCORE_FORMAT_ATTR(enallcores,	enallcores,	"config:47");		   /* F19h L3 */
 DEFINE_UNCORE_FORMAT_ATTR(sliceid,	sliceid,	"config:48-50");	   /* F19h L3 */
 DEFINE_UNCORE_FORMAT_ATTR(rdwrmask,	rdwrmask,	"config:8-9");		   /* PerfMonV2 UMC */
+DEFINE_UNCORE_FORMAT_ATTR(slicemask4,	slicemask,	"config:28-31");	   /* F18h L3 */
+DEFINE_UNCORE_FORMAT_ATTR(threadmask32,	threadmask,	"config:32-63");	   /* F18h L3 */
 
 /* Common DF and NB attributes */
 static struct attribute *amd_uncore_df_format_attr[] = {
@@ -388,6 +398,12 @@ static struct attribute *amd_f17h_uncore_l3_format_attr[] = {
 	NULL,
 };
 
+/* F18h M06h unique L3 attributes */
+static struct attribute *hygon_f18h_m6h_uncore_l3_format_attr[] = {
+	&format_attr_slicemask4.attr,	/* slicemask */
+	NULL,
+};
+
 /* F19h unique L3 attributes */
 static struct attribute *amd_f19h_uncore_l3_format_attr[] = {
 	&format_attr_coreid.attr,	/* coreid */
@@ -413,6 +429,12 @@ static struct attribute_group amd_f17h_uncore_l3_format_group = {
 	.is_visible = amd_f17h_uncore_is_visible,
 };
 
+static struct attribute_group hygon_f18h_m6h_uncore_l3_format_group = {
+	.name = "format",
+	.attrs = hygon_f18h_m6h_uncore_l3_format_attr,
+	.is_visible = hygon_f18h_m6h_uncore_is_visible,
+};
+
 static struct attribute_group amd_f19h_uncore_l3_format_group = {
 	.name = "format",
 	.attrs = amd_f19h_uncore_l3_format_attr,
@@ -442,6 +464,11 @@ static const struct attribute_group *amd_uncore_l3_attr_update[] = {
 	NULL,
 };
 
+static const struct attribute_group *hygon_uncore_l3_attr_update[] = {
+	&hygon_f18h_m6h_uncore_l3_format_group,
+	NULL,
+};
+
 static const struct attribute_group *amd_uncore_umc_attr_groups[] = {
 	&amd_uncore_attr_group,
 	&amd_uncore_umc_format_group,
@@ -820,6 +847,12 @@ static int amd_uncore_l3_event_init(struct perf_event *event)
 		mask = AMD64_L3_F19H_THREAD_MASK | AMD64_L3_EN_ALL_SLICES |
 		       AMD64_L3_EN_ALL_CORES;
 
+	if (boot_cpu_data.x86 == 0x18 &&
+	    boot_cpu_data.x86_model >= 0x6 &&
+	    boot_cpu_data.x86_model <= 0xf)
+		mask = ((config & HYGON_L3_SLICE_MASK) ? : HYGON_L3_SLICE_MASK) |
+		       ((config & HYGON_L3_THREAD_MASK) ? : HYGON_L3_THREAD_MASK);
+
 	hwc->config |= mask;
 
 	return 0;
@@ -877,7 +910,8 @@ int amd_uncore_l3_ctx_init(struct amd_uncore *uncore, unsigned int cpu)
 	pmu->rdpmc_base = RDPMC_BASE_LLC;
 	pmu->group = amd_uncore_ctx_gid(uncore, cpu);
 
-	if (boot_cpu_data.x86 >= 0x17) {
+	if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
+	    boot_cpu_data.x86 >= 0x17) {
 		*l3_attr++ = &format_attr_event8.attr;
 		*l3_attr++ = &format_attr_umask8.attr;
 		*l3_attr++ = boot_cpu_data.x86 >= 0x19 ?
@@ -904,6 +938,18 @@ int amd_uncore_l3_ctx_init(struct amd_uncore *uncore, unsigned int cpu)
 		.module		= THIS_MODULE,
 	};
 
+	if (boot_cpu_data.x86_vendor == X86_VENDOR_HYGON &&
+	    boot_cpu_data.x86 == 0x18) {
+		*l3_attr++ = &format_attr_event8.attr;
+		*l3_attr++ = &format_attr_umask8.attr;
+		if (boot_cpu_data.x86_model >= 0x6 && boot_cpu_data.x86_model <= 0xf) {
+			*l3_attr++ = &format_attr_threadmask32.attr;
+			pmu->pmu.attr_update = hygon_uncore_l3_attr_update;
+		} else {
+			*l3_attr++ = &format_attr_threadmask8.attr;
+		}
+	}
+
 	if (perf_pmu_register(&pmu->pmu, pmu->pmu.name, -1)) {
 		free_percpu(pmu->ctx);
 		pmu->ctx = NULL;
arch/x86/include/asm/perf_event.h +8 -0
index ff5acb8b1..404752601 100644
@@ -89,6 +89,14 @@
 #define AMD64_L3_COREID_MASK				\
 	(0x7ULL << AMD64_L3_COREID_SHIFT)
 
+#define HYGON_L3_SLICE_SHIFT				28
+#define HYGON_L3_SLICE_MASK				\
+	(0xFULL << HYGON_L3_SLICE_SHIFT)
+
+#define HYGON_L3_THREAD_SHIFT				32
+#define HYGON_L3_THREAD_MASK				\
+	(0xFFFFFFFFULL << HYGON_L3_THREAD_SHIFT)
+
 #define X86_RAW_EVENT_MASK		\
 	(ARCH_PERFMON_EVENTSEL_EVENT |	\
 	 ARCH_PERFMON_EVENTSEL_UMASK |	\
Signature · 1 line
2.34.1
author
#9 lore raw

PATCH 5/8 x86/microcode/hygon: Add microcode loading support for Hygon processors

In reply to Fu Hao

Add support for loading Hygon microcode, which is compatible with AMD one.

---
 arch/x86/Kconfig                         |  2 +-
 arch/x86/kernel/cpu/microcode/amd.c      | 63 ++++++++++++++++++------
 arch/x86/kernel/cpu/microcode/core.c     | 11 +++++
 arch/x86/kernel/cpu/microcode/internal.h | 12 +++++
 4 files changed, 73 insertions(+), 15 deletions(-)
arch/x86/Kconfig +1 -1
index e2df1b147..b94f3dbf1 100644
@@ -1330,7 +1330,7 @@ config X86_REBOOTFIXUPS
 
 config MICROCODE
 	def_bool y
-	depends on CPU_SUP_AMD || CPU_SUP_INTEL
+	depends on CPU_SUP_AMD || CPU_SUP_INTEL || CPU_SUP_HYGON
 	select CRYPTO_LIB_SHA256 if CPU_SUP_AMD
 
 config MICROCODE_INITRD32
arch/x86/kernel/cpu/microcode/amd.c +49 -14

158 lines not on this page · raw message

arch/x86/kernel/cpu/microcode/core.c +11 -0
index 651202e6f..813c5c157 100644
@@ -195,6 +195,9 @@ void __init load_ucode_bsp(void)
 			return;
 		intel = false;
 		break;
+	case X86_VENDOR_HYGON:
+		intel = false;
+		break;
 
 	default:
 		return;
@@ -229,6 +232,9 @@ void load_ucode_ap(void)
 		if (x86_family(cpuid_1_eax) >= 0x10)
 			load_ucode_amd_ap(cpuid_1_eax);
 		break;
+	case X86_VENDOR_HYGON:
+		load_ucode_amd_ap(cpuid_1_eax);
+		break;
 	default:
 		break;
 	}
@@ -288,6 +294,9 @@ static void reload_early_microcode(unsigned int cpu)
 		if (family >= 0x10)
 			reload_ucode_amd(cpu);
 		break;
+	case X86_VENDOR_HYGON:
+		reload_ucode_amd(cpu);
+		break;
 	default:
 		break;
 	}
@@ -895,6 +904,8 @@ static int __init microcode_init(void)
 		microcode_ops = init_intel_microcode();
 	else if (c->x86_vendor == X86_VENDOR_AMD)
 		microcode_ops = init_amd_microcode();
+	else if (c->x86_vendor == X86_VENDOR_HYGON)
+		microcode_ops = init_hygon_microcode();
 	else
 		pr_err("no support for this CPU vendor\n");
 
arch/x86/kernel/cpu/microcode/internal.h +12 -0
index 3b93c0676..75591afae 100644
@@ -61,6 +61,9 @@ struct cpio_data find_microcode_in_initrd(const char *path);
 #define CPUID_AMD1 QCHAR('A', 'u', 't', 'h')
 #define CPUID_AMD2 QCHAR('e', 'n', 't', 'i')
 #define CPUID_AMD3 QCHAR('c', 'A', 'M', 'D')
+#define CPUID_HYGON1 QCHAR('H', 'y', 'g', 'o')
+#define CPUID_HYGON2 QCHAR('n', 'G', 'e', 'n')
+#define CPUID_HYGON3 QCHAR('u', 'i', 'n', 'e')
 
 #define CPUID_IS(a, b, c, ebx, ecx, edx)	\
 		(!(((ebx) ^ (a)) | ((edx) ^ (b)) | ((ecx) ^ (c))))
@@ -87,6 +90,9 @@ static inline int x86_cpuid_vendor(void)
 	if (CPUID_IS(CPUID_AMD1, CPUID_AMD2, CPUID_AMD3, ebx, ecx, edx))
 		return X86_VENDOR_AMD;
 
+	if (CPUID_IS(CPUID_HYGON1, CPUID_HYGON2, CPUID_HYGON3, ebx, ecx, edx))
+		return X86_VENDOR_HYGON;
+
 	return X86_VENDOR_UNKNOWN;
 }
 
@@ -128,6 +134,12 @@ static inline void reload_ucode_intel(void) { }
 static inline struct microcode_ops *init_intel_microcode(void) { return NULL; }
 #endif  /* !CONFIG_CPU_SUP_INTEL */
 
+#ifdef CONFIG_CPU_SUP_HYGON
+struct microcode_ops *init_hygon_microcode(void);
+#else /* CONFIG_CPU_SUP_HYGON */
+static inline struct microcode_ops *init_hygon_microcode(void) { return NULL; }
+#endif /* !CONFIG_CPU_SUP_HYGON */
+
 #define ucode_dbg(fmt, ...)					\
 ({								\
 	if (IS_ENABLED(CONFIG_MICROCODE_DBG))			\
Signature · 1 line
2.34.1
author
#12 lore raw

PATCH 6/8 ALSA: hda: Add support for Hygon family 18h model 5h HD-Audio

In reply to Fu Hao

Add the new PCI ID 0x1d94 0x14a9 for Hygon family 18h model 5h HDA controller.

---
 include/linux/pci_ids.h       | 1 +
 sound/hda/controllers/intel.c | 5 +++++
 2 files changed, 6 insertions(+)
include/linux/pci_ids.h +1 -0
index 406abf629..19d968017 100644
@@ -2613,6 +2613,7 @@
 #define PCI_VENDOR_ID_ROCKCHIP		0x1d87
 
 #define PCI_VENDOR_ID_HYGON		0x1d94
+#define PCI_DEVICE_ID_HYGON_18H_M05H_HDA	0x14a9
 
 #define PCI_VENDOR_ID_META		0x1d9b
 
sound/hda/controllers/intel.c +5 -0
index 3f434994c..eb5d48d90 100644
@@ -241,6 +241,7 @@ enum {
 	AZX_DRIVER_ZHAOXIN,
 	AZX_DRIVER_ZHAOXINHDMI,
 	AZX_DRIVER_LOONGSON,
+	AZX_DRIVER_HYGON,
 	AZX_DRIVER_GENERIC,
 	AZX_NUM_DRIVERS, /* keep this as last entry */
 };
@@ -357,6 +358,7 @@ static const char * const driver_short_names[] = {
 	[AZX_DRIVER_ZHAOXIN] = "HDA Zhaoxin",
 	[AZX_DRIVER_ZHAOXINHDMI] = "HDA Zhaoxin HDMI",
 	[AZX_DRIVER_LOONGSON] = "HDA Loongson",
+	[AZX_DRIVER_HYGON] = "HDA Hygon",
 	[AZX_DRIVER_GENERIC] = "HD-Audio Generic",
 };
 
@@ -2818,6 +2820,9 @@ static const struct pci_device_id azx_ids[] = {
 	  .driver_data = AZX_DRIVER_LOONGSON | AZX_DCAPS_NO_TCSEL },
 	{ PCI_VDEVICE(LOONGSON, PCI_DEVICE_ID_LOONGSON_HDMI),
 	  .driver_data = AZX_DRIVER_LOONGSON | AZX_DCAPS_NO_TCSEL },
+	/* Hygon HDAudio */
+	{ PCI_VDEVICE(HYGON, PCI_DEVICE_ID_HYGON_18H_M05H_HDA),
+	  .driver_data = AZX_DRIVER_HYGON | AZX_DCAPS_POSFIX_LPIB | AZX_DCAPS_NO_MSI },
 	{ 0, }
 };
 MODULE_DEVICE_TABLE(pci, azx_ids);
Signature · 1 line
2.34.1
author
#18 lore raw

PATCH 8/8 iommu/hygon: Add support for Hygon family 18h model 4h IOAPIC

In reply to Fu Hao

The SB IOAPIC is on the device 0xb from Hygon family 18h model 4h.

---
 drivers/iommu/amd/init.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/iommu/amd/init.c +9 -1
index f3fd7f39e..568851cc2 100644
@@ -3096,6 +3096,9 @@ static void __init free_iommu_resources(void)
 /* SB IOAPIC is always on this device in AMD systems */
 #define IOAPIC_SB_DEVID		((0x00 << 8) | PCI_DEVFN(0x14, 0))
 
+/* SB IOAPIC for Hygon family 18h model 4h is on the device 0xb */
+#define IOAPIC_SB_DEVID_FAM18H_M4H	((0x00 << 8) | PCI_DEVFN(0xb, 0))
+
 static bool __init check_ioapic_information(void)
 {
 	const char *fw_bug = FW_BUG;
@@ -3121,7 +3124,12 @@ static bool __init check_ioapic_information(void)
 			pr_err("%s: IOAPIC[%d] not in IVRS table\n",
 				fw_bug, id);
 			ret = false;
-		} else if (devid == IOAPIC_SB_DEVID) {
+		} else if (devid == IOAPIC_SB_DEVID ||
+			   (boot_cpu_data.x86_vendor == X86_VENDOR_HYGON &&
+			    boot_cpu_data.x86 == 0x18 &&
+			    boot_cpu_data.x86_model >= 0x4 &&
+			    boot_cpu_data.x86_model <= 0xf &&
+			    devid == IOAPIC_SB_DEVID_FAM18H_M4H)) {
 			has_sb_ioapic = true;
 			ret           = true;
 		}
Signature · 1 line
2.34.1
maintainer
#10 lore raw

Re: [PATCH 5/8] x86/microcode/hygon: Add microcode loading support for Hygon processors

In reply to Fu Hao
Quoted 6 lines · Fu Hao

Add support for loading Hygon microcode, which is compatible with AMD one.

---
 arch/x86/Kconfig                         |  2 +-
 arch/x86/kernel/cpu/microcode/amd.c      | 63 ++++++++++++++++++------

No.

arch/x86/kernel/cpu/microcode/hygon.c

please.

Do a separate compilation unit where all the Hygon stuff can live instead of sprinkling "if HYGON" everywhere in the AMD loader.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author
#7 lore raw

PATCH 3/8 x86/cpu/hygon: Remove Spectral Chicken for Hygon processors

In reply to Fu Hao

The chicken bit is not need to be set for Hygon processors, so remove it.

Fixes d7caac991fee ("x86/cpu/amd: Add Spectral Chicken")
---
 arch/x86/kernel/cpu/hygon.c | 6 ------
 1 file changed, 6 deletions(-)
arch/x86/kernel/cpu/hygon.c +0 -6
index f39d32a68..72110eb73 100644
@@ -189,12 +189,6 @@ static void init_hygon(struct cpuinfo_x86 *c)
 
 	set_cpu_cap(c, X86_FEATURE_REP_GOOD);
 
-	/*
-	 * XXX someone from Hygon needs to confirm this DTRT
-	 *
-	init_spectral_chicken(c);
-	 */
-
 	set_cpu_cap(c, X86_FEATURE_ZEN);
 	set_cpu_cap(c, X86_FEATURE_CPB);
 
Signature · 1 line
2.34.1
author
#13 lore raw

PATCH 7/8 ALSA: hda: Fix single byte writing issue for Hygon family 18h model 5h

In reply to Fu Hao

On Hygon family 18h model 5h controller, some registers such as GCTL, SD_CTL and SD_CTL_3B should be accessed in dword, or the writing will fail.

---
 include/sound/hdaudio.h       |  1 +
 sound/hda/controllers/intel.c |  4 ++++
 sound/hda/core/controller.c   | 10 +++++++--
 sound/hda/core/stream.c       | 42 ++++++++++++++++++++++++++---------
 4 files changed, 45 insertions(+), 12 deletions(-)
include/sound/hdaudio.h +1 -0
index f11bfc6b9..57a144fec 100644
@@ -352,6 +352,7 @@ struct hdac_bus {
 	bool not_use_interrupts:1;	/* prohibiting the RIRB IRQ */
 	bool access_sdnctl_in_dword:1;	/* accessing the sdnctl register by dword */
 	bool use_pio_for_commands:1;	/* Use PIO instead of CORB for commands */
+	bool hygon_dword_access:1;
 
 	int poll_count;
 
sound/hda/controllers/intel.c +4 -0
index eb5d48d90..6b27248dc 100644
@@ -1885,6 +1885,10 @@ static int azx_first_init(struct azx *chip)
 	if (chip->driver_type == AZX_DRIVER_ZHAOXINHDMI)
 		bus->polling_mode = 1;
 
+	if (chip->driver_type == AZX_DRIVER_HYGON &&
+	    chip->pci->device == PCI_DEVICE_ID_HYGON_18H_M05H_HDA)
+		bus->hygon_dword_access = 1;
+
 	bus->remap_addr = pcim_iomap_region(pci, 0, "ICH HD audio");
 	if (IS_ERR(bus->remap_addr))
 		return PTR_ERR(bus->remap_addr);
sound/hda/core/controller.c +8 -2
index 69e11d62b..bfe817045 100644
@@ -511,7 +511,10 @@ void snd_hdac_bus_exit_link_reset(struct hdac_bus *bus)
 {
 	unsigned long timeout;
 
-	snd_hdac_chip_updateb(bus, GCTL, AZX_GCTL_RESET, AZX_GCTL_RESET);
+	if (bus->hygon_dword_access)
+		snd_hdac_chip_updatel(bus, GCTL, AZX_GCTL_RESET, AZX_GCTL_RESET);
+	else
+		snd_hdac_chip_updateb(bus, GCTL, AZX_GCTL_RESET, AZX_GCTL_RESET);
 
 	timeout = jiffies + msecs_to_jiffies(100);
 	while (!snd_hdac_chip_readb(bus, GCTL) && time_before(jiffies, timeout))
@@ -576,7 +579,10 @@ static void azx_int_disable(struct hdac_bus *bus)
 
 	/* disable interrupts in stream descriptor */
 	list_for_each_entry(azx_dev, &bus->stream_list, list)
-		snd_hdac_stream_updateb(azx_dev, SD_CTL, SD_INT_MASK, 0);
+		if (bus->hygon_dword_access)
+			snd_hdac_stream_updatel(azx_dev, SD_CTL, SD_INT_MASK, 0);
+		else
+			snd_hdac_stream_updateb(azx_dev, SD_CTL, SD_INT_MASK, 0);
 
 	/* disable SIE for all streams & disable controller CIE and GIE */
 	snd_hdac_chip_writel(bus, INTCTL, 0);
sound/hda/core/stream.c +32 -10

73 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#11 lore raw

Re: [PATCH 5/8] x86/microcode/hygon: Add microcode loading support for Hygon processors

In reply to Borislav Petkov
Quoted 10 lines · Borislav Petkov
Quoted 6 lines · Fu Hao

Add support for loading Hygon microcode, which is compatible with AMD one.

---
  arch/x86/Kconfig                         |  2 +-
  arch/x86/kernel/cpu/microcode/amd.c      | 63 ++++++++++++++++++------

No.

Quoted 9 lines

arch/x86/kernel/cpu/microcode/hygon.c

please.

Do a separate compilation unit where all the Hygon stuff can live instead of sprinkling "if HYGON" everywhere in the AMD loader.

Thx.

OK, thanks! I will create arch/x86/kernel/cpu/microcode/hygon.c in next patch series.

Signature · 2 lines
Regards,
Fu Hao
#14 lore raw

Re: [PATCH 7/8] ALSA: hda: Fix single byte writing issue for Hygon family 18h model 5h

In reply to Fu Hao
Quoted 18 lines · Fu Hao

On Hygon family 18h model 5h controller, some registers such as GCTL, SD_CTL and SD_CTL_3B should be accessed in dword, or the writing will fail.

---
 include/sound/hdaudio.h       |  1 +
 sound/hda/controllers/intel.c |  4 ++++
 sound/hda/core/controller.c   | 10 +++++++--
 sound/hda/core/stream.c       | 42 ++++++++++++++++++++++++++---------
 4 files changed, 45 insertions(+), 12 deletions(-)
include/sound/hdaudio.h +0 -0
index f11bfc6b9..57a144fec 100644

include/sound/hdaudio.h struct hdac_bus { · line 358

Quoted 7 lines
include/sound/hdaudio.h +1 -0
@@ -352,6 +352,7 @@ struct hdac_bus {
 	bool not_use_interrupts:1;	/* prohibiting the RIRB IRQ */
 	bool access_sdnctl_in_dword:1;	/* accessing the sdnctl register by dword */
 	bool use_pio_for_commands:1;	/* Use PIO instead of CORB for commands */
+	bool hygon_dword_access:1;
 
 	int poll_count;
 

I hesitate to add another flag just for this platform. And looking at the changes, all appear to be about the dword access for sdnctl writes. So I believe we can simply extend access_sdnctl_in_dword to do the dword access in each write access, instead? The performance shouldn't matter as it's no hot path.

Alternatively, you can enable bus->aligned_mmio flag, but this needs to enable CONFIG_SND_HDA_ALIGNED_MMIO. That's a visible cost for other platforms, though.

thanks,

Takashi

author
#15 lore raw

Re: [PATCH 7/8] ALSA: hda: Fix single byte writing issue for Hygon family 18h model 5h

Quoted 34 lines · Takashi Iwai
Quoted 18 lines · Fu Hao

On Hygon family 18h model 5h controller, some registers such as GCTL, SD_CTL and SD_CTL_3B should be accessed in dword, or the writing will fail.

---
  include/sound/hdaudio.h       |  1 +
  sound/hda/controllers/intel.c |  4 ++++
  sound/hda/core/controller.c   | 10 +++++++--
  sound/hda/core/stream.c       | 42 ++++++++++++++++++++++++++---------
  4 files changed, 45 insertions(+), 12 deletions(-)
include/sound/hdaudio.h +0 -0
index f11bfc6b9..57a144fec 100644

include/sound/hdaudio.h struct hdac_bus { · line 358

Quoted 7 lines
include/sound/hdaudio.h +1 -0
@@ -352,6 +352,7 @@ struct hdac_bus {
  	bool not_use_interrupts:1;	/* prohibiting the RIRB IRQ */
  	bool access_sdnctl_in_dword:1;	/* accessing the sdnctl register by dword */
  	bool use_pio_for_commands:1;	/* Use PIO instead of CORB for commands */
+	bool hygon_dword_access:1;
 
  	int poll_count;
 

I hesitate to add another flag just for this platform. And looking at the changes, all appear to be about the dword access for sdnctl writes. So I believe we can simply extend access_sdnctl_in_dword to do the dword access in each write access, instead? The performance shouldn't matter as it's no hot path.

Quoted 9 lines

Alternatively, you can enable bus->aligned_mmio flag, but this needs to enable CONFIG_SND_HDA_ALIGNED_MMIO. That's a visible cost for other platforms, though.

thanks,

Takashi

OK, thanks!I will try to use access_sdnctl_in_dword in next patch series.

Signature · 2 lines
Regards,
Fu Hao
#16 lore raw

Re: [PATCH 7/8] ALSA: hda: Fix single byte writing issue for Hygon family 18h model 5h

In reply to Fu Hao
Quoted 3 lines · On Fri, 27 Mar 2026 16:11:13 +0800 Fu Hao <[email protected]> wrote:

On Hygon family 18h model 5h controller, some registers such as GCTL, SD_CTL and SD_CTL_3B should be accessed in dword, or the writing will fail.

What's a 'dword' ?
It is short for 'double word', a 64bit cpu has a word size of 64 bits, so a dword would be 128 bits.

On Hygon family 18h model 5h controller 32bit accesses must be used to access registers such as CTL, SD_CTL and SD_CTL_3B.

David

author
#17 lore raw

Re: [PATCH 7/8] ALSA: hda: Fix single byte writing issue for Hygon family 18h model 5h

Quoted 7 lines · David Laight
Quoted 3 lines · On Fri, 27 Mar 2026 16:11:13 +0800 Fu Hao <[email protected]> wrote:

On Hygon family 18h model 5h controller, some registers such as GCTL, SD_CTL and SD_CTL_3B should be accessed in dword, or the writing will fail.

Quoted 9 lines

What's a 'dword' ?
It is short for 'double word', a 64bit cpu has a word size of 64 bits, so a dword would be 128 bits.

On Hygon family 18h model 5h controller 32bit accesses must be used to access registers such as CTL, SD_CTL and SD_CTL_3B.

David

Accessing in dword alignment means performing register read and write operations in 32-bit increments. In the current driver, some HDA registers are accessed by default in byte increments. However, for certain registers of the Hygon HD-audio controller, such as CTL, SD_CTL, and SD_CTL_3B, they need to be accessed in 32-bit increments during initialization, in accordance with the 32-bit nature of the registers themselves.

If you access it using dword, the API snd_hdac_stream_updatel(writel, 32bit) will be used.

Signature · 2 lines
Regards,
Fu Hao
maintainer
#2 lore raw

Re: [PATCH 1/8] x86/cpu/hygon: Adjust the die_id and logical_die_id for Hygon model 4h~8h

In reply to Fu Hao
Quoted 1 line · Fu Hao

The die id should be get from the NodeId field of CPUID leaf 0x8000001e

	     ^^^^^^^^^^^^^

Pls run all your English text through an LLM so that corrects it for you.

Also "die ID".

Quoted 12 lines

ecx for Hygon model 4h~8h processors.

---
 arch/x86/kernel/cpu/hygon.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
arch/x86/kernel/cpu/hygon.c +0 -0
index 7f95a74e4..f39d32a68 100644

arch/x86/kernel/cpu/hygon.c static void early_init_hygon(struct cpuinfo_x86 *c) · line 172

Quoted 5 lines
arch/x86/kernel/cpu/hygon.c +2 -0
@@ -168,6 +168,19 @@ static void early_init_hygon(struct cpuinfo_x86 *c)
 	set_cpu_cap(c, X86_FEATURE_VMMCALL);
 }
 
+/*
+ * Adjust the die_id and logical_die_id for Hygon model 4h~8h.

What does "model 4h~8h" mean?

Models 0x4-0x8 ?

arch/x86/kernel/cpu/hygon.c static void early_init_hygon(struct cpuinfo_x86 *c) · line 182

Quoted 10 lines
arch/x86/kernel/cpu/hygon.c +10 -0
+ */
+static void cpu_topology_fixup_hygon(struct cpuinfo_x86 *c)
+{
+	if (c->x86_model >= 0x4 && c->x86_model <= 0x8) {
+		c->topo.die_id = cpuid_ecx(0x8000001e) & 0xff;
+		c->topo.logical_die_id = (c->topo.die_id >> 4) *
+					 topology_amd_nodes_per_pkg() +
+					 (c->topo.die_id & 0xf);
+	}
+}

Does this really need to be a separate function or can you stick the if-conditional along with the comment where it needs to be executed?

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author
#3 lore raw

Re: [PATCH 1/8] x86/cpu/hygon: Adjust the die_id and logical_die_id for Hygon model 4h~8h

Quoted 44 lines · Borislav Petkov
Quoted 1 line · Fu Hao

The die id should be get from the NodeId field of CPUID leaf 0x8000001e

	     ^^^^^^^^^^^^^

Pls run all your English text through an LLM so that corrects it for you.

Also "die ID".

Quoted 12 lines

ecx for Hygon model 4h~8h processors.

---
  arch/x86/kernel/cpu/hygon.c | 15 +++++++++++++++
  1 file changed, 15 insertions(+)
arch/x86/kernel/cpu/hygon.c +0 -0
index 7f95a74e4..f39d32a68 100644

arch/x86/kernel/cpu/hygon.c static void early_init_hygon(struct cpuinfo_x86 *c) · line 172

Quoted 5 lines
arch/x86/kernel/cpu/hygon.c +2 -0
@@ -168,6 +168,19 @@ static void early_init_hygon(struct cpuinfo_x86 *c)
  	set_cpu_cap(c, X86_FEATURE_VMMCALL);
  }
 
+/*
+ * Adjust the die_id and logical_die_id for Hygon model 4h~8h.

What does "model 4h~8h" mean?

Models 0x4-0x8 ?

arch/x86/kernel/cpu/hygon.c static void early_init_hygon(struct cpuinfo_x86 *c) · line 182

Quoted 10 lines
arch/x86/kernel/cpu/hygon.c +10 -0
+ */
+static void cpu_topology_fixup_hygon(struct cpuinfo_x86 *c)
+{
+	if (c->x86_model >= 0x4 && c->x86_model <= 0x8) {
+		c->topo.die_id = cpuid_ecx(0x8000001e) & 0xff;
+		c->topo.logical_die_id = (c->topo.die_id >> 4) *
+					 topology_amd_nodes_per_pkg() +
+					 (c->topo.die_id & 0xf);
+	}
+}

Does this really need to be a separate function or can you stick the if-conditional along with the comment where it needs to be executed?

Quoted 2 lines

Thx.

Thank you very much for your suggestion.
The Hygon model 4h~8h, which is also the Hygon family 0x18 model 0x4~0x8 series of processors.

Using separate functions for encapsulation is primarily due to the consideration for subsequent new processors, there may be different ways to obtain the core ID, die ID and pkg ID. Of course, it can also be temporarily placed in the "init_hygon" function at present.

What about your suggestion?

Signature · 2 lines
Regards,
Fu Hao
maintainer
#4 lore raw

Re: [PATCH 1/8] x86/cpu/hygon: Adjust the die_id and logical_die_id for Hygon model 4h~8h

Quoted 3 lines · Fu Hao
Quoted 3 lines

What does "model 4h~8h" mean?

Models 0x4-0x8 ?

You didn't explain that one.

Quoted 4 lines

Using separate functions for encapsulation is primarily due to the consideration for subsequent new processors, there may be different ways to obtain the core ID, die ID and pkg ID. Of course, it can also be temporarily placed in the "init_hygon" function at present.

Yes, do that.

You can carve it out later, when it gets unwieldy.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author
#5 lore raw

Re: [PATCH 1/8] x86/cpu/hygon: Adjust the die_id and logical_die_id for Hygon model 4h~8h

Quoted 7 lines · Borislav Petkov
Quoted 3 lines · Fu Hao
Quoted 3 lines

What does "model 4h~8h" mean?

Models 0x4-0x8 ?

You didn't explain that one.

Yes. This refers to Hygon processor models 0x4–0x8.

Signature · 2 lines
Regards,
Fu Hao