aboutsummaryrefslogtreecommitdiff
path: root/secure_fw/spm/cmsis_psa/tfm_rpc.c
blob: 5872649edb9b306a5797d932f39ccbb9f6e1740c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
 * Copyright (c) 2019-2021, Arm Limited. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 *
 */

#include "spm_ipc.h"
#include "ffm/spm_psa_client_call.h"
#include "tfm_rpc.h"
#include "utilities.h"
#include "load/partition_defs.h"

static void default_handle_req(void)
{
}

static void default_mailbox_reply(const void *owner, int32_t ret)
{
    (void)owner;
    (void)ret;
}

static const void *default_get_caller_data(int32_t client_id)
{
    (void)client_id;

    return NULL;
}

static struct tfm_rpc_ops_t rpc_ops = {
    .handle_req = default_handle_req,
    .reply      = default_mailbox_reply,
    .get_caller_data = default_get_caller_data,
};

uint32_t tfm_rpc_psa_framework_version(void)
{
    return tfm_spm_client_psa_framework_version();
}

uint32_t tfm_rpc_psa_version(const struct client_call_params_t *params,
                             bool ns_caller)
{
    TFM_CORE_ASSERT(params != NULL);

    return tfm_spm_client_psa_version(params->sid, ns_caller);
}

psa_status_t tfm_rpc_psa_connect(const struct client_call_params_t *params,
                                 bool ns_caller)
{
    TFM_CORE_ASSERT(params != NULL);

    return tfm_spm_client_psa_connect(params->sid, params->version, ns_caller);
}

psa_status_t tfm_rpc_psa_call(const struct client_call_params_t *params,
                              bool ns_caller)
{
    TFM_CORE_ASSERT(params != NULL);

    return tfm_spm_client_psa_call(params->handle, params->type,
                                   params->in_vec, params->in_len,
                                   params->out_vec, params->out_len, ns_caller,
                                   TFM_PARTITION_UNPRIVILEGED_MODE);
}

void tfm_rpc_psa_close(const struct client_call_params_t *params,
                       bool ns_caller)
{
    TFM_CORE_ASSERT(params != NULL);

    tfm_spm_client_psa_close(params->handle, ns_caller);
}

int32_t tfm_rpc_register_ops(const struct tfm_rpc_ops_t *ops_ptr)
{
    if (!ops_ptr) {
        return TFM_RPC_INVAL_PARAM;
    }

    if (!ops_ptr->handle_req || !ops_ptr->reply || !ops_ptr->get_caller_data) {
        return TFM_RPC_INVAL_PARAM;
    }

    /* Currently, one and only one mailbox implementation is supported. */
    if ((rpc_ops.handle_req != default_handle_req) ||
        (rpc_ops.reply != default_mailbox_reply) || \
        (rpc_ops.get_caller_data != default_get_caller_data)) {
        return TFM_RPC_CONFLICT_CALLBACK;
    }

    rpc_ops.handle_req = ops_ptr->handle_req;
    rpc_ops.reply = ops_ptr->reply;
    rpc_ops.get_caller_data = ops_ptr->get_caller_data;

    return TFM_RPC_SUCCESS;
}

void tfm_rpc_unregister_ops(void)
{
    rpc_ops.handle_req = default_handle_req;
    rpc_ops.reply = default_mailbox_reply;
    rpc_ops.get_caller_data = default_get_caller_data;
}

void tfm_rpc_client_call_handler(void)
{
    rpc_ops.handle_req();
}

void tfm_rpc_client_call_reply(const void *owner, int32_t ret)
{
    const struct tfm_msg_body_t *msg = (const struct tfm_msg_body_t *)owner;

    rpc_ops.reply(msg->caller_data, ret);
}

void tfm_rpc_set_caller_data(struct tfm_msg_body_t *msg, int32_t client_id)
{
    msg->caller_data = rpc_ops.get_caller_data(client_id);
}