Add support for Hygon Family 18h model 4h~8h processors
Subsystems (8)
v2 cover Add support for Hygon Family 18h model 4h~8h processors
This patch series introduce support for the new-generation Hygon models 0x4-0x8 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.
v1->v2:
- Refine the patch x86/cpu/hygon.
- Do a separate compilation unit on hygon microcode loading support.
- Use "access_sdnctl_in_dword" instead of "hygon_dword_acess" for accessing the HDA registers.
Fu Hao (8):
x86/cpu/hygon: Adjust the die_id and logical_die_id for Hygon models
0x4-0x8
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 | 16 +- arch/x86/kernel/cpu/microcode/Makefile | 1 + arch/x86/kernel/cpu/microcode/core.c | 17 +- arch/x86/kernel/cpu/microcode/hygon.c | 927 +++++++++++++++++++++++ arch/x86/kernel/cpu/microcode/internal.h | 20 + drivers/iommu/amd/init.c | 10 +- include/linux/pci_ids.h | 1 + sound/hda/controllers/intel.c | 9 + sound/hda/core/controller.c | 10 +- sound/hda/core/stream.c | 40 +- 14 files changed, 1105 insertions(+), 26 deletions(-) create mode 100644 arch/x86/kernel/cpu/microcode/hygon.c
Signature · 1 line
2.34.1
PATCH v2 1/8 x86/cpu/hygon: Adjust the die_id and logical_die_id for Hygon models 0x4-0x8
The die ID should be got from the NodeId field of CPUID leaf 0x8000001e ecx for Hygon models 0x4-0x8 processors.
--- arch/x86/kernel/cpu/hygon.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/x86/kernel/cpu/hygon.c +10 -0
@@ -191,6 +191,16 @@ static void init_hygon(struct cpuinfo_x86 *c)init_hygon_cacheinfo (c); +/* +* Adjust the die_id and logical_die_id for Hygon models 0x4-0x8. +*/ +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 ); + } +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
PATCH v2 2/8 x86/cpu: Get LLC ID for Hygon family 18h model 4h
In reply to Fu HaoAdd 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
@@ -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
PATCH v2 3/8 x86/cpu/hygon: Remove Spectral Chicken for Hygon processors
In reply to Fu HaoThe chicken bit does not need to be set for Hygon processors, so remove it.
--- arch/x86/kernel/cpu/hygon.c | 6 ------ 1 file changed, 6 deletions(-)
arch/x86/kernel/cpu/hygon.c +0 -6
@@ -176,12 +176,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
PATCH v2 4/8 perf/x86/uncore: Add L3 PMU support for Hygon family 18h model 6h
In reply to Fu HaoAdjust 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
@@ -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 L3DEFINE_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
@@ -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
PATCH v2 5/8 x86/microcode/hygon: Add microcode loading support for Hygon processors
In reply to Fu HaoAdd support for loading Hygon microcode.
There are two loading methods:
1. Loading from the initrd/builtin.
2. Late loading, which depends on the kernel configuration option CONFIG_MICROCODE_LATE_LOADING being enabled, and this option is usually disabled by default, so it's not recommended.
--- arch/x86/Kconfig | 2 +- arch/x86/kernel/cpu/microcode/Makefile | 1 + arch/x86/kernel/cpu/microcode/core.c | 17 +- arch/x86/kernel/cpu/microcode/hygon.c | 927 +++++++++++++++++++++++ arch/x86/kernel/cpu/microcode/internal.h | 20 + 5 files changed, 965 insertions(+), 2 deletions(-) create mode 100644 arch/x86/kernel/cpu/microcode/hygon.c
arch/x86/Kconfig +1 -1
@@ -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/Makefile +1 -0
@@ -3,3 +3,4 @@ microcode-y := core.o obj-$(CONFIG_MICROCODE) += microcode.o microcode-$(CONFIG_CPU_SUP_INTEL) += intel.o microcode-$(CONFIG_CPU_SUP_AMD) += amd.o +microcode-$(CONFIG_CPU_SUP_HYGON) += hygon.o
arch/x86/kernel/cpu/microcode/core.c +16 -1
@@ -195,6 +195,9 @@ void __init load_ucode_bsp(void)return ; intel = false;break ; +case X86_VENDOR_HYGON : + intel = false; +break ;default :return ;
@@ -203,7 +206,11 @@ void __init load_ucode_bsp(void)if (intel)load_ucode_intel_bsp (&early_data);else -load_ucode_amd_bsp (&early_data, cpuid_1_eax); +if (x86_cpuid_vendor () ==X86_VENDOR_HYGON ) +load_ucode_hygon_bsp (&early_data, cpuid_1_eax); +else +load_ucode_amd_bsp (&early_data, cpuid_1_eax); + }void load_ucode_ap (void )
@@ -229,6 +236,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_hygon_ap (cpuid_1_eax); +break ;default :break ; }
@@ -288,6 +298,9 @@ static void reload_early_microcode(unsigned int cpu)if (family >=0x10 )reload_ucode_amd (cpu);break ; +case X86_VENDOR_HYGON : +reload_ucode_hygon (cpu); +break ;default :break ; }
@@ -895,6 +908,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/hygon.c new file +927 -0
927 lines not on this page · raw message
arch/x86/kernel/cpu/microcode/internal.h +20 -0
@@ -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,20 @@ 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 +void load_ucode_hygon_bsp (struct early_load_data *ed,unsigned int family); +void load_ucode_hygon_ap (unsigned int family); +void reload_ucode_hygon (unsigned int cpu); +struct microcode_ops *init_hygon_microcode (void ); +void exit_hygon_microcode (void ); +#else /* CONFIG_CPU_SUP_HYGON */ +static inline void load_ucode_hygon_bsp (struct early_load_data *ed,unsigned int family) { } +static inline void load_ucode_hygon_ap (unsigned int family) { } +static inline void reload_ucode_hygon (unsigned int cpu) { } +static inline struct microcode_ops *init_hygon_microcode (void ) {return NULL ; } +static inline void exit_hygon_microcode (void ) { } +#endif /* !CONFIG_CPU_SUP_HYGON */ +#define ucode_dbg (fmt, ...) \ ({ \ if (IS_ENABLED(CONFIG_MICROCODE_DBG)) \
Signature · 1 line
2.34.1
PATCH v2 7/8 ALSA: hda: Fix single byte writing issue for Hygon family 18h model 5h
In reply to Fu HaoOn 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.
--- sound/hda/controllers/intel.c | 4 ++++ sound/hda/core/controller.c | 10 +++++++-- sound/hda/core/stream.c | 40 +++++++++++++++++++++++++++-------- 3 files changed, 43 insertions(+), 11 deletions(-)
sound/hda/controllers/intel.c +4 -0
@@ -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->access_sdnctl_in_dword =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
@@ -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->access_sdnctl_in_dword) +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->access_sdnctl_in_dword) +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 +31 -9
@@ -146,8 +146,12 @@ void snd_hdac_stream_start(struct hdac_stream *azx_dev) stripe_ctl =snd_hdac_get_stream_stripe_ctl (bus, azx_dev->substream); else stripe_ctl =0 ; -snd_hdac_stream_updateb (azx_dev,SD_CTL_3B ,SD_CTL_STRIPE_MASK , - stripe_ctl); +if (bus->access_sdnctl_in_dword) +snd_hdac_stream_updatel (azx_dev,SD_CTL_3B ,SD_CTL_STRIPE_MASK , + stripe_ctl); +else +snd_hdac_stream_updateb (azx_dev,SD_CTL_3B ,SD_CTL_STRIPE_MASK , + stripe_ctl); }/* set DMA start and interrupt mask */ if (bus->access_sdnctl_in_dword)
@@ -166,11 +170,22 @@ EXPORT_SYMBOL_GPL(snd_hdac_stream_start);*/ static void snd_hdac_stream_clear (struct hdac_stream *azx_dev) { -snd_hdac_stream_updateb (azx_dev,SD_CTL , -SD_CTL_DMA_START |SD_INT_MASK ,0 ); -snd_hdac_stream_writeb (azx_dev,SD_STS ,SD_INT_MASK );/* to be sure */ -if (azx_dev->stripe) -snd_hdac_stream_updateb (azx_dev,SD_CTL_3B ,SD_CTL_STRIPE_MASK ,0 ); +struct hdac_bus *bus = azx_dev->bus; + +if (bus->access_sdnctl_in_dword) { +snd_hdac_stream_updatel (azx_dev,SD_CTL , +SD_CTL_DMA_START |SD_INT_MASK ,0 ); +snd_hdac_stream_writeb (azx_dev,SD_STS ,SD_INT_MASK );/* to be sure */ +if (azx_dev->stripe) +snd_hdac_stream_updatel (azx_dev,SD_CTL_3B ,SD_CTL_STRIPE_MASK ,0 ); + }else { +snd_hdac_stream_updateb (azx_dev,SD_CTL , +SD_CTL_DMA_START |SD_INT_MASK ,0 ); +snd_hdac_stream_writeb (azx_dev,SD_STS ,SD_INT_MASK );/* to be sure */ +if (azx_dev->stripe) +snd_hdac_stream_updateb (azx_dev,SD_CTL_3B ,SD_CTL_STRIPE_MASK ,0 ); + } + azx_dev->running = false; }
@@ -225,12 +240,16 @@ void snd_hdac_stream_reset(struct hdac_stream *azx_dev) {unsigned char val;int dma_run_state; +struct hdac_bus *bus = azx_dev->bus;snd_hdac_stream_clear (azx_dev); dma_run_state =snd_hdac_stream_readb (azx_dev,SD_CTL ) &SD_CTL_DMA_START ; -snd_hdac_stream_updateb (azx_dev,SD_CTL ,0 ,SD_CTL_STREAM_RESET ); +if (bus->access_sdnctl_in_dword) +snd_hdac_stream_updatel (azx_dev,SD_CTL ,0 ,SD_CTL_STREAM_RESET ); +else +snd_hdac_stream_updateb (azx_dev,SD_CTL ,0 ,SD_CTL_STREAM_RESET );/* wait for hardware to report that the stream entered reset */ snd_hdac_stream_readb_poll (azx_dev,SD_CTL , val, (val &SD_CTL_STREAM_RESET ),3 ,300 );
@@ -238,7 +257,10 @@ void snd_hdac_stream_reset(struct hdac_stream *azx_dev)if (azx_dev->bus->dma_stop_delay && dma_run_state)udelay (azx_dev->bus->dma_stop_delay); -snd_hdac_stream_updateb (azx_dev,SD_CTL ,SD_CTL_STREAM_RESET ,0 ); +if (bus->access_sdnctl_in_dword) +snd_hdac_stream_updatel (azx_dev,SD_CTL ,SD_CTL_STREAM_RESET ,0 ); +else +snd_hdac_stream_updateb (azx_dev,SD_CTL ,SD_CTL_STREAM_RESET ,0 );/* wait for hardware to report that the stream is out of reset */ snd_hdac_stream_readb_poll (azx_dev,SD_CTL , val, !(val &SD_CTL_STREAM_RESET ),3 ,300 );
Signature · 1 line
2.34.1
PATCH v2 8/8 iommu/hygon: Add support for Hygon family 18h model 4h IOAPIC
In reply to Fu HaoThe 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
@@ -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
PATCH v2 6/8 ALSA: hda: Add support for Hygon family 18h model 5h HD-Audio
In reply to Fu HaoAdd 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
@@ -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
@@ -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
Re: [PATCH v2 5/8] x86/microcode/hygon: Add microcode loading support for Hygon processors
In reply to Fu HaoOn 4/7/26 01:24, Fu Hao wrote:
...
Quoted 1 line
arch/x86/kernel/cpu/microcode/hygon.c | 927 +++++++++++++++++++++++
This looks a lot like:
cat amd.c | perl -pe 's/amd/hygon/' > hygon.c
If it's something like that, I think it probably needs to get mentioned up front and discussed about what's actually *different* from the AMD implementation.
Borislav Petkov
maintainerRe: [PATCH v2 5/8] x86/microcode/hygon: Add microcode loading support for Hygon processors
Quoted 10 lines · Dave Hansen
On 4/7/26 01:24, Fu Hao wrote:
...Quoted 1 line
arch/x86/kernel/cpu/microcode/hygon.c | 927 +++++++++++++++++++++++This looks a lot like:
cat
amd.c| perl -pe 's/amd/hygon/' >hygon.cIf it's something like that, I think it probably needs to get mentioned up front and discussed about what's actually *different* from the AMD implementation.
Yes, and there's a *lot* of AMD-specific stuff in there.
I'd suggest you go through the code with a fine-toothed comb and remove everything you won't need and you don't use.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH v2 5/8] x86/microcode/hygon: Add microcode loading support for Hygon processors
In reply to Dave HansenQuoted 11 lines · Dave Hansen
On 4/7/26 01:24, Fu Hao wrote:
...Quoted 1 line
arch/x86/kernel/cpu/microcode/hygon.c | 927 +++++++++++++++++++++++This looks a lot like:
cat
amd.c| perl -pe 's/amd/hygon/' >hygon.cIf it's something like that, I think it probably needs to get mentioned up front and discussed about what's actually *different* from the AMD implementation.
Thank you for the clear guidance. Indeed, the principles of microcode loading and the registers are almost identical to those of AMD.
We will rethink the code structure and specific implementation, and only retain the minimum necessary to maintain the basic functionality.
Signature · 2 lines
Regards, Fu Hao
Re: [PATCH v2 5/8] x86/microcode/hygon: Add microcode loading support for Hygon processors
In reply to Borislav PetkovQuoted 12 lines · Borislav Petkov
Quoted 10 lines · Dave Hansen
On 4/7/26 01:24, Fu Hao wrote:
...Quoted 1 line
arch/x86/kernel/cpu/microcode/hygon.c | 927 +++++++++++++++++++++++This looks a lot like:
cat
amd.c| perl -pe 's/amd/hygon/' >hygon.cIf it's something like that, I think it probably needs to get mentioned up front and discussed about what's actually *different* from the AMD implementation.
Quoted 7 lines
Yes, and there's a *lot* of AMD-specific stuff in there.
I'd suggest you go through the code with a fine-toothed comb and remove everything you won't need and you don't use.
Thx.
Thank you for the clear guidance. We will rethink the code structure and specific implementation, and only retain the minimum necessary to maintain the basic functionality.
Signature · 2 lines
Regards, Fu Hao
Re: [PATCH v2 6/8] ALSA: hda: Add support for Hygon family 18h model 5h HD-Audio
In reply to Fu HaoQuoted 14 lines · Fu Hao
Add the new PCI ID
0x1d940x14a9for Hygon family 18h model 5h HDA controller.Signed-off-by Fu Hao <[email protected]>--- include/linux/pci_ids.h | 1 + sound/hda/controllers/intel.c | 5 +++++ 2 files changed, 6 insertions(+)include/linux/pci_ids.h +0
-0
include/linux/pci_ids.h line 2616
Quoted 4 lines
include/linux/pci_ids.h +1
-0@@ -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
It looks like PCI_DEVICE_ID_HYGON_18H_M05H_HDA is only used in sound/hda/controllers/intel.c, so it should probably be defined there so you don't need to modify include/linux/pci_ids.h:
* Do not add new entries to this file unless the definitions
* are shared between multiple drivers.
Thanks for your patch series.
I've tested the changes on my hygon servers (model 4h, 6h, 7h, 8h) with kernel version 7.0.0-rc7 and everything works as expected.
Re: [PATCH v2 6/8] ALSA: hda: Add support for Hygon family 18h model 5h HD-Audio
In reply to Bjorn HelgaasQuoted 24 lines · Bjorn Helgaas
Quoted 14 lines · Fu Hao
Add the new PCI ID
0x1d940x14a9for Hygon family 18h model 5h HDA controller.Signed-off-by Fu Hao <[email protected]>--- include/linux/pci_ids.h | 1 + sound/hda/controllers/intel.c | 5 +++++ 2 files changed, 6 insertions(+)include/linux/pci_ids.h +0
-0include/linux/pci_ids.h line 2616
Quoted 4 lines
include/linux/pci_ids.h +1
-0@@ -2613,6 +2613,7 @@#define PCI_VENDOR_ID_ROCKCHIP 0x1d87#define PCI_VENDOR_ID_HYGON 0x1d94 +#define PCI_DEVICE_ID_HYGON_18H_M05H_HDA 0x14a9It looks like
PCI_DEVICE_ID_HYGON_18H_M05H_HDAis only used insound/hda/controllers/intel.c, so it should probably be defined there so you don't need to modifyinclude/linux/pci_ids.h:
Quoted 3 lines
* Do not add new entries to this file unless the definitions
* are shared between multiple drivers.
Thank you for the clear guidance.I will modify it in v3 patch.
Signature · 2 lines
Regards, Fu Hao
Re: [PATCH v2 8/8] iommu/hygon: Add support for Hygon family 18h model 4h IOAPIC
In reply to Fu HaoQuoted 6 lines · Fu Hao
The SB IOAPIC is on the device
0xbfrom Hygon family 18h model 4h.Signed-off-by Fu Hao <[email protected]>--- drivers/iommu/amd/init.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
Applied, thanks.
Borislav Petkov
maintainerRe: [PATCH v2 1/8] x86/cpu/hygon: Adjust the die_id and logical_die_id for Hygon models 0x4-0x8
In reply to Fu HaoQuoted 2 lines · Fu Hao
The die ID should be got from the NodeId field of CPUID leaf
0x8000001eecx for Hygon models 0x4-0x8 processors.
Correct the formulations in this text: "The die ID should be got from the NodeId field of CPUID leaf 0x8000001e ecx for Hygon models 0x4-0x8 processors."
AI:
Here are some corrected versions of your sentence:
Option 1 (minimal changes): "The die ID should be obtained from the NodeId field of CPUID leaf 0x8000001e ECX for Hygon processors of models 0x4–0x8."
Option 2 (more natural phrasing): "The die ID should be read from the NodeId field of CPUID leaf 0x8000001e (ECX) for Hygon processor models 0x4–0x8."
Option 3 (concise): "For Hygon processor models 0x4–0x8, the die ID should be obtained from the NodeId field in ECX of CPUID leaf 0x8000001e."
Key issues corrected:
"should be got" → "should be obtained" / "should be read" (more formal and grammatically preferred) "ecx" → "ECX" (CPU register names are conventionally capitalized)
"Hygon models 0x4-0x8 processors" → "Hygon processor models 0x4–0x8" (clearer word order) Consider using an en dash (–) instead of a hyphen (-) for the range, though a hyphen is acceptable in code comments.
Now you do it for all your commit messages please.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteBorislav Petkov
maintainerRe: [PATCH v2 2/8] x86/cpu: Get LLC ID for Hygon family 18h model 4h
In reply to Fu HaoQuoted 7 lines · Fu Hao
Add support to calculate LLC ID from the number of threads sharing the cache for Hygon family 18h model 4h processor.
Signed-off-by Fu Hao <[email protected]>--- arch/x86/kernel/cpu/cacheinfo.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
If you're going to copy code at least try to share functionality which is kinda begging to be a separate function.
Ontop of yours and untested:
arch/x86/kernel/cpu/cacheinfo.c +12 -19
@@ -305,10 +305,19 @@ static unsigned int get_cache_id(u32 apicid, const struct _cpuid4_info *id4)return apicid >> index_msb; } +/* LLC ID is calculated from the number of threads sharing the L3 cache. */ +static void __calc_llc_id (struct cpuinfo_x86 *c) +{ +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); +} +/* * AMD/Hygon CPUs may have multiple LLCs if L3 caches exist. */ -void cacheinfo_amd_init_llc_id (struct cpuinfo_x86 *c,u16 die_id) {if (!cpuid_amd_hygon_has_l3_cache ())
@@ -324,15 +333,7 @@ void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, u16 die_id)*/ c->topo.llc_id = c->topo.apicid >>3 ; }else { -/* -* Newer families: 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); +__calc_llc_id (c); } }
@@ -342,15 +343,7 @@ void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c)return ;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); +__calc_llc_id (c); }else {/* * The others are similar to AMD Family 17h up to 1F models: LLC is
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH v2 1/8] x86/cpu/hygon: Adjust the die_id and logical_die_id for Hygon models 0x4-0x8
In reply to Borislav PetkovQuoted 26 lines · Borislav Petkov
Quoted 2 lines · Fu Hao
The die ID should be got from the NodeId field of CPUID leaf
0x8000001eecx for Hygon models 0x4-0x8 processors.Correct the formulations in this text: "The die ID should be got from the NodeId field of CPUID leaf
0x8000001eecx for Hygon models 0x4-0x8 processors."AI:
Here are some corrected versions of your sentence:
Option 1 (minimal changes): "The die ID should be obtained from the NodeId field of CPUID leaf
0x8000001eECX for Hygon processors of models 0x4–0x8."Option 2 (more natural phrasing): "The die ID should be read from the NodeId field of CPUID leaf
0x8000001e(ECX) for Hygon processor models 0x4–0x8."Option 3 (concise): "For Hygon processor models 0x4–0x8, the die ID should be obtained from the NodeId field in ECX of CPUID leaf
0x8000001e."Key issues corrected:
Quoted 8 lines
"should be got" → "should be obtained" / "should be read" (more formal and grammatically preferred) "ecx" → "ECX" (CPU register names are conventionally capitalized)
"Hygon models 0x4-0x8 processors" → "Hygon processor models 0x4–0x8" (clearer word order) Consider using an en dash (–) instead of a hyphen (-) for the range, though a hyphen is acceptable in code comments.Now you do it for all your commit messages please.
Hi Boris,
Thank you very much for reviewing this patch and providing such
detailed guidance. Please accept my apologies for the non-compliant patch comments and commit messages in the previous version, and I will fix it in v3.
Signature · 2 lines
Regards, Fu Hao
Re: [PATCH v2 2/8] x86/cpu: Get LLC ID for Hygon family 18h model 4h
In reply to Borislav PetkovQuoted 64 lines · Borislav Petkov
Quoted 7 lines · Fu Hao
Add support to calculate LLC ID from the number of threads sharing the cache for Hygon family 18h model 4h processor.
Signed-off-by Fu Hao <[email protected]>--- arch/x86/kernel/cpu/cacheinfo.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)If you're going to copy code at least try to share functionality which is kinda begging to be a separate function.
Ontop of yours and untested:
arch/x86/kernel/cpu/cacheinfo.c +11
-13@@ -305,10 +305,19 @@ static unsigned int get_cache_id(u32 apicid, const struct _cpuid4_info *id4)return apicid >> index_msb; } +/* LLC ID is calculated from the number of threads sharing the L3 cache. */ +static void __calc_llc_id (struct cpuinfo_x86 *c) +{ +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); +} +/* * AMD/Hygon CPUs may have multiple LLCs if L3 caches exist. */ -void cacheinfo_amd_init_llc_id (struct cpuinfo_x86 *c,u16 die_id) {if (!cpuid_amd_hygon_has_l3_cache ())@@ -324,15 +333,7 @@ void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, u16 die_id)*/ c->topo.llc_id = c->topo.apicid >>3 ; }else { -/* -* Newer families: 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); +__calc_llc_id (c); } }@@ -342,15 +343,7 @@ void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c)return ;if (c->x86_model >=0x4 ) { -/* -* From model 4h: LLC ID is calculated from the number -* of threads sharing the L3 cache.
arch/x86/kernel/cpu/cacheinfo.c void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c) · line 349
Quoted 10 lines
arch/x86/kernel/cpu/cacheinfo.c +1
-6-*/ -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); +__calc_llc_id (c); }else {/* * The others are similar to AMD Family 17h up to 1F models: LLC is
Hi Boris,
Thanks for your guidance. The goal here was to keep the changes
minimal and consistent with the existing code flow. Since Hygon reports the same CPUID leaves as AMD, it made sense to just follow AMD's current implementation rather than introduce a separate path.
For Hygon processors, the LLC ID comes from fixed bit positions
regardless of whether SMT is enabled or not. Therefore, perhaps I could implement it as follows:
@@ -341,11 +341,18 @@ 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;
+ switch (c->x86_model) {
+ case 0x6:+ c->topo.llc_id = c->topo.apicid >> 4;
+ break;
+ case 0x7:
+ case 0x8:
+ c->topo.llc_id = c->topo.apicid >> 5;
+ break;
+ default:
+ c->topo.llc_id = c->topo.apicid >> 3;
+ break;
+ }
}
Thank you again for reviewing and offering your suggestions.
Signature · 2 lines
Regards, Fu Hao
Borislav Petkov
maintainerRe: [PATCH v2 2/8] x86/cpu: Get LLC ID for Hygon family 18h model 4h
Quoted 3 lines · Fu Hao
For Hygon processors, the LLC ID comes from fixed bit positions
regardless of whether SMT is enabled or not. Therefore, perhaps I could implement it as follows:
I don't know.
This is different from what you sent but in the end of the day, you have the hw and you can test.
My goal is to not duplicate code if it can be helped and common functionality makes sense to be carved out into a separate helper. IOW, keep the code from becoming a mess.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette