libcpuid_util.h 3.1 KB

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