blob: e57b839a2be3a980a7690832c9831eb69879ac70 [file] [log] [blame]
Anton Komlev4bfd6c52022-06-29 17:10:26 +01001/*
Jackson Cooper-Driver90d89a02025-03-03 16:41:37 +00002 * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
Anton Komlev4bfd6c52022-06-29 17:10:26 +01003 *
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"
Jackson Cooper-Driver90d89a02025-03-03 16:41:37 +000012#include "tfm_log_unpriv.h"
Anton Komlev4bfd6c52022-06-29 17:10:26 +010013
14/**
15 * \brief An example service implementation that prints out an argument from the
Kevin Pengf04486e2022-08-09 10:04:02 +080016 * client.
Anton Komlev4bfd6c52022-06-29 17:10:26 +010017 */
Kevin Penga9ec66f2022-07-05 15:21:16 +080018psa_status_t tfm_example_service_sfn(const psa_msg_t *msg)
Anton Komlev4bfd6c52022-06-29 17:10:26 +010019{
20 psa_status_t status;
21 uint32_t arg;
Anton Komlev4bfd6c52022-06-29 17:10:26 +010022
23 /* Decode the message */
Kevin Penga9ec66f2022-07-05 15:21:16 +080024 switch (msg->type) {
Anton Komlev4bfd6c52022-06-29 17:10:26 +010025 case PSA_IPC_CONNECT:
26 case PSA_IPC_DISCONNECT:
Kevin Penga9ec66f2022-07-05 15:21:16 +080027 /*
28 * This service does not require any setup or teardown on connect or
Anton Komlev4bfd6c52022-06-29 17:10:26 +010029 * disconnect, so just reply with success.
30 */
31 status = PSA_SUCCESS;
32 break;
33 case PSA_IPC_CALL:
Kevin Penga9ec66f2022-07-05 15:21:16 +080034 if (msg->in_size[0] != sizeof(arg)) {
Anton Komlev4bfd6c52022-06-29 17:10:26 +010035 status = PSA_ERROR_PROGRAMMER_ERROR;
36 break;
37 }
38
39 /* Print arg from client */
Kevin Penga9ec66f2022-07-05 15:21:16 +080040 psa_read(msg->handle, 0, &arg, sizeof(arg));
Jackson Cooper-Driver90d89a02025-03-03 16:41:37 +000041 INFO_UNPRIV_RAW("[Example partition] Service called! arg=%x\n", arg);
Anton Komlev4bfd6c52022-06-29 17:10:26 +010042
Anton Komlev4bfd6c52022-06-29 17:10:26 +010043 status = PSA_SUCCESS;
44 break;
45 default:
46 /* Invalid message type */
47 status = PSA_ERROR_PROGRAMMER_ERROR;
48 break;
49 }
50
Kevin Penga9ec66f2022-07-05 15:21:16 +080051 return status;
Anton Komlev4bfd6c52022-06-29 17:10:26 +010052}
53
54/**
55 * \brief The example partition's entry function.
56 */
Kevin Penga9ec66f2022-07-05 15:21:16 +080057psa_status_t tfm_example_partition_main(void)
Anton Komlev4bfd6c52022-06-29 17:10:26 +010058{
Jackson Cooper-Driver90d89a02025-03-03 16:41:37 +000059 INFO_UNPRIV_RAW("Example Partition initializing\n");
Anton Komlev4bfd6c52022-06-29 17:10:26 +010060
Kevin Penga9ec66f2022-07-05 15:21:16 +080061 return PSA_SUCCESS;
Anton Komlev4bfd6c52022-06-29 17:10:26 +010062}