Antonio Nino Diaz | 26b3864 | 2019-03-28 13:16:04 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2018-2019, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
| 8 | #include <cdefs.h> |
| 9 | #include <errno.h> |
| 10 | #include <quark_def.h> |
| 11 | #include <sprt_client.h> |
| 12 | #include <sprt_svc.h> |
| 13 | #include <utils_def.h> |
| 14 | |
| 15 | #include "quark.h" |
| 16 | #include "quark_def.h" |
| 17 | |
| 18 | /* NOTE: This partition doesn't have text output capabilities */ |
| 19 | |
| 20 | static void quark_message_handler(struct sprt_queue_entry_message *message) |
| 21 | { |
| 22 | u_register_t ret0 = 0U, ret1 = 0U, ret2 = 0U, ret3 = 0U; |
| 23 | |
| 24 | if (message->type == SPRT_MSG_TYPE_SERVICE_REQUEST) { |
| 25 | switch (message->args[1]) { |
| 26 | |
| 27 | case QUARK_GET_MAGIC: |
| 28 | ret1 = QUARK_MAGIC_NUMBER; |
| 29 | ret0 = SPRT_SUCCESS; |
| 30 | break; |
| 31 | |
| 32 | default: |
| 33 | ret0 = SPRT_NOT_SUPPORTED; |
| 34 | break; |
| 35 | } |
| 36 | } else { |
| 37 | ret0 = SPRT_NOT_SUPPORTED; |
| 38 | } |
| 39 | |
| 40 | sprt_message_end(message, ret0, ret1, ret2, ret3); |
| 41 | } |
| 42 | |
| 43 | void __dead2 quark_main(void) |
| 44 | { |
| 45 | /* |
| 46 | * Handle secure service requests. |
| 47 | */ |
| 48 | sprt_initialize_queues((void *)QUARK_SPM_BUF_BASE); |
| 49 | |
| 50 | while (1) { |
| 51 | struct sprt_queue_entry_message message; |
| 52 | |
| 53 | /* |
| 54 | * Try to fetch a message from the blocking requests queue. If |
| 55 | * it is empty, try to fetch from the non-blocking requests |
| 56 | * queue. Repeat until both of them are empty. |
| 57 | */ |
| 58 | while (1) { |
| 59 | int err = sprt_get_next_message(&message, |
| 60 | SPRT_QUEUE_NUM_BLOCKING); |
| 61 | if (err == -ENOENT) { |
| 62 | err = sprt_get_next_message(&message, |
| 63 | SPRT_QUEUE_NUM_NON_BLOCKING); |
| 64 | if (err == -ENOENT) { |
| 65 | break; |
| 66 | } else { |
| 67 | assert(err == 0); |
| 68 | quark_message_handler(&message); |
| 69 | } |
| 70 | } else { |
| 71 | assert(err == 0); |
| 72 | quark_message_handler(&message); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | sprt_wait_for_messages(); |
| 77 | } |
| 78 | } |