blob: af2306e17ac30e24d7b18e0ab8a35a8d372c35fe [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 */
34 SLOT_RTT = SLOT_REC_AUX0 + MAX_REC_AUX_GRANULES,
35 SLOT_RTT2, /* Some commands access two RTT granules at a time*/
36 SLOT_RSI_CALL,
37 NR_CPU_SLOTS
38};
39
40struct granule;
41
42void assert_cpu_slots_empty(void);
43void *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);
51bool ns_buffer_write(enum buffer_slot slot,
AlexeiFedorov950bd7b2023-08-24 15:25:22 +010052 struct granule *ns_gr,
Soby Mathewb4c6df42022-11-09 11:13:29 +000053 unsigned int offset,
AlexeiFedorov4faab852023-08-30 15:06:49 +010054 size_t size,
Soby Mathewb4c6df42022-11-09 11:13:29 +000055 void *src);
56
57/*
Javier Almansa Sobrinoed932592023-01-24 12:50:41 +000058 * Finishes initializing the slot buffer mechanism.
59 * This function should be called after the MMU is enabled, during the
60 * warmboot path.
61 */
62void slot_buf_finish_warmboot_init(void);
Soby Mathewb4c6df42022-11-09 11:13:29 +000063
64/******************************************************************************
65 * Internal APIs not meant to be invoked by generic RMM code.
66 * These are exposed to facilitate testing.
67 *****************************************************************************/
68
69/*
Javier Almansa Sobrinod528efd2023-01-05 16:23:54 +000070 * Maps a given PA into the specified slot.
Soby Mathewb4c6df42022-11-09 11:13:29 +000071 *
72 * On success, it returns the VA of the slot where the PA has been mapped to.
73 * Otherwise, it will return NULL.
74 */
Javier Almansa Sobrinod528efd2023-01-05 16:23:54 +000075void *buffer_map_internal(enum buffer_slot slot, unsigned long addr);
Soby Mathewb4c6df42022-11-09 11:13:29 +000076
77/*
78 * Unmaps the slot buffer corresponding to the VA passed via `buf` argument.
79 */
80void buffer_unmap_internal(void *buf);
81
82#endif /* BUFFER_H */