Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
ea830cd1
Commit
ea830cd1
authored
Aug 11, 2015
by
A. Samy
Committed by
Rusty Russell
Aug 12, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cpuid: minor clean up
parent
f9ab3593
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
50 deletions
+45
-50
ccan/cpuid/cpuid.c
ccan/cpuid/cpuid.c
+10
-39
ccan/cpuid/cpuid.h
ccan/cpuid/cpuid.h
+35
-11
No files found.
ccan/cpuid/cpuid.c
View file @
ea830cd1
...
@@ -215,7 +215,7 @@ static uint32_t fetch_edx(uint32_t what)
...
@@ -215,7 +215,7 @@ static uint32_t fetch_edx(uint32_t what)
static uint32_t REGISTER; \
static uint32_t REGISTER; \
if (REGISTER == 0) \
if (REGISTER == 0) \
REGISTER = fetch_##REGISTER(TYPE); \
REGISTER = fetch_##REGISTER(TYPE); \
return
(REGISTER & feature) == feature
; \
return
!!(REGISTER & feature)
; \
}
}
DEFINE_FEATURE_FUNC
(
ecxfeature
,
ecx
,
CPUID_PROCINFO_AND_FEATUREBITS
)
DEFINE_FEATURE_FUNC
(
ecxfeature
,
ecx
,
CPUID_PROCINFO_AND_FEATUREBITS
)
...
@@ -226,25 +226,6 @@ DEFINE_FEATURE_FUNC(edxfeature_ext, edx, CPUID_EXTENDED_PROC_INFO_FEATURE_BITS)
...
@@ -226,25 +226,6 @@ DEFINE_FEATURE_FUNC(edxfeature_ext, edx, CPUID_EXTENDED_PROC_INFO_FEATURE_BITS)
#undef DEFINE_FEATURE_FUNC
#undef DEFINE_FEATURE_FUNC
static
const
char
*
const
cpuids
[]
=
{
"Nooooooooone"
,
"AMDisbetter!"
,
"AuthenticAMD"
,
"CentaurHauls"
,
"CyrixInstead"
,
"GenuineIntel"
,
"TransmetaCPU"
,
"GeniuneTMx86"
,
"Geode by NSC"
,
"NexGenDriven"
,
"RiseRiseRise"
,
"SiS SiS SiS "
,
"UMC UMC UMC "
,
"VIA VIA VIA "
,
"Vortex86 SoC"
,
"KVMKVMKVMKVM"
};
cputype_t
cpuid_get_cpu_type
(
void
)
cputype_t
cpuid_get_cpu_type
(
void
)
{
{
static
cputype_t
cputype
;
static
cputype_t
cputype
;
...
@@ -256,8 +237,8 @@ cputype_t cpuid_get_cpu_type(void)
...
@@ -256,8 +237,8 @@ cputype_t cpuid_get_cpu_type(void)
uint32_t
i
;
uint32_t
i
;
___cpuid
(
CPUID_VENDORID
,
&
i
,
&
u
.
bufu32
[
0
],
&
u
.
bufu32
[
2
],
&
u
.
bufu32
[
1
]);
___cpuid
(
CPUID_VENDORID
,
&
i
,
&
u
.
bufu32
[
0
],
&
u
.
bufu32
[
2
],
&
u
.
bufu32
[
1
]);
for
(
i
=
0
;
i
<
sizeof
(
c
puids
)
/
sizeof
(
cpuids
[
0
]
);
++
i
)
{
for
(
i
=
0
;
i
<
sizeof
(
c
_cpunames
)
/
sizeof
(
c_cpunames
);
++
i
)
{
if
(
strncmp
(
c
puids
[
i
],
u
.
buf
,
12
)
==
0
)
{
if
(
strncmp
(
c
_cpunames
[
i
],
u
.
buf
,
sizeof
(
c_cpunames
[
0
])
)
==
0
)
{
cputype
=
(
cputype_t
)
i
;
cputype
=
(
cputype_t
)
i
;
break
;
break
;
}
}
...
@@ -267,16 +248,6 @@ cputype_t cpuid_get_cpu_type(void)
...
@@ -267,16 +248,6 @@ cputype_t cpuid_get_cpu_type(void)
return
cputype
;
return
cputype
;
}
}
bool
cpuid_sprintf_cputype
(
const
cputype_t
cputype
,
char
*
buf
)
{
if
(
cputype
==
CT_NONE
)
return
false
;
memcpy
(
buf
,
cpuids
[(
int
)
cputype
],
12
);
buf
[
12
]
=
'\0'
;
return
true
;
}
uint32_t
cpuid_highest_ext_func_supported
(
void
)
uint32_t
cpuid_highest_ext_func_supported
(
void
)
{
{
static
uint32_t
highest
;
static
uint32_t
highest
;
...
@@ -300,16 +271,16 @@ uint32_t cpuid_highest_ext_func_supported(void)
...
@@ -300,16 +271,16 @@ uint32_t cpuid_highest_ext_func_supported(void)
return
highest
;
return
highest
;
}
}
void
cpuid
(
cpuid_t
info
,
uint32_t
*
buf
)
void
cpuid
(
cpuid_t
request
,
uint32_t
*
buf
)
{
{
/* Sanity checks, make sure we're not trying to do something
/* Sanity checks, make sure we're not trying to do something
* invalid or we are trying to get information that isn't supported
* invalid or we are trying to get information that isn't supported
* by the CPU. */
* by the CPU. */
if
(
info
>
CPUID_VIRT_PHYS_ADDR_SIZES
||
(
info
>
CPUID_HIGHEST_EXTENDED_FUNCTION_SUPPORTED
if
(
request
>
CPUID_VIRT_PHYS_ADDR_SIZES
||
(
request
>
CPUID_HIGHEST_EXTENDED_FUNCTION_SUPPORTED
&&
!
cpuid_test_feature
(
info
)))
&&
!
cpuid_test_feature
(
request
)))
return
;
return
;
if
(
info
==
CPUID_PROC_BRAND_STRING
)
{
if
(
request
==
CPUID_PROC_BRAND_STRING
)
{
static
char
cached
[
48
]
=
{
0
};
static
char
cached
[
48
]
=
{
0
};
if
(
cached
[
0
]
==
'\0'
)
{
if
(
cached
[
0
]
==
'\0'
)
{
___cpuid
(
CPUID_PROC_BRAND_STRING
,
&
buf
[
0
],
&
buf
[
1
],
&
buf
[
2
],
&
buf
[
3
]
);
___cpuid
(
CPUID_PROC_BRAND_STRING
,
&
buf
[
0
],
&
buf
[
1
],
&
buf
[
2
],
&
buf
[
3
]
);
...
@@ -321,15 +292,15 @@ void cpuid(cpuid_t info, uint32_t *buf)
...
@@ -321,15 +292,15 @@ void cpuid(cpuid_t info, uint32_t *buf)
buf
=
(
uint32_t
*
)
cached
;
buf
=
(
uint32_t
*
)
cached
;
return
;
return
;
}
else
if
(
info
==
CPUID_HIGHEST_EXTENDED_FUNCTION_SUPPORTED
)
{
}
else
if
(
request
==
CPUID_HIGHEST_EXTENDED_FUNCTION_SUPPORTED
)
{
*
buf
=
cpuid_highest_ext_func_supported
();
*
buf
=
cpuid_highest_ext_func_supported
();
return
;
return
;
}
}
uint32_t
eax
,
ebx
,
ecx
,
edx
;
uint32_t
eax
,
ebx
,
ecx
,
edx
;
___cpuid
(
info
,
&
eax
,
&
ebx
,
&
ecx
,
&
edx
);
___cpuid
(
request
,
&
eax
,
&
ebx
,
&
ecx
,
&
edx
);
switch
(
info
)
{
switch
(
request
)
{
case
CPUID_VENDORID
:
case
CPUID_VENDORID
:
buf
[
0
]
=
ebx
;
buf
[
0
]
=
ebx
;
buf
[
1
]
=
edx
;
buf
[
1
]
=
edx
;
...
...
ccan/cpuid/cpuid.h
View file @
ea830cd1
/*
/*
* Copyright (c) 2013 Ahmed Samy <f.fallen45@gmail.com>
* Copyright (c) 2013
, 2015
Ahmed Samy <f.fallen45@gmail.com>
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* of this software and associated documentation files (the "Software"), to deal
...
@@ -230,6 +230,25 @@ typedef enum cputype {
...
@@ -230,6 +230,25 @@ typedef enum cputype {
CT_KVM
CT_KVM
}
cputype_t
;
}
cputype_t
;
static
char
const
*
const
c_cpunames
[]
=
{
"Nooooooooone"
,
"AMDisbetter!"
,
"AuthenticAMD"
,
"CentaurHauls"
,
"CyrixInstead"
,
"GenuineIntel"
,
"TransmetaCPU"
,
"GeniuneTMx86"
,
"Geode by NSC"
,
"NexGenDriven"
,
"RiseRiseRise"
,
"SiS SiS SiS "
,
"UMC UMC UMC "
,
"VIA VIA VIA "
,
"Vortex86 SoC"
,
"KVMKVMKVMKVM"
};
#if defined(__i386__) || defined(__i386) || defined(__x86_64) \
#if defined(__i386__) || defined(__i386) || defined(__x86_64) \
|| defined(_M_AMD64) || defined(__M_X64)
|| defined(_M_AMD64) || defined(__M_X64)
...
@@ -240,17 +259,22 @@ typedef enum cputype {
...
@@ -240,17 +259,22 @@ typedef enum cputype {
*
*
* See also: cpuid_get_cpu_type_string()
* See also: cpuid_get_cpu_type_string()
*/
*/
#define is_intel_cpu() cpuid_get_cpu_type() == CT_INTEL
#define is_amd_cpu() cpuid_get_cpu_type() == CT_AMDK5 || cpuid_get_cpu_type() == CT_AMD
cputype_t
cpuid_get_cpu_type
(
void
);
cputype_t
cpuid_get_cpu_type
(
void
);
/**
static
inline
bool
is_intel_cpu
(
void
)
* cpuid_sprintf_cputype - Get CPU Type string
{
* @cputype: a char of atleast 12 bytes in it.
return
cpuid_get_cpu_type
()
==
CT_INTEL
;
*
}
* Returns true on success, false on failure
*/
static
inline
bool
is_amd_cpu
(
void
)
bool
cpuid_sprintf_cputype
(
const
cputype_t
cputype
,
char
*
buf
);
{
return
cpuid_get_cpu_type
()
==
CT_AMDK5
||
cpuid_get_cpu_type
()
==
CT_AMD
;
}
static
inline
const
char
*
cpuid_get_name
(
void
)
{
return
c_cpunames
[(
int
)
cpuid_get_cpu_type
()];
}
/**
/**
* cpuid_is_supported - test if the CPUID instruction is supported
* cpuid_is_supported - test if the CPUID instruction is supported
...
@@ -341,7 +365,7 @@ uint32_t cpuid_highest_ext_func_supported(void);
...
@@ -341,7 +365,7 @@ uint32_t cpuid_highest_ext_func_supported(void);
*
*
* If an invalid flag has been passed a 0xbaadf00d is returned in *buf.
* If an invalid flag has been passed a 0xbaadf00d is returned in *buf.
*/
*/
void
cpuid
(
cpuid_t
info
,
uint32_t
*
buf
);
void
cpuid
(
cpuid_t
request
,
uint32_t
*
buf
);
/**
/**
* cpuid_write_info - Write specified CPU information to a file.
* cpuid_write_info - Write specified CPU information to a file.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment