libicuid  1.4.1
icuid.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 - 2016, Kurt Cancemi ([email protected])
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef __LIBICUID_H__
18 #define __LIBICUID_H__
19 
20 #include <icuid/icuid_err.h>
21 #include <icuid/icuid_limits.h>
22 #include <icuid/icuid_types.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
50 void cpuid(uint32_t eax, uint32_t *regs);
51 
59 void cpuid_ext(uint32_t *regs);
60 
66 int cpuid_is_supported(void);
67 
75 uint64_t icuid_xgetbv(const uint32_t xcr);
76 
97 typedef enum {
98  /* cpuid 0x00000001, ecx */
115  /* 16 Reserved */
132  /* cpuid 0x00000001, edx */
143  /* 10 Reserved */
165  /* cpuid 0x00000007, ebx */
172  /* 6 Reserved */
179  /* 13 Reserved */
181  /* 15 Reserved */
187  /* 21 Reserved */
198  /* cpuid 0x80000001, ecx */
213  /* 14 Reserved */
217  /* 18 Reserved */
219  /* 20 Reserved */
224  /* 25 Reserved */
226  /* 27 Reserved */
230  /* cpuid 0x80000001, edx */
231  /* 0-10 Reserved */
233  /* 12-19 Reserved */
235  /* 21 Reserved */
237  /* 23-24 Reserved */
241  /* 28 Reserved */
246  /* cpuid 0x80000007, edx */
260  /* 13-31 Reserved */
261 
262  /* cpuid 0x80000008, ebx */
265  /* 2-31 Reserved */
266 
267  /* cpuid 0x8000001F, eax */
269  /* 1-31 Reserved */
270 
273 
279 typedef enum {
297 } cpu_vendor_t;
298 
303 typedef enum {
315 } xfeature_t;
316 
317 typedef struct {
322  uint32_t cpuid[MAX_CPUID_LEVEL][4];
323 
329 
334  uint32_t intel_dc[MAX_INTEL_DC_LEVEL][4];
335 
340  uint32_t intel_et[MAX_INTEL_ET_LEVEL][4];
342 
343 typedef struct {
345  char vendor_str[VENDOR_STR_MAX];
347  char brand_str[BRAND_STR_MAX];
348 
350  cpu_vendor_t vendor;
351 
353  uint8_t family;
355  uint8_t model;
357  uint8_t stepping;
359  uint8_t ext_family;
361  uint8_t ext_model;
363  uint8_t type;
365  uint32_t signature;
367  const char *codename;
368 
370  uint32_t cpuid_max_basic;
372  uint32_t cpuid_max_ext;
374  uint8_t flags[CPU_FLAGS_MAX];
375 
377  uint32_t cores;
378 
384  uint32_t logical_cpus;
385 
390  uint32_t l1_data_cache;
391 
397 
402  uint32_t l2_cache;
403 
408  uint32_t l3_cache;
409 
412 
415 
418 
420  uint32_t l1_cacheline;
421 
423  uint32_t l2_cacheline;
424 
426  uint32_t l3_cacheline;
427 
430 
433 
435  uint8_t xfeatures[XFEATURE_FLAGS_MAX];
436 } cpuid_data_t;
437 
443 const char *cpu_feature_str(cpuid_feature_t feature);
444 
453 
466 int cpuid_serialize_raw_data(cpuid_raw_data_t *raw, const char *file);
467 
480 int cpuid_deserialize_raw_data(cpuid_raw_data_t *raw, const char *file);
481 
495 
496 #ifdef __cplusplus
497 }
498 #endif
499 
500 #endif /* __LIBICUID_H__ */
#define VENDOR_STR_MAX
Definition: icuid_limits.h:21
Definition: icuid.h:133
Definition: icuid.h:202
uint32_t l1_instruction_cache
Definition: icuid.h:396
Definition: icuid.h:249
Definition: icuid.h:137
Definition: icuid.h:313
Definition: icuid.h:209
Definition: icuid.h:292
Definition: icuid.h:140
Definition: icuid.h:282
uint32_t l1_data_cache
Definition: icuid.h:390
Definition: icuid.h:156
Definition: icuid.h:146
Definition: icuid.h:134
Definition: icuid.h:102
Definition: icuid.h:205
Definition: icuid.h:280
Definition: icuid.h:225
uint32_t l3_associativity
Definition: icuid.h:417
Definition: icuid.h:130
Definition: icuid.h:203
Definition: icuid.h:238
Definition: icuid.h:257
Definition: icuid.h:99
uint8_t type
Definition: icuid.h:363
Definition: icuid.h:255
Definition: icuid.h:343
Definition: icuid.h:199
Definition: icuid.h:239
Definition: icuid.h:168
Definition: icuid.h:161
Definition: icuid.h:107
Definition: icuid.h:195
xfeature_t
XSAVE Features, used to determine if a particular feature is supported and enabled by the OS...
Definition: icuid.h:303
Definition: icuid.h:122
Definition: icuid.h:128
#define BRAND_STR_MAX
Definition: icuid_limits.h:22
Definition: icuid.h:293
#define XFEATURE_FLAGS_MAX
Definition: icuid_limits.h:24
Definition: icuid.h:236
Definition: icuid.h:188
Definition: icuid.h:157
Definition: icuid.h:254
uint32_t cpuid_max_ext
Definition: icuid.h:372
Definition: icuid.h:200
Definition: icuid.h:138
Definition: icuid.h:250
Definition: icuid.h:314
Definition: icuid.h:178
Definition: icuid.h:264
Definition: icuid.h:191
Definition: icuid.h:155
Definition: icuid.h:228
Definition: icuid.h:251
Definition: icuid.h:110
Definition: icuid.h:212
cpu_vendor_t vendor
Definition: icuid.h:350
uint64_t icuid_xgetbv(const uint32_t xcr)
Run the xgetbv instruction.
Definition: icuid.h:308
uint32_t l2_cacheline
Definition: icuid.h:423
Definition: icuid.h:114
uint8_t ext_family
Definition: icuid.h:359
Definition: icuid.h:145
Definition: icuid.h:117
Definition: icuid.h:150
uint32_t virtual_address_bits
Definition: icuid.h:432
Definition: icuid.h:126
Definition: icuid.h:139
Definition: icuid.h:287
uint8_t ext_model
Definition: icuid.h:361
Definition: icuid.h:193
Definition: icuid.h:304
void cpuid(uint32_t eax, uint32_t *regs)
Run the cpuid instruction.
Definition: icuid.h:152
Definition: icuid.h:180
Definition: icuid.h:109
Definition: icuid.h:290
Definition: icuid.h:174
Definition: icuid.h:305
Definition: icuid.h:207
#define MAX_INTEL_ET_LEVEL
Definition: icuid_limits.h:28
#define MAX_CPUID_LEVEL
Definition: icuid_limits.h:25
Definition: icuid.h:271
Definition: icuid.h:192
Definition: icuid.h:216
Definition: icuid.h:118
Definition: icuid.h:291
Definition: icuid.h:108
Definition: icuid.h:184
Definition: icuid.h:244
Definition: icuid.h:189
Definition: icuid.h:310
Definition: icuid.h:101
Definition: icuid.h:170
Definition: icuid.h:123
uint32_t l3_cacheline
Definition: icuid.h:426
Definition: icuid.h:148
Definition: icuid.h:167
Definition: icuid.h:113
Definition: icuid.h:234
Definition: icuid.h:177
int cpuid_serialize_raw_data(cpuid_raw_data_t *raw, const char *file)
Writes the raw CPUID info to a file or stdout.
Definition: icuid.c:123
Definition: icuid.h:227
Definition: icuid.h:284
Definition: icuid.h:253
Definition: icuid.h:159
cpu_vendor_t
CPU vendor, as we determined from the Vendor String.
Definition: icuid.h:279
Definition: icuid.h:144
Definition: icuid.h:259
Definition: icuid.h:160
int icuid_identify(cpuid_raw_data_t *raw, cpuid_data_t *data)
Identifies the CPU.
Definition: icuid.c:243
Definition: icuid.h:176
uint32_t l3_cache
Definition: icuid.h:408
Definition: icuid.h:135
#define MAX_EXT_CPUID_LEVEL
Definition: icuid_limits.h:26
Definition: icuid.h:120
Definition: icuid.h:194
uint8_t model
Definition: icuid.h:355
uint32_t cpuid_max_basic
Definition: icuid.h:370
Definition: icuid.h:306
uint8_t family
Definition: icuid.h:353
Definition: icuid.h:119
Definition: icuid.h:171
Definition: icuid.h:116
Definition: icuid.h:153
Definition: icuid.h:147
Definition: icuid.h:317
uint32_t l2_cache
Definition: icuid.h:402
Definition: icuid.h:218
Definition: icuid.h:268
Definition: icuid.h:100
Definition: icuid.h:283
Definition: icuid.h:211
Definition: icuid.h:206
Definition: icuid.h:105
Definition: icuid.h:162
Definition: icuid.h:149
Definition: icuid.h:121
Definition: icuid.h:215
uint32_t l1_associativity
Definition: icuid.h:411
Definition: icuid.h:223
Definition: icuid.h:208
Definition: icuid.h:103
Definition: icuid.h:142
Definition: icuid.h:242
Definition: icuid.h:127
uint32_t logical_cpus
Definition: icuid.h:384
const char * codename
Definition: icuid.h:367
Definition: icuid.h:129
uint32_t signature
Definition: icuid.h:365
Definition: icuid.h:169
Definition: icuid.h:258
Definition: icuid.h:196
Definition: icuid.h:281
Definition: icuid.h:295
void cpuid_ext(uint32_t *regs)
Run the cpuid instruction with custom register values.
Definition: icuid.h:175
Definition: icuid.h:294
Definition: icuid.h:256
Definition: icuid.h:112
Definition: icuid.h:106
Definition: icuid.h:252
Definition: icuid.h:183
Definition: icuid.h:220
Definition: icuid.h:185
int cpuid_get_raw_data(cpuid_raw_data_t *raw)
Obtains the raw CPUID info from the CPU.
Definition: icuid.c:31
uint32_t physical_address_bits
Definition: icuid.h:429
Definition: icuid.h:151
Definition: icuid.h:186
cpuid_feature_t
CPU feature bits.
Definition: icuid.h:97
Definition: icuid.h:154
Definition: icuid.h:286
Definition: icuid.h:158
Definition: icuid.h:204
Definition: icuid.h:247
Definition: icuid.h:248
#define CPU_FLAGS_MAX
Definition: icuid_limits.h:23
Definition: icuid.h:166
int cpuid_is_supported(void)
Check if the cpuid instruction is supported.
Definition: icuid.h:201
uint32_t l1_cacheline
Definition: icuid.h:420
const char * cpu_feature_str(cpuid_feature_t feature)
Returns the short form of the CPU feature flag.
Definition: features.c:36
Definition: icuid.h:214
Definition: icuid.h:141
uint8_t stepping
Definition: icuid.h:357
Definition: icuid.h:232
Definition: icuid.h:104
Definition: icuid.h:243
Definition: icuid.h:312
uint32_t cores
Definition: icuid.h:377
#define MAX_INTEL_DC_LEVEL
Definition: icuid_limits.h:27
Definition: icuid.h:311
Definition: icuid.h:210
Definition: icuid.h:136
Definition: icuid.h:163
Definition: icuid.h:263
uint32_t l2_associativity
Definition: icuid.h:414
Definition: icuid.h:182
Definition: icuid.h:240
Definition: icuid.h:289
Definition: icuid.h:307
Definition: icuid.h:285
Definition: icuid.h:173
Definition: icuid.h:111
Definition: icuid.h:288
Definition: icuid.h:190
Definition: icuid.h:309
Definition: icuid.h:221
Definition: icuid.h:296
int cpuid_deserialize_raw_data(cpuid_raw_data_t *raw, const char *file)
Reads the raw CPUID info to a file or stdin.
Definition: icuid.c:165
Definition: icuid.h:222
Definition: icuid.h:125
Definition: icuid.h:124