• 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 CPUINFO_INTERNAL struct cpuinfo_x86_isa cpuinfo_x86_nacl_detect_isa(void);
97 
98 CPUINFO_INTERNAL void cpuinfo_x86_detect_topology(
99 	uint32_t max_base_index,
100 	uint32_t max_extended_index,
101 	struct cpuid_regs leaf1,
102 	struct cpuinfo_x86_topology* topology);
103 
104 CPUINFO_INTERNAL void cpuinfo_x86_detect_cache(
105 	uint32_t max_base_index, uint32_t max_extended_index,
106 	bool amd_topology_extensions,
107 	enum cpuinfo_vendor vendor,
108 	const struct cpuinfo_x86_model_info* model_info,
109 	struct cpuinfo_x86_caches* cache,
110 	struct cpuinfo_tlb* itlb_4KB,
111 	struct cpuinfo_tlb* itlb_2MB,
112 	struct cpuinfo_tlb* itlb_4MB,
113 	struct cpuinfo_tlb* dtlb0_4KB,
114 	struct cpuinfo_tlb* dtlb0_2MB,
115 	struct cpuinfo_tlb* dtlb0_4MB,
116 	struct cpuinfo_tlb* dtlb_4KB,
117 	struct cpuinfo_tlb* dtlb_2MB,
118 	struct cpuinfo_tlb* dtlb_4MB,
119 	struct cpuinfo_tlb* dtlb_1GB,
120 	struct cpuinfo_tlb* stlb2_4KB,
121 	struct cpuinfo_tlb* stlb2_2MB,
122 	struct cpuinfo_tlb* stlb2_1GB,
123 	uint32_t* log2_package_cores_max);
124 
125 CPUINFO_INTERNAL void cpuinfo_x86_decode_cache_descriptor(
126 	uint8_t descriptor, enum cpuinfo_vendor vendor,
127 	const struct cpuinfo_x86_model_info* model_info,
128 	struct cpuinfo_x86_caches* cache,
129 	struct cpuinfo_tlb* itlb_4KB,
130 	struct cpuinfo_tlb* itlb_2MB,
131 	struct cpuinfo_tlb* itlb_4MB,
132 	struct cpuinfo_tlb* dtlb0_4KB,
133 	struct cpuinfo_tlb* dtlb0_2MB,
134 	struct cpuinfo_tlb* dtlb0_4MB,
135 	struct cpuinfo_tlb* dtlb_4KB,
136 	struct cpuinfo_tlb* dtlb_2MB,
137 	struct cpuinfo_tlb* dtlb_4MB,
138 	struct cpuinfo_tlb* dtlb_1GB,
139 	struct cpuinfo_tlb* stlb2_4KB,
140 	struct cpuinfo_tlb* stlb2_2MB,
141 	struct cpuinfo_tlb* stlb2_1GB,
142 	uint32_t* prefetch_size);
143 
144 CPUINFO_INTERNAL bool cpuinfo_x86_decode_deterministic_cache_parameters(
145 	struct cpuid_regs regs,
146 	struct cpuinfo_x86_caches* cache,
147 	uint32_t* package_cores_max);
148 
149 CPUINFO_INTERNAL bool cpuinfo_x86_decode_cache_properties(
150 	struct cpuid_regs regs,
151 	struct cpuinfo_x86_caches* cache);
152 
153 CPUINFO_INTERNAL uint32_t cpuinfo_x86_normalize_brand_string(
154 	const char raw_name[48],
155 	char normalized_name[48]);
156 
157 CPUINFO_INTERNAL uint32_t cpuinfo_x86_format_package_name(
158 	enum cpuinfo_vendor vendor,
159 	const char normalized_brand_string[48],
160 	char package_name[CPUINFO_PACKAGE_NAME_MAX]);
161