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