blob: 20ea2db5ef1d4c11e5d01f03436da749a08821cf [file] [log] [blame]
Soby Mathewb4c6df42022-11-09 11:13:29 +00001/*
2 * SPDX-License-Identifier: BSD-3-Clause
3 * SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
4 */
5
6#ifndef BUFFER_H
7#define BUFFER_H
8
9#include <assert.h>
10#include <smc-rmi.h>
11#include <stdbool.h>
AlexeiFedorov4faab852023-08-30 15:06:49 +010012#include <stddef.h>
Soby Mathewb4c6df42022-11-09 11:13:29 +000013#include <utils_def.h>
14
15enum buffer_slot {
16 /*
17 * NS.
18 */
19 SLOT_NS,
20
21 /*
22 * RMM-private.
23 */
24 SLOT_DELEGATED,
25 SLOT_RD,
26 SLOT_REC,
27 SLOT_REC2, /* Some commands access two REC granules at a time*/
28 SLOT_REC_TARGET, /* Target REC for interrupts */
29 SLOT_REC_AUX0, /* Reserve slots for max rec auxiliary granules
30 * so that all of them can be mapped at once.
31 * If the max aux granules is 0, no slots will
32 * be reserved.
33 */
Shruti Gupta0e378132023-12-05 10:06:46 +000034 SLOT_RTT = U(SLOT_REC_AUX0) + MAX_REC_AUX_GRANULES,
Soby Mathewb4c6df42022-11-09 11:13:29 +000035 SLOT_RTT2, /* Some commands access two RTT granules at a time*/
36 SLOT_RSI_CALL,
37 NR_CPU_SLOTS
38};
39
40struct granule;
41
AlexeiFedorov7c38ef42023-11-28 11:39:19 +000042bool check_cpu_slots_empty(void);
Soby Mathewb4c6df42022-11-09 11:13:29 +000043void *granule_map(struct granule *g, enum buffer_slot slot);
44void buffer_unmap(void *buf);
45
46bool ns_buffer_read(enum buffer_slot slot,
AlexeiFedorov950bd7b2023-08-24 15:25:22 +010047 struct granule *ns_gr,
Soby Mathewb4c6df42022-11-09 11:13:29 +000048 unsigned int offset,
AlexeiFedorov4faab852023-08-30 15:06:49 +010049 size_t size,
Soby Mathewb4c6df42022-11-09 11:13:29 +000050 void *dest);
AlexeiFedorov7c38ef42023-11-28 11:39:19 +000051
Soby Mathewb4c6df42022-11-09 11:13:29 +000052bool ns_buffer_write(enum buffer_slot slot,
AlexeiFedorov950bd7b2023-08-24 15:25:22 +010053 struct granule *ns_gr,
Soby Mathewb4c6df42022-11-09 11:13:29 +000054 unsigned int offset,
AlexeiFedorov4faab852023-08-30 15:06:49 +010055 size_t size,
Soby Mathewb4c6df42022-11-09 11:13:29 +000056 void *src);
57
58/*
Javier Almansa Sobrinoed932592023-01-24 12:50:41 +000059 * Finishes initializing the slot buffer mechanism.
60 * This function should be called after the MMU is enabled, during the
61 * warmboot path.
62 */
63void slot_buf_finish_warmboot_init(void);
Soby Mathewb4c6df42022-11-09 11:13:29 +000064
65/******************************************************************************
66 * Internal APIs not meant to be invoked by generic RMM code.
67 * These are exposed to facilitate testing.
68 *****************************************************************************/
69
70/*
Javier Almansa Sobrinod528efd2023-01-05 16:23:54 +000071 * Maps a given PA into the specified slot.
Soby Mathewb4c6df42022-11-09 11:13:29 +000072 *
73 * On success, it returns the VA of the slot where the PA has been mapped to.
74 * Otherwise, it will return NULL.
75 */
Javier Almansa Sobrinod528efd2023-01-05 16:23:54 +000076void *buffer_map_internal(enum buffer_slot slot, unsigned long addr);
Soby Mathewb4c6df42022-11-09 11:13:29 +000077
78/*
79 * Unmaps the slot buffer corresponding to the VA passed via `buf` argument.
80 */
81void buffer_unmap_internal(void *buf);
82
83#endif /* BUFFER_H */