]> git.ozlabs.org Git - ccan/blobdiff - ccan/cpuid/cpuid.h
cpuid: only compile source file if x86 cpu
[ccan] / ccan / cpuid / cpuid.h
index d119e4f51e9ea5dd3dee534b1420ed890baf0059..2861394608313dede06e863900189af6dd8dafef 100644 (file)
 #ifndef CCAN_CPUID_H
 #define CCAN_CPUID_H
 
+/**
+ * enum cpuid - stuff to get information on from the CPU.
+ *
+ * This is used as a parameter in cpuid().
+ *
+ * CPU_VENDORID:
+ *     The CPU's Vendor ID.
+ *
+ * CPU_PROCINFO_AND_FEATUREBITS:
+ *     Processor information and feature bits (SSE, etc.).
+ *
+ * CPU_CACHE_AND_TLBD_INFO
+ *     Cache and TLBD Information.
+ *
+ * CPU_HIGHEST_EXTENDED_FUNCTION_SUPPORTED:
+ *     Highest extended function supported address.
+ *     Can be like 0x80000008.
+ *
+ * CPU_EXTENDED_PROC_INFO_FEATURE_BITS:
+ *     Extended processor information and feature bits (64bit etc.)
+ *
+ * CPU_PROC_BRAND_STRING:
+ *     The Processor's brand string.
+ *
+ * CPU_L1_CACHE_AND_TLB_IDS:
+ *     L1 Cache and TLB Identifications.
+ *
+ * CPU_EXTENDED_L2_CACHE_FEATURES:
+ *     Extended L2 Cache features.
+ *
+ * CPU_ADV_POWER_MGT_INFO:
+ *     Advaned power management information.
+ *
+ * CPU_VIRT_PHYS_ADDR_SIZES:
+ *     Virtual and physical address sizes.
+ */
+
 typedef enum cpuid {
        CPU_VENDORID                                    = 0,
        CPU_PROCINFO_AND_FEATUREBITS                    = 1,
@@ -36,45 +73,90 @@ typedef enum cpuid {
        CPU_VIRT_PHYS_ADDR_SIZES                        = 0x80000008
 } cpuid_t;
 
-typedef enum cpufeature {
-       CF_MMX          = 1 << 23,
-       CF_SSE          = 1 << 25,
-       CF_SSE2         = 1 << 26,
-       CF_SSE3         = 1 << 0,
+#define CF_MMX                 0
+#define CF_SSE                 1
+#define CF_SSE2        2
+#define CF_SSE3        3
+#define CF_FPU                 4
+#define CF_TSC                 5
+#define CF_MSR                 6
+#define CF_SSSE3       7
+#define CF_AVX                 8
+#define CF_FMA                 9
+
+#define CEF_x64        10
+#define CEF_FPU        11
+#define CEF_DE                 12
+#define CEF_SYSCALLRET         13
+#define CEF_CMOV       14
+#define CEF_SSE4a      15
+#define CEF_FMA4       16
+#define CEF_XOP        17
 
-       CF_SSSE3        = 1 << 9,
-       CF_SSE41        = 1 << 19,
-       CF_SSE42        = 1 << 20,
+typedef enum cputype {
+       CT_NONE,
+       CT_AMDK5,
+       CT_AMD,
+       CT_CENTAUR,
+       CT_CYRIX,
+       CT_INTEL,
+       CT_TRANSMETA,
+       CT_NATIONAL_SEMICONDUCTOR,
+       CT_NEXGEN,
+       CT_RISE,
+       CT_SIS,
+       CT_UMC,
+       CT_VIA,
+       CT_VORTEX,
+       CT_KVM
+} cputype_t;
 
-       CF_AVX          = 1 << 28,
-       CF_FMA          = 1 << 12
-} cpufeature_t;
+/**
+ * cpuid_get_cpu_type - Get CPU Type
+ *
+ * Returns the CPU Type as cputype_t.
+ *
+ * See also: cpuid_get_cpu_type_string()
+ */
+cputype_t cpuid_get_cpu_type(void);
 
-typedef enum cpuextfeature {
-       CEF_x64         = 1 << 29,
-       CEF_SSE4a       = 1 << 6,
-       CEF_FMA4        = 1 << 16,
-       CEF_XOP         = 1 << 11
-} cpuextfeature_t;
+/**
+ * cpuid_get_cpu_type_string - Get CPU Type string
+ *
+ * Returns the CPU type string based off cputype_t.
+ */
+const char *cpuid_get_cpu_type_string(const cputype_t cputype);
 
-/* returns 1 if the cpuid instruction is supported, 0 otherwise.
+/**
+ * cpuid_is_supported - test if the CPUID instruction is supported
+ *
+ * CPUID is not supported by old CPUS.
  *
- * CPUID isn't supported on very old Intel CPUs.
- * Defined in issupprted.S
+ * Returns 1 if the cpuid instruction is supported, 0 otherwise.
+ *
+ * See also: cpuid()
  */
 int cpuid_is_supported(void);
 
-/* returns the highest extended function supported.
+/**
+ * cpuid_highest_ext_func_supported - Get the highest extended function supported
+ *
+ *
+ * Returns the highest extended function supported.
  *
  * This is the same as calling:
  *     cpuid(CPU_HIGHEST_EEXTENDED_FUNCTION_SUPPORTED, &highest);
  *
  * This is made visible to the linker because it's easier to call it
  * instead of calling cpuid with less type-checking.  cpuid calls this.
+ *
+ * See also: cpuid()
  */
-int highest_ext_func_supported(void);
+int cpuid_highest_ext_func_supported(void);
 
-/* Get Some information from the CPU.
+/**
+ * cpuid - Get Some information from the CPU.
+ *
  * This function expects buf to be a valid pointer to a string/int/...
  * depending on the requested information.
  *
@@ -110,7 +192,9 @@ int highest_ext_func_supported(void);
  */
 void cpuid(cpuid_t info, void *buf);
 
-/*
+/**
+ * cpuid_test_feature - Test if @feature is available
+ *
  * Returns 1 if feature is supported, 0 otherwise.
  *
  * The feature parameter must be >= CPU_EXTENDED_PROC_INFO_FEATURE_BITS
@@ -118,30 +202,31 @@ void cpuid(cpuid_t info, void *buf);
  */
 int cpuid_test_feature(cpuid_t feature);
 
-/* Test if the CPU supports MMX/SSE*
+/**
+ * cpuid_has_feature - Test if @feature is supported
  *
- * Returns 1 if the feature is available, 0 otherwise.
- */
-#define cpuid_has_mmx()        cpuid_has_feature(CF_MMX)
-#define cpuid_has_sse()        cpuid_has_feature(CF_SSE)
-#define cpuid_has_sse2()       cpuid_has_feature(CF_SSE2)
-#define cpuid_has_sse3()       cpuid_has_feature(CF_SSE3)
-#define cpuid_has_ssse3()      cpuid_has_feature(CF_SSSE3)
-#define cpuid_has_sse41()      cpuid_has_feature(CF_SSE41)
-#define cpuid_has_sse42()      cpuid_has_feature(CF_SSE42)
-#define cpuid_has_avx()        cpuid_has_feature(CF_AVX)
-#define cpuid_has_fma()        cpuid_has_feature(CF_FMA)
-int cpuid_has_feature(cpufeature_t feature);
-
-/* Test if the CPU supports an extended feature.
+ * Test if the CPU supports MMX/SSE* etc.
+ * For the extended parameter, usually you want to pass it as
+ * 0 if you're not passing CEF_*.
  *
- * Returns 1 if available, 0 otherwise.
+ * For more information about the CPU extended features, have a look
+ * at:
+ *     http://en.wikipedia.org/wiki/CPUID
+ *
+ * Returns 1 if the feature is available, 0 otherwise.
  */
-#define cpuid_has_x64()        cpuid_has_ext_feature(CEF_x64)
-#define cpuid_has_sse4a()      cpuid_has_ext_feature(CEF_SSE4a)
-#define cpuid_has_fma4()       cpuid_has_ext_feature(CEF_FMA4)
-#define cpuid_has_xop()        cpuid_has_ext_feature(CEF_XOP)
-int cpuid_has_ext_feature(cpuextfeature_t extfeature);
+#define cpuid_has_mmx()        cpuid_has_feature(CF_MMX,       0)
+#define cpuid_has_sse()        cpuid_has_feature(CF_SSE,       0)
+#define cpuid_has_sse2()       cpuid_has_feature(CF_SSE2,      0)
+#define cpuid_has_sse3()       cpuid_has_feature(CF_SSE3,      0)
+#define cpuid_has_ssse3()      cpuid_has_feature(CF_SSSE3,     0)
+#define cpuid_has_avx()        cpuid_has_feature(CF_AVX,       0)
+#define cpuid_has_fma()        cpuid_has_feature(CF_FMA,       0)
+#define cpuid_has_x64()        cpuid_has_feature(CEF_x64,      1)
+#define cpuid_has_sse4a()      cpuid_has_feature(CEF_SSE4a,    1)
+#define cpuid_has_fma4()       cpuid_has_feature(CEF_FMA4,     1)
+#define cpuid_has_xop()        cpuid_has_feature(CEF_XOP,      1)
+int cpuid_has_feature(int feature, int extended);
 
 #endif