blob: 804179f22f1ce7e513fbf44f16ee6a7f33bc1219 [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>
12#include <utils_def.h>
13
14enum buffer_slot {
15 /*
16 * NS.
17 */
18 SLOT_NS,
19
20 /*
21 * RMM-private.
22 */
23 SLOT_DELEGATED,
24 SLOT_RD,
25 SLOT_REC,
26 SLOT_REC2, /* Some commands access two REC granules at a time*/
27 SLOT_REC_TARGET, /* Target REC for interrupts */
28 SLOT_REC_AUX0, /* Reserve slots for max rec auxiliary granules
29 * so that all of them can be mapped at once.
30 * If the max aux granules is 0, no slots will
31 * be reserved.
32 */
33 SLOT_RTT = SLOT_REC_AUX0 + MAX_REC_AUX_GRANULES,
34 SLOT_RTT2, /* Some commands access two RTT granules at a time*/
35 SLOT_RSI_CALL,
36 NR_CPU_SLOTS
37};
38
39struct granule;
40
41void assert_cpu_slots_empty(void);
42void *granule_map(struct granule *g, enum buffer_slot slot);
43void buffer_unmap(void *buf);
44
45bool ns_buffer_read(enum buffer_slot slot,
46 struct granule *granule,
47 unsigned int offset,
48 unsigned int size,
49 void *dest);
50bool ns_buffer_write(enum buffer_slot slot,
51 struct granule *granule,
52 unsigned int offset,
53 unsigned int size,
54 void *src);
55
56/*
57 * Initializes and enables the VMSA for the slot buffer mechanism.
58 *
59 * Create an empty translation context for the current CPU.
60 * If the context already exists (e.g. current CPU was previously
61 * turned on and therefore the context is already in memory),
62 * nothing happens.
63 */
64void slot_buf_setup_xlat(void);
65
66/*
67 * Finishes initializing the slot buffer mechanism.
68 * This function should be called after the MMU is enabled.
69 */
70void slot_buf_init(void);
71
72/******************************************************************************
73 * Internal APIs not meant to be invoked by generic RMM code.
74 * These are exposed to facilitate testing.
75 *****************************************************************************/
76
77/*
78 * Maps a given PA into the specified slot. This API verifies that the slot
79 * matches the 'ns' argument.
80 *
81 * On success, it returns the VA of the slot where the PA has been mapped to.
82 * Otherwise, it will return NULL.
83 */
84void *buffer_map_internal(enum buffer_slot slot, unsigned long addr, bool ns);
85
86/*
87 * Unmaps the slot buffer corresponding to the VA passed via `buf` argument.
88 */
89void buffer_unmap_internal(void *buf);
90
91#endif /* BUFFER_H */