blob: 7a1eeb4a5848ca55b1b4973c127eb7647e865579 [file] [log] [blame]
Anton Komlev4bfd6c52022-06-29 17:10:26 +01001/*
2 * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#include <stdint.h>
9
10#include "psa/service.h"
11#include "psa_manifest/tfm_example_partition.h"
12#include "tfm/tfm_spm_services.h"
13#include "tfm_plat_test.h"
14#include "tfm_sp_log.h"
15
16/**
17 * \brief An example service implementation that prints out an argument from the
18 * client and then starts a timer.
19 */
20static void tfm_example_service(void)
21{
22 psa_status_t status;
23 uint32_t arg;
24 psa_msg_t msg;
25
26 /* Retrieve the message corresponding to the example service signal */
27 status = psa_get(TFM_EXAMPLE_SERVICE_SIGNAL, &msg);
28 if (status != PSA_SUCCESS) {
29 return;
30 }
31
32 /* Decode the message */
33 switch (msg.type) {
34 case PSA_IPC_CONNECT:
35 case PSA_IPC_DISCONNECT:
36 /* This service does not require any setup or teardown on connect or
37 * disconnect, so just reply with success.
38 */
39 status = PSA_SUCCESS;
40 break;
41 case PSA_IPC_CALL:
42 if (msg.in_size[0] != sizeof(arg)) {
43 status = PSA_ERROR_PROGRAMMER_ERROR;
44 break;
45 }
46
47 /* Print arg from client */
48 psa_read(msg.handle, 0, &arg, sizeof(arg));
49 LOG_INFFMT("[Example partition] Service called! arg=%p\r\n", arg);
50
51 /* Start timer. The interrupt triggered when it expires will be handled
52 * by tfm_example_timer_handler().
53 */
54 tfm_plat_test_secure_timer_start();
55 LOG_INFFMT("[Example partition] Timer started...\r\n");
56
57 status = PSA_SUCCESS;
58 break;
59 default:
60 /* Invalid message type */
61 status = PSA_ERROR_PROGRAMMER_ERROR;
62 break;
63 }
64
65 /* Reply with the message result status to unblock the client */
66 psa_reply(msg.handle, status);
67}
68
69/**
70 * \brief An example interrupt handler.
71 */
72static void tfm_example_timer_handler(void)
73{
74 /* Stop timer */
75 tfm_plat_test_secure_timer_stop();
76 /* Inform the SPM that the timer interrupt has been handled */
77 psa_eoi(TFM_EXAMPLE_SIGNAL_TIMER_0_IRQ);
78}
79
80/**
81 * \brief The example partition's entry function.
82 */
83void tfm_example_partition_main(void)
84{
85 psa_signal_t signals;
86
87 /* Enable timer IRQ */
88 psa_irq_enable(TFM_EXAMPLE_SIGNAL_TIMER_0_IRQ);
89
90 /* Continually wait for one or more of the partition's RoT Service or
91 * interrupt signals to be asserted and then handle the asserted signal(s).
92 */
93 while (1) {
94 signals = psa_wait(PSA_WAIT_ANY, PSA_BLOCK);
95
96 if (signals & TFM_EXAMPLE_SERVICE_SIGNAL) {
97 tfm_example_service();
98 }
99 if (signals & TFM_EXAMPLE_SIGNAL_TIMER_0_IRQ) {
100 tfm_example_timer_handler();
101 }
102 }
103}