blob: 0cf6eb4923d1934957e71cd28da3f4431691a04e [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
Madhukar Pappireddy54680c72020-10-23 15:02:38 -050018#define MANIFEST_INVALID_ID UINT32_MAX
David Brazdil080ee312020-02-25 15:30:30 -080019
Olivier Deprez62d99e32020-01-09 15:58:07 +010020#define SP_PKG_HEADER_MAGIC (0x474b5053)
21#define SP_PKG_HEADER_VERSION (0x1)
22
23#define SP_RTX_BUF_NAME_SIZE 10
24
Manish Pandey6542f5c2020-04-27 14:37:46 +010025#define SP_MAX_MEMORY_REGIONS 8
Manish Pandeye68e7932020-04-23 15:29:28 +010026#define SP_MAX_DEVICE_REGIONS 8
27#define SP_MAX_INTERRUPTS_PER_DEVICE 4
28#define SP_MAX_STREAMS_PER_DEVICE 4
Manish Pandey6542f5c2020-04-27 14:37:46 +010029
30/** Mask for getting read/write/execute permission */
31#define MM_PERM_MASK 0x7
32
J-Alvesb37fd082020-10-22 12:29:21 +010033#define DEFAULT_BOOT_ORDER 0x0
34
Olivier Deprez62d99e32020-01-09 15:58:07 +010035enum run_time_el {
36 EL1 = 0,
37 S_EL0,
38 S_EL1,
39 SUPERVISOR_MODE,
40 SECURE_USER_MODE,
41 SECURE_SUPERVISOR_MODE
42};
43
44enum execution_state { AARCH64 = 0, AARCH32 };
45
46enum xlat_granule { PAGE_4KB = 0, PAGE_16KB, PAGE_64KB };
47
Olivier Deprez62d99e32020-01-09 15:58:07 +010048/**
Manish Pandey6542f5c2020-04-27 14:37:46 +010049 * Partition Memory region as described in PSA FFA v1.0 spec, Table 10
50 */
51struct memory_region {
52 /**
53 * Specify PA, VA for S-EL0 partitions or IPA
54 * for S-EL1 partitions - optional.
55 */
56 uintptr_t base_address;
57 /** Page count - mandatory */
58 uint32_t page_count;
59 /** Memory attributes - mandatory */
60 uint32_t attributes;
61 /** Name of memory region - optional */
62 struct string name;
63};
64
Manish Pandeye68e7932020-04-23 15:29:28 +010065struct interrupt {
66 uint32_t id;
67 uint32_t attributes;
68};
69
70/**
71 * Partition Device region as described in PSA FFA v1.0 spec, Table 11
72 */
73struct device_region {
74 /** Device base PA - mandatory */
75 uintptr_t base_address;
76 /** Page count - mandatory */
77 uint32_t page_count;
78 /** Memory attributes - mandatory */
79 uint32_t attributes;
80 /** List of physical interrupt ID's and their attributes - optional */
81 struct interrupt interrupts[SP_MAX_INTERRUPTS_PER_DEVICE];
82 /** SMMU ID - optional */
83 uint32_t smmu_id;
Madhukar Pappireddy54680c72020-10-23 15:02:38 -050084 /** Count of Stream IDs assigned to device - optional */
85 uint8_t stream_count;
Manish Pandeye68e7932020-04-23 15:29:28 +010086 /** List of Stream IDs assigned to device - optional */
87 uint32_t stream_ids[SP_MAX_STREAMS_PER_DEVICE];
88 /** Exclusive access to an endpoint - optional */
89 bool exclusive_access;
90 /** Name of Device region - optional */
91 struct string name;
92};
93
Manish Pandey6542f5c2020-04-27 14:37:46 +010094/**
Manish Pandeyfa1f2912020-05-05 12:57:01 +010095 * RX/TX buffer, reference to memory-region entries that describe RX/TX
96 * buffers in partition manifest.
97 */
98struct rx_tx {
99 bool available;
100 uint32_t rx_phandle;
101 uint32_t tx_phandle;
102 struct memory_region *rx_buffer;
103 struct memory_region *tx_buffer;
104};
105
106/**
Olivier Deprez62d99e32020-01-09 15:58:07 +0100107 * Partition manifest as described in PSA FF-A v1.0 spec section 3.1
108 */
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700109struct partition_manifest {
Olivier Deprez62d99e32020-01-09 15:58:07 +0100110 /** PSA-FF-A expected version - mandatory */
111 uint32_t ffa_version;
112 /** UUID - mandatory */
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100113 struct ffa_uuid uuid;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100114 /** Partition id - optional */
115 ffa_vm_id_t id;
116 /** Aux ids for mem transactions - optional */
117 ffa_vm_id_t aux_id;
118
119 /* NOTE: optional name field maps to VM debug_name field */
120
121 /** mandatory */
122 ffa_vcpu_count_t execution_ctx_count;
123 /** EL1 or secure EL1, secure EL0 - mandatory */
124 enum run_time_el run_time_el;
125 /** AArch32 / AArch64 - mandatory */
126 enum execution_state execution_state;
127 /** optional */
128 uintpaddr_t load_addr;
129 /** optional */
130 size_t ep_offset;
J-Alves4369bd92020-08-07 16:35:36 +0100131 /** 4/16/64KB - optional */
Olivier Deprez62d99e32020-01-09 15:58:07 +0100132 enum xlat_granule xlat_granule;
133 /** optional */
134 uint16_t boot_order;
135
136 /** Optional RX/TX buffers */
Manish Pandeyfa1f2912020-05-05 12:57:01 +0100137 struct rx_tx rxtx;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100138
139 /** mandatory - direct/indirect msg or both */
Maksims Svecovsb596eab2021-04-27 00:52:27 +0100140 uint8_t messaging_method;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100141 /** optional */
Maksims Svecovs9ddf86a2021-05-06 17:17:21 +0100142 bool managed_exit;
143 /** optional */
Olivier Deprez62d99e32020-01-09 15:58:07 +0100144 bool has_primary_scheduler;
145 /** optional - preemptible / run to completion */
146 uint8_t runtime_model;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100147 /** optional - tuples SEPID/SMMUID/streamId */
148 uint32_t stream_ep_ids[1];
Manish Pandey6542f5c2020-04-27 14:37:46 +0100149
150 /** Memory regions */
Manish Pandey2145c212020-05-01 16:04:22 +0100151 uint8_t mem_region_count;
Manish Pandey6542f5c2020-04-27 14:37:46 +0100152 struct memory_region mem_regions[SP_MAX_MEMORY_REGIONS];
Manish Pandeye68e7932020-04-23 15:29:28 +0100153 /** Device regions */
Manish Pandey2145c212020-05-01 16:04:22 +0100154 uint8_t dev_region_count;
Manish Pandeye68e7932020-04-23 15:29:28 +0100155 struct device_region dev_regions[SP_MAX_DEVICE_REGIONS];
Olivier Deprez62d99e32020-01-09 15:58:07 +0100156};
157
158/**
159 * Header for a PSA FF-A partition package.
160 */
161struct sp_pkg_header {
162 /** Magic used to identify a SP package. Value is "SPKG" */
163 uint32_t magic;
164 /** Version number of the header */
165 uint32_t version;
166 /** Offset in bytes to the partition manifest */
167 uint32_t pm_offset;
168 /** Size in bytes of the partition manifest */
169 uint32_t pm_size;
170 /** Offset in bytes to the base address of the partition binary */
171 uint32_t img_offset;
172 /** Size in bytes of the partition binary */
173 uint32_t img_size;
174};
175
David Brazdil0dbb41f2019-09-09 18:03:35 +0100176/**
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 Krishnamurthy8c250a92021-07-02 12:16:42 -0700185 struct partition_manifest partition;
David Brazdil7a462ec2019-08-15 12:27:47 +0100186
David Brazdile6f83222019-09-23 14:47:37 +0100187 union {
188 /* Properties specific to the primary VM. */
189 struct {
David Brazdil080ee312020-02-25 15:30:30 -0800190 uint64_t boot_address;
David Brazdile6f83222019-09-23 14:47:37 +0100191 struct string ramdisk_filename;
192 } primary;
193 /* Properties specific to secondary VMs. */
194 struct {
195 uint64_t mem_size;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100196 ffa_vcpu_count_t vcpu_count;
Fuad Tabba50469e02020-06-30 15:14:28 +0100197 struct string fdt_filename;
David Brazdile6f83222019-09-23 14:47:37 +0100198 } secondary;
199 };
David Brazdil7a462ec2019-08-15 12:27:47 +0100200};
201
202/**
203 * Hafnium manifest parsed from FDT.
204 */
205struct manifest {
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100206 bool ffa_tee_enabled;
207 ffa_vm_count_t vm_count;
David Brazdil7a462ec2019-08-15 12:27:47 +0100208 struct manifest_vm vm[MAX_VMS];
209};
210
211enum manifest_return_code {
212 MANIFEST_SUCCESS = 0,
David Brazdila2358d42020-01-27 18:51:38 +0000213 MANIFEST_ERROR_FILE_SIZE,
Olivier Deprez62d99e32020-01-09 15:58:07 +0100214 MANIFEST_ERROR_MALFORMED_DTB,
David Brazdila2358d42020-01-27 18:51:38 +0000215 MANIFEST_ERROR_NO_ROOT_NODE,
David Brazdil7a462ec2019-08-15 12:27:47 +0100216 MANIFEST_ERROR_NO_HYPERVISOR_FDT_NODE,
David Brazdil74e9c3b2019-08-28 11:09:08 +0100217 MANIFEST_ERROR_NOT_COMPATIBLE,
David Brazdil7a462ec2019-08-15 12:27:47 +0100218 MANIFEST_ERROR_RESERVED_VM_ID,
219 MANIFEST_ERROR_NO_PRIMARY_VM,
220 MANIFEST_ERROR_TOO_MANY_VMS,
221 MANIFEST_ERROR_PROPERTY_NOT_FOUND,
222 MANIFEST_ERROR_MALFORMED_STRING,
David Brazdil0dbb41f2019-09-09 18:03:35 +0100223 MANIFEST_ERROR_STRING_TOO_LONG,
David Brazdil7a462ec2019-08-15 12:27:47 +0100224 MANIFEST_ERROR_MALFORMED_INTEGER,
225 MANIFEST_ERROR_INTEGER_OVERFLOW,
Andrew Scullae9962e2019-10-03 16:51:16 +0100226 MANIFEST_ERROR_MALFORMED_INTEGER_LIST,
Andrew Scullb2c3a242019-11-04 13:52:36 +0000227 MANIFEST_ERROR_MALFORMED_BOOLEAN,
Manish Pandey6542f5c2020-04-27 14:37:46 +0100228 MANIFEST_ERROR_MEMORY_REGION_NODE_EMPTY,
Manish Pandeye68e7932020-04-23 15:29:28 +0100229 MANIFEST_ERROR_DEVICE_REGION_NODE_EMPTY,
Manish Pandeyf06c9072020-09-29 15:41:58 +0100230 MANIFEST_ERROR_RXTX_SIZE_MISMATCH,
David Brazdil7a462ec2019-08-15 12:27:47 +0100231};
232
Olivier Deprez62d99e32020-01-09 15:58:07 +0100233enum manifest_return_code manifest_init(struct mm_stage1_locked stage1_locked,
234 struct manifest *manifest,
235 struct memiter *manifest_fdt,
236 struct mpool *ppool);
237
238void manifest_dump(struct manifest_vm *vm);
David Brazdil7a462ec2019-08-15 12:27:47 +0100239
240const char *manifest_strerror(enum manifest_return_code ret_code);