diff options
author | Werner Koch <wk@gnupg.org> | 2013-12-12 18:53:39 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2013-12-12 18:53:39 +0100 |
commit | 4ae77322b681a13da62d01274bcab25be2af12d0 (patch) | |
tree | 4b3a2e31cb86fae492800e58cce8138c91bc4bd3 /src | |
parent | 3b30e9840d4b351c4de73b126e561154cb7df4cc (diff) | |
download | libgcrypt-4ae77322b681a13da62d01274bcab25be2af12d0.tar.gz |
Move list of hardware features to hwfeatures.c.
* src/global.c (hwflist, disabled_hw_features): Move to ..
* src/hwfeatures.c: here.
(_gcry_disable_hw_feature): New.
(_gcry_enum_hw_features): New.
(_gcry_detect_hw_features): Remove arg DISABLED_FEATURES.
* src/global.c (print_config, _gcry_vcontrol, global_init): Adjust
accordingly.
--
It is better to keep the hardware feature infor at one place.
Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/g10lib.h | 4 | ||||
-rw-r--r-- | src/global.c | 51 | ||||
-rw-r--r-- | src/hwf-arm.c | 6 | ||||
-rw-r--r-- | src/hwfeatures.c | 57 |
4 files changed, 70 insertions, 48 deletions
diff --git a/src/g10lib.h b/src/g10lib.h index 4e083b8d..1e58ef69 100644 --- a/src/g10lib.h +++ b/src/g10lib.h @@ -206,8 +206,10 @@ int _gcry_log_verbosity( int level ); #define HWF_ARM_NEON 4096 +gpg_err_code_t _gcry_disable_hw_feature (const char *name); +void _gcry_detect_hw_features (void); unsigned int _gcry_get_hw_features (void); -void _gcry_detect_hw_features (unsigned int); +const char *_gcry_enum_hw_features (int idx, unsigned int *r_feature); /*-- mpi/mpiutil.c --*/ diff --git a/src/global.c b/src/global.c index cb66d371..9af499e2 100644 --- a/src/global.c +++ b/src/global.c @@ -55,31 +55,6 @@ static int force_fips_mode; /* Controlled by global_init(). */ static int any_init_done; -/* A table to map hardware features to a string. */ -static struct -{ - unsigned int flag; - const char *desc; -} hwflist[] = - { - { HWF_PADLOCK_RNG, "padlock-rng" }, - { HWF_PADLOCK_AES, "padlock-aes" }, - { HWF_PADLOCK_SHA, "padlock-sha" }, - { HWF_PADLOCK_MMUL,"padlock-mmul"}, - { HWF_INTEL_PCLMUL,"intel-pclmul" }, - { HWF_INTEL_AESNI, "intel-aesni" }, - { HWF_INTEL_RDRAND,"intel-rdrand" }, - { HWF_INTEL_AVX, "intel-avx" }, - { HWF_INTEL_AVX2, "intel-avx2" }, - { HWF_ARM_NEON, "arm-neon" }, - { 0, NULL} - }; - -/* A bit vector with the hardware features which shall not be used. - This variable must be set prior to any initialization. */ -static unsigned int disabled_hw_features; - - /* Memory management. */ static gcry_handler_alloc_t alloc_func; @@ -125,7 +100,7 @@ global_init (void) /* Before we do any other initialization we need to test available hardware features. */ - _gcry_detect_hw_features (disabled_hw_features); + _gcry_detect_hw_features (); /* Initialize the modules - this is mainly allocating some memory and creating mutexes. */ @@ -289,8 +264,9 @@ _gcry_check_version (const char *req_version) static void print_config ( int (*fnc)(FILE *fp, const char *format, ...), FILE *fp) { - unsigned int hwf; + unsigned int hwfeatures, afeature; int i; + const char *s; fnc (fp, "version:%s:\n", VERSION); fnc (fp, "ciphers:%s:\n", LIBGCRYPT_CIPHERS); @@ -329,11 +305,11 @@ print_config ( int (*fnc)(FILE *fp, const char *format, ...), FILE *fp) ":\n"); fnc (fp, "mpi-asm:%s:\n", _gcry_mpi_get_hw_config ()); fnc (fp, "threads:%s:\n", ath_get_model (NULL)); - hwf = _gcry_get_hw_features (); + hwfeatures = _gcry_get_hw_features (); fnc (fp, "hwflist:"); - for (i=0; hwflist[i].desc; i++) - if ( (hwf & hwflist[i].flag) ) - fnc (fp, "%s:", hwflist[i].desc); + for (i=0; (s = _gcry_enum_hw_features (i, &afeature)); i++) + if ((hwfeatures & afeature)) + fnc (fp, "%s:", s); fnc (fp, "\n"); /* We use y/n instead of 1/0 for the simple reason that Emacsen's compile error parser would accidently flag that line when printed @@ -343,8 +319,6 @@ print_config ( int (*fnc)(FILE *fp, const char *format, ...), FILE *fp) _gcry_enforced_fips_mode ()? 'y':'n' ); /* The currently used RNG type. */ { - const char *s; - i = _gcry_get_rng_type (0); switch (i) { @@ -653,16 +627,7 @@ _gcry_vcontrol (enum gcry_ctl_cmds cmd, va_list arg_ptr) case GCRYCTL_DISABLE_HWF: { const char *name = va_arg (arg_ptr, const char *); - int i; - - for (i=0; hwflist[i].desc; i++) - if (!strcmp (hwflist[i].desc, name)) - { - disabled_hw_features |= hwflist[i].flag; - break; - } - if (!hwflist[i].desc) - rc = GPG_ERR_INV_NAME; + rc = _gcry_disable_hw_feature (name); } break; diff --git a/src/hwf-arm.c b/src/hwf-arm.c index 9ab4cd0f..5c99a1dd 100644 --- a/src/hwf-arm.c +++ b/src/hwf-arm.c @@ -39,7 +39,8 @@ #define AT_HWCAP 16 #define HWCAP_NEON 4096 -static int get_hwcap(unsigned int *hwcap) +static int +get_hwcap(unsigned int *hwcap) { struct { unsigned int a_type; unsigned int a_val; } auxv; FILE *f; @@ -76,7 +77,8 @@ static int get_hwcap(unsigned int *hwcap) return err; } -static unsigned int detect_arm_at_hwcap(void) +static unsigned int +detect_arm_at_hwcap(void) { unsigned int hwcap; unsigned int features = 0; diff --git a/src/hwfeatures.c b/src/hwfeatures.c index 1e3c27dc..43847d22 100644 --- a/src/hwfeatures.c +++ b/src/hwfeatures.c @@ -29,11 +29,51 @@ #include "hwf-common.h" +/* A table to map hardware features to a string. */ +static struct +{ + unsigned int flag; + const char *desc; +} hwflist[] = + { + { HWF_PADLOCK_RNG, "padlock-rng" }, + { HWF_PADLOCK_AES, "padlock-aes" }, + { HWF_PADLOCK_SHA, "padlock-sha" }, + { HWF_PADLOCK_MMUL,"padlock-mmul"}, + { HWF_INTEL_PCLMUL,"intel-pclmul" }, + { HWF_INTEL_AESNI, "intel-aesni" }, + { HWF_INTEL_RDRAND,"intel-rdrand" }, + { HWF_INTEL_AVX, "intel-avx" }, + { HWF_INTEL_AVX2, "intel-avx2" }, + { HWF_ARM_NEON, "arm-neon" } + }; + +/* A bit vector with the hardware features which shall not be used. + This variable must be set prior to any initialization. */ +static unsigned int disabled_hw_features; + /* A bit vector describing the hardware features currently available. */ static unsigned int hw_features; +/* Disable a feature by name. This function must be called *before* + _gcry_detect_hw_features is called. */ +gpg_err_code_t +_gcry_disable_hw_feature (const char *name) +{ + int i; + + for (i=0; i < DIM (hwflist); i++) + if (!strcmp (hwflist[i].desc, name)) + { + disabled_hw_features |= hwflist[i].flag; + return 0; + } + return GPG_ERR_INV_NAME; +} + + /* Return a bit vector describing the available hardware features. The HWF_ constants are used to test for them. */ unsigned int @@ -43,11 +83,24 @@ _gcry_get_hw_features (void) } +/* Enumerate all features. The caller is expected to start with an + IDX of 0 and then increment IDX until NULL is returned. */ +const char * +_gcry_enum_hw_features (int idx, unsigned int *r_feature) +{ + if (idx < 0 || idx >= DIM (hwflist)) + return NULL; + if (r_feature) + *r_feature = hwflist[idx].flag; + return hwflist[idx].desc; +} + + /* Detect the available hardware features. This function is called once right at startup and we assume that no other threads are running. */ void -_gcry_detect_hw_features (unsigned int disabled_features) +_gcry_detect_hw_features (void) { hw_features = 0; @@ -65,5 +118,5 @@ _gcry_detect_hw_features (unsigned int disabled_features) } #endif /* HAVE_CPU_ARCH_ARM */ - hw_features &= ~disabled_features; + hw_features &= ~disabled_hw_features; } |