blob: 582f564b1e52728372b2ff17d6c472bcb1efa477 [file] [log] [blame]
David Brazdil7a462ec2019-08-15 12:27:47 +01001/*
2 * Copyright 2019 The Hafnium Authors.
3 *
Andrew Walbrane959ec12020-06-17 15:01:09 +01004 * Use of this source code is governed by a BSD-style
5 * license that can be found in the LICENSE file or at
6 * https://opensource.org/licenses/BSD-3-Clause.
David Brazdil7a462ec2019-08-15 12:27:47 +01007 */
8
9#pragma once
10
Olivier Deprez62d99e32020-01-09 15:58:07 +010011#include "hf/addr.h"
Raghu Krishnamurthyb49549e2021-07-02 08:27:38 -070012#include "hf/fdt.h"
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010013#include "hf/ffa.h"
David Brazdil7a462ec2019-08-15 12:27:47 +010014#include "hf/memiter.h"
David Brazdil136f2942019-09-23 14:11:03 +010015#include "hf/string.h"
Andrew Scullae9962e2019-10-03 16:51:16 +010016#include "hf/vm.h"
David Brazdil0dbb41f2019-09-09 18:03:35 +010017
David Brazdil080ee312020-02-25 15:30:30 -080018#define MANIFEST_INVALID_ADDRESS UINT64_MAX
Madhukar Pappireddy54680c72020-10-23 15:02:38 -050019#define MANIFEST_INVALID_ID UINT32_MAX
David Brazdil080ee312020-02-25 15:30:30 -080020
Olivier Deprez62d99e32020-01-09 15:58:07 +010021#define SP_RTX_BUF_NAME_SIZE 10
22
Manish Pandey6542f5c2020-04-27 14:37:46 +010023#define SP_MAX_MEMORY_REGIONS 8
Manish Pandeye68e7932020-04-23 15:29:28 +010024#define SP_MAX_DEVICE_REGIONS 8
25#define SP_MAX_INTERRUPTS_PER_DEVICE 4
26#define SP_MAX_STREAMS_PER_DEVICE 4
Manish Pandey6542f5c2020-04-27 14:37:46 +010027
Olivier Deprez035fa152022-03-14 11:19:10 +010028/** FF-A manifest memory and device regions attributes. */
29#define MANIFEST_REGION_ATTR_READ (UINT32_C(1) << 0)
30#define MANIFEST_REGION_ATTR_WRITE (UINT32_C(1) << 1)
31#define MANIFEST_REGION_ATTR_EXEC (UINT32_C(1) << 2)
32#define MANIFEST_REGION_ATTR_SECURITY (UINT32_C(1) << 3)
33
34#define MANIFEST_REGION_ALL_ATTR_MASK \
35 (MANIFEST_REGION_ATTR_READ | MANIFEST_REGION_ATTR_WRITE | \
36 MANIFEST_REGION_ATTR_EXEC | MANIFEST_REGION_ATTR_SECURITY)
Manish Pandey6542f5c2020-04-27 14:37:46 +010037
J-Alvesbeeb6dc2021-12-08 18:21:32 +000038/* Highest possible value for the boot-order field. */
39#define DEFAULT_BOOT_ORDER 0xFFFF
J-Alves35315782022-01-25 17:58:32 +000040#define DEFAULT_BOOT_GP_REGISTER UINT32_C(-1)
J-Alvesb37fd082020-10-22 12:29:21 +010041
Olivier Deprez62d99e32020-01-09 15:58:07 +010042enum run_time_el {
43 EL1 = 0,
44 S_EL0,
45 S_EL1,
46 SUPERVISOR_MODE,
47 SECURE_USER_MODE,
48 SECURE_SUPERVISOR_MODE
49};
50
51enum execution_state { AARCH64 = 0, AARCH32 };
52
53enum xlat_granule { PAGE_4KB = 0, PAGE_16KB, PAGE_64KB };
54
Olivier Deprez62d99e32020-01-09 15:58:07 +010055/**
Olivier Deprezc13a8692022-04-08 17:47:14 +020056 * Partition Memory region as described in FFA v1.0 spec, Table 10
Manish Pandey6542f5c2020-04-27 14:37:46 +010057 */
58struct memory_region {
59 /**
60 * Specify PA, VA for S-EL0 partitions or IPA
61 * for S-EL1 partitions - optional.
62 */
63 uintptr_t base_address;
64 /** Page count - mandatory */
65 uint32_t page_count;
66 /** Memory attributes - mandatory */
67 uint32_t attributes;
68 /** Name of memory region - optional */
69 struct string name;
70};
71
Manish Pandeye68e7932020-04-23 15:29:28 +010072struct interrupt {
73 uint32_t id;
74 uint32_t attributes;
75};
76
77/**
Olivier Deprezc13a8692022-04-08 17:47:14 +020078 * Partition Device region as described in FFA v1.0 spec, Table 11
Manish Pandeye68e7932020-04-23 15:29:28 +010079 */
80struct device_region {
81 /** Device base PA - mandatory */
82 uintptr_t base_address;
83 /** Page count - mandatory */
84 uint32_t page_count;
85 /** Memory attributes - mandatory */
86 uint32_t attributes;
87 /** List of physical interrupt ID's and their attributes - optional */
88 struct interrupt interrupts[SP_MAX_INTERRUPTS_PER_DEVICE];
Madhukar Pappireddy5fc8be12021-08-03 11:42:53 -050089 /** Count of physical interrupts - optional */
90 uint8_t interrupt_count;
Manish Pandeye68e7932020-04-23 15:29:28 +010091 /** SMMU ID - optional */
92 uint32_t smmu_id;
Madhukar Pappireddy54680c72020-10-23 15:02:38 -050093 /** Count of Stream IDs assigned to device - optional */
94 uint8_t stream_count;
Manish Pandeye68e7932020-04-23 15:29:28 +010095 /** List of Stream IDs assigned to device - optional */
96 uint32_t stream_ids[SP_MAX_STREAMS_PER_DEVICE];
97 /** Exclusive access to an endpoint - optional */
98 bool exclusive_access;
99 /** Name of Device region - optional */
100 struct string name;
101};
102
Manish Pandey6542f5c2020-04-27 14:37:46 +0100103/**
Manish Pandeyfa1f2912020-05-05 12:57:01 +0100104 * RX/TX buffer, reference to memory-region entries that describe RX/TX
105 * buffers in partition manifest.
106 */
107struct rx_tx {
108 bool available;
109 uint32_t rx_phandle;
110 uint32_t tx_phandle;
111 struct memory_region *rx_buffer;
112 struct memory_region *tx_buffer;
113};
114
115/**
Olivier Deprezc13a8692022-04-08 17:47:14 +0200116 * Partition manifest as described in FF-A v1.0 spec section 3.1
Olivier Deprez62d99e32020-01-09 15:58:07 +0100117 */
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700118struct partition_manifest {
Olivier Deprezc13a8692022-04-08 17:47:14 +0200119 /** FF-A expected version - mandatory */
Olivier Deprez62d99e32020-01-09 15:58:07 +0100120 uint32_t ffa_version;
121 /** UUID - mandatory */
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100122 struct ffa_uuid uuid;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100123 /** Partition id - optional */
124 ffa_vm_id_t id;
125 /** Aux ids for mem transactions - optional */
126 ffa_vm_id_t aux_id;
127
128 /* NOTE: optional name field maps to VM debug_name field */
129
130 /** mandatory */
131 ffa_vcpu_count_t execution_ctx_count;
132 /** EL1 or secure EL1, secure EL0 - mandatory */
133 enum run_time_el run_time_el;
134 /** AArch32 / AArch64 - mandatory */
135 enum execution_state execution_state;
136 /** optional */
137 uintpaddr_t load_addr;
138 /** optional */
139 size_t ep_offset;
J-Alves4369bd92020-08-07 16:35:36 +0100140 /** 4/16/64KB - optional */
Olivier Deprez62d99e32020-01-09 15:58:07 +0100141 enum xlat_granule xlat_granule;
J-Alves35315782022-01-25 17:58:32 +0000142 /** Register id from w0/x0-w3/x3 - optional. */
143 uint32_t gp_register_num;
144 /**
145 * Flags the presence of the optional IMPDEF node to define Partition's
146 * Boot Info.
147 */
148 bool boot_info;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100149 /** optional */
150 uint16_t boot_order;
151
152 /** Optional RX/TX buffers */
Manish Pandeyfa1f2912020-05-05 12:57:01 +0100153 struct rx_tx rxtx;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100154
155 /** mandatory - direct/indirect msg or both */
Maksims Svecovsb596eab2021-04-27 00:52:27 +0100156 uint8_t messaging_method;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100157 /** optional */
Maksims Svecovs9ddf86a2021-05-06 17:17:21 +0100158 bool managed_exit;
J-Alvesa4730db2021-11-02 10:31:01 +0000159 /** optional - receipt of notifications. */
160 bool notification_support;
Maksims Svecovs9ddf86a2021-05-06 17:17:21 +0100161 /** optional */
Olivier Deprez62d99e32020-01-09 15:58:07 +0100162 bool has_primary_scheduler;
163 /** optional - preemptible / run to completion */
164 uint8_t runtime_model;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100165 /** optional - tuples SEPID/SMMUID/streamId */
166 uint32_t stream_ep_ids[1];
Manish Pandey6542f5c2020-04-27 14:37:46 +0100167
168 /** Memory regions */
Manish Pandey2145c212020-05-01 16:04:22 +0100169 uint8_t mem_region_count;
Manish Pandey6542f5c2020-04-27 14:37:46 +0100170 struct memory_region mem_regions[SP_MAX_MEMORY_REGIONS];
Manish Pandeye68e7932020-04-23 15:29:28 +0100171 /** Device regions */
Manish Pandey2145c212020-05-01 16:04:22 +0100172 uint8_t dev_region_count;
Manish Pandeye68e7932020-04-23 15:29:28 +0100173 struct device_region dev_regions[SP_MAX_DEVICE_REGIONS];
Olivier Deprez62d99e32020-01-09 15:58:07 +0100174};
175
176/**
David Brazdil7a462ec2019-08-15 12:27:47 +0100177 * Holds information about one of the VMs described in the manifest.
178 */
179struct manifest_vm {
180 /* Properties defined for both primary and secondary VMs. */
David Brazdil136f2942019-09-23 14:11:03 +0100181 struct string debug_name;
182 struct string kernel_filename;
Andrew Scullae9962e2019-10-03 16:51:16 +0100183 struct smc_whitelist smc_whitelist;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100184 bool is_ffa_partition;
Raghu Krishnamurthyb49549e2021-07-02 08:27:38 -0700185 bool is_hyp_loaded;
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700186 struct partition_manifest partition;
David Brazdil7a462ec2019-08-15 12:27:47 +0100187
David Brazdile6f83222019-09-23 14:47:37 +0100188 union {
189 /* Properties specific to the primary VM. */
190 struct {
David Brazdil080ee312020-02-25 15:30:30 -0800191 uint64_t boot_address;
David Brazdile6f83222019-09-23 14:47:37 +0100192 struct string ramdisk_filename;
193 } primary;
194 /* Properties specific to secondary VMs. */
195 struct {
196 uint64_t mem_size;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100197 ffa_vcpu_count_t vcpu_count;
Fuad Tabba50469e02020-06-30 15:14:28 +0100198 struct string fdt_filename;
David Brazdile6f83222019-09-23 14:47:37 +0100199 } secondary;
200 };
David Brazdil7a462ec2019-08-15 12:27:47 +0100201};
202
203/**
204 * Hafnium manifest parsed from FDT.
205 */
206struct manifest {
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100207 bool ffa_tee_enabled;
208 ffa_vm_count_t vm_count;
David Brazdil7a462ec2019-08-15 12:27:47 +0100209 struct manifest_vm vm[MAX_VMS];
210};
211
212enum manifest_return_code {
213 MANIFEST_SUCCESS = 0,
David Brazdila2358d42020-01-27 18:51:38 +0000214 MANIFEST_ERROR_FILE_SIZE,
Olivier Deprez62d99e32020-01-09 15:58:07 +0100215 MANIFEST_ERROR_MALFORMED_DTB,
David Brazdila2358d42020-01-27 18:51:38 +0000216 MANIFEST_ERROR_NO_ROOT_NODE,
David Brazdil7a462ec2019-08-15 12:27:47 +0100217 MANIFEST_ERROR_NO_HYPERVISOR_FDT_NODE,
David Brazdil74e9c3b2019-08-28 11:09:08 +0100218 MANIFEST_ERROR_NOT_COMPATIBLE,
David Brazdil7a462ec2019-08-15 12:27:47 +0100219 MANIFEST_ERROR_RESERVED_VM_ID,
220 MANIFEST_ERROR_NO_PRIMARY_VM,
221 MANIFEST_ERROR_TOO_MANY_VMS,
222 MANIFEST_ERROR_PROPERTY_NOT_FOUND,
223 MANIFEST_ERROR_MALFORMED_STRING,
David Brazdil0dbb41f2019-09-09 18:03:35 +0100224 MANIFEST_ERROR_STRING_TOO_LONG,
David Brazdil7a462ec2019-08-15 12:27:47 +0100225 MANIFEST_ERROR_MALFORMED_INTEGER,
226 MANIFEST_ERROR_INTEGER_OVERFLOW,
Andrew Scullae9962e2019-10-03 16:51:16 +0100227 MANIFEST_ERROR_MALFORMED_INTEGER_LIST,
Andrew Scullb2c3a242019-11-04 13:52:36 +0000228 MANIFEST_ERROR_MALFORMED_BOOLEAN,
J-Alves35315782022-01-25 17:58:32 +0000229 MANIFEST_ERROR_ARGUMENTS_LIST_EMPTY,
Manish Pandey6542f5c2020-04-27 14:37:46 +0100230 MANIFEST_ERROR_MEMORY_REGION_NODE_EMPTY,
Manish Pandeye68e7932020-04-23 15:29:28 +0100231 MANIFEST_ERROR_DEVICE_REGION_NODE_EMPTY,
Manish Pandeyf06c9072020-09-29 15:41:58 +0100232 MANIFEST_ERROR_RXTX_SIZE_MISMATCH,
Raghu Krishnamurthy384693c2021-10-11 13:56:24 -0700233 MANIFEST_ERROR_INVALID_MEM_PERM,
David Brazdil7a462ec2019-08-15 12:27:47 +0100234};
235
Olivier Deprez62d99e32020-01-09 15:58:07 +0100236enum manifest_return_code manifest_init(struct mm_stage1_locked stage1_locked,
237 struct manifest *manifest,
238 struct memiter *manifest_fdt,
239 struct mpool *ppool);
240
Raghu Krishnamurthyb49549e2021-07-02 08:27:38 -0700241enum manifest_return_code parse_ffa_manifest(struct fdt *fdt,
J-Alves35315782022-01-25 17:58:32 +0000242 struct manifest_vm *vm,
243 struct fdt_node *boot_info);
244
Raghu Krishnamurthyb49549e2021-07-02 08:27:38 -0700245enum manifest_return_code sanity_check_ffa_manifest(struct manifest_vm *vm);
Olivier Deprez62d99e32020-01-09 15:58:07 +0100246void manifest_dump(struct manifest_vm *vm);
David Brazdil7a462ec2019-08-15 12:27:47 +0100247
248const char *manifest_strerror(enum manifest_return_code ret_code);