~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/x86/kernel/cpu/hygon.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /arch/x86/kernel/cpu/hygon.c (Architecture sparc) and /arch/alpha/kernel/cpu/hygon.c (Architecture alpha)


  1 // SPDX-License-Identifier: GPL-2.0+                1 
  2 /*                                                
  3  * Hygon Processor Support for Linux              
  4  *                                                
  5  * Copyright (C) 2018 Chengdu Haiguang IC Desi    
  6  *                                                
  7  * Author: Pu Wen <puwen@hygon.cn>                
  8  */                                               
  9 #include <linux/io.h>                             
 10                                                   
 11 #include <asm/apic.h>                             
 12 #include <asm/cpu.h>                              
 13 #include <asm/smp.h>                              
 14 #include <asm/numa.h>                             
 15 #include <asm/cacheinfo.h>                        
 16 #include <asm/spec-ctrl.h>                        
 17 #include <asm/delay.h>                            
 18                                                   
 19 #include "cpu.h"                                  
 20                                                   
 21 #ifdef CONFIG_NUMA                                
 22 /*                                                
 23  * To workaround broken NUMA config.  Read the    
 24  * srat_detect_node().                            
 25  */                                               
 26 static int nearby_node(int apicid)                
 27 {                                                 
 28         int i, node;                              
 29                                                   
 30         for (i = apicid - 1; i >= 0; i--) {       
 31                 node = __apicid_to_node[i];       
 32                 if (node != NUMA_NO_NODE && no    
 33                         return node;              
 34         }                                         
 35         for (i = apicid + 1; i < MAX_LOCAL_API    
 36                 node = __apicid_to_node[i];       
 37                 if (node != NUMA_NO_NODE && no    
 38                         return node;              
 39         }                                         
 40         return first_node(node_online_map); /*    
 41 }                                                 
 42 #endif                                            
 43                                                   
 44 static void srat_detect_node(struct cpuinfo_x8    
 45 {                                                 
 46 #ifdef CONFIG_NUMA                                
 47         int cpu = smp_processor_id();             
 48         int node;                                 
 49         unsigned int apicid = c->topo.apicid;     
 50                                                   
 51         node = numa_cpu_node(cpu);                
 52         if (node == NUMA_NO_NODE)                 
 53                 node = c->topo.llc_id;            
 54                                                   
 55         /*                                        
 56          * On multi-fabric platform (e.g. Numa    
 57          * platform-specific handler needs to     
 58          * IDs of the CPU.                        
 59          */                                       
 60         if (x86_cpuinit.fixup_cpu_id)             
 61                 x86_cpuinit.fixup_cpu_id(c, no    
 62                                                   
 63         if (!node_online(node)) {                 
 64                 /*                                
 65                  * Two possibilities here:        
 66                  *                                
 67                  * - The CPU is missing memory    
 68                  *   that case try picking one    
 69                  *                                
 70                  * - The APIC IDs differ from     
 71                  *   Assume they are all incre    
 72                  *   in the same order as the     
 73                  *   result in a usable node f    
 74                  *   previous case.               
 75                  *                                
 76                  * This workaround operates di    
 77                  * APIC ID and NUMA node, assu    
 78                  * between APIC ID, HT node ID    
 79                  * through CPU mapping may alt    
 80                  * access __apicid_to_node[].     
 81                  */                               
 82                 int ht_nodeid = c->topo.initia    
 83                                                   
 84                 if (__apicid_to_node[ht_nodeid    
 85                         node = __apicid_to_nod    
 86                 /* Pick a nearby node */          
 87                 if (!node_online(node))           
 88                         node = nearby_node(api    
 89         }                                         
 90         numa_set_node(cpu, node);                 
 91 #endif                                            
 92 }                                                 
 93                                                   
 94 static void bsp_init_hygon(struct cpuinfo_x86     
 95 {                                                 
 96         if (cpu_has(c, X86_FEATURE_CONSTANT_TS    
 97                 u64 val;                          
 98                                                   
 99                 rdmsrl(MSR_K7_HWCR, val);         
100                 if (!(val & BIT(24)))             
101                         pr_warn(FW_BUG "TSC do    
102         }                                         
103                                                   
104         if (cpu_has(c, X86_FEATURE_MWAITX))       
105                 use_mwaitx_delay();               
106                                                   
107         if (!boot_cpu_has(X86_FEATURE_AMD_SSBD    
108             !boot_cpu_has(X86_FEATURE_VIRT_SSB    
109                 /*                                
110                  * Try to cache the base value    
111                  * avoid RMW. If that faults,     
112                  */                               
113                 if (!rdmsrl_safe(MSR_AMD64_LS_    
114                         setup_force_cpu_cap(X8    
115                         setup_force_cpu_cap(X8    
116                         x86_amd_ls_cfg_ssbd_ma    
117                 }                                 
118         }                                         
119 }                                                 
120                                                   
121 static void early_init_hygon(struct cpuinfo_x8    
122 {                                                 
123         u32 dummy;                                
124                                                   
125         set_cpu_cap(c, X86_FEATURE_K8);           
126                                                   
127         rdmsr_safe(MSR_AMD64_PATCH_LEVEL, &c->    
128                                                   
129         /*                                        
130          * c->x86_power is 8000_0007 edx. Bit     
131          * with P/T states and does not stop i    
132          */                                       
133         if (c->x86_power & (1 << 8)) {            
134                 set_cpu_cap(c, X86_FEATURE_CON    
135                 set_cpu_cap(c, X86_FEATURE_NON    
136         }                                         
137                                                   
138         /* Bit 12 of 8000_0007 edx is accumula    
139         if (c->x86_power & BIT(12))               
140                 set_cpu_cap(c, X86_FEATURE_ACC    
141                                                   
142         /* Bit 14 indicates the Runtime Averag    
143         if (c->x86_power & BIT(14))               
144                 set_cpu_cap(c, X86_FEATURE_RAP    
145                                                   
146 #ifdef CONFIG_X86_64                              
147         set_cpu_cap(c, X86_FEATURE_SYSCALL32);    
148 #endif                                            
149                                                   
150 #if defined(CONFIG_X86_LOCAL_APIC) && defined(    
151         /*                                        
152          * ApicID can always be treated as an     
153          * can safely set X86_FEATURE_EXTD_API    
154          */                                       
155         if (boot_cpu_has(X86_FEATURE_APIC))       
156                 set_cpu_cap(c, X86_FEATURE_EXT    
157 #endif                                            
158                                                   
159         /*                                        
160          * This is only needed to tell the ker    
161          * and VMMCALL.  VMMCALL is never exec    
162          * we can set it unconditionally.         
163          */                                       
164         set_cpu_cap(c, X86_FEATURE_VMMCALL);      
165 }                                                 
166                                                   
167 static void init_hygon(struct cpuinfo_x86 *c)     
168 {                                                 
169         u64 vm_cr;                                
170                                                   
171         early_init_hygon(c);                      
172                                                   
173         /*                                        
174          * Bit 31 in normal CPUID used for non    
175          * 3DNow is IDd by bit 31 in extended     
176          */                                       
177         clear_cpu_cap(c, 0*32+31);                
178                                                   
179         set_cpu_cap(c, X86_FEATURE_REP_GOOD);     
180                                                   
181         /*                                        
182          * XXX someone from Hygon needs to con    
183          *                                        
184         init_spectral_chicken(c);                 
185          */                                       
186                                                   
187         set_cpu_cap(c, X86_FEATURE_ZEN);          
188         set_cpu_cap(c, X86_FEATURE_CPB);          
189                                                   
190         cpu_detect_cache_sizes(c);                
191                                                   
192         srat_detect_node(c);                      
193                                                   
194         init_hygon_cacheinfo(c);                  
195                                                   
196         if (cpu_has(c, X86_FEATURE_SVM)) {        
197                 rdmsrl(MSR_VM_CR, vm_cr);         
198                 if (vm_cr & SVM_VM_CR_SVM_DIS_    
199                         pr_notice_once("SVM di    
200                         clear_cpu_cap(c, X86_F    
201                 }                                 
202         }                                         
203                                                   
204         if (cpu_has(c, X86_FEATURE_XMM2)) {       
205                 /*                                
206                  * Use LFENCE for execution se    
207                  * don't have that MSR, LFENCE    
208                  * msr_set_bit() uses the safe    
209                  * is not present.                
210                  */                               
211                 msr_set_bit(MSR_AMD64_DE_CFG,     
212                             MSR_AMD64_DE_CFG_L    
213                                                   
214                 /* A serializing LFENCE stops     
215                 set_cpu_cap(c, X86_FEATURE_LFE    
216         }                                         
217                                                   
218         /*                                        
219          * Hygon processors have APIC timer ru    
220          */                                       
221         set_cpu_cap(c, X86_FEATURE_ARAT);         
222                                                   
223         /* Hygon CPUs don't reset SS attribute    
224         if (!cpu_feature_enabled(X86_FEATURE_X    
225                 set_cpu_bug(c, X86_BUG_SYSRET_    
226                                                   
227         check_null_seg_clears_base(c);            
228                                                   
229         /* Hygon CPUs don't need fencing after    
230         clear_cpu_cap(c, X86_FEATURE_APIC_MSRS    
231 }                                                 
232                                                   
233 static void cpu_detect_tlb_hygon(struct cpuinf    
234 {                                                 
235         u32 ebx, eax, ecx, edx;                   
236         u16 mask = 0xfff;                         
237                                                   
238         if (c->extended_cpuid_level < 0x800000    
239                 return;                           
240                                                   
241         cpuid(0x80000006, &eax, &ebx, &ecx, &e    
242                                                   
243         tlb_lld_4k[ENTRIES] = (ebx >> 16) & ma    
244         tlb_lli_4k[ENTRIES] = ebx & mask;         
245                                                   
246         /* Handle DTLB 2M and 4M sizes, fall b    
247         if (!((eax >> 16) & mask))                
248                 tlb_lld_2m[ENTRIES] = (cpuid_e    
249         else                                      
250                 tlb_lld_2m[ENTRIES] = (eax >>     
251                                                   
252         /* a 4M entry uses two 2M entries */      
253         tlb_lld_4m[ENTRIES] = tlb_lld_2m[ENTRI    
254                                                   
255         /* Handle ITLB 2M and 4M sizes, fall b    
256         if (!(eax & mask)) {                      
257                 cpuid(0x80000005, &eax, &ebx,     
258                 tlb_lli_2m[ENTRIES] = eax & 0x    
259         } else                                    
260                 tlb_lli_2m[ENTRIES] = eax & ma    
261                                                   
262         tlb_lli_4m[ENTRIES] = tlb_lli_2m[ENTRI    
263 }                                                 
264                                                   
265 static const struct cpu_dev hygon_cpu_dev = {     
266         .c_vendor       = "Hygon",                
267         .c_ident        = { "HygonGenuine" },     
268         .c_early_init   = early_init_hygon,       
269         .c_detect_tlb   = cpu_detect_tlb_hygon    
270         .c_bsp_init     = bsp_init_hygon,         
271         .c_init         = init_hygon,             
272         .c_x86_vendor   = X86_VENDOR_HYGON,       
273 };                                                
274                                                   
275 cpu_dev_register(hygon_cpu_dev);                  
276                                                   

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php