blob: 8a58227b77659f894a36fba2a9bc3f753b07c5a7 [file] [log] [blame]
Jose Marinho4e4e4d52019-02-22 16:23:51 +00001/*
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
Jose Marinho4e4e4d52019-02-22 16:23:51 +000017#pragma once
18
Jose Marinho75509b42019-04-09 09:34:59 +010019#include "hf/types.h"
20
Jose Marinho4e4e4d52019-02-22 16:23:51 +000021/* clang-format off */
22
23#define SPCI_LOW_32_ID 0x84000060
24#define SPCI_HIGH_32_ID 0x8400007F
25#define SPCI_LOW_64_ID 0xC4000060
26#define SPCI_HIGH_32_ID 0x8400007F
27
28/* SPCI function identifiers. */
Andrew Walbran0de4f162019-09-03 16:44:20 +010029#define SPCI_ERROR_32 0x84000060
30#define SPCI_SUCCESS_32 0x84000061
31#define SPCI_INTERRUPT_32 0x84000062
32#define SPCI_VERSION_32 0x84000063
Jose Marinho021528f2019-10-08 17:21:20 +010033#define SPCI_FEATURES_32 0x84000064
34#define SPCI_RX_RELEASE_32 0x84000065
35#define SPCI_RXTX_MAP_32 0x84000066
36#define SPCI_RXTX_UNMAP_32 0x84000067
37#define SPCI_PARTITION_INFO_GET_32 0x84000068
38#define SPCI_ID_GET_32 0x84000069
Andrew Walbran0de4f162019-09-03 16:44:20 +010039#define SPCI_MSG_POLL_32 0x8400006A
Jose Marinho021528f2019-10-08 17:21:20 +010040#define SPCI_MSG_WAIT_32 0x8400006B
41#define SPCI_YIELD_32 0x8400006C
Andrew Walbran0de4f162019-09-03 16:44:20 +010042#define SPCI_RUN_32 0x8400006D
Jose Marinho021528f2019-10-08 17:21:20 +010043#define SPCI_MSG_SEND_32 0x8400006E
44#define SPCI_MSG_SEND_DIRECT_REQ_32 0x8400006F
45#define SPCI_MSG_SEND_DIRECT_RESP_32 0x84000070
Jose Marinho4e4e4d52019-02-22 16:23:51 +000046
Andrew Walbran0de4f162019-09-03 16:44:20 +010047/* SPCI error codes. */
Jose Marinho4e4e4d52019-02-22 16:23:51 +000048#define SPCI_NOT_SUPPORTED INT32_C(-1)
49#define SPCI_INVALID_PARAMETERS INT32_C(-2)
50#define SPCI_NO_MEMORY INT32_C(-3)
51#define SPCI_BUSY INT32_C(-4)
52#define SPCI_INTERRUPTED INT32_C(-5)
53#define SPCI_DENIED INT32_C(-6)
Jose Marinho4e4e4d52019-02-22 16:23:51 +000054#define SPCI_RETRY INT32_C(-7)
55
Jose Marinho75509b42019-04-09 09:34:59 +010056/* Architected memory sharing message IDs. */
57enum spci_memory_share {
Andrew Walbran648fc3e2019-10-22 16:23:05 +010058 SPCI_MEMORY_DONATE = 0x0,
59 SPCI_MEMORY_LEND = 0x1,
60 SPCI_MEMORY_SHARE = 0x2,
61 SPCI_MEMORY_RELINQUISH = 0x3,
Jose Marinho75509b42019-04-09 09:34:59 +010062};
63
Jose Marinho4e4e4d52019-02-22 16:23:51 +000064/* SPCI function specific constants. */
Andrew Walbran70bc8622019-10-07 14:15:58 +010065#define SPCI_MSG_RECV_BLOCK 0x1
Andrew Scull1262ac22019-04-05 12:44:26 +010066#define SPCI_MSG_RECV_BLOCK_MASK 0x1
Jose Marinho4e4e4d52019-02-22 16:23:51 +000067
68#define SPCI_MSG_SEND_NOTIFY 0x1
Andrew Walbran70bc8622019-10-07 14:15:58 +010069#define SPCI_MSG_SEND_NOTIFY_MASK 0x1
70#define SPCI_MSG_SEND_LEGACY_MEMORY 0x2
71#define SPCI_MSG_SEND_LEGACY_MEMORY_MASK 0x2
Andrew Scull1262ac22019-04-05 12:44:26 +010072
73/* The maximum length possible for a single message. */
Andrew Walbran70bc8622019-10-07 14:15:58 +010074#define SPCI_MSG_PAYLOAD_MAX HF_MAILBOX_SIZE
Jose Marinho713f13a2019-05-21 11:54:16 +010075
Andrew Walbranf5972182019-10-15 15:41:26 +010076enum spci_memory_access {
77 SPCI_MEMORY_RO_NX,
78 SPCI_MEMORY_RO_X,
79 SPCI_MEMORY_RW_NX,
80 SPCI_MEMORY_RW_X,
Jose Marinho713f13a2019-05-21 11:54:16 +010081};
82
Andrew Walbranf5972182019-10-15 15:41:26 +010083enum spci_memory_type {
84 SPCI_MEMORY_DEVICE_MEM,
85 SPCI_MEMORY_NORMAL_MEM,
Jose Marinho713f13a2019-05-21 11:54:16 +010086};
87
Andrew Walbranf5972182019-10-15 15:41:26 +010088enum spci_memory_cacheability {
89 SPCI_MEMORY_CACHE_RESERVED = 0x0,
90 SPCI_MEMORY_CACHE_NON_CACHEABLE = 0x1,
91 SPCI_MEMORY_CACHE_WRITE_THROUGH = 0x2,
92 SPCI_MEMORY_CACHE_WRITE_BACK = 0x4,
93 SPCI_MEMORY_DEV_NGNRNE = 0x0,
94 SPCI_MEMORY_DEV_NGNRE = 0x1,
95 SPCI_MEMORY_DEV_NGRE = 0x2,
96 SPCI_MEMORY_DEV_GRE = 0x3,
Jose Marinho713f13a2019-05-21 11:54:16 +010097};
98
Andrew Walbranf5972182019-10-15 15:41:26 +010099enum spci_memory_shareability {
100 SPCI_MEMORY_SHARE_NON_SHAREABLE,
101 SPCI_MEMORY_RESERVED,
102 SPCI_MEMORY_OUTER_SHAREABLE,
103 SPCI_MEMORY_INNER_SHAREABLE,
Jose Marinho713f13a2019-05-21 11:54:16 +0100104};
105
Andrew Walbranf5972182019-10-15 15:41:26 +0100106#define SPCI_MEMORY_ACCESS_OFFSET (0x5U)
107#define SPCI_MEMORY_ACCESS_MASK ((0x3U) << SPCI_MEMORY_ACCESS_OFFSET)
Jose Marinho713f13a2019-05-21 11:54:16 +0100108
Andrew Walbranf5972182019-10-15 15:41:26 +0100109#define SPCI_MEMORY_TYPE_OFFSET (0x4U)
110#define SPCI_MEMORY_TYPE_MASK ((0x1U) << SPCI_MEMORY_TYPE_OFFSET)
Jose Marinho713f13a2019-05-21 11:54:16 +0100111
Andrew Walbranf5972182019-10-15 15:41:26 +0100112#define SPCI_MEMORY_CACHEABILITY_OFFSET (0x2U)
113#define SPCI_MEMORY_CACHEABILITY_MASK ((0x3U) <<\
114 SPCI_MEMORY_CACHEABILITY_OFFSET)
Jose Marinho713f13a2019-05-21 11:54:16 +0100115
Andrew Walbranf5972182019-10-15 15:41:26 +0100116#define SPCI_MEMORY_SHAREABILITY_OFFSET (0x0U)
117#define SPCI_MEMORY_SHAREABILITY_MASK ((0x3U) <<\
118 SPCI_MEMORY_SHAREABILITY_OFFSET)
Jose Marinho713f13a2019-05-21 11:54:16 +0100119
120#define LEND_ATTR_FUNCTION_SET(name, offset, mask) \
Andrew Walbranf5972182019-10-15 15:41:26 +0100121static inline void spci_set_memory_##name##_attr(uint16_t *attr,\
122 const enum spci_memory_##name perm)\
Jose Marinho713f13a2019-05-21 11:54:16 +0100123{\
Andrew Walbranf5972182019-10-15 15:41:26 +0100124 *attr = (*attr & ~(mask)) | ((perm << offset) & mask);\
Jose Marinho713f13a2019-05-21 11:54:16 +0100125}
126
127#define LEND_ATTR_FUNCTION_GET(name, offset, mask) \
Andrew Walbranf5972182019-10-15 15:41:26 +0100128static inline enum spci_memory_##name spci_get_memory_##name##_attr(\
129 uint16_t attr)\
Jose Marinho713f13a2019-05-21 11:54:16 +0100130{\
Andrew Walbranf5972182019-10-15 15:41:26 +0100131 return (enum spci_memory_##name)((attr & mask) >> offset);\
Jose Marinho713f13a2019-05-21 11:54:16 +0100132}
133
Andrew Walbranf5972182019-10-15 15:41:26 +0100134LEND_ATTR_FUNCTION_SET(access, SPCI_MEMORY_ACCESS_OFFSET,
135 SPCI_MEMORY_ACCESS_MASK)
136LEND_ATTR_FUNCTION_GET(access, SPCI_MEMORY_ACCESS_OFFSET,
137 SPCI_MEMORY_ACCESS_MASK)
Jose Marinho713f13a2019-05-21 11:54:16 +0100138
Andrew Walbranf5972182019-10-15 15:41:26 +0100139LEND_ATTR_FUNCTION_SET(type, SPCI_MEMORY_TYPE_OFFSET, SPCI_MEMORY_TYPE_MASK)
140LEND_ATTR_FUNCTION_GET(type, SPCI_MEMORY_TYPE_OFFSET, SPCI_MEMORY_TYPE_MASK)
Jose Marinho713f13a2019-05-21 11:54:16 +0100141
Andrew Walbranf5972182019-10-15 15:41:26 +0100142LEND_ATTR_FUNCTION_SET(cacheability, SPCI_MEMORY_CACHEABILITY_OFFSET,
143 SPCI_MEMORY_CACHEABILITY_MASK)
Jose Marinho713f13a2019-05-21 11:54:16 +0100144
Andrew Walbranf5972182019-10-15 15:41:26 +0100145LEND_ATTR_FUNCTION_GET(cacheability, SPCI_MEMORY_CACHEABILITY_OFFSET,
146 SPCI_MEMORY_CACHEABILITY_MASK)
Jose Marinho713f13a2019-05-21 11:54:16 +0100147
Andrew Walbranf5972182019-10-15 15:41:26 +0100148LEND_ATTR_FUNCTION_SET(shareability, SPCI_MEMORY_SHAREABILITY_OFFSET,
149 SPCI_MEMORY_SHAREABILITY_MASK)
Jose Marinho713f13a2019-05-21 11:54:16 +0100150
Andrew Walbranf5972182019-10-15 15:41:26 +0100151LEND_ATTR_FUNCTION_GET(shareability, SPCI_MEMORY_SHAREABILITY_OFFSET,
152 SPCI_MEMORY_SHAREABILITY_MASK)
Jose Marinho713f13a2019-05-21 11:54:16 +0100153
Jose Marinho4e4e4d52019-02-22 16:23:51 +0000154/* clang-format on */
155
Fuad Tabba494376e2019-08-05 12:35:10 +0100156/** The ID of a VM. These are assigned sequentially starting with an offset. */
Jose Marinho4e4e4d52019-02-22 16:23:51 +0000157typedef uint16_t spci_vm_id_t;
Jose Marinho75509b42019-04-09 09:34:59 +0100158typedef uint32_t spci_memory_handle_t;
Jose Marinho4e4e4d52019-02-22 16:23:51 +0000159
Andrew Walbran52d99672019-06-25 15:51:11 +0100160/**
161 * A count of VMs. This has the same range as the VM IDs but we give it a
162 * different name to make the different semantics clear.
163 */
164typedef spci_vm_id_t spci_vm_count_t;
Andrew Walbranc6d23c42019-06-26 13:30:42 +0100165
166/** The index of a vCPU within a particular VM. */
Andrew Walbranb037d5b2019-06-25 17:19:41 +0100167typedef uint16_t spci_vcpu_index_t;
Andrew Walbran52d99672019-06-25 15:51:11 +0100168
Andrew Walbranc6d23c42019-06-26 13:30:42 +0100169/**
170 * A count of vCPUs. This has the same range as the vCPU indices but we give it
171 * a different name to make the different semantics clear.
172 */
173typedef spci_vcpu_index_t spci_vcpu_count_t;
174
Andrew Walbranf18e63c2019-10-07 15:13:59 +0100175/** Parameter and return type of SPCI functions. */
Andrew Walbran7f920af2019-09-03 17:09:30 +0100176struct spci_value {
177 uint64_t func;
178 uint64_t arg1;
179 uint64_t arg2;
180 uint64_t arg3;
181 uint64_t arg4;
182 uint64_t arg5;
183 uint64_t arg6;
184 uint64_t arg7;
185};
Jose Marinho75509b42019-04-09 09:34:59 +0100186
Andrew Walbrand4d2fa12019-10-01 16:47:25 +0100187static inline spci_vm_id_t spci_msg_send_sender(struct spci_value args)
188{
189 return (args.arg1 >> 16) & 0xffff;
190}
191
192static inline spci_vm_id_t spci_msg_send_receiver(struct spci_value args)
193{
194 return args.arg1 & 0xffff;
195}
196
197static inline uint32_t spci_msg_send_size(struct spci_value args)
198{
199 return args.arg3;
200}
201
Andrew Walbran70bc8622019-10-07 14:15:58 +0100202static inline uint32_t spci_msg_send_attributes(struct spci_value args)
203{
204 return args.arg4;
205}
Jose Marinho4e4e4d52019-02-22 16:23:51 +0000206
Jose Marinho75509b42019-04-09 09:34:59 +0100207struct spci_architected_message_header {
208 uint16_t type;
209
210 /*
211 * TODO: Padding is present to ensure that the field
212 * payload is aligned on a 64B boundary. SPCI
213 * spec must be updated to reflect this.
214 */
215 uint16_t reserved[3];
216 uint8_t payload[];
217};
218
219struct spci_memory_region_constituent {
Andrew Walbranf5972182019-10-15 15:41:26 +0100220 /**
221 * The base IPA of the constituent memory region, aligned to 4 kiB page
222 * size granularity.
223 */
Jose Marinho75509b42019-04-09 09:34:59 +0100224 uint64_t address;
Andrew Walbranf5972182019-10-15 15:41:26 +0100225 /** The number of 4 kiB pages in the constituent memory region. */
Jose Marinho75509b42019-04-09 09:34:59 +0100226 uint32_t page_count;
227
228 uint32_t reserved;
229};
230
Andrew Walbranf5972182019-10-15 15:41:26 +0100231struct spci_memory_region_attributes {
232 /** The ID of the VM to which the memory is being given or shared. */
233 spci_vm_id_t receiver;
234 /**
235 * The attributes with which the memory region should be mapped in the
236 * receiver's page table.
237 */
238 uint16_t memory_attributes;
Jose Marinho75509b42019-04-09 09:34:59 +0100239};
240
Andrew Walbranf5972182019-10-15 15:41:26 +0100241struct spci_memory_region {
242 /**
243 * An implementation defined value associated with the receiver and the
244 * memory region.
245 */
246 uint32_t tag;
247 /** Flags to control behaviour of the transaction. */
248 uint32_t flags;
249 /**
250 * The total number of 4 kiB pages included in this memory region. This
251 * must be equal to the sum of page counts specified in each
252 * `spci_memory_region_constituent`.
253 */
254 uint32_t page_count;
255 /**
256 * The number of constituents (`spci_memory_region_constituent`)
257 * included in this memory region.
258 */
259 uint32_t constituent_count;
260 /**
261 * The offset in bytes from the base address of this
262 * `spci_memory_region` to the start of the first
263 * `spci_memory_region_constituent`.
264 */
265 uint32_t constituent_offset;
266 /**
267 * The number of `spci_memory_region_attributes` entries included in
268 * this memory region.
269 */
270 uint32_t attribute_count;
271 /**
272 * An array of `attribute_count` memory region attribute descriptors.
273 * Each one specifies an endpoint and the attributes with which this
274 * memory region should be mapped in that endpoint's page table.
275 */
276 struct spci_memory_region_attributes attributes[];
Jose Marinho713f13a2019-05-21 11:54:16 +0100277};
278
Jose Marinho75509b42019-04-09 09:34:59 +0100279/* TODO: Move all the functions below this line to a support library. */
Andrew Walbran70bc8622019-10-07 14:15:58 +0100280
Andrew Walbranf5972182019-10-15 15:41:26 +0100281/**
282 * Gets the constituent array for an `spci_memory_region`.
283 */
284static inline struct spci_memory_region_constituent *
285spci_memory_region_get_constituents(struct spci_memory_region *memory_region)
Jose Marinho4e4e4d52019-02-22 16:23:51 +0000286{
Andrew Walbranf5972182019-10-15 15:41:26 +0100287 return (struct spci_memory_region_constituent
288 *)((uint8_t *)memory_region +
289 memory_region->constituent_offset);
Jose Marinho75509b42019-04-09 09:34:59 +0100290}
291
292/**
293 * Helper method to fill in the information about the architected message.
294 */
Andrew Walbran70bc8622019-10-07 14:15:58 +0100295static inline void spci_architected_message_init(void *message,
Jose Marinho75509b42019-04-09 09:34:59 +0100296 enum spci_memory_share type)
297{
Jose Marinho75509b42019-04-09 09:34:59 +0100298 /* Fill the architected header. */
Andrew Walbran70bc8622019-10-07 14:15:58 +0100299 struct spci_architected_message_header *architected_header =
300 (struct spci_architected_message_header *)message;
Jose Marinho75509b42019-04-09 09:34:59 +0100301 architected_header->type = type;
302 architected_header->reserved[0] = 0;
303 architected_header->reserved[1] = 0;
304 architected_header->reserved[2] = 0;
305}
306
Andrew Walbranf5972182019-10-15 15:41:26 +0100307/** Gets the spci_memory_region within an architected message. */
308static inline struct spci_memory_region *spci_get_memory_region(void *message)
Jose Marinho75509b42019-04-09 09:34:59 +0100309{
310 struct spci_architected_message_header *architected_header =
Andrew Walbran70bc8622019-10-07 14:15:58 +0100311 (struct spci_architected_message_header *)message;
Jose Marinho75509b42019-04-09 09:34:59 +0100312 return (struct spci_memory_region *)architected_header->payload;
313}
314
315/**
Andrew Walbranf5972182019-10-15 15:41:26 +0100316 * Initialises the given `spci_memory_region` and copies the constituent
317 * information to it. Returns the length in bytes occupied by the data copied to
318 * `memory_region` (attributes, constituents and memory region header size).
Jose Marinho75509b42019-04-09 09:34:59 +0100319 */
Andrew Walbranf5972182019-10-15 15:41:26 +0100320static inline uint32_t spci_memory_region_init(
321 struct spci_memory_region *memory_region, spci_vm_id_t receiver,
Jose Marinho75509b42019-04-09 09:34:59 +0100322 const struct spci_memory_region_constituent constituents[],
Andrew Walbranf5972182019-10-15 15:41:26 +0100323 uint32_t constituent_count, uint32_t tag,
324 enum spci_memory_access access, enum spci_memory_type type,
325 enum spci_memory_cacheability cacheability,
326 enum spci_memory_shareability shareability)
Jose Marinho75509b42019-04-09 09:34:59 +0100327{
Jose Marinho75509b42019-04-09 09:34:59 +0100328 uint32_t constituents_length =
Andrew Walbranf5972182019-10-15 15:41:26 +0100329 constituent_count *
Jose Marinho75509b42019-04-09 09:34:59 +0100330 sizeof(struct spci_memory_region_constituent);
331 uint32_t index;
Andrew Walbranf5972182019-10-15 15:41:26 +0100332 struct spci_memory_region_constituent *region_constituents;
333 uint16_t attributes = 0;
Jose Marinho75509b42019-04-09 09:34:59 +0100334
Andrew Walbranf5972182019-10-15 15:41:26 +0100335 /* Set memory region's page attributes. */
336 spci_set_memory_access_attr(&attributes, access);
337 spci_set_memory_type_attr(&attributes, type);
338 spci_set_memory_cacheability_attr(&attributes, cacheability);
339 spci_set_memory_shareability_attr(&attributes, shareability);
Jose Marinho75509b42019-04-09 09:34:59 +0100340
Andrew Walbranf5972182019-10-15 15:41:26 +0100341 memory_region->tag = tag;
342 memory_region->flags = 0;
343 memory_region->page_count = 0;
344 memory_region->constituent_count = constituent_count;
345 memory_region->attribute_count = 1;
346 memory_region->attributes[0].receiver = receiver;
347 memory_region->attributes[0].memory_attributes = attributes;
348
349 memory_region->constituent_offset =
350 sizeof(struct spci_memory_region) +
351 memory_region->attribute_count *
352 sizeof(struct spci_memory_region_attributes);
353 region_constituents =
354 spci_memory_region_get_constituents(memory_region);
355
356 for (index = 0; index < constituent_count; index++) {
357 region_constituents[index] = constituents[index];
358 region_constituents[index].reserved = 0;
359 memory_region->page_count += constituents[index].page_count;
Jose Marinho75509b42019-04-09 09:34:59 +0100360 }
361
362 /*
363 * TODO: Add assert ensuring that the specified message
364 * length is not greater than SPCI_MSG_PAYLOAD_MAX.
365 */
Jose Marinho713f13a2019-05-21 11:54:16 +0100366
Andrew Walbranf5972182019-10-15 15:41:26 +0100367 return memory_region->constituent_offset + constituents_length;
Jose Marinho75509b42019-04-09 09:34:59 +0100368}
369
Andrew Walbran648fc3e2019-10-22 16:23:05 +0100370/**
371 * Constructs an 'architected message' for SPCI memory sharing of the given
372 * type.
373 */
374static inline uint32_t spci_memory_init(
375 void *message, enum spci_memory_share share_type, spci_vm_id_t receiver,
Jose Marinho75509b42019-04-09 09:34:59 +0100376 struct spci_memory_region_constituent *region_constituents,
Andrew Walbranf5972182019-10-15 15:41:26 +0100377 uint32_t constituent_count, uint32_t tag,
378 enum spci_memory_access access, enum spci_memory_type type,
379 enum spci_memory_cacheability cacheability,
380 enum spci_memory_shareability shareability)
Jose Marinho75509b42019-04-09 09:34:59 +0100381{
Andrew Walbranf5972182019-10-15 15:41:26 +0100382 uint32_t message_length =
383 sizeof(struct spci_architected_message_header);
Jose Marinho713f13a2019-05-21 11:54:16 +0100384 struct spci_memory_region *memory_region =
Andrew Walbranf5972182019-10-15 15:41:26 +0100385 spci_get_memory_region(message);
Jose Marinho75509b42019-04-09 09:34:59 +0100386
387 /* Fill in the details on the common message header. */
Andrew Walbran648fc3e2019-10-22 16:23:05 +0100388 spci_architected_message_init(message, share_type);
Jose Marinho75509b42019-04-09 09:34:59 +0100389
Andrew Walbranf5972182019-10-15 15:41:26 +0100390 /* Fill in memory region. */
391 message_length += spci_memory_region_init(
392 memory_region, receiver, region_constituents, constituent_count,
393 tag, access, type, cacheability, shareability);
Andrew Walbran70bc8622019-10-07 14:15:58 +0100394 return message_length;
Jose Marinho75509b42019-04-09 09:34:59 +0100395}
Jose Marinho56c25732019-05-20 09:48:53 +0100396
Andrew Walbran648fc3e2019-10-22 16:23:05 +0100397/** Constructs an SPCI donate memory region message. */
398static inline uint32_t spci_memory_donate_init(
Andrew Walbranf5972182019-10-15 15:41:26 +0100399 void *message, spci_vm_id_t receiver,
Jose Marinho56c25732019-05-20 09:48:53 +0100400 struct spci_memory_region_constituent *region_constituents,
Andrew Walbran648fc3e2019-10-22 16:23:05 +0100401 uint32_t constituent_count, uint32_t tag,
402 enum spci_memory_access access, enum spci_memory_type type,
403 enum spci_memory_cacheability cacheability,
404 enum spci_memory_shareability shareability)
Jose Marinho56c25732019-05-20 09:48:53 +0100405{
Andrew Walbran648fc3e2019-10-22 16:23:05 +0100406 return spci_memory_init(message, SPCI_MEMORY_DONATE, receiver,
407 region_constituents, constituent_count, tag,
408 access, type, cacheability, shareability);
Jose Marinho713f13a2019-05-21 11:54:16 +0100409}
410
411/**
Andrew Walbranf5972182019-10-15 15:41:26 +0100412 * Constructs an SPCI memory region lend message.
Jose Marinho713f13a2019-05-21 11:54:16 +0100413 */
Andrew Walbran70bc8622019-10-07 14:15:58 +0100414static inline uint32_t spci_memory_lend_init(
Andrew Walbranf5972182019-10-15 15:41:26 +0100415 void *message, spci_vm_id_t receiver,
Jose Marinho713f13a2019-05-21 11:54:16 +0100416 struct spci_memory_region_constituent *region_constituents,
Andrew Walbranf5972182019-10-15 15:41:26 +0100417 uint32_t constituent_count, uint32_t tag,
418 enum spci_memory_access access, enum spci_memory_type type,
419 enum spci_memory_cacheability cacheability,
420 enum spci_memory_shareability shareability)
Jose Marinho713f13a2019-05-21 11:54:16 +0100421{
Andrew Walbran648fc3e2019-10-22 16:23:05 +0100422 return spci_memory_init(message, SPCI_MEMORY_LEND, receiver,
423 region_constituents, constituent_count, tag,
424 access, type, cacheability, shareability);
425}
Jose Marinho713f13a2019-05-21 11:54:16 +0100426
Andrew Walbran648fc3e2019-10-22 16:23:05 +0100427/**
428 * Constructs an SPCI memory region share message.
429 */
430static inline uint32_t spci_memory_share_init(
431 void *message, spci_vm_id_t receiver,
432 struct spci_memory_region_constituent *region_constituents,
433 uint32_t constituent_count, uint32_t tag,
434 enum spci_memory_access access, enum spci_memory_type type,
435 enum spci_memory_cacheability cacheability,
436 enum spci_memory_shareability shareability)
437{
438 return spci_memory_init(message, SPCI_MEMORY_SHARE, receiver,
439 region_constituents, constituent_count, tag,
440 access, type, cacheability, shareability);
441}
Jose Marinho713f13a2019-05-21 11:54:16 +0100442
Andrew Walbran648fc3e2019-10-22 16:23:05 +0100443/**
444 * Constructs an SPCI memory region relinquish message.
445 * A set of memory regions can be given back to the owner.
446 */
447static inline uint32_t spci_memory_relinquish_init(
448 void *message, spci_vm_id_t receiver,
449 struct spci_memory_region_constituent *region_constituents,
450 uint32_t constituent_count, uint32_t tag)
451{
452 return spci_memory_init(message, SPCI_MEMORY_RELINQUISH, receiver,
453 region_constituents, constituent_count, tag,
454 SPCI_MEMORY_RW_X, SPCI_MEMORY_DEVICE_MEM,
455 SPCI_MEMORY_DEV_NGNRNE,
456 SPCI_MEMORY_SHARE_NON_SHAREABLE);
Jose Marinho56c25732019-05-20 09:48:53 +0100457}