Mate Toth-Pal | 83a45bd | 2023-09-01 11:17:19 +0200 | [diff] [blame] | 1 | /* |
| 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-Pal | 83a45bd | 2023-09-01 11:17:19 +0200 | [diff] [blame] | 12 | #include "host_defs.h" |
| 13 | #include "host_utils.h" |
| 14 | #include "platform_api.h" |
Mate Toth-Pal | a18676e | 2023-10-27 17:05:01 +0200 | [diff] [blame] | 15 | #include "sizes.h" |
Mate Toth-Pal | 83a45bd | 2023-09-01 11:17:19 +0200 | [diff] [blame] | 16 | |
| 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 | |
| 29 | enum granule_gpt { |
Soby Mathew | bdd30ee | 2023-11-28 09:50:28 +0000 | [diff] [blame] | 30 | GPT_SECURE, |
Mate Toth-Pal | 83a45bd | 2023-09-01 11:17:19 +0200 | [diff] [blame] | 31 | GPT_NS, |
| 32 | GPT_REALM, |
| 33 | GPT_ROOT, |
Soby Mathew | bdd30ee | 2023-11-28 09:50:28 +0000 | [diff] [blame] | 34 | GPT_AAP |
Mate Toth-Pal | 83a45bd | 2023-09-01 11:17:19 +0200 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | struct SPEC_granule { |
| 38 | enum granule_gpt gpt; |
AlexeiFedorov | d6d93d8 | 2024-02-13 16:52:11 +0000 | [diff] [blame^] | 39 | unsigned char state; |
Mate Toth-Pal | 83a45bd | 2023-09-01 11:17:19 +0200 | [diff] [blame] | 40 | }; |
| 41 | |
Mate Toth-Pal | c751c0d | 2023-11-14 16:56:41 +0100 | [diff] [blame] | 42 | /* |
| 43 | * CBMC needs access to the below data structures which are not otherwise |
| 44 | * visible outside their respective files. |
| 45 | */ |
Mate Toth-Pal | 83a45bd | 2023-09-01 11:17:19 +0200 | [diff] [blame] | 46 | extern unsigned char granules_buffer[HOST_MEM_SIZE]; |
Mate Toth-Pal | c751c0d | 2023-11-14 16:56:41 +0100 | [diff] [blame] | 47 | extern struct granule granules[RMM_MAX_GRANULES]; |
Mate Toth-Pal | 83a45bd | 2023-09-01 11:17:19 +0200 | [diff] [blame] | 48 | |
| 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 | */ |
| 54 | struct granule nondet_struct_granule(void); |
| 55 | struct SPEC_granule nondet_struct_SPEC_granule(void); |
| 56 | |
| 57 | bool valid_granule_ptr(struct granule *p); |
| 58 | struct granule init_granule(void); |
| 59 | void init_granule_and_page(void); |
| 60 | |
| 61 | /* |
| 62 | * Pedicates |
| 63 | */ |
| 64 | bool AddrIsGranuleAligned(uint64_t addr); |
| 65 | bool PaIsDelegable(uint64_t addr); |
| 66 | struct SPEC_granule Granule(uint64_t addr); |
| 67 | |
| 68 | #endif /* !TB_GRANULES_H */ |