blob: 9286202eaee9ae2d0b3877061287d399f0f07186 [file] [log] [blame]
David Brazdil7a462ec2019-08-15 12:27:47 +01001/*
2 * Copyright 2019 The Hafnium Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
Olivier Deprez62d99e32020-01-09 15:58:07 +010019#include "hf/addr.h"
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010020#include "hf/ffa.h"
David Brazdil7a462ec2019-08-15 12:27:47 +010021#include "hf/memiter.h"
David Brazdil136f2942019-09-23 14:11:03 +010022#include "hf/string.h"
Andrew Scullae9962e2019-10-03 16:51:16 +010023#include "hf/vm.h"
David Brazdil0dbb41f2019-09-09 18:03:35 +010024
David Brazdil080ee312020-02-25 15:30:30 -080025#define MANIFEST_INVALID_ADDRESS UINT64_MAX
26
Olivier Deprez62d99e32020-01-09 15:58:07 +010027#define SP_PKG_HEADER_MAGIC (0x474b5053)
28#define SP_PKG_HEADER_VERSION (0x1)
29
30#define SP_RTX_BUF_NAME_SIZE 10
31
32enum 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/**
52 * Partition manifest as described in PSA FF-A v1.0 spec section 3.1
53 */
54struct sp_manifest {
55 /** PSA-FF-A expected version - mandatory */
56 uint32_t ffa_version;
57 /** UUID - mandatory */
58 uint32_t uuid[4];
59 /** Partition id - optional */
60 ffa_vm_id_t id;
61 /** Aux ids for mem transactions - optional */
62 ffa_vm_id_t aux_id;
63
64 /* NOTE: optional name field maps to VM debug_name field */
65
66 /** mandatory */
67 ffa_vcpu_count_t execution_ctx_count;
68 /** EL1 or secure EL1, secure EL0 - mandatory */
69 enum run_time_el run_time_el;
70 /** AArch32 / AArch64 - mandatory */
71 enum execution_state execution_state;
72 /** optional */
73 uintpaddr_t load_addr;
74 /** optional */
75 size_t ep_offset;
76 /** 4/16/64KB - mandatory */
77 enum xlat_granule xlat_granule;
78 /** optional */
79 uint16_t boot_order;
80
81 /** Optional RX/TX buffers */
82 struct {
83 bool rxtx_found;
84 /** optional */
85 uint64_t base_address;
86 /** optional */
87 uint16_t pages_count;
88 /** mandatory */
89 uint16_t attributes;
90 /** Optional */
91 char name[SP_RTX_BUF_NAME_SIZE];
92 } rxtx;
93
94 /** mandatory - direct/indirect msg or both */
95 enum messaging_method messaging_method;
96 /** optional */
97 bool has_primary_scheduler;
98 /** optional - preemptible / run to completion */
99 uint8_t runtime_model;
100 /** optional */
101 bool time_slice_mem;
102 /** optional - tuples SEPID/SMMUID/streamId */
103 uint32_t stream_ep_ids[1];
104};
105
106/**
107 * Header for a PSA FF-A partition package.
108 */
109struct sp_pkg_header {
110 /** Magic used to identify a SP package. Value is "SPKG" */
111 uint32_t magic;
112 /** Version number of the header */
113 uint32_t version;
114 /** Offset in bytes to the partition manifest */
115 uint32_t pm_offset;
116 /** Size in bytes of the partition manifest */
117 uint32_t pm_size;
118 /** Offset in bytes to the base address of the partition binary */
119 uint32_t img_offset;
120 /** Size in bytes of the partition binary */
121 uint32_t img_size;
122};
123
David Brazdil0dbb41f2019-09-09 18:03:35 +0100124/**
David Brazdil7a462ec2019-08-15 12:27:47 +0100125 * Holds information about one of the VMs described in the manifest.
126 */
127struct manifest_vm {
128 /* Properties defined for both primary and secondary VMs. */
David Brazdil136f2942019-09-23 14:11:03 +0100129 struct string debug_name;
130 struct string kernel_filename;
Andrew Scullae9962e2019-10-03 16:51:16 +0100131 struct smc_whitelist smc_whitelist;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100132 bool is_ffa_partition;
133 struct sp_manifest sp;
David Brazdil7a462ec2019-08-15 12:27:47 +0100134
David Brazdile6f83222019-09-23 14:47:37 +0100135 union {
136 /* Properties specific to the primary VM. */
137 struct {
David Brazdil080ee312020-02-25 15:30:30 -0800138 uint64_t boot_address;
David Brazdile6f83222019-09-23 14:47:37 +0100139 struct string ramdisk_filename;
140 } primary;
141 /* Properties specific to secondary VMs. */
142 struct {
143 uint64_t mem_size;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100144 ffa_vcpu_count_t vcpu_count;
David Brazdile6f83222019-09-23 14:47:37 +0100145 } secondary;
146 };
David Brazdil7a462ec2019-08-15 12:27:47 +0100147};
148
149/**
150 * Hafnium manifest parsed from FDT.
151 */
152struct manifest {
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100153 bool ffa_tee_enabled;
154 ffa_vm_count_t vm_count;
David Brazdil7a462ec2019-08-15 12:27:47 +0100155 struct manifest_vm vm[MAX_VMS];
156};
157
158enum manifest_return_code {
159 MANIFEST_SUCCESS = 0,
David Brazdila2358d42020-01-27 18:51:38 +0000160 MANIFEST_ERROR_FILE_SIZE,
Olivier Deprez62d99e32020-01-09 15:58:07 +0100161 MANIFEST_ERROR_MALFORMED_DTB,
David Brazdila2358d42020-01-27 18:51:38 +0000162 MANIFEST_ERROR_NO_ROOT_NODE,
David Brazdil7a462ec2019-08-15 12:27:47 +0100163 MANIFEST_ERROR_NO_HYPERVISOR_FDT_NODE,
David Brazdil74e9c3b2019-08-28 11:09:08 +0100164 MANIFEST_ERROR_NOT_COMPATIBLE,
David Brazdil7a462ec2019-08-15 12:27:47 +0100165 MANIFEST_ERROR_RESERVED_VM_ID,
166 MANIFEST_ERROR_NO_PRIMARY_VM,
167 MANIFEST_ERROR_TOO_MANY_VMS,
168 MANIFEST_ERROR_PROPERTY_NOT_FOUND,
169 MANIFEST_ERROR_MALFORMED_STRING,
David Brazdil0dbb41f2019-09-09 18:03:35 +0100170 MANIFEST_ERROR_STRING_TOO_LONG,
David Brazdil7a462ec2019-08-15 12:27:47 +0100171 MANIFEST_ERROR_MALFORMED_INTEGER,
172 MANIFEST_ERROR_INTEGER_OVERFLOW,
Andrew Scullae9962e2019-10-03 16:51:16 +0100173 MANIFEST_ERROR_MALFORMED_INTEGER_LIST,
Andrew Scullb2c3a242019-11-04 13:52:36 +0000174 MANIFEST_ERROR_MALFORMED_BOOLEAN,
David Brazdil7a462ec2019-08-15 12:27:47 +0100175};
176
Olivier Deprez62d99e32020-01-09 15:58:07 +0100177enum manifest_return_code manifest_init(struct mm_stage1_locked stage1_locked,
178 struct manifest *manifest,
179 struct memiter *manifest_fdt,
180 struct mpool *ppool);
181
182void manifest_dump(struct manifest_vm *vm);
David Brazdil7a462ec2019-08-15 12:27:47 +0100183
184const char *manifest_strerror(enum manifest_return_code ret_code);