mirror of
https://github.com/anrieff/libcpuid
synced 2024-12-16 16:35:45 +00:00
Add cpu_request_core_type function
This commit is contained in:
parent
b714dcb00d
commit
7b185baec8
4 changed files with 44 additions and 0 deletions
|
@ -755,6 +755,26 @@ int cpu_identify_all(struct cpu_raw_data_array_t *raw_array, struct system_id_t*
|
|||
return ret_error;
|
||||
}
|
||||
|
||||
struct cpu_id_t* cpu_request_core_type(cpu_purpose_t purpose, struct cpu_raw_data_array_t* raw_array, struct system_id_t* system)
|
||||
{
|
||||
uint8_t cpu_type_index = 0;
|
||||
struct system_id_t my_system;
|
||||
|
||||
if (!system) {
|
||||
system = &my_system;
|
||||
if (cpu_identify_all(raw_array, system) != ERR_OK)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (cpu_type_index = 0; cpu_type_index < system->num_cpu_types; cpu_type_index++) {
|
||||
if (purpose == system->cpu_types[cpu_type_index].purpose)
|
||||
return &system->cpu_types[cpu_type_index];
|
||||
}
|
||||
|
||||
set_error(ERR_NOT_FOUND);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* cpu_architecture_str(cpu_architecture_t architecture)
|
||||
{
|
||||
const struct { cpu_architecture_t architecture; const char* name; }
|
||||
|
@ -940,6 +960,7 @@ const char* cpuid_error(void)
|
|||
{ ERR_INVCNB , "Invalid core number"},
|
||||
{ ERR_HANDLE_R , "Error on handle read"},
|
||||
{ ERR_INVRANGE , "Invalid given range"},
|
||||
{ ERR_NOT_FOUND, "Requested type not found"},
|
||||
};
|
||||
unsigned i;
|
||||
for (i = 0; i < COUNT_OF(matchtable); i++)
|
||||
|
|
|
@ -34,5 +34,6 @@ cpu_rdmsr_range @30
|
|||
cpuid_get_epc @31
|
||||
msr_serialize_raw_data @32
|
||||
cpu_identify_all @36
|
||||
cpu_request_core_type @37
|
||||
cpu_architecture_str @38
|
||||
cpu_purpose_str @39
|
||||
|
|
|
@ -654,6 +654,7 @@ typedef enum {
|
|||
ERR_INVCNB = -14, /*!< Invalid core number */
|
||||
ERR_HANDLE_R = -15, /*!< Error on handle read */
|
||||
ERR_INVRANGE = -16, /*!< Invalid given range */
|
||||
ERR_NOT_FOUND= -17, /*!< Requested type not found */
|
||||
} cpu_error_t;
|
||||
|
||||
/**
|
||||
|
@ -784,6 +785,26 @@ int cpu_identify(struct cpu_raw_data_t* raw, struct cpu_id_t* data);
|
|||
*/
|
||||
int cpu_identify_all(struct cpu_raw_data_array_t *raw_array, struct system_id_t* system);
|
||||
|
||||
/**
|
||||
* @brief Identifies a given CPU type
|
||||
* @param purpose - Input - a \ref cpu_purpose_t to request
|
||||
* @param raw_array - Optional input - a pointer to the array of raw CPUID data, which is obtained
|
||||
* either by cpuid_get_all_raw_data or cpuid_deserialize_all_raw_data.
|
||||
* Can also be NULL, in which case the functions calls
|
||||
* cpuid_get_all_raw_data itself.
|
||||
* @param system - Optional input - the decoded CPU features/info for each CPU type, which is obtained
|
||||
* by cpu_identify_all.
|
||||
* Can also be NULL, in which case the functions calls
|
||||
* cpu_identify_all itself.
|
||||
* @note The function is based on cpu_identify_all. Refer to cpu_identify notes.
|
||||
* @returns the decoded CPU features/info matching purpose if purpose found successfully,
|
||||
* ERR_NOT_FOUND if CPU type not found,
|
||||
* or a different negative number on error.
|
||||
* The error message can be obtained by calling \ref cpuid_error.
|
||||
* @see cpu_error_t
|
||||
*/
|
||||
struct cpu_id_t* cpu_request_core_type(cpu_purpose_t purpose, struct cpu_raw_data_array_t* raw_array, struct system_id_t* system);
|
||||
|
||||
/**
|
||||
* @brief Returns the short textual representation of a CPU architecture
|
||||
* @param architecture - the architecture, whose textual representation is wanted.
|
||||
|
|
|
@ -31,5 +31,6 @@ cpu_rdmsr_range
|
|||
cpuid_get_epc
|
||||
msr_serialize_raw_data
|
||||
cpu_identify_all
|
||||
cpu_request_core_type
|
||||
cpu_architecture_str
|
||||
cpu_purpose_str
|
||||
|
|
Loading…
Reference in a new issue