blob: d2f9428234ce0c1f0628718f87178d56377f2372 [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
Olivier Deprez035fa152022-03-14 11:19:10 +010023/** FF-A manifest memory and device regions attributes. */
24#define MANIFEST_REGION_ATTR_READ (UINT32_C(1) << 0)
25#define MANIFEST_REGION_ATTR_WRITE (UINT32_C(1) << 1)
26#define MANIFEST_REGION_ATTR_EXEC (UINT32_C(1) << 2)
27#define MANIFEST_REGION_ATTR_SECURITY (UINT32_C(1) << 3)
28
29#define MANIFEST_REGION_ALL_ATTR_MASK \
30 (MANIFEST_REGION_ATTR_READ | MANIFEST_REGION_ATTR_WRITE | \
31 MANIFEST_REGION_ATTR_EXEC | MANIFEST_REGION_ATTR_SECURITY)
Manish Pandey6542f5c2020-04-27 14:37:46 +010032
J-Alvesbeeb6dc2021-12-08 18:21:32 +000033/* Highest possible value for the boot-order field. */
34#define DEFAULT_BOOT_ORDER 0xFFFF
J-Alves35315782022-01-25 17:58:32 +000035#define DEFAULT_BOOT_GP_REGISTER UINT32_C(-1)
J-Alvesb37fd082020-10-22 12:29:21 +010036
Olivier Deprez62d99e32020-01-09 15:58:07 +010037enum run_time_el {
38 EL1 = 0,
39 S_EL0,
40 S_EL1,
41 SUPERVISOR_MODE,
42 SECURE_USER_MODE,
43 SECURE_SUPERVISOR_MODE
44};
45
46enum execution_state { AARCH64 = 0, AARCH32 };
47
48enum xlat_granule { PAGE_4KB = 0, PAGE_16KB, PAGE_64KB };
49
Olivier Deprez62d99e32020-01-09 15:58:07 +010050/**
Olivier Deprezc13a8692022-04-08 17:47:14 +020051 * Partition Memory region as described in FFA v1.0 spec, Table 10
Manish Pandey6542f5c2020-04-27 14:37:46 +010052 */
53struct memory_region {
54 /**
55 * Specify PA, VA for S-EL0 partitions or IPA
56 * for S-EL1 partitions - optional.
57 */
58 uintptr_t base_address;
59 /** Page count - mandatory */
60 uint32_t page_count;
61 /** Memory attributes - mandatory */
62 uint32_t attributes;
63 /** Name of memory region - optional */
64 struct string name;
65};
66
Raghu Krishnamurthyad38a9c2022-07-20 07:30:36 -070067struct interrupt_info {
Manish Pandeye68e7932020-04-23 15:29:28 +010068 uint32_t id;
69 uint32_t attributes;
70};
71
72/**
Olivier Deprezc13a8692022-04-08 17:47:14 +020073 * Partition Device region as described in FFA v1.0 spec, Table 11
Manish Pandeye68e7932020-04-23 15:29:28 +010074 */
75struct device_region {
76 /** Device base PA - mandatory */
77 uintptr_t base_address;
78 /** Page count - mandatory */
79 uint32_t page_count;
80 /** Memory attributes - mandatory */
81 uint32_t attributes;
82 /** List of physical interrupt ID's and their attributes - optional */
Raghu Krishnamurthyad38a9c2022-07-20 07:30:36 -070083 struct interrupt_info interrupts[PARTITION_MAX_INTERRUPTS_PER_DEVICE];
Madhukar Pappireddy5fc8be12021-08-03 11:42:53 -050084 /** Count of physical interrupts - optional */
85 uint8_t interrupt_count;
Manish Pandeye68e7932020-04-23 15:29:28 +010086 /** SMMU ID - optional */
87 uint32_t smmu_id;
Madhukar Pappireddy54680c72020-10-23 15:02:38 -050088 /** Count of Stream IDs assigned to device - optional */
89 uint8_t stream_count;
Manish Pandeye68e7932020-04-23 15:29:28 +010090 /** List of Stream IDs assigned to device - optional */
Raghu Krishnamurthy641dcd82022-07-19 23:21:20 -070091 uint32_t stream_ids[PARTITION_MAX_STREAMS_PER_DEVICE];
Manish Pandeye68e7932020-04-23 15:29:28 +010092 /** Exclusive access to an endpoint - optional */
93 bool exclusive_access;
94 /** Name of Device region - optional */
95 struct string name;
96};
97
Manish Pandey6542f5c2020-04-27 14:37:46 +010098/**
Manish Pandeyfa1f2912020-05-05 12:57:01 +010099 * RX/TX buffer, reference to memory-region entries that describe RX/TX
100 * buffers in partition manifest.
101 */
102struct rx_tx {
103 bool available;
104 uint32_t rx_phandle;
105 uint32_t tx_phandle;
106 struct memory_region *rx_buffer;
107 struct memory_region *tx_buffer;
108};
109
110/**
Olivier Deprezc13a8692022-04-08 17:47:14 +0200111 * Partition manifest as described in FF-A v1.0 spec section 3.1
Olivier Deprez62d99e32020-01-09 15:58:07 +0100112 */
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700113struct partition_manifest {
Olivier Deprezc13a8692022-04-08 17:47:14 +0200114 /** FF-A expected version - mandatory */
Olivier Deprez62d99e32020-01-09 15:58:07 +0100115 uint32_t ffa_version;
116 /** UUID - mandatory */
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100117 struct ffa_uuid uuid;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100118 /** Partition id - optional */
119 ffa_vm_id_t id;
120 /** Aux ids for mem transactions - optional */
121 ffa_vm_id_t aux_id;
122
123 /* NOTE: optional name field maps to VM debug_name field */
124
125 /** mandatory */
126 ffa_vcpu_count_t execution_ctx_count;
127 /** EL1 or secure EL1, secure EL0 - mandatory */
128 enum run_time_el run_time_el;
129 /** AArch32 / AArch64 - mandatory */
130 enum execution_state execution_state;
131 /** optional */
132 uintpaddr_t load_addr;
133 /** optional */
134 size_t ep_offset;
J-Alves4369bd92020-08-07 16:35:36 +0100135 /** 4/16/64KB - optional */
Olivier Deprez62d99e32020-01-09 15:58:07 +0100136 enum xlat_granule xlat_granule;
J-Alves35315782022-01-25 17:58:32 +0000137 /** Register id from w0/x0-w3/x3 - optional. */
138 uint32_t gp_register_num;
139 /**
140 * Flags the presence of the optional IMPDEF node to define Partition's
141 * Boot Info.
142 */
143 bool boot_info;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100144 /** optional */
145 uint16_t boot_order;
146
147 /** Optional RX/TX buffers */
Manish Pandeyfa1f2912020-05-05 12:57:01 +0100148 struct rx_tx rxtx;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100149
150 /** mandatory - direct/indirect msg or both */
Maksims Svecovsb596eab2021-04-27 00:52:27 +0100151 uint8_t messaging_method;
Madhukar Pappireddy84154052022-06-21 18:30:25 -0500152 /** mandatory - action in response to non secure interrupt */
153 uint8_t ns_interrupts_action;
Madhukar Pappireddy046dad02022-06-21 18:43:33 -0500154 /** optional - managed exit signaled through vIRQ */
155 bool me_signal_virq;
J-Alvesa4730db2021-11-02 10:31:01 +0000156 /** optional - receipt of notifications. */
157 bool notification_support;
Maksims Svecovs9ddf86a2021-05-06 17:17:21 +0100158 /** optional */
Olivier Deprez62d99e32020-01-09 15:58:07 +0100159 bool has_primary_scheduler;
160 /** optional - preemptible / run to completion */
161 uint8_t runtime_model;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100162 /** optional - tuples SEPID/SMMUID/streamId */
163 uint32_t stream_ep_ids[1];
Manish Pandey6542f5c2020-04-27 14:37:46 +0100164
165 /** Memory regions */
Raghu Krishnamurthy641dcd82022-07-19 23:21:20 -0700166 uint16_t mem_region_count;
167 struct memory_region mem_regions[PARTITION_MAX_MEMORY_REGIONS];
Manish Pandeye68e7932020-04-23 15:29:28 +0100168 /** Device regions */
Raghu Krishnamurthy641dcd82022-07-19 23:21:20 -0700169 uint16_t dev_region_count;
170 struct device_region dev_regions[PARTITION_MAX_DEVICE_REGIONS];
Olivier Deprez62d99e32020-01-09 15:58:07 +0100171};
172
173/**
David Brazdil7a462ec2019-08-15 12:27:47 +0100174 * Holds information about one of the VMs described in the manifest.
175 */
176struct manifest_vm {
177 /* Properties defined for both primary and secondary VMs. */
David Brazdil136f2942019-09-23 14:11:03 +0100178 struct string debug_name;
179 struct string kernel_filename;
Andrew Scullae9962e2019-10-03 16:51:16 +0100180 struct smc_whitelist smc_whitelist;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100181 bool is_ffa_partition;
Raghu Krishnamurthyb49549e2021-07-02 08:27:38 -0700182 bool is_hyp_loaded;
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700183 struct partition_manifest partition;
David Brazdil7a462ec2019-08-15 12:27:47 +0100184
David Brazdile6f83222019-09-23 14:47:37 +0100185 union {
186 /* Properties specific to the primary VM. */
187 struct {
David Brazdil080ee312020-02-25 15:30:30 -0800188 uint64_t boot_address;
David Brazdile6f83222019-09-23 14:47:37 +0100189 struct string ramdisk_filename;
190 } primary;
191 /* Properties specific to secondary VMs. */
192 struct {
193 uint64_t mem_size;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100194 ffa_vcpu_count_t vcpu_count;
Fuad Tabba50469e02020-06-30 15:14:28 +0100195 struct string fdt_filename;
David Brazdile6f83222019-09-23 14:47:37 +0100196 } secondary;
197 };
David Brazdil7a462ec2019-08-15 12:27:47 +0100198};
199
200/**
201 * Hafnium manifest parsed from FDT.
202 */
203struct manifest {
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100204 bool ffa_tee_enabled;
205 ffa_vm_count_t vm_count;
David Brazdil7a462ec2019-08-15 12:27:47 +0100206 struct manifest_vm vm[MAX_VMS];
207};
208
209enum manifest_return_code {
210 MANIFEST_SUCCESS = 0,
David Brazdila2358d42020-01-27 18:51:38 +0000211 MANIFEST_ERROR_FILE_SIZE,
Olivier Deprez62d99e32020-01-09 15:58:07 +0100212 MANIFEST_ERROR_MALFORMED_DTB,
David Brazdila2358d42020-01-27 18:51:38 +0000213 MANIFEST_ERROR_NO_ROOT_NODE,
David Brazdil7a462ec2019-08-15 12:27:47 +0100214 MANIFEST_ERROR_NO_HYPERVISOR_FDT_NODE,
David Brazdil74e9c3b2019-08-28 11:09:08 +0100215 MANIFEST_ERROR_NOT_COMPATIBLE,
David Brazdil7a462ec2019-08-15 12:27:47 +0100216 MANIFEST_ERROR_RESERVED_VM_ID,
217 MANIFEST_ERROR_NO_PRIMARY_VM,
218 MANIFEST_ERROR_TOO_MANY_VMS,
219 MANIFEST_ERROR_PROPERTY_NOT_FOUND,
220 MANIFEST_ERROR_MALFORMED_STRING,
David Brazdil0dbb41f2019-09-09 18:03:35 +0100221 MANIFEST_ERROR_STRING_TOO_LONG,
David Brazdil7a462ec2019-08-15 12:27:47 +0100222 MANIFEST_ERROR_MALFORMED_INTEGER,
223 MANIFEST_ERROR_INTEGER_OVERFLOW,
Andrew Scullae9962e2019-10-03 16:51:16 +0100224 MANIFEST_ERROR_MALFORMED_INTEGER_LIST,
Andrew Scullb2c3a242019-11-04 13:52:36 +0000225 MANIFEST_ERROR_MALFORMED_BOOLEAN,
J-Alves35315782022-01-25 17:58:32 +0000226 MANIFEST_ERROR_ARGUMENTS_LIST_EMPTY,
Manish Pandey6542f5c2020-04-27 14:37:46 +0100227 MANIFEST_ERROR_MEMORY_REGION_NODE_EMPTY,
Manish Pandeye68e7932020-04-23 15:29:28 +0100228 MANIFEST_ERROR_DEVICE_REGION_NODE_EMPTY,
Manish Pandeyf06c9072020-09-29 15:41:58 +0100229 MANIFEST_ERROR_RXTX_SIZE_MISMATCH,
Daniel Boulbya7e9e182022-06-27 14:21:01 +0100230 MANIFEST_ERROR_MEM_REGION_OVERLAP,
Raghu Krishnamurthy384693c2021-10-11 13:56:24 -0700231 MANIFEST_ERROR_INVALID_MEM_PERM,
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100232 MANIFEST_ERROR_INTERRUPT_ID_REPEATED,
Madhukar Pappireddy84154052022-06-21 18:30:25 -0500233 MANIFEST_ILLEGAL_NS_ACTION,
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,
Olivier Deprez93644652022-09-09 11:01:12 +0200237 struct manifest **manifest,
Olivier Deprez62d99e32020-01-09 15:58:07 +0100238 struct memiter *manifest_fdt,
239 struct mpool *ppool);
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100240void manifest_deinit(struct mpool *ppool);
Olivier Deprez62d99e32020-01-09 15:58:07 +0100241
Raghu Krishnamurthyb49549e2021-07-02 08:27:38 -0700242enum manifest_return_code parse_ffa_manifest(struct fdt *fdt,
J-Alves35315782022-01-25 17:58:32 +0000243 struct manifest_vm *vm,
244 struct fdt_node *boot_info);
245
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);