blob: 9e571b142de2ee1caaedcd72fd35b8a519c6812c [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
24enum run_time_el {
25 EL1 = 0,
26 S_EL0,
27 S_EL1,
28 SUPERVISOR_MODE,
29 SECURE_USER_MODE,
30 SECURE_SUPERVISOR_MODE
31};
32
33enum execution_state { AARCH64 = 0, AARCH32 };
34
35enum xlat_granule { PAGE_4KB = 0, PAGE_16KB, PAGE_64KB };
36
37enum messaging_method {
38 DIRECT_MESSAGING = 0,
39 INDIRECT_MESSAGING,
40 BOTH_MESSAGING
41};
42
43/**
44 * Partition manifest as described in PSA FF-A v1.0 spec section 3.1
45 */
46struct sp_manifest {
47 /** PSA-FF-A expected version - mandatory */
48 uint32_t ffa_version;
49 /** UUID - mandatory */
50 uint32_t uuid[4];
51 /** Partition id - optional */
52 ffa_vm_id_t id;
53 /** Aux ids for mem transactions - optional */
54 ffa_vm_id_t aux_id;
55
56 /* NOTE: optional name field maps to VM debug_name field */
57
58 /** mandatory */
59 ffa_vcpu_count_t execution_ctx_count;
60 /** EL1 or secure EL1, secure EL0 - mandatory */
61 enum run_time_el run_time_el;
62 /** AArch32 / AArch64 - mandatory */
63 enum execution_state execution_state;
64 /** optional */
65 uintpaddr_t load_addr;
66 /** optional */
67 size_t ep_offset;
68 /** 4/16/64KB - mandatory */
69 enum xlat_granule xlat_granule;
70 /** optional */
71 uint16_t boot_order;
72
73 /** Optional RX/TX buffers */
74 struct {
75 bool rxtx_found;
76 /** optional */
77 uint64_t base_address;
78 /** optional */
79 uint16_t pages_count;
80 /** mandatory */
81 uint16_t attributes;
82 /** Optional */
83 char name[SP_RTX_BUF_NAME_SIZE];
84 } rxtx;
85
86 /** mandatory - direct/indirect msg or both */
87 enum messaging_method messaging_method;
88 /** optional */
89 bool has_primary_scheduler;
90 /** optional - preemptible / run to completion */
91 uint8_t runtime_model;
92 /** optional */
93 bool time_slice_mem;
94 /** optional - tuples SEPID/SMMUID/streamId */
95 uint32_t stream_ep_ids[1];
96};
97
98/**
99 * Header for a PSA FF-A partition package.
100 */
101struct sp_pkg_header {
102 /** Magic used to identify a SP package. Value is "SPKG" */
103 uint32_t magic;
104 /** Version number of the header */
105 uint32_t version;
106 /** Offset in bytes to the partition manifest */
107 uint32_t pm_offset;
108 /** Size in bytes of the partition manifest */
109 uint32_t pm_size;
110 /** Offset in bytes to the base address of the partition binary */
111 uint32_t img_offset;
112 /** Size in bytes of the partition binary */
113 uint32_t img_size;
114};
115
David Brazdil0dbb41f2019-09-09 18:03:35 +0100116/**
David Brazdil7a462ec2019-08-15 12:27:47 +0100117 * Holds information about one of the VMs described in the manifest.
118 */
119struct manifest_vm {
120 /* Properties defined for both primary and secondary VMs. */
David Brazdil136f2942019-09-23 14:11:03 +0100121 struct string debug_name;
122 struct string kernel_filename;
Andrew Scullae9962e2019-10-03 16:51:16 +0100123 struct smc_whitelist smc_whitelist;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100124 bool is_ffa_partition;
125 struct sp_manifest sp;
David Brazdil7a462ec2019-08-15 12:27:47 +0100126
David Brazdile6f83222019-09-23 14:47:37 +0100127 union {
128 /* Properties specific to the primary VM. */
129 struct {
David Brazdil080ee312020-02-25 15:30:30 -0800130 uint64_t boot_address;
David Brazdile6f83222019-09-23 14:47:37 +0100131 struct string ramdisk_filename;
132 } primary;
133 /* Properties specific to secondary VMs. */
134 struct {
135 uint64_t mem_size;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100136 ffa_vcpu_count_t vcpu_count;
Fuad Tabba50469e02020-06-30 15:14:28 +0100137 struct string fdt_filename;
David Brazdile6f83222019-09-23 14:47:37 +0100138 } secondary;
139 };
David Brazdil7a462ec2019-08-15 12:27:47 +0100140};
141
142/**
143 * Hafnium manifest parsed from FDT.
144 */
145struct manifest {
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100146 bool ffa_tee_enabled;
147 ffa_vm_count_t vm_count;
David Brazdil7a462ec2019-08-15 12:27:47 +0100148 struct manifest_vm vm[MAX_VMS];
149};
150
151enum manifest_return_code {
152 MANIFEST_SUCCESS = 0,
David Brazdila2358d42020-01-27 18:51:38 +0000153 MANIFEST_ERROR_FILE_SIZE,
Olivier Deprez62d99e32020-01-09 15:58:07 +0100154 MANIFEST_ERROR_MALFORMED_DTB,
David Brazdila2358d42020-01-27 18:51:38 +0000155 MANIFEST_ERROR_NO_ROOT_NODE,
David Brazdil7a462ec2019-08-15 12:27:47 +0100156 MANIFEST_ERROR_NO_HYPERVISOR_FDT_NODE,
David Brazdil74e9c3b2019-08-28 11:09:08 +0100157 MANIFEST_ERROR_NOT_COMPATIBLE,
David Brazdil7a462ec2019-08-15 12:27:47 +0100158 MANIFEST_ERROR_RESERVED_VM_ID,
159 MANIFEST_ERROR_NO_PRIMARY_VM,
160 MANIFEST_ERROR_TOO_MANY_VMS,
161 MANIFEST_ERROR_PROPERTY_NOT_FOUND,
162 MANIFEST_ERROR_MALFORMED_STRING,
David Brazdil0dbb41f2019-09-09 18:03:35 +0100163 MANIFEST_ERROR_STRING_TOO_LONG,
David Brazdil7a462ec2019-08-15 12:27:47 +0100164 MANIFEST_ERROR_MALFORMED_INTEGER,
165 MANIFEST_ERROR_INTEGER_OVERFLOW,
Andrew Scullae9962e2019-10-03 16:51:16 +0100166 MANIFEST_ERROR_MALFORMED_INTEGER_LIST,
Andrew Scullb2c3a242019-11-04 13:52:36 +0000167 MANIFEST_ERROR_MALFORMED_BOOLEAN,
David Brazdil7a462ec2019-08-15 12:27:47 +0100168};
169
Olivier Deprez62d99e32020-01-09 15:58:07 +0100170enum manifest_return_code manifest_init(struct mm_stage1_locked stage1_locked,
171 struct manifest *manifest,
172 struct memiter *manifest_fdt,
173 struct mpool *ppool);
174
175void manifest_dump(struct manifest_vm *vm);
David Brazdil7a462ec2019-08-15 12:27:47 +0100176
177const char *manifest_strerror(enum manifest_return_code ret_code);