diff options
| author | Simon Rettberg | 2019-08-02 10:04:37 +0200 |
|---|---|---|
| committer | Simon Rettberg | 2019-08-02 10:04:37 +0200 |
| commit | 610d4d9ea836366ebe5302512c8a4292b47effa0 (patch) | |
| tree | 42dcb5a7668e6603a59589aa61c6f8eb4a7a5cc9 /src/interface | |
| parent | Merge branch 'master' into openslx (diff) | |
| parent | [efi] Put rdrand workaround in sep. function (diff) | |
| download | ipxe-610d4d9ea836366ebe5302512c8a4292b47effa0.tar.gz ipxe-610d4d9ea836366ebe5302512c8a4292b47effa0.tar.xz ipxe-610d4d9ea836366ebe5302512c8a4292b47effa0.zip | |
Merge branch 'openslx' of git.openslx.org:openslx-ng/ipxe into openslx
Diffstat (limited to 'src/interface')
| -rw-r--r-- | src/interface/efi/efi_entropy.c | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/src/interface/efi/efi_entropy.c b/src/interface/efi/efi_entropy.c index 2dd231b22..a1dfaaa79 100644 --- a/src/interface/efi/efi_entropy.c +++ b/src/interface/efi/efi_entropy.c @@ -125,28 +125,6 @@ static int efi_entropy_tick ( void ) { EFI_STATUS efirc; int rc; -#if defined(__i386) || defined(__x86_64) - if ( have_hwrnd == 0 ) { - struct x86_features features; - x86_features( &features ); - if ( features.intel.ecx & ( 1 << 30 ) ) { - have_hwrnd = 1; - } else { - have_hwrnd = 2; - } - DBGC( &tick, "Have RDRAND: %s\n", ( have_hwrnd == 1 ? "YES!" : "NO :-(" ) ); - } - if ( have_hwrnd == 1 ) { - int ret, retries = 10; - char ok; - while ( --retries > 0 ) { - __asm__ volatile ( "rdrand %0; setc %1" : "=r" ( ret ), "=qm" ( ok ) ); - if ( ok ) - return ret & 0x7fffffff; - } - } -#endif - /* Wait for next timer tick */ if ( ( efirc = bs->SetTimer ( tick, TimerRelative, EFI_ENTROPY_TRIGGER_TIME ) ) != 0 ) { @@ -169,6 +147,40 @@ static int efi_entropy_tick ( void ) { } /** + * Get noise sample from rdrand + * + * @ret noise Noise sample + * @ret rc Return status code + */ +static int efi_get_noise_rdrand ( noise_sample_t *noise ) { +#if defined(__i386) || defined(__x86_64) + if ( have_hwrnd == 0 ) { + struct x86_features features; + x86_features( &features ); + if ( features.intel.ecx & ( 1 << 30 ) ) { + have_hwrnd = 1; + } else { + have_hwrnd = 2; + } + DBGC( &tick, "Have RDRAND: %s\n", ( have_hwrnd == 1 ? "YES!" : "NO :-(" ) ); + } + if ( have_hwrnd == 1 ) { + int ret, retries = 10; + char ok; + while ( --retries > 0 ) { + __asm__ volatile ( "rdrand %0; setc %1" : "=r" ( ret ), "=qm" ( ok ) ); + if ( ok ) { + *noise = ret; + return 0; + } + } + return -EBUSY; + } +#endif + return -ENOTSUP; +} + +/** * Get noise sample from timer ticks * * @ret noise Noise sample @@ -244,6 +256,7 @@ static int efi_get_noise ( noise_sample_t *noise ) { /* Try RNG first, falling back to timer ticks */ if ( ( ( rc = efi_get_noise_rng ( noise ) ) != 0 ) && + ( ( rc = efi_get_noise_rdrand ( noise ) ) != 0 ) && ( ( rc = efi_get_noise_ticks ( noise ) ) != 0 ) ) return rc; |
