blob: 0bee77d4b8481378adb476d00267e3e5bcc0675b [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
Manish Pandey6542f5c2020-04-27 14:37:46 +010023#define SP_MAX_MEMORY_REGIONS 8
Manish Pandeye68e7932020-04-23 15:29:28 +010024#define SP_MAX_DEVICE_REGIONS 8
25#define SP_MAX_INTERRUPTS_PER_DEVICE 4
26#define SP_MAX_STREAMS_PER_DEVICE 4
Manish Pandey6542f5c2020-04-27 14:37:46 +010027
28/** Mask for getting read/write/execute permission */
29#define MM_PERM_MASK 0x7
30
J-Alvesbeeb6dc2021-12-08 18:21:32 +000031/* Highest possible value for the boot-order field. */
32#define DEFAULT_BOOT_ORDER 0xFFFF
J-Alvesb37fd082020-10-22 12:29:21 +010033
Olivier Deprez62d99e32020-01-09 15:58:07 +010034enum run_time_el {
35 EL1 = 0,
36 S_EL0,
37 S_EL1,
38 SUPERVISOR_MODE,
39 SECURE_USER_MODE,
40 SECURE_SUPERVISOR_MODE
41};
42
43enum execution_state { AARCH64 = 0, AARCH32 };
44
45enum xlat_granule { PAGE_4KB = 0, PAGE_16KB, PAGE_64KB };
46
Olivier Deprez62d99e32020-01-09 15:58:07 +010047/**
Olivier Deprezc13a8692022-04-08 17:47:14 +020048 * Partition Memory region as described in FFA v1.0 spec, Table 10
Manish Pandey6542f5c2020-04-27 14:37:46 +010049 */
50struct memory_region {
51 /**
52 * Specify PA, VA for S-EL0 partitions or IPA
53 * for S-EL1 partitions - optional.
54 */
55 uintptr_t base_address;
56 /** Page count - mandatory */
57 uint32_t page_count;
58 /** Memory attributes - mandatory */
59 uint32_t attributes;
60 /** Name of memory region - optional */
61 struct string name;
62};
63
Manish Pandeye68e7932020-04-23 15:29:28 +010064struct interrupt {
65 uint32_t id;
66 uint32_t attributes;
67};
68
69/**
Olivier Deprezc13a8692022-04-08 17:47:14 +020070 * Partition Device region as described in FFA v1.0 spec, Table 11
Manish Pandeye68e7932020-04-23 15:29:28 +010071 */
72struct device_region {
73 /** Device base PA - mandatory */
74 uintptr_t base_address;
75 /** Page count - mandatory */
76 uint32_t page_count;
77 /** Memory attributes - mandatory */
78 uint32_t attributes;
79 /** List of physical interrupt ID's and their attributes - optional */
80 struct interrupt interrupts[SP_MAX_INTERRUPTS_PER_DEVICE];
Madhukar Pappireddy5fc8be12021-08-03 11:42:53 -050081 /** Count of physical interrupts - optional */
82 uint8_t interrupt_count;
Manish Pandeye68e7932020-04-23 15:29:28 +010083 /** SMMU ID - optional */
84 uint32_t smmu_id;
Madhukar Pappireddy54680c72020-10-23 15:02:38 -050085 /** Count of Stream IDs assigned to device - optional */
86 uint8_t stream_count;
Manish Pandeye68e7932020-04-23 15:29:28 +010087 /** 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 Deprezc13a8692022-04-08 17:47:14 +0200108 * Partition manifest as described in FF-A v1.0 spec section 3.1
Olivier Deprez62d99e32020-01-09 15:58:07 +0100109 */
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700110struct partition_manifest {
Olivier Deprezc13a8692022-04-08 17:47:14 +0200111 /** FF-A expected version - mandatory */
Olivier Deprez62d99e32020-01-09 15:58:07 +0100112 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;
J-Alves4369bd92020-08-07 16:35:36 +0100132 /** 4/16/64KB - optional */
Olivier Deprez62d99e32020-01-09 15:58:07 +0100133 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 */
Maksims Svecovsb596eab2021-04-27 00:52:27 +0100141 uint8_t messaging_method;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100142 /** optional */
Maksims Svecovs9ddf86a2021-05-06 17:17:21 +0100143 bool managed_exit;
J-Alvesa4730db2021-11-02 10:31:01 +0000144 /** optional - receipt of notifications. */
145 bool notification_support;
Maksims Svecovs9ddf86a2021-05-06 17:17:21 +0100146 /** optional */
Olivier Deprez62d99e32020-01-09 15:58:07 +0100147 bool has_primary_scheduler;
148 /** optional - preemptible / run to completion */
149 uint8_t runtime_model;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100150 /** optional - tuples SEPID/SMMUID/streamId */
151 uint32_t stream_ep_ids[1];
Manish Pandey6542f5c2020-04-27 14:37:46 +0100152
153 /** Memory regions */
Manish Pandey2145c212020-05-01 16:04:22 +0100154 uint8_t mem_region_count;
Manish Pandey6542f5c2020-04-27 14:37:46 +0100155 struct memory_region mem_regions[SP_MAX_MEMORY_REGIONS];
Manish Pandeye68e7932020-04-23 15:29:28 +0100156 /** Device regions */
Manish Pandey2145c212020-05-01 16:04:22 +0100157 uint8_t dev_region_count;
Manish Pandeye68e7932020-04-23 15:29:28 +0100158 struct device_region dev_regions[SP_MAX_DEVICE_REGIONS];
Olivier Deprez62d99e32020-01-09 15:58:07 +0100159};
160
161/**
David Brazdil7a462ec2019-08-15 12:27:47 +0100162 * Holds information about one of the VMs described in the manifest.
163 */
164struct manifest_vm {
165 /* Properties defined for both primary and secondary VMs. */
David Brazdil136f2942019-09-23 14:11:03 +0100166 struct string debug_name;
167 struct string kernel_filename;
Andrew Scullae9962e2019-10-03 16:51:16 +0100168 struct smc_whitelist smc_whitelist;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100169 bool is_ffa_partition;
Raghu Krishnamurthyb49549e2021-07-02 08:27:38 -0700170 bool is_hyp_loaded;
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700171 struct partition_manifest partition;
David Brazdil7a462ec2019-08-15 12:27:47 +0100172
David Brazdile6f83222019-09-23 14:47:37 +0100173 union {
174 /* Properties specific to the primary VM. */
175 struct {
David Brazdil080ee312020-02-25 15:30:30 -0800176 uint64_t boot_address;
David Brazdile6f83222019-09-23 14:47:37 +0100177 struct string ramdisk_filename;
178 } primary;
179 /* Properties specific to secondary VMs. */
180 struct {
181 uint64_t mem_size;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100182 ffa_vcpu_count_t vcpu_count;
Fuad Tabba50469e02020-06-30 15:14:28 +0100183 struct string fdt_filename;
David Brazdile6f83222019-09-23 14:47:37 +0100184 } secondary;
185 };
David Brazdil7a462ec2019-08-15 12:27:47 +0100186};
187
188/**
189 * Hafnium manifest parsed from FDT.
190 */
191struct manifest {
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100192 bool ffa_tee_enabled;
193 ffa_vm_count_t vm_count;
David Brazdil7a462ec2019-08-15 12:27:47 +0100194 struct manifest_vm vm[MAX_VMS];
195};
196
197enum manifest_return_code {
198 MANIFEST_SUCCESS = 0,
David Brazdila2358d42020-01-27 18:51:38 +0000199 MANIFEST_ERROR_FILE_SIZE,
Olivier Deprez62d99e32020-01-09 15:58:07 +0100200 MANIFEST_ERROR_MALFORMED_DTB,
David Brazdila2358d42020-01-27 18:51:38 +0000201 MANIFEST_ERROR_NO_ROOT_NODE,
David Brazdil7a462ec2019-08-15 12:27:47 +0100202 MANIFEST_ERROR_NO_HYPERVISOR_FDT_NODE,
David Brazdil74e9c3b2019-08-28 11:09:08 +0100203 MANIFEST_ERROR_NOT_COMPATIBLE,
David Brazdil7a462ec2019-08-15 12:27:47 +0100204 MANIFEST_ERROR_RESERVED_VM_ID,
205 MANIFEST_ERROR_NO_PRIMARY_VM,
206 MANIFEST_ERROR_TOO_MANY_VMS,
207 MANIFEST_ERROR_PROPERTY_NOT_FOUND,
208 MANIFEST_ERROR_MALFORMED_STRING,
David Brazdil0dbb41f2019-09-09 18:03:35 +0100209 MANIFEST_ERROR_STRING_TOO_LONG,
David Brazdil7a462ec2019-08-15 12:27:47 +0100210 MANIFEST_ERROR_MALFORMED_INTEGER,
211 MANIFEST_ERROR_INTEGER_OVERFLOW,
Andrew Scullae9962e2019-10-03 16:51:16 +0100212 MANIFEST_ERROR_MALFORMED_INTEGER_LIST,
Andrew Scullb2c3a242019-11-04 13:52:36 +0000213 MANIFEST_ERROR_MALFORMED_BOOLEAN,
Manish Pandey6542f5c2020-04-27 14:37:46 +0100214 MANIFEST_ERROR_MEMORY_REGION_NODE_EMPTY,
Manish Pandeye68e7932020-04-23 15:29:28 +0100215 MANIFEST_ERROR_DEVICE_REGION_NODE_EMPTY,
Manish Pandeyf06c9072020-09-29 15:41:58 +0100216 MANIFEST_ERROR_RXTX_SIZE_MISMATCH,
Raghu Krishnamurthy384693c2021-10-11 13:56:24 -0700217 MANIFEST_ERROR_INVALID_MEM_PERM,
David Brazdil7a462ec2019-08-15 12:27:47 +0100218};
219
Olivier Deprez62d99e32020-01-09 15:58:07 +0100220enum manifest_return_code manifest_init(struct mm_stage1_locked stage1_locked,
221 struct manifest *manifest,
222 struct memiter *manifest_fdt,
223 struct mpool *ppool);
224
Raghu Krishnamurthyb49549e2021-07-02 08:27:38 -0700225enum manifest_return_code parse_ffa_manifest(struct fdt *fdt,
226 struct manifest_vm *vm);
227enum manifest_return_code sanity_check_ffa_manifest(struct manifest_vm *vm);
Olivier Deprez62d99e32020-01-09 15:58:07 +0100228void manifest_dump(struct manifest_vm *vm);
David Brazdil7a462ec2019-08-15 12:27:47 +0100229
230const char *manifest_strerror(enum manifest_return_code ret_code);