blob: 852b64831e28c4da21fdf7e15dac60a6ab7baa41 [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 MEMORY_ALLOC_H
7#define MEMORY_ALLOC_H
8
9#include <stddef.h>
10
11struct _memory_header;
12typedef struct memory_header_s memory_header_t;
13
AlexeiFedoroveaec0c42023-02-01 18:13:32 +000014/* MbedTLS needs 8K of heap for attestation usecases */
Soby Mathewb4c6df42022-11-09 11:13:29 +000015#define REC_HEAP_PAGES 2
AlexeiFedoroveaec0c42023-02-01 18:13:32 +000016#define REC_HEAP_SIZE (REC_HEAP_PAGES * SZ_4K)
17
18/* Number of pages per REC for PMU state */
19#define REC_PMU_PAGES 1
Arunachalam Ganapathyf6491212023-02-23 16:04:34 +000020#define REC_PMU_SIZE (REC_PMU_PAGES * SZ_4K)
AlexeiFedoroveaec0c42023-02-01 18:13:32 +000021
Arunachalam Ganapathyf6491212023-02-23 16:04:34 +000022/*
23 * SIMD context that holds FPU/SVE registers. Space to save max arch supported
24 * SVE vector length of 2048 bits.
25 * Size of 32 Z registers (256 bytes each): 8192 bytes
26 * Size of 16 P registers (32 bytes each) : 512 bytes
27 * Size of 1 FFR register (32 bytes each) : 32 bytes
28 * Size of other status registers : 32 bytes
29 * Total size is ~3 Pages (rounded up to page size).
30 */
31#define REC_SIMD_PAGES 3
32
33/* Number of aux granules pages per REC to be used */
34#define REC_NUM_PAGES (REC_HEAP_PAGES + REC_PMU_PAGES + REC_SIMD_PAGES)
Soby Mathewb4c6df42022-11-09 11:13:29 +000035
36struct buffer_alloc_ctx {
37 unsigned char *buf;
38 size_t len;
39 memory_header_t *first;
40 memory_header_t *first_free;
41 int verify;
42};
43
44struct memory_header_s {
45 size_t magic1;
46 size_t size;
47 size_t alloc;
48 memory_header_t *prev;
49 memory_header_t *next;
50 memory_header_t *prev_free;
51 memory_header_t *next_free;
52 size_t magic2;
53};
54
Soby Mathewb4c6df42022-11-09 11:13:29 +000055/*
56 * Function to assign a heap context to the current CPU for
57 * use by the MbedCrypto. In case the heap needs to be isolated
58 * to the CPU executing a realm , this function must to be
59 * called before entering a Realm. This will ensure that any
60 * crypto operations triggered via RSI will used the assigned
61 * heap.
62 * Arguments:
63 * ctx - Pointer to a valid context for the memory allocator.
64 * Returns:
65 * 0 on success or a POSIX error code or error.
66 */
67int buffer_alloc_ctx_assign(struct buffer_alloc_ctx *ctx);
68
69/*
70 * Function to unasign a heap context from the current CPU.
71 * In case the heap was isolated to the CPU executing a realm,
72 * this function must to be called after exiting a Realm.
73 */
74void buffer_alloc_ctx_unassign(void);
75
76#endif /* MEMORY_ALLOC_H */