blob: c4d436e1ce3f550370127a4dc3572de163d87744 [file] [log] [blame]
Antonio Nino Diaz9bf1d232018-11-08 09:21:48 +00001/*
2 * Copyright (c) 2018, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <errno.h>
8#include <stddef.h>
9#include <stdint.h>
10
11#include "sprt_common.h"
12#include "sprt_queue.h"
13
14void sprt_initialize_queues(void *buffer_base, size_t buffer_size)
15{
16 /* Initialize queue for blocking messages */
17
18 void *blocking_base = buffer_base;
19 uint32_t blocking_num = 4U;
20 size_t blocking_size = SPRT_QUEUE_HEADER_SIZE +
21 SPRT_QUEUE_ENTRY_MSG_SIZE * blocking_num;
22
23 sprt_queue_init(blocking_base, blocking_num, SPRT_QUEUE_ENTRY_MSG_SIZE);
24
25 /* Initialize queue for non-blocking messages */
26
27 void *non_blocking_base = (void *)((uintptr_t)blocking_base + blocking_size);
28 size_t non_blocking_size = buffer_size - blocking_size;
29 uint32_t non_blocking_num = (non_blocking_size - SPRT_QUEUE_HEADER_SIZE) /
30 SPRT_QUEUE_ENTRY_MSG_SIZE;
31
32 sprt_queue_init(non_blocking_base, non_blocking_num, SPRT_QUEUE_ENTRY_MSG_SIZE);
33}
34
35int sprt_push_message(void *buffer_base,
36 const struct sprt_queue_entry_message *message,
37 int queue_num)
38{
39 struct sprt_queue *q = buffer_base;
40
41 while (queue_num-- > 0) {
42 uintptr_t next_addr = (uintptr_t)q + sizeof(struct sprt_queue) +
43 q->entry_num * q->entry_size;
44 q = (struct sprt_queue *) next_addr;
45 }
46
47 return sprt_queue_push(q, message);
48}