Antonio Nino Diaz | e46924e | 2018-11-08 10:58:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
| 8 | #include <errno.h> |
| 9 | #include <sprt_svc.h> |
| 10 | #include <stddef.h> |
| 11 | |
| 12 | #include "sprt_client.h" |
| 13 | #include "sprt_client_private.h" |
| 14 | #include "sprt_common.h" |
| 15 | #include "sprt_queue.h" |
| 16 | |
| 17 | uint32_t sprt_version(void) |
| 18 | { |
| 19 | struct svc_args args; |
| 20 | |
| 21 | args.arg0 = SPRT_VERSION; |
| 22 | |
| 23 | return sprt_client_svc(&args); |
| 24 | } |
| 25 | |
| 26 | void sprt_wait_for_messages(void) |
| 27 | { |
| 28 | struct svc_args args; |
| 29 | |
| 30 | args.arg0 = SPRT_YIELD_AARCH64; |
| 31 | |
| 32 | sprt_client_svc(&args); |
| 33 | } |
| 34 | |
| 35 | /* |
| 36 | * Variable that points to the memory buffer that contains the queues used by |
| 37 | * this Secure Partition. |
| 38 | */ |
| 39 | static void *queue_messages; |
| 40 | |
| 41 | void sprt_initialize_queues(void *buffer_base) |
| 42 | { |
| 43 | queue_messages = buffer_base; |
| 44 | } |
| 45 | |
| 46 | int sprt_get_next_message(struct sprt_queue_entry_message *message, |
| 47 | int queue_num) |
| 48 | { |
| 49 | struct sprt_queue *q = queue_messages; |
| 50 | |
| 51 | while (queue_num-- > 0) { |
| 52 | uintptr_t next_addr = (uintptr_t)q + sizeof(struct sprt_queue) + |
| 53 | q->entry_num * q->entry_size; |
| 54 | q = (struct sprt_queue *) next_addr; |
| 55 | } |
| 56 | |
| 57 | return sprt_queue_pop(q, message); |
| 58 | } |
| 59 | |
| 60 | void sprt_message_end(struct sprt_queue_entry_message *message, |
| 61 | u_register_t arg0, u_register_t arg1, u_register_t arg2, |
| 62 | u_register_t arg3) |
| 63 | { |
| 64 | struct svc_args args; |
| 65 | |
| 66 | if (message->type == SPRT_MSG_TYPE_SERVICE_REQUEST) { |
| 67 | args.arg0 = SPRT_PUT_RESPONSE_AARCH64; |
| 68 | args.arg1 = message->token; |
| 69 | } |
| 70 | |
| 71 | args.arg2 = arg0; |
| 72 | args.arg3 = arg1; |
| 73 | args.arg4 = arg2; |
| 74 | args.arg5 = arg3; |
| 75 | args.arg6 = ((uint32_t)message->service_handle << 16U) |
| 76 | | message->client_id; |
| 77 | args.arg7 = message->session_id; |
| 78 | |
| 79 | sprt_client_svc(&args); |
| 80 | } |