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> |
AlexeiFedorov | 4faab85 | 2023-08-30 15:06:49 +0100 | [diff] [blame] | 12 | #include <stddef.h> |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 13 | #include <utils_def.h> |
| 14 | |
| 15 | enum 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 | |
| 40 | struct granule; |
| 41 | |
| 42 | void assert_cpu_slots_empty(void); |
| 43 | void *granule_map(struct granule *g, enum buffer_slot slot); |
| 44 | void buffer_unmap(void *buf); |
| 45 | |
| 46 | bool ns_buffer_read(enum buffer_slot slot, |
AlexeiFedorov | 950bd7b | 2023-08-24 15:25:22 +0100 | [diff] [blame] | 47 | struct granule *ns_gr, |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 48 | unsigned int offset, |
AlexeiFedorov | 4faab85 | 2023-08-30 15:06:49 +0100 | [diff] [blame] | 49 | size_t size, |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 50 | void *dest); |
| 51 | bool ns_buffer_write(enum buffer_slot slot, |
AlexeiFedorov | 950bd7b | 2023-08-24 15:25:22 +0100 | [diff] [blame] | 52 | struct granule *ns_gr, |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 53 | unsigned int offset, |
AlexeiFedorov | 4faab85 | 2023-08-30 15:06:49 +0100 | [diff] [blame] | 54 | size_t size, |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 55 | void *src); |
| 56 | |
| 57 | /* |
Javier Almansa Sobrino | ed93259 | 2023-01-24 12:50:41 +0000 | [diff] [blame] | 58 | * Finishes initializing the slot buffer mechanism. |
| 59 | * This function should be called after the MMU is enabled, during the |
| 60 | * warmboot path. |
| 61 | */ |
| 62 | void slot_buf_finish_warmboot_init(void); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 63 | |
| 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 Sobrino | d528efd | 2023-01-05 16:23:54 +0000 | [diff] [blame] | 70 | * Maps a given PA into the specified slot. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 71 | * |
| 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 Sobrino | d528efd | 2023-01-05 16:23:54 +0000 | [diff] [blame] | 75 | void *buffer_map_internal(enum buffer_slot slot, unsigned long addr); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 76 | |
| 77 | /* |
| 78 | * Unmaps the slot buffer corresponding to the VA passed via `buf` argument. |
| 79 | */ |
| 80 | void buffer_unmap_internal(void *buf); |
| 81 | |
| 82 | #endif /* BUFFER_H */ |