blob: 7cb0a391a4bf288342dcb4b4925882b97f72ec5a [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 *
Javier Almansa Sobrinoed932592023-01-24 12:50:41 +000059 * Create an empty translation context for the current PE.
60 * If the context already exists (e.g. current PE was previously
Soby Mathewb4c6df42022-11-09 11:13:29 +000061 * turned on and therefore the context is already in memory),
62 * nothing happens.
63 */
64void slot_buf_setup_xlat(void);
65
66/*
Javier Almansa Sobrinoed932592023-01-24 12:50:41 +000067 * Initializes the slot buffer components common to all PEs. This function
68 * must only be called once during cold boot initialization.
69 *
70 * Returns 0 on success and a negative POSIX error code otherwise.
Soby Mathewb4c6df42022-11-09 11:13:29 +000071 */
Javier Almansa Sobrinoed932592023-01-24 12:50:41 +000072int slot_buf_coldboot_init(void);
73
74/*
75 * Finishes initializing the slot buffer mechanism.
76 * This function should be called after the MMU is enabled, during the
77 * warmboot path.
78 */
79void slot_buf_finish_warmboot_init(void);
Soby Mathewb4c6df42022-11-09 11:13:29 +000080
81/******************************************************************************
82 * Internal APIs not meant to be invoked by generic RMM code.
83 * These are exposed to facilitate testing.
84 *****************************************************************************/
85
86/*
Javier Almansa Sobrinod528efd2023-01-05 16:23:54 +000087 * Maps a given PA into the specified slot.
Soby Mathewb4c6df42022-11-09 11:13:29 +000088 *
89 * On success, it returns the VA of the slot where the PA has been mapped to.
90 * Otherwise, it will return NULL.
91 */
Javier Almansa Sobrinod528efd2023-01-05 16:23:54 +000092void *buffer_map_internal(enum buffer_slot slot, unsigned long addr);
Soby Mathewb4c6df42022-11-09 11:13:29 +000093
94/*
95 * Unmaps the slot buffer corresponding to the VA passed via `buf` argument.
96 */
97void buffer_unmap_internal(void *buf);
98
99#endif /* BUFFER_H */