Anton Komlev | 4bfd6c5 | 2022-06-29 17:10:26 +0100 | [diff] [blame] | 1 | /* |
Jackson Cooper-Driver | 90d89a0 | 2025-03-03 16:41:37 +0000 | [diff] [blame^] | 2 | * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors |
Anton Komlev | 4bfd6c5 | 2022-06-29 17:10:26 +0100 | [diff] [blame] | 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" |
Jackson Cooper-Driver | 90d89a0 | 2025-03-03 16:41:37 +0000 | [diff] [blame^] | 12 | #include "tfm_log_unpriv.h" |
Anton Komlev | 4bfd6c5 | 2022-06-29 17:10:26 +0100 | [diff] [blame] | 13 | |
| 14 | /** |
| 15 | * \brief An example service implementation that prints out an argument from the |
Kevin Peng | f04486e | 2022-08-09 10:04:02 +0800 | [diff] [blame] | 16 | * client. |
Anton Komlev | 4bfd6c5 | 2022-06-29 17:10:26 +0100 | [diff] [blame] | 17 | */ |
Kevin Peng | a9ec66f | 2022-07-05 15:21:16 +0800 | [diff] [blame] | 18 | psa_status_t tfm_example_service_sfn(const psa_msg_t *msg) |
Anton Komlev | 4bfd6c5 | 2022-06-29 17:10:26 +0100 | [diff] [blame] | 19 | { |
| 20 | psa_status_t status; |
| 21 | uint32_t arg; |
Anton Komlev | 4bfd6c5 | 2022-06-29 17:10:26 +0100 | [diff] [blame] | 22 | |
| 23 | /* Decode the message */ |
Kevin Peng | a9ec66f | 2022-07-05 15:21:16 +0800 | [diff] [blame] | 24 | switch (msg->type) { |
Anton Komlev | 4bfd6c5 | 2022-06-29 17:10:26 +0100 | [diff] [blame] | 25 | case PSA_IPC_CONNECT: |
| 26 | case PSA_IPC_DISCONNECT: |
Kevin Peng | a9ec66f | 2022-07-05 15:21:16 +0800 | [diff] [blame] | 27 | /* |
| 28 | * This service does not require any setup or teardown on connect or |
Anton Komlev | 4bfd6c5 | 2022-06-29 17:10:26 +0100 | [diff] [blame] | 29 | * disconnect, so just reply with success. |
| 30 | */ |
| 31 | status = PSA_SUCCESS; |
| 32 | break; |
| 33 | case PSA_IPC_CALL: |
Kevin Peng | a9ec66f | 2022-07-05 15:21:16 +0800 | [diff] [blame] | 34 | if (msg->in_size[0] != sizeof(arg)) { |
Anton Komlev | 4bfd6c5 | 2022-06-29 17:10:26 +0100 | [diff] [blame] | 35 | status = PSA_ERROR_PROGRAMMER_ERROR; |
| 36 | break; |
| 37 | } |
| 38 | |
| 39 | /* Print arg from client */ |
Kevin Peng | a9ec66f | 2022-07-05 15:21:16 +0800 | [diff] [blame] | 40 | psa_read(msg->handle, 0, &arg, sizeof(arg)); |
Jackson Cooper-Driver | 90d89a0 | 2025-03-03 16:41:37 +0000 | [diff] [blame^] | 41 | INFO_UNPRIV_RAW("[Example partition] Service called! arg=%x\n", arg); |
Anton Komlev | 4bfd6c5 | 2022-06-29 17:10:26 +0100 | [diff] [blame] | 42 | |
Anton Komlev | 4bfd6c5 | 2022-06-29 17:10:26 +0100 | [diff] [blame] | 43 | status = PSA_SUCCESS; |
| 44 | break; |
| 45 | default: |
| 46 | /* Invalid message type */ |
| 47 | status = PSA_ERROR_PROGRAMMER_ERROR; |
| 48 | break; |
| 49 | } |
| 50 | |
Kevin Peng | a9ec66f | 2022-07-05 15:21:16 +0800 | [diff] [blame] | 51 | return status; |
Anton Komlev | 4bfd6c5 | 2022-06-29 17:10:26 +0100 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /** |
| 55 | * \brief The example partition's entry function. |
| 56 | */ |
Kevin Peng | a9ec66f | 2022-07-05 15:21:16 +0800 | [diff] [blame] | 57 | psa_status_t tfm_example_partition_main(void) |
Anton Komlev | 4bfd6c5 | 2022-06-29 17:10:26 +0100 | [diff] [blame] | 58 | { |
Jackson Cooper-Driver | 90d89a0 | 2025-03-03 16:41:37 +0000 | [diff] [blame^] | 59 | INFO_UNPRIV_RAW("Example Partition initializing\n"); |
Anton Komlev | 4bfd6c5 | 2022-06-29 17:10:26 +0100 | [diff] [blame] | 60 | |
Kevin Peng | a9ec66f | 2022-07-05 15:21:16 +0800 | [diff] [blame] | 61 | return PSA_SUCCESS; |
Anton Komlev | 4bfd6c5 | 2022-06-29 17:10:26 +0100 | [diff] [blame] | 62 | } |