Jose Marinho | 4e4e4d5 | 2019-02-22 16:23:51 +0000 | [diff] [blame] | 1 | /* |
| 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 Marinho | 4e4e4d5 | 2019-02-22 16:23:51 +0000 | [diff] [blame] | 17 | #pragma once |
| 18 | |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 19 | #include "hf/types.h" |
| 20 | |
Jose Marinho | 4e4e4d5 | 2019-02-22 16:23:51 +0000 | [diff] [blame] | 21 | /* 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 Walbran | 0de4f16 | 2019-09-03 16:44:20 +0100 | [diff] [blame] | 29 | #define SPCI_ERROR_32 0x84000060 |
| 30 | #define SPCI_SUCCESS_32 0x84000061 |
| 31 | #define SPCI_INTERRUPT_32 0x84000062 |
| 32 | #define SPCI_VERSION_32 0x84000063 |
Jose Marinho | 021528f | 2019-10-08 17:21:20 +0100 | [diff] [blame] | 33 | #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 Walbran | 0de4f16 | 2019-09-03 16:44:20 +0100 | [diff] [blame] | 39 | #define SPCI_MSG_POLL_32 0x8400006A |
Jose Marinho | 021528f | 2019-10-08 17:21:20 +0100 | [diff] [blame] | 40 | #define SPCI_MSG_WAIT_32 0x8400006B |
| 41 | #define SPCI_YIELD_32 0x8400006C |
Andrew Walbran | 0de4f16 | 2019-09-03 16:44:20 +0100 | [diff] [blame] | 42 | #define SPCI_RUN_32 0x8400006D |
Jose Marinho | 021528f | 2019-10-08 17:21:20 +0100 | [diff] [blame] | 43 | #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 Marinho | 4e4e4d5 | 2019-02-22 16:23:51 +0000 | [diff] [blame] | 46 | |
Andrew Walbran | 0de4f16 | 2019-09-03 16:44:20 +0100 | [diff] [blame] | 47 | /* SPCI error codes. */ |
Jose Marinho | 4e4e4d5 | 2019-02-22 16:23:51 +0000 | [diff] [blame] | 48 | #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 Marinho | 4e4e4d5 | 2019-02-22 16:23:51 +0000 | [diff] [blame] | 54 | #define SPCI_RETRY INT32_C(-7) |
| 55 | |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 56 | /* Architected memory sharing message IDs. */ |
| 57 | enum spci_memory_share { |
Jose Marinho | 713f13a | 2019-05-21 11:54:16 +0100 | [diff] [blame] | 58 | SPCI_MEMORY_LEND = 0x0, |
Jose Marinho | 56c2573 | 2019-05-20 09:48:53 +0100 | [diff] [blame] | 59 | SPCI_MEMORY_RELINQUISH = 0x1, |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 60 | SPCI_MEMORY_DONATE = 0x2, |
| 61 | }; |
| 62 | |
Jose Marinho | 4e4e4d5 | 2019-02-22 16:23:51 +0000 | [diff] [blame] | 63 | /* SPCI function specific constants. */ |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 64 | #define SPCI_MSG_RECV_BLOCK 0x1 |
Andrew Scull | 1262ac2 | 2019-04-05 12:44:26 +0100 | [diff] [blame] | 65 | #define SPCI_MSG_RECV_BLOCK_MASK 0x1 |
Jose Marinho | 4e4e4d5 | 2019-02-22 16:23:51 +0000 | [diff] [blame] | 66 | |
| 67 | #define SPCI_MSG_SEND_NOTIFY 0x1 |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 68 | #define SPCI_MSG_SEND_NOTIFY_MASK 0x1 |
| 69 | #define SPCI_MSG_SEND_LEGACY_MEMORY 0x2 |
| 70 | #define SPCI_MSG_SEND_LEGACY_MEMORY_MASK 0x2 |
Andrew Scull | 1262ac2 | 2019-04-05 12:44:26 +0100 | [diff] [blame] | 71 | |
| 72 | /* The maximum length possible for a single message. */ |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 73 | #define SPCI_MSG_PAYLOAD_MAX HF_MAILBOX_SIZE |
Jose Marinho | 713f13a | 2019-05-21 11:54:16 +0100 | [diff] [blame] | 74 | |
| 75 | enum spci_lend_access { |
| 76 | SPCI_LEND_RO_NX, |
| 77 | SPCI_LEND_RO_X, |
| 78 | SPCI_LEND_RW_NX, |
| 79 | SPCI_LEND_RW_X, |
| 80 | }; |
| 81 | |
| 82 | enum spci_lend_type { |
| 83 | SPCI_LEND_NORMAL_MEM, |
| 84 | SPCI_LEND_DEV_NGNRNE, |
| 85 | SPCI_LEND_DEV_NGNRE, |
| 86 | SPCI_LEND_DEV_NGRE, |
| 87 | SPCI_LEND_DEV_GRE, |
| 88 | }; |
| 89 | |
| 90 | enum spci_lend_cacheability { |
| 91 | SPCI_LEND_CACHE_NON_CACHEABLE, |
| 92 | SPCI_LEND_CACHE_WRITE_THROUGH, |
| 93 | SPCI_LEND_CACHE_WRITE_BACK, |
| 94 | }; |
| 95 | |
| 96 | enum spci_lend_shareability { |
| 97 | SPCI_LEND_SHARE_NON_SHAREABLE, |
| 98 | SPCI_LEND_RESERVED, |
| 99 | SPCI_LEND_OUTER_SHAREABLE, |
| 100 | SPCI_LEND_INNER_SHAREABLE, |
| 101 | }; |
| 102 | |
| 103 | #define SPCI_LEND_ACCESS_OFFSET (0x7U) |
| 104 | #define SPCI_LEND_ACCESS_MASK ((0x3U) << SPCI_LEND_ACCESS_OFFSET) |
| 105 | |
| 106 | #define SPCI_LEND_TYPE_OFFSET (0x4U) |
| 107 | #define SPCI_LEND_TYPE_MASK ((0x7U) << SPCI_LEND_TYPE_OFFSET) |
| 108 | |
| 109 | #define SPCI_LEND_CACHEABILITY_OFFSET (0x2U) |
| 110 | #define SPCI_LEND_CACHEABILITY_MASK ((0x3U) <<\ |
| 111 | SPCI_LEND_CACHEABILITY_OFFSET) |
| 112 | |
| 113 | #define SPCI_LEND_SHAREABILITY_OFFSET (0x0U) |
| 114 | #define SPCI_LEND_SHAREABILITY_MASK ((0x3U) <<\ |
| 115 | SPCI_LEND_SHAREABILITY_OFFSET) |
| 116 | |
| 117 | #define LEND_ATTR_FUNCTION_SET(name, offset, mask) \ |
| 118 | static inline void spci_set_lend_##name##_attr(uint16_t *lend_attr,\ |
| 119 | const enum spci_lend_##name perm)\ |
| 120 | {\ |
| 121 | *lend_attr = (*lend_attr & ~(mask)) | ((perm << offset) & mask);\ |
| 122 | } |
| 123 | |
| 124 | #define LEND_ATTR_FUNCTION_GET(name, offset, mask) \ |
| 125 | static inline enum spci_lend_##name spci_get_lend_##name##_attr(\ |
| 126 | uint16_t lend_attr)\ |
| 127 | {\ |
| 128 | return (enum spci_lend_##name)((lend_attr & mask) >> offset);\ |
| 129 | } |
| 130 | |
| 131 | LEND_ATTR_FUNCTION_SET(access, SPCI_LEND_ACCESS_OFFSET, SPCI_LEND_ACCESS_MASK) |
| 132 | LEND_ATTR_FUNCTION_GET(access, SPCI_LEND_ACCESS_OFFSET, SPCI_LEND_ACCESS_MASK) |
| 133 | |
| 134 | LEND_ATTR_FUNCTION_SET(type, SPCI_LEND_TYPE_OFFSET, SPCI_LEND_TYPE_MASK) |
| 135 | LEND_ATTR_FUNCTION_GET(type, SPCI_LEND_TYPE_OFFSET, SPCI_LEND_TYPE_MASK) |
| 136 | |
| 137 | LEND_ATTR_FUNCTION_SET(cacheability, SPCI_LEND_CACHEABILITY_OFFSET, |
| 138 | SPCI_LEND_CACHEABILITY_MASK) |
| 139 | |
| 140 | LEND_ATTR_FUNCTION_GET(cacheability, SPCI_LEND_CACHEABILITY_OFFSET, |
| 141 | SPCI_LEND_CACHEABILITY_MASK) |
| 142 | |
| 143 | LEND_ATTR_FUNCTION_SET(shareability, SPCI_LEND_SHAREABILITY_OFFSET, |
| 144 | SPCI_LEND_SHAREABILITY_MASK) |
| 145 | |
| 146 | LEND_ATTR_FUNCTION_GET(shareability, SPCI_LEND_SHAREABILITY_OFFSET, |
| 147 | SPCI_LEND_SHAREABILITY_MASK) |
| 148 | |
| 149 | enum spci_lend_flags { |
| 150 | SPCI_LEND_KEEP_MAPPED = 0x0, |
| 151 | SPCI_LEND_UNMAP = 0x1 |
| 152 | }; |
| 153 | |
Jose Marinho | 4e4e4d5 | 2019-02-22 16:23:51 +0000 | [diff] [blame] | 154 | /* clang-format on */ |
| 155 | |
Fuad Tabba | 494376e | 2019-08-05 12:35:10 +0100 | [diff] [blame] | 156 | /** The ID of a VM. These are assigned sequentially starting with an offset. */ |
Jose Marinho | 4e4e4d5 | 2019-02-22 16:23:51 +0000 | [diff] [blame] | 157 | typedef uint16_t spci_vm_id_t; |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 158 | typedef uint32_t spci_memory_handle_t; |
Jose Marinho | 4e4e4d5 | 2019-02-22 16:23:51 +0000 | [diff] [blame] | 159 | |
Andrew Walbran | 52d9967 | 2019-06-25 15:51:11 +0100 | [diff] [blame] | 160 | /** |
| 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 | */ |
| 164 | typedef spci_vm_id_t spci_vm_count_t; |
Andrew Walbran | c6d23c4 | 2019-06-26 13:30:42 +0100 | [diff] [blame] | 165 | |
| 166 | /** The index of a vCPU within a particular VM. */ |
Andrew Walbran | b037d5b | 2019-06-25 17:19:41 +0100 | [diff] [blame] | 167 | typedef uint16_t spci_vcpu_index_t; |
Andrew Walbran | 52d9967 | 2019-06-25 15:51:11 +0100 | [diff] [blame] | 168 | |
Andrew Walbran | c6d23c4 | 2019-06-26 13:30:42 +0100 | [diff] [blame] | 169 | /** |
| 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 | */ |
| 173 | typedef spci_vcpu_index_t spci_vcpu_count_t; |
| 174 | |
Andrew Walbran | f18e63c | 2019-10-07 15:13:59 +0100 | [diff] [blame] | 175 | /** Parameter and return type of SPCI functions. */ |
Andrew Walbran | 7f920af | 2019-09-03 17:09:30 +0100 | [diff] [blame] | 176 | struct 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 Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 186 | |
Andrew Walbran | d4d2fa1 | 2019-10-01 16:47:25 +0100 | [diff] [blame] | 187 | static inline spci_vm_id_t spci_msg_send_sender(struct spci_value args) |
| 188 | { |
| 189 | return (args.arg1 >> 16) & 0xffff; |
| 190 | } |
| 191 | |
| 192 | static inline spci_vm_id_t spci_msg_send_receiver(struct spci_value args) |
| 193 | { |
| 194 | return args.arg1 & 0xffff; |
| 195 | } |
| 196 | |
| 197 | static inline uint32_t spci_msg_send_size(struct spci_value args) |
| 198 | { |
| 199 | return args.arg3; |
| 200 | } |
| 201 | |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 202 | static inline uint32_t spci_msg_send_attributes(struct spci_value args) |
| 203 | { |
| 204 | return args.arg4; |
| 205 | } |
Jose Marinho | 4e4e4d5 | 2019-02-22 16:23:51 +0000 | [diff] [blame] | 206 | |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 207 | struct 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 | |
| 219 | struct spci_memory_region_constituent { |
| 220 | uint64_t address; |
| 221 | uint32_t page_count; |
| 222 | |
| 223 | uint32_t reserved; |
| 224 | }; |
| 225 | |
| 226 | struct spci_memory_region { |
| 227 | spci_memory_handle_t handle; |
| 228 | uint32_t count; |
| 229 | |
| 230 | struct spci_memory_region_constituent constituents[]; |
| 231 | }; |
| 232 | |
Jose Marinho | 713f13a | 2019-05-21 11:54:16 +0100 | [diff] [blame] | 233 | struct spci_memory_lend { |
| 234 | uint16_t flags; |
| 235 | uint16_t borrower_attributes; |
| 236 | |
| 237 | uint32_t reserved; |
| 238 | |
| 239 | uint8_t payload[]; |
| 240 | }; |
| 241 | |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 242 | /* TODO: Move all the functions below this line to a support library. */ |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 243 | |
| 244 | static inline struct spci_memory_lend *spci_get_lend_descriptor(void *message) |
Jose Marinho | 4e4e4d5 | 2019-02-22 16:23:51 +0000 | [diff] [blame] | 245 | { |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 246 | return (struct spci_memory_lend |
| 247 | *)((struct spci_architected_message_header *)message) |
| 248 | ->payload; |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | /** |
| 252 | * Helper method to fill in the information about the architected message. |
| 253 | */ |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 254 | static inline void spci_architected_message_init(void *message, |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 255 | enum spci_memory_share type) |
| 256 | { |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 257 | /* Fill the architected header. */ |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 258 | struct spci_architected_message_header *architected_header = |
| 259 | (struct spci_architected_message_header *)message; |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 260 | architected_header->type = type; |
| 261 | architected_header->reserved[0] = 0; |
| 262 | architected_header->reserved[1] = 0; |
| 263 | architected_header->reserved[2] = 0; |
| 264 | } |
| 265 | |
| 266 | /** Obtain a pointer to the start of the memory region in the donate message. */ |
| 267 | static inline struct spci_memory_region *spci_get_donated_memory_region( |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 268 | void *message) |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 269 | { |
| 270 | struct spci_architected_message_header *architected_header = |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 271 | (struct spci_architected_message_header *)message; |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 272 | return (struct spci_memory_region *)architected_header->payload; |
| 273 | } |
| 274 | |
| 275 | /** |
Jose Marinho | 713f13a | 2019-05-21 11:54:16 +0100 | [diff] [blame] | 276 | * Helper function that copies the memory constituents and the handle |
| 277 | * information onto the address pointed to by memory_region. |
| 278 | * The function returns the length in bytes occupied by the data copied to |
| 279 | * memory_region (constituents and memory region header size). |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 280 | */ |
Jose Marinho | 713f13a | 2019-05-21 11:54:16 +0100 | [diff] [blame] | 281 | static inline uint32_t spci_memory_region_add( |
| 282 | struct spci_memory_region *memory_region, spci_memory_handle_t handle, |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 283 | const struct spci_memory_region_constituent constituents[], |
| 284 | uint32_t num_constituents) |
| 285 | { |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 286 | uint32_t constituents_length = |
| 287 | num_constituents * |
| 288 | sizeof(struct spci_memory_region_constituent); |
| 289 | uint32_t index; |
| 290 | |
| 291 | memory_region->handle = handle; |
| 292 | memory_region->count = num_constituents; |
| 293 | |
| 294 | for (index = 0; index < num_constituents; index++) { |
| 295 | memory_region->constituents[index] = constituents[index]; |
| 296 | memory_region->constituents[index].reserved = 0; |
| 297 | } |
| 298 | |
| 299 | /* |
| 300 | * TODO: Add assert ensuring that the specified message |
| 301 | * length is not greater than SPCI_MSG_PAYLOAD_MAX. |
| 302 | */ |
Jose Marinho | 713f13a | 2019-05-21 11:54:16 +0100 | [diff] [blame] | 303 | |
| 304 | return sizeof(struct spci_memory_region) + constituents_length; |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | /** Construct the SPCI donate memory region message. */ |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 308 | static inline uint32_t spci_memory_donate_init( |
| 309 | void *message, |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 310 | struct spci_memory_region_constituent *region_constituents, |
| 311 | uint32_t num_elements, uint32_t handle) |
| 312 | { |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 313 | uint32_t message_length; |
Jose Marinho | 713f13a | 2019-05-21 11:54:16 +0100 | [diff] [blame] | 314 | struct spci_memory_region *memory_region = |
| 315 | spci_get_donated_memory_region(message); |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 316 | |
| 317 | message_length = sizeof(struct spci_architected_message_header); |
| 318 | |
| 319 | /* Fill in the details on the common message header. */ |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 320 | spci_architected_message_init(message, SPCI_MEMORY_DONATE); |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 321 | |
| 322 | /* Create single memory region. */ |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 323 | message_length += spci_memory_region_add( |
Jose Marinho | 713f13a | 2019-05-21 11:54:16 +0100 | [diff] [blame] | 324 | memory_region, handle, region_constituents, num_elements); |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 325 | return message_length; |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 326 | } |
Jose Marinho | 56c2573 | 2019-05-20 09:48:53 +0100 | [diff] [blame] | 327 | |
| 328 | /** |
| 329 | * Construct the SPCI memory region relinquish message. |
| 330 | * A set of memory regions can be given back to the owner. |
| 331 | */ |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 332 | static inline uint32_t spci_memory_relinquish_init( |
| 333 | void *message, |
Jose Marinho | 56c2573 | 2019-05-20 09:48:53 +0100 | [diff] [blame] | 334 | struct spci_memory_region_constituent *region_constituents, |
| 335 | uint64_t num_elements, uint32_t handle) |
| 336 | { |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 337 | uint32_t message_length; |
Jose Marinho | 713f13a | 2019-05-21 11:54:16 +0100 | [diff] [blame] | 338 | struct spci_memory_region *memory_region = |
| 339 | spci_get_donated_memory_region(message); |
Jose Marinho | 56c2573 | 2019-05-20 09:48:53 +0100 | [diff] [blame] | 340 | |
| 341 | message_length = sizeof(struct spci_architected_message_header); |
| 342 | |
| 343 | /* Fill in the details on the common message header. */ |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 344 | spci_architected_message_init(message, SPCI_MEMORY_RELINQUISH); |
Jose Marinho | 56c2573 | 2019-05-20 09:48:53 +0100 | [diff] [blame] | 345 | |
| 346 | /* Create single memory region. */ |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 347 | message_length += spci_memory_region_add( |
Jose Marinho | 713f13a | 2019-05-21 11:54:16 +0100 | [diff] [blame] | 348 | memory_region, handle, region_constituents, num_elements); |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 349 | return message_length; |
Jose Marinho | 713f13a | 2019-05-21 11:54:16 +0100 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | /** |
| 353 | * Construct the SPCI memory region lend message. |
| 354 | */ |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 355 | static inline uint32_t spci_memory_lend_init( |
| 356 | void *message, |
Jose Marinho | 713f13a | 2019-05-21 11:54:16 +0100 | [diff] [blame] | 357 | struct spci_memory_region_constituent *region_constituents, |
| 358 | uint64_t num_elements, uint32_t handle, enum spci_lend_access access, |
| 359 | enum spci_lend_type type, enum spci_lend_cacheability cacheability, |
| 360 | enum spci_lend_shareability shareability) |
| 361 | { |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 362 | uint32_t message_length; |
Jose Marinho | 713f13a | 2019-05-21 11:54:16 +0100 | [diff] [blame] | 363 | struct spci_memory_region *memory_region; |
| 364 | |
| 365 | const struct spci_memory_lend lend_init = {0}; |
| 366 | |
| 367 | struct spci_memory_lend *lend_descriptor = |
| 368 | spci_get_lend_descriptor(message); |
| 369 | memory_region = (struct spci_memory_region *)lend_descriptor->payload; |
| 370 | |
| 371 | /* Initilise all struct elements to zero. */ |
| 372 | *lend_descriptor = lend_init; |
| 373 | |
| 374 | message_length = sizeof(struct spci_architected_message_header) + |
| 375 | sizeof(struct spci_memory_lend); |
| 376 | |
| 377 | /* Fill in the details on the common message header. */ |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 378 | spci_architected_message_init(message, SPCI_MEMORY_LEND); |
Jose Marinho | 713f13a | 2019-05-21 11:54:16 +0100 | [diff] [blame] | 379 | |
| 380 | lend_descriptor->flags = SPCI_LEND_KEEP_MAPPED; |
| 381 | |
| 382 | /* Set memory region's page attributes. */ |
| 383 | spci_set_lend_access_attr(&lend_descriptor->borrower_attributes, |
| 384 | access); |
| 385 | spci_set_lend_type_attr(&lend_descriptor->borrower_attributes, type); |
| 386 | spci_set_lend_cacheability_attr(&lend_descriptor->borrower_attributes, |
| 387 | cacheability); |
| 388 | spci_set_lend_shareability_attr(&lend_descriptor->borrower_attributes, |
| 389 | shareability); |
| 390 | |
| 391 | /* Create single memory region. */ |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 392 | message_length += spci_memory_region_add( |
Jose Marinho | 713f13a | 2019-05-21 11:54:16 +0100 | [diff] [blame] | 393 | memory_region, handle, region_constituents, num_elements); |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 394 | return message_length; |
Jose Marinho | 56c2573 | 2019-05-20 09:48:53 +0100 | [diff] [blame] | 395 | } |