blob: 3e9eaf4f7af4b905a505076fd79e0785dd852582 [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"
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010012#include "hf/ffa.h"
David Brazdil7a462ec2019-08-15 12:27:47 +010013#include "hf/memiter.h"
David Brazdil136f2942019-09-23 14:11:03 +010014#include "hf/string.h"
Andrew Scullae9962e2019-10-03 16:51:16 +010015#include "hf/vm.h"
David Brazdil0dbb41f2019-09-09 18:03:35 +010016
David Brazdil080ee312020-02-25 15:30:30 -080017#define MANIFEST_INVALID_ADDRESS UINT64_MAX
18
Olivier Deprez62d99e32020-01-09 15:58:07 +010019#define SP_PKG_HEADER_MAGIC (0x474b5053)
20#define SP_PKG_HEADER_VERSION (0x1)
21
22#define SP_RTX_BUF_NAME_SIZE 10
23
Manish Pandey6542f5c2020-04-27 14:37:46 +010024#define SP_MAX_MEMORY_REGIONS 8
Manish Pandeye68e7932020-04-23 15:29:28 +010025#define SP_MAX_DEVICE_REGIONS 8
26#define SP_MAX_INTERRUPTS_PER_DEVICE 4
27#define SP_MAX_STREAMS_PER_DEVICE 4
Manish Pandey6542f5c2020-04-27 14:37:46 +010028
29/** Mask for getting read/write/execute permission */
30#define MM_PERM_MASK 0x7
31
Olivier Deprez62d99e32020-01-09 15:58:07 +010032enum run_time_el {
33 EL1 = 0,
34 S_EL0,
35 S_EL1,
36 SUPERVISOR_MODE,
37 SECURE_USER_MODE,
38 SECURE_SUPERVISOR_MODE
39};
40
41enum execution_state { AARCH64 = 0, AARCH32 };
42
43enum xlat_granule { PAGE_4KB = 0, PAGE_16KB, PAGE_64KB };
44
45enum messaging_method {
46 DIRECT_MESSAGING = 0,
47 INDIRECT_MESSAGING,
48 BOTH_MESSAGING
49};
50
51/**
Manish Pandey6542f5c2020-04-27 14:37:46 +010052 * Partition Memory region as described in PSA FFA v1.0 spec, Table 10
53 */
54struct memory_region {
55 /**
56 * Specify PA, VA for S-EL0 partitions or IPA
57 * for S-EL1 partitions - optional.
58 */
59 uintptr_t base_address;
60 /** Page count - mandatory */
61 uint32_t page_count;
62 /** Memory attributes - mandatory */
63 uint32_t attributes;
64 /** Name of memory region - optional */
65 struct string name;
66};
67
Manish Pandeye68e7932020-04-23 15:29:28 +010068struct interrupt {
69 uint32_t id;
70 uint32_t attributes;
71};
72
73/**
74 * Partition Device region as described in PSA FFA v1.0 spec, Table 11
75 */
76struct device_region {
77 /** Device base PA - mandatory */
78 uintptr_t base_address;
79 /** Page count - mandatory */
80 uint32_t page_count;
81 /** Memory attributes - mandatory */
82 uint32_t attributes;
83 /** List of physical interrupt ID's and their attributes - optional */
84 struct interrupt interrupts[SP_MAX_INTERRUPTS_PER_DEVICE];
85 /** SMMU ID - optional */
86 uint32_t smmu_id;
87 /** List of Stream IDs assigned to device - optional */
88 uint32_t stream_ids[SP_MAX_STREAMS_PER_DEVICE];
89 /** Exclusive access to an endpoint - optional */
90 bool exclusive_access;
91 /** Name of Device region - optional */
92 struct string name;
93};
94
Manish Pandey6542f5c2020-04-27 14:37:46 +010095/**
Manish Pandeyfa1f2912020-05-05 12:57:01 +010096 * RX/TX buffer, reference to memory-region entries that describe RX/TX
97 * buffers in partition manifest.
98 */
99struct rx_tx {
100 bool available;
101 uint32_t rx_phandle;
102 uint32_t tx_phandle;
103 struct memory_region *rx_buffer;
104 struct memory_region *tx_buffer;
105};
106
107/**
Olivier Deprez62d99e32020-01-09 15:58:07 +0100108 * Partition manifest as described in PSA FF-A v1.0 spec section 3.1
109 */
110struct sp_manifest {
111 /** PSA-FF-A expected version - mandatory */
112 uint32_t ffa_version;
113 /** UUID - mandatory */
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100114 struct ffa_uuid uuid;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100115 /** Partition id - optional */
116 ffa_vm_id_t id;
117 /** Aux ids for mem transactions - optional */
118 ffa_vm_id_t aux_id;
119
120 /* NOTE: optional name field maps to VM debug_name field */
121
122 /** mandatory */
123 ffa_vcpu_count_t execution_ctx_count;
124 /** EL1 or secure EL1, secure EL0 - mandatory */
125 enum run_time_el run_time_el;
126 /** AArch32 / AArch64 - mandatory */
127 enum execution_state execution_state;
128 /** optional */
129 uintpaddr_t load_addr;
130 /** optional */
131 size_t ep_offset;
132 /** 4/16/64KB - mandatory */
133 enum xlat_granule xlat_granule;
134 /** optional */
135 uint16_t boot_order;
136
137 /** Optional RX/TX buffers */
Manish Pandeyfa1f2912020-05-05 12:57:01 +0100138 struct rx_tx rxtx;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100139
140 /** mandatory - direct/indirect msg or both */
141 enum messaging_method messaging_method;
142 /** optional */
143 bool has_primary_scheduler;
144 /** optional - preemptible / run to completion */
145 uint8_t runtime_model;
146 /** optional */
147 bool time_slice_mem;
148 /** optional - tuples SEPID/SMMUID/streamId */
149 uint32_t stream_ep_ids[1];
Manish Pandey6542f5c2020-04-27 14:37:46 +0100150
151 /** Memory regions */
Manish Pandey2145c212020-05-01 16:04:22 +0100152 uint8_t mem_region_count;
Manish Pandey6542f5c2020-04-27 14:37:46 +0100153 struct memory_region mem_regions[SP_MAX_MEMORY_REGIONS];
Manish Pandeye68e7932020-04-23 15:29:28 +0100154 /** Device regions */
Manish Pandey2145c212020-05-01 16:04:22 +0100155 uint8_t dev_region_count;
Manish Pandeye68e7932020-04-23 15:29:28 +0100156 struct device_region dev_regions[SP_MAX_DEVICE_REGIONS];
Olivier Deprez62d99e32020-01-09 15:58:07 +0100157};
158
159/**
160 * Header for a PSA FF-A partition package.
161 */
162struct sp_pkg_header {
163 /** Magic used to identify a SP package. Value is "SPKG" */
164 uint32_t magic;
165 /** Version number of the header */
166 uint32_t version;
167 /** Offset in bytes to the partition manifest */
168 uint32_t pm_offset;
169 /** Size in bytes of the partition manifest */
170 uint32_t pm_size;
171 /** Offset in bytes to the base address of the partition binary */
172 uint32_t img_offset;
173 /** Size in bytes of the partition binary */
174 uint32_t img_size;
175};
176
David Brazdil0dbb41f2019-09-09 18:03:35 +0100177/**
David Brazdil7a462ec2019-08-15 12:27:47 +0100178 * Holds information about one of the VMs described in the manifest.
179 */
180struct manifest_vm {
181 /* Properties defined for both primary and secondary VMs. */
David Brazdil136f2942019-09-23 14:11:03 +0100182 struct string debug_name;
183 struct string kernel_filename;
Andrew Scullae9962e2019-10-03 16:51:16 +0100184 struct smc_whitelist smc_whitelist;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100185 bool is_ffa_partition;
186 struct sp_manifest sp;
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,
Manish Pandey6542f5c2020-04-27 14:37:46 +0100229 MANIFEST_ERROR_MEMORY_REGION_NODE_EMPTY,
Manish Pandeye68e7932020-04-23 15:29:28 +0100230 MANIFEST_ERROR_DEVICE_REGION_NODE_EMPTY,
Manish Pandeyf06c9072020-09-29 15:41:58 +0100231 MANIFEST_ERROR_RXTX_SIZE_MISMATCH,
David Brazdil7a462ec2019-08-15 12:27:47 +0100232};
233
Olivier Deprez62d99e32020-01-09 15:58:07 +0100234enum manifest_return_code manifest_init(struct mm_stage1_locked stage1_locked,
235 struct manifest *manifest,
236 struct memiter *manifest_fdt,
237 struct mpool *ppool);
238
239void manifest_dump(struct manifest_vm *vm);
David Brazdil7a462ec2019-08-15 12:27:47 +0100240
241const char *manifest_strerror(enum manifest_return_code ret_code);