1 | /* Copyright (c) 2018, Google Inc. |
2 | * |
3 | * Permission to use, copy, modify, and/or distribute this software for any |
4 | * purpose with or without fee is hereby granted, provided that the above |
5 | * copyright notice and this permission notice appear in all copies. |
6 | * |
7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ |
14 | |
15 | #include <openssl/cpu.h> |
16 | |
17 | #if defined(OPENSSL_AARCH64) && defined(OPENSSL_FUCHSIA) && \ |
18 | !defined(OPENSSL_STATIC_ARMCAP) |
19 | |
20 | #include <zircon/features.h> |
21 | #include <zircon/syscalls.h> |
22 | #include <zircon/types.h> |
23 | |
24 | #include <openssl/arm_arch.h> |
25 | |
26 | #include "internal.h" |
27 | |
28 | extern uint32_t OPENSSL_armcap_P; |
29 | |
30 | void OPENSSL_cpuid_setup(void) { |
31 | uint32_t hwcap; |
32 | zx_status_t rc = zx_system_get_features(ZX_FEATURE_KIND_CPU, &hwcap); |
33 | if (rc != ZX_OK || (hwcap & ZX_ARM64_FEATURE_ISA_ASIMD) == 0) { |
34 | // Matching OpenSSL, if NEON/ASIMD is missing, don't report other features |
35 | // either. |
36 | return; |
37 | } |
38 | |
39 | OPENSSL_armcap_P |= ARMV7_NEON; |
40 | |
41 | if (hwcap & ZX_ARM64_FEATURE_ISA_AES) { |
42 | OPENSSL_armcap_P |= ARMV8_AES; |
43 | } |
44 | if (hwcap & ZX_ARM64_FEATURE_ISA_PMULL) { |
45 | OPENSSL_armcap_P |= ARMV8_PMULL; |
46 | } |
47 | if (hwcap & ZX_ARM64_FEATURE_ISA_SHA1) { |
48 | OPENSSL_armcap_P |= ARMV8_SHA1; |
49 | } |
50 | if (hwcap & ZX_ARM64_FEATURE_ISA_SHA2) { |
51 | OPENSSL_armcap_P |= ARMV8_SHA256; |
52 | } |
53 | } |
54 | |
55 | #endif // OPENSSL_AARCH64 && !OPENSSL_STATIC_ARMCAP |
56 | |