aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2021-05-12 10:24:00 +0100
committerMichael Brown <mcb30@ipxe.org>2021-05-12 10:24:00 +0100
commit05fcf1a2f0809b8d87ca5affea1f1bfe0996235b (patch)
treebfa6c7eb41d6f0879f2fa33f7926d30f480fedbe
parent13c1abe10abd1c24307a6777b6cedfc5b46b088d (diff)
downloadipxe-05fcf1a2f0809b8d87ca5affea1f1bfe0996235b.zip
ipxe-05fcf1a2f0809b8d87ca5affea1f1bfe0996235b.tar.gz
ipxe-05fcf1a2f0809b8d87ca5affea1f1bfe0996235b.tar.bz2
[rng] Check for TSC support before using RTC entropy source
Signed-off-by: Michael Brown <mcb30@ipxe.org>
-rw-r--r--src/arch/x86/include/ipxe/cpuid.h3
-rw-r--r--src/arch/x86/interface/pcbios/rtc_entropy.c11
2 files changed, 14 insertions, 0 deletions
diff --git a/src/arch/x86/include/ipxe/cpuid.h b/src/arch/x86/include/ipxe/cpuid.h
index b5403bd..3983dfb 100644
--- a/src/arch/x86/include/ipxe/cpuid.h
+++ b/src/arch/x86/include/ipxe/cpuid.h
@@ -42,6 +42,9 @@ struct x86_features {
/** Hypervisor is present */
#define CPUID_FEATURES_INTEL_ECX_HYPERVISOR 0x80000000UL
+/** TSC is present */
+#define CPUID_FEATURES_INTEL_EDX_TSC 0x00000010UL
+
/** FXSAVE and FXRSTOR are supported */
#define CPUID_FEATURES_INTEL_EDX_FXSR 0x01000000UL
diff --git a/src/arch/x86/interface/pcbios/rtc_entropy.c b/src/arch/x86/interface/pcbios/rtc_entropy.c
index e9e6baa..e0c1756 100644
--- a/src/arch/x86/interface/pcbios/rtc_entropy.c
+++ b/src/arch/x86/interface/pcbios/rtc_entropy.c
@@ -36,6 +36,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <biosint.h>
#include <pic8259.h>
#include <rtc.h>
+#include <ipxe/cpuid.h>
#include <ipxe/entropy.h>
/** Maximum time to wait for an RTC interrupt, in milliseconds */
@@ -174,8 +175,17 @@ static int rtc_entropy_check ( void ) {
* @ret rc Return status code
*/
static int rtc_entropy_enable ( void ) {
+ struct x86_features features;
int rc;
+ /* Check that TSC is supported */
+ x86_features ( &features );
+ if ( ! ( features.intel.edx & CPUID_FEATURES_INTEL_EDX_TSC ) ) {
+ DBGC ( &rtc_flag, "RTC has no TSC\n" );
+ rc = -ENOTSUP;
+ goto err_no_tsc;
+ }
+
/* Hook ISR and enable RTC interrupts */
rtc_hook_isr();
enable_irq ( RTC_IRQ );
@@ -191,6 +201,7 @@ static int rtc_entropy_enable ( void ) {
rtc_disable_int();
disable_irq ( RTC_IRQ );
rtc_unhook_isr();
+ err_no_tsc:
return rc;
}