summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhao Yakui <yakui.zhao@intel.com>2014-09-26 09:15:36 +0800
committerZhao, Yakui <yakui.zhao@intel.com>2014-09-28 09:14:12 +0800
commit925c98afcd381e52b37eb3870c3c80ff9c59a069 (patch)
tree3a6131974c2103fb62bd114aeca97c9c2040fb8e
parent095ba812b995e92bf7cb26795ab696e0bc55b577 (diff)
Use the inline CPUID assembly to obtain CPUID string instead of /proc/cpuinfo
On some systems there is no access to /proc/cpuinfo. So the inline assembly is used directly to detect the CPUID string. V2->V3: Follow the suggestion from Google engineer to remove the unused code of "if 0". And the "unsigned int" data type is updated to "uint32_t". V1->V2: Based on the Matt Turner's suggestion the __cpuid defined in GCC cpuid.h is called directly, which is helpful to handle the PIC issue on 32-bit. Signed-off-by: Zhao Yakui <yakui.zhao@intel.com> (cherry picked from commit 3e8cce4e7292651af10c9f375a6ad2e9fa494021)
-rw-r--r--src/i965_device_info.c54
1 files changed, 26 insertions, 28 deletions
diff --git a/src/i965_device_info.c b/src/i965_device_info.c
index fd5d81c..282e56e 100644
--- a/src/i965_device_info.c
+++ b/src/i965_device_info.c
@@ -30,6 +30,7 @@
#include <string.h>
#include <strings.h>
#include <errno.h>
+#include <cpuid.h>
/* Extra set of chroma formats supported for H.264 decoding (beyond YUV 4:2:0) */
#define EXTRA_H264_DEC_CHROMA_FORMATS \
@@ -375,43 +376,40 @@ i965_get_device_info(int devid)
}
}
+static void cpuid(unsigned int op,
+ uint32_t *eax, uint32_t *ebx,
+ uint32_t *ecx, uint32_t *edx)
+{
+ __cpuid_count(op, 0, *eax, *ebx, *ecx, *edx);
+}
+
+/*
+ * This function doesn't check the length. And the caller should
+ * assure that the length of input string should be greater than 48.
+ */
static int intel_driver_detect_cpustring(char *model_id)
{
- FILE *fp;
- size_t line_length;
- ssize_t read_length;
- char *line_string, *model_ptr;
- bool found;
+ uint32_t *rdata;
if (model_id == NULL)
return -EINVAL;
- fp = fopen("/proc/cpuinfo", "r");
- if (fp == NULL) {
- fprintf(stderr, "no permission to access /proc/cpuinfo\n");
- return -EACCES;
- }
- line_string = NULL;
- found = false;
+ rdata = (uint32_t *)model_id;
- while((read_length = getline(&line_string, &line_length, fp)) != -1) {
- if (strstr(line_string, "model name")) {
- model_ptr = strstr(line_string, ": ");
- model_ptr += 2;
- found = true;
- strncpy(model_id, model_ptr, strlen(model_ptr));
- break;
- }
- }
- fclose(fp);
+ /* obtain the max supported extended CPUID info */
+ cpuid(0x80000000, &rdata[0], &rdata[1], &rdata[2], &rdata[3]);
- if (line_string)
- free(line_string);
+ /* If the max extended CPUID info is less than 0x80000004, fail */
+ if (rdata[0] < 0x80000004)
+ return -EINVAL;
- if (found)
- return 0;
- else
- return -EINVAL;
+ /* obtain the CPUID string */
+ cpuid(0x80000002, &rdata[0], &rdata[1], &rdata[2], &rdata[3]);
+ cpuid(0x80000003, &rdata[4], &rdata[5], &rdata[6], &rdata[7]);
+ cpuid(0x80000004, &rdata[8], &rdata[9], &rdata[10], &rdata[11]);
+
+ *(model_id + 48) = '\0';
+ return 0;
}
/*