1 /* 2 * Copyright 2016 Veselin Georgiev, 3 * anrieffNOSPAM @ mgail_DOT.com (convert to gmail) 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 #ifndef __LIBCPUID_INTERNAL_H__ 27 #define __LIBCPUID_INTERNAL_H__ 28 /* 29 * This file contains internal undocumented declarations and function prototypes 30 * for the workings of the internal library infrastructure. 31 */ 32 33 #define EXTRACTS_BIT(reg, bit) ((reg >> bit) & 0x1) 34 #define EXTRACTS_BITS(reg, highbit, lowbit) ((reg >> lowbit) & ((1ULL << (highbit - lowbit + 1)) - 1)) 35 36 enum _common_codes_t { 37 NA = 0, 38 NC, /* No code */ 39 }; 40 41 #define CODE(x) x 42 #define CODE2(x, y) x = y 43 enum _amd_code_t { 44 #include "amd_code_t.h" 45 }; 46 typedef enum _amd_code_t amd_code_t; 47 48 enum _intel_code_t { 49 #include "intel_code_t.h" 50 }; 51 typedef enum _intel_code_t intel_code_t; 52 #undef CODE 53 #undef CODE2 54 55 struct internal_id_info_t { 56 union { 57 amd_code_t amd; 58 intel_code_t intel; 59 } code; 60 uint64_t bits; 61 int score; // detection (matchtable) score 62 }; 63 64 #define LBIT(x) (((long long) 1) << x) 65 66 enum _common_bits_t { 67 _M_ = LBIT( 0 ), 68 MOBILE_ = LBIT( 1 ), 69 _MP_ = LBIT( 2 ), 70 _3 = LBIT( 3 ), 71 _5 = LBIT( 4 ), 72 _7 = LBIT( 5 ), 73 _9 = LBIT( 6 ), 74 }; 75 76 // additional detection bits for Intel CPUs: 77 enum _intel_bits_t { 78 PENTIUM_ = LBIT( 10 ), 79 CELERON_ = LBIT( 11 ), 80 CORE_ = LBIT( 12 ), 81 _I_ = LBIT( 13 ), 82 XEON_ = LBIT( 14 ), 83 ATOM_ = LBIT( 15 ), 84 }; 85 typedef enum _intel_bits_t intel_bits_t; 86 87 enum _amd_bits_t { 88 ATHLON_ = LBIT( 10 ), 89 _XP_ = LBIT( 11 ), 90 DURON_ = LBIT( 12 ), 91 SEMPRON_ = LBIT( 13 ), 92 OPTERON_ = LBIT( 14 ), 93 TURION_ = LBIT( 15 ), 94 RYZEN_ = LBIT( 16 ), 95 RYZEN_TR_ = LBIT( 17 ), 96 EPYC_ = LBIT( 18 ), 97 _LV_ = LBIT( 19 ), 98 _64_ = LBIT( 20 ), 99 _X2 = LBIT( 21 ), 100 _X3 = LBIT( 22 ), 101 _X4 = LBIT( 23 ), 102 _X6 = LBIT( 24 ), 103 _FX = LBIT( 25 ), 104 _APU_ = LBIT( 26 ), 105 C86_ = LBIT( 27 ), 106 }; 107 typedef enum _amd_bits_t amd_bits_t; 108 109 110 111 int cpu_ident_internal(struct cpu_raw_data_t* raw, struct cpu_id_t* data, 112 struct internal_id_info_t* internal); 113 114 #endif /* __LIBCPUID_INTERNAL_H__ */ 115