blob: 189df9aacd94668613daf31a8ac890e4e57a66d5 [file] [log] [blame]
Manish Pandey29495372020-04-09 15:19:26 +01001/*
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
26typedef unsigned short spci_vm_id_t;
27typedef unsigned short spci_vm_count_t;
28typedef unsigned short spci_vcpu_count_t;
29
30/* Functions */
31
32static 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
44static 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
55static 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
65static 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
74static 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 */
84static 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
97static 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__ */