topology.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef ARCH_X86_TOPOLOGY_H
  3. #define ARCH_X86_TOPOLOGY_H
  4. struct topo_scan {
  5. struct cpuinfo_x86 *c;
  6. unsigned int dom_shifts[TOPO_MAX_DOMAIN];
  7. unsigned int dom_ncpus[TOPO_MAX_DOMAIN];
  8. /* Legacy CPUID[1]:EBX[23:16] number of logical processors */
  9. unsigned int ebx1_nproc_shift;
  10. /* AMD specific node ID which cannot be mapped into APIC space. */
  11. u16 amd_nodes_per_pkg;
  12. u16 amd_node_id;
  13. };
  14. void cpu_init_topology(struct cpuinfo_x86 *c);
  15. void cpu_parse_topology(struct cpuinfo_x86 *c);
  16. void topology_set_dom(struct topo_scan *tscan, enum x86_topology_domains dom,
  17. unsigned int shift, unsigned int ncpus);
  18. bool cpu_parse_topology_ext(struct topo_scan *tscan);
  19. void cpu_parse_topology_amd(struct topo_scan *tscan);
  20. void cpu_topology_fixup_amd(struct topo_scan *tscan);
  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. static inline u32 topo_relative_domain_id(u32 apicid, enum x86_topology_domains dom)
  28. {
  29. if (dom != TOPO_SMT_DOMAIN)
  30. apicid >>= x86_topo_system.dom_shifts[dom - 1];
  31. return apicid & (x86_topo_system.dom_size[dom] - 1);
  32. }
  33. static inline u32 topo_domain_mask(enum x86_topology_domains dom)
  34. {
  35. return (1U << x86_topo_system.dom_shifts[dom]) - 1;
  36. }
  37. /*
  38. * Update a domain level after the fact without propagating. Used to fixup
  39. * broken CPUID enumerations.
  40. */
  41. static inline void topology_update_dom(struct topo_scan *tscan, enum x86_topology_domains dom,
  42. unsigned int shift, unsigned int ncpus)
  43. {
  44. tscan->dom_shifts[dom] = shift;
  45. tscan->dom_ncpus[dom] = ncpus;
  46. }
  47. #ifdef CONFIG_X86_LOCAL_APIC
  48. unsigned int topology_unit_count(u32 apicid, enum x86_topology_domains which_units,
  49. enum x86_topology_domains at_level);
  50. #else
  51. static inline unsigned int topology_unit_count(u32 apicid, enum x86_topology_domains which_units,
  52. enum x86_topology_domains at_level)
  53. {
  54. return 1;
  55. }
  56. #endif
  57. #endif /* ARCH_X86_TOPOLOGY_H */