cpuid: hardcode cores num for <v6 processors

This commit is contained in:
Alibek Omarov 2021-03-21 20:25:19 +03:00
parent 8beef4d855
commit d4f8cc067c

View File

@ -14,7 +14,7 @@ as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
/**
* e2k cpuid single-header library, v1
*
*
* Changes from v0:
* - initial release
*
@ -37,6 +37,7 @@ typedef enum e2k_cpuid_mdl_e
{
MDL_E2S = 0x03, /* Elbrus-4C */
MDL_ES2 = 0x04, /* Elbrus-2C+ */
MDL_RESERVED = 0x05, /* unknown "reserved" processor */
MDL_ES2_NO_DSP = 0x06, /* Elbrus-2CM */
MDL_E8C = 0x07, /* Elbrus-8C */
MDL_E1CP = 0x08, /* Elbrus-1C+ */
@ -48,7 +49,7 @@ typedef enum e2k_cpuid_mdl_e
int e2k_cpuid( e2k_cpuid_t *cpuid );
int e2k_cpuid_from_regs( e2k_cpuid_t *cpuid, uint64_t idr, uint32_t core_mode /* only v6 */ );
int e2k_cpuid_model_from_mdl( char *out, size_t len, uint32_t mdl );
int e2k_cpuid_model_from_mdl( char *modelname, size_t len, uint32_t mdl );
#ifdef E2K_CPUID_IMPLEMENTATION
@ -86,6 +87,7 @@ int e2k_cpuid_model_from_mdl( char *out, size_t len, uint32_t mdl )
{
case MDL_E2S: str = "Elbrus-4C"; break;
case MDL_ES2: str = "Elbrus-2C+"; break;
case MDL_RESERVED: str = "Elbrus-Reserved"; break;
case MDL_ES2_NO_DSP: str = "Elbrus-2CM"; break;
case MDL_E8C: str = "Elbrus-8C"; break;
case MDL_E1CP: str = "Elbrus-1C+"; break;
@ -109,6 +111,21 @@ int e2k_cpuid_model_from_mdl( char *out, size_t len, uint32_t mdl )
return retval;
}
static int e2k_cpuid_cores_from_mdl( uint32_t mdl )
{
/* only for processors that doesn't report cores num through IDR */
switch( mdl )
{
case MDL_E1CP: return 1;
case MDL_ES2:
case MDL_ES2_NO_DSP: return 2;
case MDL_E2S: return 4;
case MDL_E8C2:
case MDL_E8C: return 8;
default: return 1;
}
}
int e2k_cpuid_from_regs( e2k_cpuid_t *cpuid, uint64_t idr, uint32_t core_mode )
{
int retval = 0;
@ -129,6 +146,10 @@ int e2k_cpuid_from_regs( e2k_cpuid_t *cpuid, uint64_t idr, uint32_t core_mode )
cpuid->is_guest = extract32( core_mode, CORE_MODE_GUEST_START, CORE_MODE_GUEST_BITS );
}
else
{
cpuid->cores = e2k_cpuid_cores_from_mdl( cpuid->mdl );
}
// finalize data
cpuid->l2_wb_len = IDR_WBL_TO_BYTES( cpuid->l2_wb_len );