Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 14 | enum 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 | |
| 39 | struct granule; |
| 40 | |
| 41 | void assert_cpu_slots_empty(void); |
| 42 | void *granule_map(struct granule *g, enum buffer_slot slot); |
| 43 | void buffer_unmap(void *buf); |
| 44 | |
| 45 | bool ns_buffer_read(enum buffer_slot slot, |
AlexeiFedorov | 950bd7b | 2023-08-24 15:25:22 +0100 | [diff] [blame^] | 46 | struct granule *ns_gr, |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 47 | unsigned int offset, |
| 48 | unsigned int size, |
| 49 | void *dest); |
| 50 | bool ns_buffer_write(enum buffer_slot slot, |
AlexeiFedorov | 950bd7b | 2023-08-24 15:25:22 +0100 | [diff] [blame^] | 51 | struct granule *ns_gr, |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 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 Sobrino | ed93259 | 2023-01-24 12:50:41 +0000 | [diff] [blame] | 59 | * Create an empty translation context for the current PE. |
| 60 | * If the context already exists (e.g. current PE was previously |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 61 | * turned on and therefore the context is already in memory), |
| 62 | * nothing happens. |
| 63 | */ |
| 64 | void slot_buf_setup_xlat(void); |
| 65 | |
| 66 | /* |
Javier Almansa Sobrino | ed93259 | 2023-01-24 12:50:41 +0000 | [diff] [blame] | 67 | * 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 Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 71 | */ |
Javier Almansa Sobrino | ed93259 | 2023-01-24 12:50:41 +0000 | [diff] [blame] | 72 | int 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 | */ |
| 79 | void slot_buf_finish_warmboot_init(void); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 80 | |
| 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 Sobrino | d528efd | 2023-01-05 16:23:54 +0000 | [diff] [blame] | 87 | * Maps a given PA into the specified slot. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 88 | * |
| 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 Sobrino | d528efd | 2023-01-05 16:23:54 +0000 | [diff] [blame] | 92 | void *buffer_map_internal(enum buffer_slot slot, unsigned long addr); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 93 | |
| 94 | /* |
| 95 | * Unmaps the slot buffer corresponding to the VA passed via `buf` argument. |
| 96 | */ |
| 97 | void buffer_unmap_internal(void *buf); |
| 98 | |
| 99 | #endif /* BUFFER_H */ |