Arunachalam Ganapathy | 0bbdc2d | 2023-04-05 15:30:18 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2023, Arm Limited. All rights reserved. |
| 3 | * SPDX-License-Identifier: BSD-3-Clause |
| 4 | */ |
| 5 | |
| 6 | #include <arch.h> |
| 7 | #include <arch_features.h> |
| 8 | #include <arch_helpers.h> |
| 9 | #include <assert.h> |
| 10 | #include <debug.h> |
| 11 | #include <lib/extensions/sve.h> |
| 12 | |
| 13 | #include <host_realm_sve.h> |
| 14 | #include <host_shared_data.h> |
| 15 | |
| 16 | /* Returns the maximum supported VL. This test is called only by sve Realm */ |
| 17 | bool test_realm_sve_rdvl(void) |
| 18 | { |
| 19 | host_shared_data_t *sd = realm_get_shared_structure(); |
| 20 | struct sve_cmd_rdvl *output; |
| 21 | |
| 22 | assert(is_armv8_2_sve_present()); |
| 23 | |
| 24 | output = (struct sve_cmd_rdvl *)sd->realm_cmd_output_buffer; |
| 25 | memset((void *)output, 0, sizeof(struct sve_cmd_rdvl)); |
| 26 | |
| 27 | sve_config_vq(SVE_VQ_ARCH_MAX); |
| 28 | output->rdvl = sve_vector_length_get(); |
| 29 | |
| 30 | return true; |
| 31 | } |
| 32 | |
| 33 | /* |
| 34 | * Reads and returns the ID_AA64PFR0_EL1 and ID_AA64ZFR0_EL1 registers |
| 35 | * This test could be called from sve or non-sve Realm |
| 36 | */ |
| 37 | bool test_realm_sve_read_id_registers(void) |
| 38 | { |
| 39 | host_shared_data_t *sd = realm_get_shared_structure(); |
| 40 | struct sve_cmd_id_regs *output; |
| 41 | |
| 42 | output = (struct sve_cmd_id_regs *)sd->realm_cmd_output_buffer; |
| 43 | memset((void *)output, 0, sizeof(struct sve_cmd_id_regs)); |
| 44 | |
| 45 | realm_printf("Realm: reading ID registers: ID_AA64PFR0_EL1, " |
| 46 | " ID_AA64ZFR0_EL1\n"); |
| 47 | output->id_aa64pfr0_el1 = read_id_aa64pfr0_el1(); |
| 48 | output->id_aa64zfr0_el1 = read_id_aa64zfr0_el1(); |
| 49 | |
| 50 | return true; |
| 51 | } |
| 52 | |
| 53 | /* |
| 54 | * Probes all VLs and return the bitmap with the bit set for each corresponding |
| 55 | * valid VQ. This test is called only by sve Realm |
| 56 | */ |
| 57 | bool test_realm_sve_probe_vl(void) |
| 58 | { |
| 59 | host_shared_data_t *sd = realm_get_shared_structure(); |
| 60 | struct sve_cmd_probe_vl *output; |
| 61 | |
| 62 | assert(is_armv8_2_sve_present()); |
| 63 | |
| 64 | output = (struct sve_cmd_probe_vl *)&sd->realm_cmd_output_buffer; |
| 65 | memset((void *)output, 0, sizeof(struct sve_cmd_probe_vl)); |
| 66 | |
| 67 | /* Probe all VLs */ |
| 68 | output->vl_bitmap = sve_probe_vl(SVE_VQ_ARCH_MAX); |
| 69 | |
| 70 | return true; |
| 71 | } |