• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #pragma once
2 
3 #include <stdbool.h>
4 #include <stdint.h>
5 
6 #include <cpuinfo.h>
7 #include <cpuinfo/common.h>
8 
9 
10 struct cpuid_regs {
11 	uint32_t eax;
12 	uint32_t ebx;
13 	uint32_t ecx;
14 	uint32_t edx;
15 };
16 
17 struct cpuinfo_x86_cache {
18 	uint32_t size;
19 	uint32_t associativity;
20 	uint32_t sets;
21 	uint32_t partitions;
22 	uint32_t line_size;
23 	uint32_t flags;
24 	uint32_t apic_bits;
25 };
26 
27 struct cpuinfo_x86_caches {
28 	struct cpuinfo_trace_cache trace;
29 	struct cpuinfo_x86_cache l1i;
30 	struct cpuinfo_x86_cache l1d;
31 	struct cpuinfo_x86_cache l2;
32 	struct cpuinfo_x86_cache l3;
33 	struct cpuinfo_x86_cache l4;
34 	uint32_t prefetch_size;
35 };
36 
37 struct cpuinfo_x86_model_info {
38 	uint32_t model;
39 	uint32_t family;
40 
41 	uint32_t base_model;
42 	uint32_t base_family;
43 	uint32_t stepping;
44 	uint32_t extended_model;
45 	uint32_t extended_family;
46 	uint32_t processor_type;
47 };
48 
49 struct cpuinfo_x86_topology {
50 	uint32_t apic_id;
51 	uint32_t thread_bits_offset;
52 	uint32_t thread_bits_length;
53 	uint32_t core_bits_offset;
54 	uint32_t core_bits_length;
55 };
56 
57 struct cpuinfo_x86_processor {
58 	uint32_t cpuid;
59 	enum cpuinfo_vendor vendor;
60 	enum cpuinfo_uarch uarch;
61 #ifdef __linux__
62 	int linux_id;
63 #endif
64 	struct cpuinfo_x86_caches cache;
65 	struct {
66 		struct cpuinfo_tlb itlb_4KB;
67 		struct cpuinfo_tlb itlb_2MB;
68 		struct cpuinfo_tlb itlb_4MB;
69 		struct cpuinfo_tlb dtlb0_4KB;
70 		struct cpuinfo_tlb dtlb0_2MB;
71 		struct cpuinfo_tlb dtlb0_4MB;
72 		struct cpuinfo_tlb dtlb_4KB;
73 		struct cpuinfo_tlb dtlb_2MB;
74 		struct cpuinfo_tlb dtlb_4MB;
75 		struct cpuinfo_tlb dtlb_1GB;
76 		struct cpuinfo_tlb stlb2_4KB;
77 		struct cpuinfo_tlb stlb2_2MB;
78 		struct cpuinfo_tlb stlb2_1GB;
79 	} tlb;
80 	struct cpuinfo_x86_topology topology;
81 	char brand_string[CPUINFO_PACKAGE_NAME_MAX];
82 };
83 
84 CPUINFO_INTERNAL void cpuinfo_x86_init_processor(struct cpuinfo_x86_processor* processor);
85 
86 CPUINFO_INTERNAL enum cpuinfo_vendor cpuinfo_x86_decode_vendor(uint32_t ebx, uint32_t ecx, uint32_t edx);
87 CPUINFO_INTERNAL struct cpuinfo_x86_model_info cpuinfo_x86_decode_model_info(uint32_t eax);
88 CPUINFO_INTERNAL enum cpuinfo_uarch cpuinfo_x86_decode_uarch(
89 	enum cpuinfo_vendor vendor,
90 	const struct cpuinfo_x86_model_info* model_info);
91 
92 CPUINFO_INTERNAL struct cpuinfo_x86_isa cpuinfo_x86_detect_isa(
93 	const struct cpuid_regs basic_info, const struct cpuid_regs extended_info,
94 	uint32_t max_base_index, uint32_t max_extended_index,
95 	enum cpuinfo_vendor vendor, enum cpuinfo_uarch uarch);
96 
97 CPUINFO_INTERNAL void cpuinfo_x86_detect_topology(
98 	uint32_t max_base_index,
99 	uint32_t max_extended_index,
100 	struct cpuid_regs leaf1,
101 	struct cpuinfo_x86_topology* topology);
102 
103 CPUINFO_INTERNAL void cpuinfo_x86_detect_cache(
104 	uint32_t max_base_index, uint32_t max_extended_index,
105 	bool amd_topology_extensions,
106 	enum cpuinfo_vendor vendor,
107 	const struct cpuinfo_x86_model_info* model_info,
108 	struct cpuinfo_x86_caches* cache,
109 	struct cpuinfo_tlb* itlb_4KB,
110 	struct cpuinfo_tlb* itlb_2MB,
111 	struct cpuinfo_tlb* itlb_4MB,
112 	struct cpuinfo_tlb* dtlb0_4KB,
113 	struct cpuinfo_tlb* dtlb0_2MB,
114 	struct cpuinfo_tlb* dtlb0_4MB,
115 	struct cpuinfo_tlb* dtlb_4KB,
116 	struct cpuinfo_tlb* dtlb_2MB,
117 	struct cpuinfo_tlb* dtlb_4MB,
118 	struct cpuinfo_tlb* dtlb_1GB,
119 	struct cpuinfo_tlb* stlb2_4KB,
120 	struct cpuinfo_tlb* stlb2_2MB,
121 	struct cpuinfo_tlb* stlb2_1GB,
122 	uint32_t* log2_package_cores_max);
123 
124 CPUINFO_INTERNAL void cpuinfo_x86_decode_cache_descriptor(
125 	uint8_t descriptor, enum cpuinfo_vendor vendor,
126 	const struct cpuinfo_x86_model_info* model_info,
127 	struct cpuinfo_x86_caches* cache,
128 	struct cpuinfo_tlb* itlb_4KB,
129 	struct cpuinfo_tlb* itlb_2MB,
130 	struct cpuinfo_tlb* itlb_4MB,
131 	struct cpuinfo_tlb* dtlb0_4KB,
132 	struct cpuinfo_tlb* dtlb0_2MB,
133 	struct cpuinfo_tlb* dtlb0_4MB,
134 	struct cpuinfo_tlb* dtlb_4KB,
135 	struct cpuinfo_tlb* dtlb_2MB,
136 	struct cpuinfo_tlb* dtlb_4MB,
137 	struct cpuinfo_tlb* dtlb_1GB,
138 	struct cpuinfo_tlb* stlb2_4KB,
139 	struct cpuinfo_tlb* stlb2_2MB,
140 	struct cpuinfo_tlb* stlb2_1GB,
141 	uint32_t* prefetch_size);
142 
143 CPUINFO_INTERNAL bool cpuinfo_x86_decode_deterministic_cache_parameters(
144 	struct cpuid_regs regs,
145 	struct cpuinfo_x86_caches* cache,
146 	uint32_t* package_cores_max);
147 
148 CPUINFO_INTERNAL bool cpuinfo_x86_decode_cache_properties(
149 	struct cpuid_regs regs,
150 	struct cpuinfo_x86_caches* cache);
151 
152 CPUINFO_INTERNAL uint32_t cpuinfo_x86_normalize_brand_string(
153 	const char raw_name[48],
154 	char normalized_name[48]);
155 
156 CPUINFO_INTERNAL uint32_t cpuinfo_x86_format_package_name(
157 	enum cpuinfo_vendor vendor,
158 	const char normalized_brand_string[48],
159 	char package_name[CPUINFO_PACKAGE_NAME_MAX]);
160