libcpuid_util.h 3.1 KB

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