blob: b4a966591beb8d7dbba2169fb12c11d13f02cad1 [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
AlexeiFedorovec35c542023-04-27 17:52:02 +010032#define REC_SIMD_SIZE (REC_SIMD_PAGES * SZ_4K)
Arunachalam Ganapathyf6491212023-02-23 16:04:34 +000033
AlexeiFedorovec35c542023-04-27 17:52:02 +010034/* Number of pages per REC for 'rec_attest_data' structure */
35#define REC_ATTEST_PAGES 1
36#define REC_ATTEST_SIZE (REC_ATTEST_PAGES * SZ_4K)
37
38/* Number of pages per REC to be allocated */
39#define REC_NUM_PAGES (REC_HEAP_PAGES + \
40 REC_PMU_PAGES + \
41 REC_SIMD_PAGES + \
42 REC_ATTEST_PAGES)
Soby Mathewb4c6df42022-11-09 11:13:29 +000043
44struct buffer_alloc_ctx {
45 unsigned char *buf;
46 size_t len;
47 memory_header_t *first;
48 memory_header_t *first_free;
49 int verify;
50};
51
52struct memory_header_s {
53 size_t magic1;
54 size_t size;
55 size_t alloc;
56 memory_header_t *prev;
57 memory_header_t *next;
58 memory_header_t *prev_free;
59 memory_header_t *next_free;
60 size_t magic2;
61};
62
Soby Mathewb4c6df42022-11-09 11:13:29 +000063/*
64 * Function to assign a heap context to the current CPU for
65 * use by the MbedCrypto. In case the heap needs to be isolated
66 * to the CPU executing a realm , this function must to be
67 * called before entering a Realm. This will ensure that any
68 * crypto operations triggered via RSI will used the assigned
69 * heap.
70 * Arguments:
71 * ctx - Pointer to a valid context for the memory allocator.
72 * Returns:
73 * 0 on success or a POSIX error code or error.
74 */
75int buffer_alloc_ctx_assign(struct buffer_alloc_ctx *ctx);
76
77/*
78 * Function to unasign a heap context from the current CPU.
79 * In case the heap was isolated to the CPU executing a realm,
80 * this function must to be called after exiting a Realm.
81 */
82void buffer_alloc_ctx_unassign(void);
83
84#endif /* MEMORY_ALLOC_H */