2 * Copyright (c) 2013 Ahmed Samy <f.fallen45@gmail.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 * enum cpuid - stuff to get information on from the CPU.
28 * This is used as a parameter in cpuid().
31 * The CPU's Vendor ID.
33 * CPU_PROCINFO_AND_FEATUREBITS:
34 * Processor information and feature bits (SSE, etc.).
36 * CPU_CACHE_AND_TLBD_INFO
37 * Cache and TLBD Information.
39 * CPU_HIGHEST_EXTENDED_FUNCTION_SUPPORTED:
40 * Highest extended function supported address.
41 * Can be like 0x80000008.
43 * CPU_EXTENDED_PROC_INFO_FEATURE_BITS:
44 * Extended processor information and feature bits (64bit etc.)
46 * CPU_PROC_BRAND_STRING:
47 * The Processor's brand string.
49 * CPU_L1_CACHE_AND_TLB_IDS:
50 * L1 Cache and TLB Identifications.
52 * CPU_EXTENDED_L2_CACHE_FEATURES:
53 * Extended L2 Cache features.
55 * CPU_ADV_POWER_MGT_INFO:
56 * Advaned power management information.
58 * CPU_VIRT_PHYS_ADDR_SIZES:
59 * Virtual and physical address sizes.
64 CPU_PROCINFO_AND_FEATUREBITS = 1,
65 CPU_CACHE_AND_TLBD_INFO = 2,
67 CPU_HIGHEST_EXTENDED_FUNCTION_SUPPORTED = 0x80000000,
68 CPU_EXTENDED_PROC_INFO_FEATURE_BITS = 0x80000001,
69 CPU_PROC_BRAND_STRING = 0x80000002,
70 CPU_L1_CACHE_AND_TLB_IDS = 0x80000005,
71 CPU_EXTENDED_L2_CACHE_FEATURES = 0x80000006,
72 CPU_ADV_POWER_MGT_INFO = 0x80000007,
73 CPU_VIRT_PHYS_ADDR_SIZES = 0x80000008
79 * This is used by cpuid_has_feature().
82 * Test for MMX support.
85 * Test for SSE* support.
88 * Test for AVX support.
91 * Test for FMA support.
94 typedef enum cpufeature {
109 * enum cpuextfeature - Test for an extended feature provided by the CPU
111 * This is used by cpuid_has_ext_feature()
119 * Test for SSE4a/FMA4/XOP
121 typedef enum cpuextfeature {
129 * cpuid_is_supported - test if the CPUID instruction is supported
131 * CPUID is not supported by old CPUS.
133 * Returns 1 if the cpuid instruction is supported, 0 otherwise.
137 int cpuid_is_supported(void);
140 * highest_ext_func_supported - Get the highest extended function supported
143 * Returns the highest extended function supported.
145 * This is the same as calling:
146 * cpuid(CPU_HIGHEST_EEXTENDED_FUNCTION_SUPPORTED, &highest);
148 * This is made visible to the linker because it's easier to call it
149 * instead of calling cpuid with less type-checking. cpuid calls this.
153 int highest_ext_func_supported(void);
156 * cpuid - Get Some information from the CPU.
158 * This function expects buf to be a valid pointer to a string/int/...
159 * depending on the requested information.
162 * Returns a string into buf.
164 * For CPU_PROCINFO_AND_FEATUREBITS:
169 * - 13:12 - Processor Type
170 * - 19:16 - Extended Model
171 * - 27:20 - Extended family
175 * Additional feature information.
177 * For CPU_HIGHEST_EXTENDED_FUNCTION_SUPPORTED:
178 * Returns the highest supported function in *buf (expects an integer ofc)
180 * For CPU_EXTENDED_PROC_INFO_FEATURE_BITS:
181 * Returns them in buf[0] and buf[1].
183 * For CPU_VIRT_PHYS_ADDR_SIZES:
184 * Returns it as an integer in *buf.
186 * For CPU_PROC_BRAND_STRING:
187 * Have a char array with at least 48 bytes assigned to it.
189 * If an invalid flag has been passed a 0xbaadf00d is returned in *buf.
191 void cpuid(cpuid_t info, void *buf);
194 * cpuid_test_feature - Test if @feature is available
196 * Returns 1 if feature is supported, 0 otherwise.
198 * The feature parameter must be >= CPU_EXTENDED_PROC_INFO_FEATURE_BITS
199 * and <= CPU_VIRT_PHYS_ADDR_SIZES.
201 int cpuid_test_feature(cpuid_t feature);
204 * cpuid_has_feature - Test if @feature is supported
206 * Test if the CPU supports MMX/SSE* etc
208 * Returns 1 if the feature is available, 0 otherwise.
210 #define cpuid_has_mmx() cpuid_has_feature(CF_MMX)
211 #define cpuid_has_sse() cpuid_has_feature(CF_SSE)
212 #define cpuid_has_sse2() cpuid_has_feature(CF_SSE2)
213 #define cpuid_has_sse3() cpuid_has_feature(CF_SSE3)
214 #define cpuid_has_ssse3() cpuid_has_feature(CF_SSSE3)
215 #define cpuid_has_sse41() cpuid_has_feature(CF_SSE41)
216 #define cpuid_has_sse42() cpuid_has_feature(CF_SSE42)
217 #define cpuid_has_avx() cpuid_has_feature(CF_AVX)
218 #define cpuid_has_fma() cpuid_has_feature(CF_FMA)
219 int cpuid_has_feature(cpufeature_t feature);
222 * cpuid_has_ext_feature - Test if @extfeature is an extended feature
223 * that's supported by the CPU.
225 * Test if the CPU supports this extended feature.
227 * Returns 1 if available, 0 otherwise.
229 #define cpuid_has_x64() cpuid_has_ext_feature(CEF_x64)
230 #define cpuid_has_sse4a() cpuid_has_ext_feature(CEF_SSE4a)
231 #define cpuid_has_fma4() cpuid_has_ext_feature(CEF_FMA4)
232 #define cpuid_has_xop() cpuid_has_ext_feature(CEF_XOP)
233 int cpuid_has_ext_feature(cpuextfeature_t extfeature);