libcpuid  0.2.2
libcpuid_util.h
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, model_code;
42  char name[32];
43 };
44 
45 void match_cpu_codename(const struct match_entry_t* matchtable, int count,
46  struct cpu_id_t* data, int brand_code, int model_code);
47 
48 void warnf(const char* format, ...)
49 #ifdef __GNUC__
50 __attribute__((format(printf, 1, 2)))
51 #endif
52 ;
53 void debugf(int verboselevel, const char* format, ...)
54 #ifdef __GNUC__
55 __attribute__((format(printf, 2, 3)))
56 #endif
57 ;
58 void generic_get_cpu_list(const struct match_entry_t* matchtable, int count,
59  struct cpu_list_t* list);
60 
61 /*
62  * Seek for a pattern in `haystack'.
63  * Pattern may be an fixed string, or contain the special metacharacters
64  * '.' - match any single character
65  * '#' - match any digit
66  * '[<chars>] - match any of the given chars (regex-like ranges are not
67  * supported)
68  * Return val: 0 if the pattern is not found. Nonzero if it is found (actually,
69  * x + 1 where x is the index where the match is found).
70  */
71 int match_pattern(const char* haystack, const char* pattern);
72 
73 /*
74  * Gets an initialized cpu_id_t. It is cached, so that internal libcpuid
75  * machinery doesn't need to issue cpu_identify more than once.
76  */
77 struct cpu_id_t* get_cached_cpuid(void);
78 
79 /*
80  * Sets the current errno
81  */
82 int set_error(cpu_error_t err);
83 
84 extern libcpuid_warn_fn_t _warn_fun;
85 extern int _current_verboselevel;
86 
87 #endif /* __LIBCPUID_UTIL_H__ */
cpu_error_t
Describes common library error codes.
Definition: libcpuid.h:405
a structure that holds a list of processor names
Definition: libcpuid.h:796
This contains the recognized CPU features/info.
Definition: libcpuid.h:139
Definition: libcpuid_util.h:39
Definition: libcpuid_util.h:31
cpu_feature_t
CPU feature identifiers.
Definition: libcpuid.h:279