1 /*
2  * Copyright (c) 2022-2023, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef RMM_CORE_MANIFEST_H
8 #define RMM_CORE_MANIFEST_H
9 
10 #include <assert.h>
11 #include <stddef.h>
12 #include <stdint.h>
13 
14 #include <lib/cassert.h>
15 
16 #define RMMD_MANIFEST_VERSION_MAJOR		U(0)
17 #define RMMD_MANIFEST_VERSION_MINOR		U(3)
18 
19 #define RMM_CONSOLE_MAX_NAME_LEN		U(8)
20 
21 /*
22  * Manifest version encoding:
23  *	- Bit[31] RES0
24  *	- Bits [30:16] Major version
25  *	- Bits [15:0] Minor version
26  */
27 #define SET_RMMD_MANIFEST_VERSION(_major, _minor)		\
28 	((((_major) & 0x7FFF) << 16) | ((_minor) & 0xFFFF))
29 
30 #define RMMD_MANIFEST_VERSION	SET_RMMD_MANIFEST_VERSION(	\
31 				RMMD_MANIFEST_VERSION_MAJOR,	\
32 				RMMD_MANIFEST_VERSION_MINOR)
33 
34 #define RMMD_GET_MANIFEST_VERSION_MAJOR(_version)		\
35 	((_version >> 16) & 0x7FFF)
36 
37 #define RMMD_GET_MANIFEST_VERSION_MINOR(_version)		\
38 	(_version & 0xFFFF)
39 
40 /* NS DRAM bank structure */
41 struct ns_dram_bank {
42 	uintptr_t base;			/* Base address */
43 	uint64_t size;			/* Size of bank */
44 };
45 
46 CASSERT(offsetof(struct ns_dram_bank, base) == 0UL,
47 			rmm_manifest_base_unaligned);
48 CASSERT(offsetof(struct ns_dram_bank, size) == 8UL,
49 			rmm_manifest_size_unaligned);
50 
51 /* NS DRAM layout info structure */
52 struct ns_dram_info {
53 	uint64_t num_banks;		/* Number of NS DRAM banks */
54 	struct ns_dram_bank *banks;	/* Pointer to ns_dram_bank[] */
55 	uint64_t checksum;		/* Checksum of ns_dram_info data */
56 };
57 
58 CASSERT(offsetof(struct ns_dram_info, num_banks) == 0UL,
59 			rmm_manifest_num_banks_unaligned);
60 CASSERT(offsetof(struct ns_dram_info, banks) == 8UL,
61 			rmm_manifest_dram_data_unaligned);
62 CASSERT(offsetof(struct ns_dram_info, checksum) == 16UL,
63 			rmm_manifest_checksum_unaligned);
64 
65 /* Console info structure */
66 struct console_info {
67 	uintptr_t base;			/* Console base address */
68 	uint64_t map_pages;		/* Num of pages to be mapped in RMM for the console MMIO */
69 	char name[RMM_CONSOLE_MAX_NAME_LEN];	/* Name of console */
70 	uint64_t clk_in_hz;		/* UART clock (in HZ) for the console */
71 	uint64_t baud_rate;		/* Baud rate */
72 	uint64_t flags;			/* Additional flags RES0 */
73 };
74 
75 CASSERT(offsetof(struct console_info, base) == 0UL,
76 			rmm_manifest_console_base_unaligned);
77 CASSERT(offsetof(struct console_info, map_pages) == 8UL,
78 			rmm_manifest_console_map_pages_unaligned);
79 CASSERT(offsetof(struct console_info, name) == 16UL,
80 			rmm_manifest_console_name_unaligned);
81 CASSERT(offsetof(struct console_info, clk_in_hz) == 24UL,
82 			rmm_manifest_console_clk_in_hz_unaligned);
83 CASSERT(offsetof(struct console_info, baud_rate) == 32UL,
84 			rmm_manifest_console_baud_rate_unaligned);
85 CASSERT(offsetof(struct console_info, flags) == 40UL,
86 			rmm_manifest_console_flags_unaligned);
87 
88 struct console_list {
89 	uint64_t num_consoles;		/* Number of consoles */
90 	struct console_info *consoles;	/* Pointer to ns_dram_bank[] */
91 	uint64_t checksum;		/* Checksum of ns_dram_info data */
92 };
93 
94 CASSERT(offsetof(struct console_list, num_consoles) == 0UL,
95 			rmm_manifest_num_consoles);
96 CASSERT(offsetof(struct console_list, consoles) == 8UL,
97 			rmm_manifest_consoles);
98 CASSERT(offsetof(struct console_list, checksum) == 16UL,
99 			rmm_manifest_console_list_checksum);
100 
101 /* Boot manifest core structure as per v0.3 */
102 struct rmm_manifest {
103 	uint32_t version;			/* Manifest version */
104 	uint32_t padding;			/* RES0 */
105 	uintptr_t plat_data;			/* Manifest platform data */
106 	struct ns_dram_info plat_dram;		/* Platform NS DRAM data (v0.2) */
107 	struct console_list plat_console;	/* Platform console list (v0.3) */
108 };
109 
110 CASSERT(offsetof(struct rmm_manifest, version) == 0UL,
111 			rmm_manifest_version_unaligned);
112 CASSERT(offsetof(struct rmm_manifest, plat_data) == 8UL,
113 			rmm_manifest_plat_data_unaligned);
114 CASSERT(offsetof(struct rmm_manifest, plat_dram) == 16UL,
115 			rmm_manifest_plat_dram_unaligned);
116 CASSERT(offsetof(struct rmm_manifest, plat_console) == 40UL,
117 			rmm_manifest_plat_console_unaligned);
118 
119 #endif /* RMM_CORE_MANIFEST_H */
120