1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef ARCH_X86_TOPOLOGY_H 3 #define ARCH_X86_TOPOLOGY_H 4 5 struct topo_scan { 6 struct cpuinfo_x86 *c; 7 unsigned int dom_shifts[TOPO_MAX_DOMAIN]; 8 unsigned int dom_ncpus[TOPO_MAX_DOMAIN]; 9 10 /* Legacy CPUID[1]:EBX[23:16] number of logical processors */ 11 unsigned int ebx1_nproc_shift; 12 }; 13 14 bool topo_is_converted(struct cpuinfo_x86 *c); 15 void cpu_init_topology(struct cpuinfo_x86 *c); 16 void cpu_parse_topology(struct cpuinfo_x86 *c); 17 void topology_set_dom(struct topo_scan *tscan, enum x86_topology_domains dom, 18 unsigned int shift, unsigned int ncpus); 19 bool cpu_parse_topology_ext(struct topo_scan *tscan); 20 21 static inline u32 topo_shift_apicid(u32 apicid, enum x86_topology_domains dom) 22 { 23 if (dom == TOPO_SMT_DOMAIN) 24 return apicid; 25 return apicid >> x86_topo_system.dom_shifts[dom - 1]; 26 } 27 28 static inline u32 topo_relative_domain_id(u32 apicid, enum x86_topology_domains dom) 29 { 30 if (dom != TOPO_SMT_DOMAIN) 31 apicid >>= x86_topo_system.dom_shifts[dom - 1]; 32 return apicid & (x86_topo_system.dom_size[dom] - 1); 33 } 34 35 static inline u32 topo_domain_mask(enum x86_topology_domains dom) 36 { 37 return (1U << x86_topo_system.dom_shifts[dom]) - 1; 38 } 39 40 /* 41 * Update a domain level after the fact without propagating. Used to fixup 42 * broken CPUID enumerations. 43 */ 44 static inline void topology_update_dom(struct topo_scan *tscan, enum x86_topology_domains dom, 45 unsigned int shift, unsigned int ncpus) 46 { 47 tscan->dom_shifts[dom] = shift; 48 tscan->dom_ncpus[dom] = ncpus; 49 } 50 51 #endif /* ARCH_X86_TOPOLOGY_H */ 52