blob: c045432a5f9dcc803469bde53c643b36a0e6cff9 [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-Alvesbeeb6dc2021-12-08 18:21:32 +000033/* Highest possible value for the boot-order field. */
34#define DEFAULT_BOOT_ORDER 0xFFFF
J-Alvesb37fd082020-10-22 12:29:21 +010035
Olivier Deprez62d99e32020-01-09 15:58:07 +010036enum run_time_el {
37 EL1 = 0,
38 S_EL0,
39 S_EL1,
40 SUPERVISOR_MODE,
41 SECURE_USER_MODE,
42 SECURE_SUPERVISOR_MODE
43};
44
45enum execution_state { AARCH64 = 0, AARCH32 };
46
47enum xlat_granule { PAGE_4KB = 0, PAGE_16KB, PAGE_64KB };
48
Olivier Deprez62d99e32020-01-09 15:58:07 +010049/**
Manish Pandey6542f5c2020-04-27 14:37:46 +010050 * Partition Memory region as described in PSA FFA v1.0 spec, Table 10
51 */
52struct memory_region {
53 /**
54 * Specify PA, VA for S-EL0 partitions or IPA
55 * for S-EL1 partitions - optional.
56 */
57 uintptr_t base_address;
58 /** Page count - mandatory */
59 uint32_t page_count;
60 /** Memory attributes - mandatory */
61 uint32_t attributes;
62 /** Name of memory region - optional */
63 struct string name;
64};
65
Manish Pandeye68e7932020-04-23 15:29:28 +010066struct interrupt {
67 uint32_t id;
68 uint32_t attributes;
69};
70
71/**
72 * Partition Device region as described in PSA FFA v1.0 spec, Table 11
73 */
74struct device_region {
75 /** Device base PA - mandatory */
76 uintptr_t base_address;
77 /** Page count - mandatory */
78 uint32_t page_count;
79 /** Memory attributes - mandatory */
80 uint32_t attributes;
81 /** List of physical interrupt ID's and their attributes - optional */
82 struct interrupt interrupts[SP_MAX_INTERRUPTS_PER_DEVICE];
Madhukar Pappireddy5fc8be12021-08-03 11:42:53 -050083 /** Count of physical interrupts - optional */
84 uint8_t interrupt_count;
Manish Pandeye68e7932020-04-23 15:29:28 +010085 /** SMMU ID - optional */
86 uint32_t smmu_id;
Madhukar Pappireddy54680c72020-10-23 15:02:38 -050087 /** Count of Stream IDs assigned to device - optional */
88 uint8_t stream_count;
Manish Pandeye68e7932020-04-23 15:29:28 +010089 /** List of Stream IDs assigned to device - optional */
90 uint32_t stream_ids[SP_MAX_STREAMS_PER_DEVICE];
91 /** Exclusive access to an endpoint - optional */
92 bool exclusive_access;
93 /** Name of Device region - optional */
94 struct string name;
95};
96
Manish Pandey6542f5c2020-04-27 14:37:46 +010097/**
Manish Pandeyfa1f2912020-05-05 12:57:01 +010098 * RX/TX buffer, reference to memory-region entries that describe RX/TX
99 * buffers in partition manifest.
100 */
101struct rx_tx {
102 bool available;
103 uint32_t rx_phandle;
104 uint32_t tx_phandle;
105 struct memory_region *rx_buffer;
106 struct memory_region *tx_buffer;
107};
108
109/**
Olivier Deprez62d99e32020-01-09 15:58:07 +0100110 * Partition manifest as described in PSA FF-A v1.0 spec section 3.1
111 */
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700112struct partition_manifest {
Olivier Deprez62d99e32020-01-09 15:58:07 +0100113 /** PSA-FF-A expected version - mandatory */
114 uint32_t ffa_version;
115 /** UUID - mandatory */
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100116 struct ffa_uuid uuid;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100117 /** Partition id - optional */
118 ffa_vm_id_t id;
119 /** Aux ids for mem transactions - optional */
120 ffa_vm_id_t aux_id;
121
122 /* NOTE: optional name field maps to VM debug_name field */
123
124 /** mandatory */
125 ffa_vcpu_count_t execution_ctx_count;
126 /** EL1 or secure EL1, secure EL0 - mandatory */
127 enum run_time_el run_time_el;
128 /** AArch32 / AArch64 - mandatory */
129 enum execution_state execution_state;
130 /** optional */
131 uintpaddr_t load_addr;
132 /** optional */
133 size_t ep_offset;
J-Alves4369bd92020-08-07 16:35:36 +0100134 /** 4/16/64KB - optional */
Olivier Deprez62d99e32020-01-09 15:58:07 +0100135 enum xlat_granule xlat_granule;
136 /** optional */
137 uint16_t boot_order;
138
139 /** Optional RX/TX buffers */
Manish Pandeyfa1f2912020-05-05 12:57:01 +0100140 struct rx_tx rxtx;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100141
142 /** mandatory - direct/indirect msg or both */
Maksims Svecovsb596eab2021-04-27 00:52:27 +0100143 uint8_t messaging_method;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100144 /** optional */
Maksims Svecovs9ddf86a2021-05-06 17:17:21 +0100145 bool managed_exit;
J-Alvesa4730db2021-11-02 10:31:01 +0000146 /** optional - receipt of notifications. */
147 bool notification_support;
Maksims Svecovs9ddf86a2021-05-06 17:17:21 +0100148 /** optional */
Olivier Deprez62d99e32020-01-09 15:58:07 +0100149 bool has_primary_scheduler;
150 /** optional - preemptible / run to completion */
151 uint8_t runtime_model;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100152 /** optional - tuples SEPID/SMMUID/streamId */
153 uint32_t stream_ep_ids[1];
Manish Pandey6542f5c2020-04-27 14:37:46 +0100154
155 /** Memory regions */
Manish Pandey2145c212020-05-01 16:04:22 +0100156 uint8_t mem_region_count;
Manish Pandey6542f5c2020-04-27 14:37:46 +0100157 struct memory_region mem_regions[SP_MAX_MEMORY_REGIONS];
Manish Pandeye68e7932020-04-23 15:29:28 +0100158 /** Device regions */
Manish Pandey2145c212020-05-01 16:04:22 +0100159 uint8_t dev_region_count;
Manish Pandeye68e7932020-04-23 15:29:28 +0100160 struct device_region dev_regions[SP_MAX_DEVICE_REGIONS];
Olivier Deprez62d99e32020-01-09 15:58:07 +0100161};
162
163/**
164 * Header for a PSA FF-A partition package.
165 */
166struct sp_pkg_header {
167 /** Magic used to identify a SP package. Value is "SPKG" */
168 uint32_t magic;
169 /** Version number of the header */
170 uint32_t version;
171 /** Offset in bytes to the partition manifest */
172 uint32_t pm_offset;
173 /** Size in bytes of the partition manifest */
174 uint32_t pm_size;
175 /** Offset in bytes to the base address of the partition binary */
176 uint32_t img_offset;
177 /** Size in bytes of the partition binary */
178 uint32_t img_size;
179};
180
David Brazdil0dbb41f2019-09-09 18:03:35 +0100181/**
David Brazdil7a462ec2019-08-15 12:27:47 +0100182 * Holds information about one of the VMs described in the manifest.
183 */
184struct manifest_vm {
185 /* Properties defined for both primary and secondary VMs. */
David Brazdil136f2942019-09-23 14:11:03 +0100186 struct string debug_name;
187 struct string kernel_filename;
Andrew Scullae9962e2019-10-03 16:51:16 +0100188 struct smc_whitelist smc_whitelist;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100189 bool is_ffa_partition;
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700190 struct partition_manifest partition;
David Brazdil7a462ec2019-08-15 12:27:47 +0100191
David Brazdile6f83222019-09-23 14:47:37 +0100192 union {
193 /* Properties specific to the primary VM. */
194 struct {
David Brazdil080ee312020-02-25 15:30:30 -0800195 uint64_t boot_address;
David Brazdile6f83222019-09-23 14:47:37 +0100196 struct string ramdisk_filename;
197 } primary;
198 /* Properties specific to secondary VMs. */
199 struct {
200 uint64_t mem_size;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100201 ffa_vcpu_count_t vcpu_count;
Fuad Tabba50469e02020-06-30 15:14:28 +0100202 struct string fdt_filename;
David Brazdile6f83222019-09-23 14:47:37 +0100203 } secondary;
204 };
David Brazdil7a462ec2019-08-15 12:27:47 +0100205};
206
207/**
208 * Hafnium manifest parsed from FDT.
209 */
210struct manifest {
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100211 bool ffa_tee_enabled;
212 ffa_vm_count_t vm_count;
David Brazdil7a462ec2019-08-15 12:27:47 +0100213 struct manifest_vm vm[MAX_VMS];
214};
215
216enum manifest_return_code {
217 MANIFEST_SUCCESS = 0,
David Brazdila2358d42020-01-27 18:51:38 +0000218 MANIFEST_ERROR_FILE_SIZE,
Olivier Deprez62d99e32020-01-09 15:58:07 +0100219 MANIFEST_ERROR_MALFORMED_DTB,
David Brazdila2358d42020-01-27 18:51:38 +0000220 MANIFEST_ERROR_NO_ROOT_NODE,
David Brazdil7a462ec2019-08-15 12:27:47 +0100221 MANIFEST_ERROR_NO_HYPERVISOR_FDT_NODE,
David Brazdil74e9c3b2019-08-28 11:09:08 +0100222 MANIFEST_ERROR_NOT_COMPATIBLE,
David Brazdil7a462ec2019-08-15 12:27:47 +0100223 MANIFEST_ERROR_RESERVED_VM_ID,
224 MANIFEST_ERROR_NO_PRIMARY_VM,
225 MANIFEST_ERROR_TOO_MANY_VMS,
226 MANIFEST_ERROR_PROPERTY_NOT_FOUND,
227 MANIFEST_ERROR_MALFORMED_STRING,
David Brazdil0dbb41f2019-09-09 18:03:35 +0100228 MANIFEST_ERROR_STRING_TOO_LONG,
David Brazdil7a462ec2019-08-15 12:27:47 +0100229 MANIFEST_ERROR_MALFORMED_INTEGER,
230 MANIFEST_ERROR_INTEGER_OVERFLOW,
Andrew Scullae9962e2019-10-03 16:51:16 +0100231 MANIFEST_ERROR_MALFORMED_INTEGER_LIST,
Andrew Scullb2c3a242019-11-04 13:52:36 +0000232 MANIFEST_ERROR_MALFORMED_BOOLEAN,
Manish Pandey6542f5c2020-04-27 14:37:46 +0100233 MANIFEST_ERROR_MEMORY_REGION_NODE_EMPTY,
Manish Pandeye68e7932020-04-23 15:29:28 +0100234 MANIFEST_ERROR_DEVICE_REGION_NODE_EMPTY,
Manish Pandeyf06c9072020-09-29 15:41:58 +0100235 MANIFEST_ERROR_RXTX_SIZE_MISMATCH,
Raghu Krishnamurthy384693c2021-10-11 13:56:24 -0700236 MANIFEST_ERROR_INVALID_MEM_PERM,
David Brazdil7a462ec2019-08-15 12:27:47 +0100237};
238
Olivier Deprez62d99e32020-01-09 15:58:07 +0100239enum manifest_return_code manifest_init(struct mm_stage1_locked stage1_locked,
240 struct manifest *manifest,
241 struct memiter *manifest_fdt,
242 struct mpool *ppool);
243
244void manifest_dump(struct manifest_vm *vm);
David Brazdil7a462ec2019-08-15 12:27:47 +0100245
246const char *manifest_strerror(enum manifest_return_code ret_code);