blob: 4dabfcea711fc1e876f2b1932c7ffbdd933490c1 [file] [log] [blame]
Mate Toth-Pal83a45bd2023-09-01 11:17:19 +02001/*
2 * SPDX-License-Identifier: BSD-3-Clause
3 * SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
4 */
5
6#ifndef TB_GRANULES_H
7#define TB_GRANULES_H
8
9#include "buffer.h"
10#include "granule.h"
11#include "granule_types.h"
Mate Toth-Pal83a45bd2023-09-01 11:17:19 +020012#include "host_defs.h"
13#include "host_utils.h"
14#include "platform_api.h"
Mate Toth-Pala18676e2023-10-27 17:05:01 +020015#include "sizes.h"
Mate Toth-Pal83a45bd2023-09-01 11:17:19 +020016
17/*
18 * The granule states and gpt state
19 */
20#define UNDELEGATED GRANULE_STATE_NS
21#define DELEGATED GRANULE_STATE_DELEGATED
22#define RD GRANULE_STATE_RD
23#define DATA GRANULE_STATE_DATA
24#define REC GRANULE_STATE_REC
25#define RTT GRANULE_STATE_RTT
26
27#define RMM_GRANULE_SIZE GRANULE_SIZE
28
29enum granule_gpt {
Soby Mathewbdd30ee2023-11-28 09:50:28 +000030 GPT_SECURE,
Mate Toth-Pal83a45bd2023-09-01 11:17:19 +020031 GPT_NS,
32 GPT_REALM,
33 GPT_ROOT,
Soby Mathewbdd30ee2023-11-28 09:50:28 +000034 GPT_AAP
Mate Toth-Pal83a45bd2023-09-01 11:17:19 +020035};
36
37struct SPEC_granule {
38 enum granule_gpt gpt;
AlexeiFedorovd6d93d82024-02-13 16:52:11 +000039 unsigned char state;
Mate Toth-Pal83a45bd2023-09-01 11:17:19 +020040};
41
Mate Toth-Palc751c0d2023-11-14 16:56:41 +010042/*
43 * CBMC needs access to the below data structures which are not otherwise
44 * visible outside their respective files.
45 */
Mate Toth-Pal83a45bd2023-09-01 11:17:19 +020046extern unsigned char granules_buffer[HOST_MEM_SIZE];
Mate Toth-Palc751c0d2023-11-14 16:56:41 +010047extern struct granule granules[RMM_MAX_GRANULES];
Mate Toth-Pal83a45bd2023-09-01 11:17:19 +020048
49/*
50 * Declare nondet_* functions.
51 * CBMC automatically returns nondet values based on the return types.
52 * However, enum is treated as integer hence the value might out of range.
53 */
54struct granule nondet_struct_granule(void);
55struct SPEC_granule nondet_struct_SPEC_granule(void);
56
57bool valid_granule_ptr(struct granule *p);
58struct granule init_granule(void);
59void init_granule_and_page(void);
60
61/*
62 * Pedicates
63 */
64bool AddrIsGranuleAligned(uint64_t addr);
65bool PaIsDelegable(uint64_t addr);
66struct SPEC_granule Granule(uint64_t addr);
67
68#endif /* !TB_GRANULES_H */