Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2020, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef __SPCI_HELPERS_H__ |
| 8 | #define __SPCI_HELPERS_H__ |
| 9 | |
| 10 | |
| 11 | #include <spci_svc.h> |
| 12 | #include "tftf_lib.h" |
| 13 | |
| 14 | #define SPM_VM_ID_FIRST (1) |
| 15 | |
| 16 | #define SPM_VM_GET_COUNT (0xFF01) |
| 17 | #define SPM_VCPU_GET_COUNT (0xFF02) |
| 18 | #define SPM_DEBUG_LOG (0xBD000000) |
| 19 | |
| 20 | /* Hypervisor ID at physical SPCI instance */ |
| 21 | #define HYP_ID (0) |
| 22 | |
| 23 | /* By convention, SP IDs (as opposed to VM IDs) have bit 15 set */ |
| 24 | #define SP_ID(x) ((x) | (1 << 15)) |
| 25 | |
| 26 | typedef unsigned short spci_vm_id_t; |
| 27 | typedef unsigned short spci_vm_count_t; |
| 28 | typedef unsigned short spci_vcpu_count_t; |
| 29 | |
| 30 | /* Functions */ |
| 31 | |
| 32 | static inline spci_vcpu_count_t spm_vcpu_get_count(spci_vm_id_t vm_id) |
| 33 | { |
| 34 | hvc_args args = { |
| 35 | .fid = SPM_VCPU_GET_COUNT, |
| 36 | .arg1 = vm_id |
| 37 | }; |
| 38 | |
| 39 | hvc_ret_values ret = tftf_hvc(&args); |
| 40 | |
| 41 | return ret.ret0; |
| 42 | } |
| 43 | |
| 44 | static inline spci_vm_count_t spm_vm_get_count(void) |
| 45 | { |
| 46 | hvc_args args = { |
| 47 | .fid = SPM_VM_GET_COUNT |
| 48 | }; |
| 49 | |
| 50 | hvc_ret_values ret = tftf_hvc(&args); |
| 51 | |
| 52 | return ret.ret0; |
| 53 | } |
| 54 | |
| 55 | static inline void spm_debug_log(char c) |
| 56 | { |
| 57 | hvc_args args = { |
| 58 | .fid = SPM_DEBUG_LOG, |
| 59 | .arg1 = c |
| 60 | }; |
| 61 | |
| 62 | (void)tftf_hvc(&args); |
| 63 | } |
| 64 | |
| 65 | static inline smc_ret_values spci_id_get(void) |
| 66 | { |
| 67 | smc_args args = { |
| 68 | .fid = SPCI_ID_GET |
| 69 | }; |
| 70 | |
| 71 | return tftf_smc(&args); |
| 72 | } |
| 73 | |
| 74 | static inline smc_ret_values spci_msg_wait(void) |
| 75 | { |
| 76 | smc_args args = { |
| 77 | .fid = SPCI_MSG_WAIT |
| 78 | }; |
| 79 | |
| 80 | return tftf_smc(&args); |
| 81 | } |
| 82 | |
| 83 | /* Send response through registers using direct messaging */ |
| 84 | static inline smc_ret_values spci_msg_send_direct_resp(spci_vm_id_t sender_vm_id, |
| 85 | spci_vm_id_t target_vm_id, |
| 86 | uint32_t message) |
| 87 | { |
| 88 | smc_args args = { |
| 89 | .fid = SPCI_MSG_SEND_DIRECT_RESP_SMC32, |
| 90 | .arg1 = ((uint32_t)sender_vm_id << 16) | target_vm_id, |
| 91 | .arg3 = message |
| 92 | }; |
| 93 | |
| 94 | return tftf_smc(&args); |
| 95 | } |
| 96 | |
| 97 | static inline smc_ret_values spci_error(int32_t error_code) |
| 98 | { |
| 99 | smc_args args = { |
| 100 | .fid = SPCI_ERROR, |
| 101 | .arg1 = 0, |
| 102 | .arg2 = error_code |
| 103 | }; |
| 104 | |
| 105 | return tftf_smc(&args); |
| 106 | } |
| 107 | |
| 108 | #endif /* __SPCI_HELPERS_H__ */ |