blob: 1ff2b9e707fe738732ac421db597458aa6589c4d [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
20
21/* Number of pages per REC to be allocated */
22#define REC_NUM_PAGES (REC_HEAP_PAGES + REC_PMU_PAGES)
Soby Mathewb4c6df42022-11-09 11:13:29 +000023
24struct buffer_alloc_ctx {
25 unsigned char *buf;
26 size_t len;
27 memory_header_t *first;
28 memory_header_t *first_free;
29 int verify;
30};
31
32struct memory_header_s {
33 size_t magic1;
34 size_t size;
35 size_t alloc;
36 memory_header_t *prev;
37 memory_header_t *next;
38 memory_header_t *prev_free;
39 memory_header_t *next_free;
40 size_t magic2;
41};
42
Soby Mathewb4c6df42022-11-09 11:13:29 +000043/*
44 * Function to assign a heap context to the current CPU for
45 * use by the MbedCrypto. In case the heap needs to be isolated
46 * to the CPU executing a realm , this function must to be
47 * called before entering a Realm. This will ensure that any
48 * crypto operations triggered via RSI will used the assigned
49 * heap.
50 * Arguments:
51 * ctx - Pointer to a valid context for the memory allocator.
52 * Returns:
53 * 0 on success or a POSIX error code or error.
54 */
55int buffer_alloc_ctx_assign(struct buffer_alloc_ctx *ctx);
56
57/*
58 * Function to unasign a heap context from the current CPU.
59 * In case the heap was isolated to the CPU executing a realm,
60 * this function must to be called after exiting a Realm.
61 */
62void buffer_alloc_ctx_unassign(void);
63
64#endif /* MEMORY_ALLOC_H */