1 /* 2 * Copyright 2008 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_UTIL_H__ 27 #define __LIBCPUID_UTIL_H__ 28 29 #define COUNT_OF(array) (sizeof(array) / sizeof(array[0])) 30 31 struct feature_map_t { 32 unsigned bit; 33 cpu_feature_t feature; 34 }; 35 36 void match_features(const struct feature_map_t* matchtable, int count, 37 uint32_t reg, struct cpu_id_t* data); 38 39 struct match_entry_t { 40 int family, model, stepping, ext_family, ext_model; 41 int ncores, l2cache, l3cache, brand_code; 42 uint64_t model_bits; 43 int model_code; 44 char name[32]; 45 }; 46 47 // returns the match score: 48 int match_cpu_codename(const struct match_entry_t* matchtable, int count, 49 struct cpu_id_t* data, int brand_code, uint64_t bits, 50 int model_code); 51 52 void warnf(const char* format, ...) 53 #ifdef __GNUC__ 54 __attribute__((format(printf, 1, 2))) 55 #endif 56 ; 57 void debugf(int verboselevel, const char* format, ...) 58 #ifdef __GNUC__ 59 __attribute__((format(printf, 2, 3))) 60 #endif 61 ; 62 void generic_get_cpu_list(const struct match_entry_t* matchtable, int count, 63 struct cpu_list_t* list); 64 65 /* 66 * Seek for a pattern in `haystack'. 67 * Pattern may be an fixed string, or contain the special metacharacters 68 * '.' - match any single character 69 * '#' - match any digit 70 * '[<chars>] - match any of the given chars (regex-like ranges are not 71 * supported) 72 * Return val: 0 if the pattern is not found. Nonzero if it is found (actually, 73 * x + 1 where x is the index where the match is found). 74 */ 75 int match_pattern(const char* haystack, const char* pattern); 76 77 /* 78 * Gets an initialized cpu_id_t. It is cached, so that internal libcpuid 79 * machinery doesn't need to issue cpu_identify more than once. 80 */ 81 struct cpu_id_t* get_cached_cpuid(void); 82 83 84 /* returns true if all bits of mask are present in `bits'. */ 85 int match_all(uint64_t bits, uint64_t mask); 86 87 /* print what bits a mask consists of */ 88 void debug_print_lbits(int debuglevel, uint64_t mask); 89 90 /* 91 * Sets the current errno 92 */ 93 int set_error(cpu_error_t err); 94 95 extern libcpuid_warn_fn_t _warn_fun; 96 extern int _current_verboselevel; 97 98 #endif /* __LIBCPUID_UTIL_H__ */ 99