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 | |
| 17 | #include "hf/types.h" |
| 18 | |
| 19 | #pragma once |
| 20 | |
| 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. */ |
| 29 | #define SPCI_VERSION_32 0x84000060 |
| 30 | #define SPCI_MSG_BUF_LIST_EXCHANGE_32 0x84000061 |
| 31 | #define SPCI_MSG_RECV_32 0x84000062 |
| 32 | #define SPCI_MSG_PUT_32 0x84000063 |
| 33 | #define SPCI_MSG_SEND_32 0x84000064 |
| 34 | #define SPCI_MSG_SEND_REC_32 0x84000065 |
| 35 | #define SPCI_RUN_32 0x84000066 |
| 36 | #define SPCI_YIELD_32 0x84000067 |
| 37 | |
| 38 | /* SPCI return codes. */ |
| 39 | #define SPCI_SUCCESS INT32_C(0) |
| 40 | #define SPCI_NOT_SUPPORTED INT32_C(-1) |
| 41 | #define SPCI_INVALID_PARAMETERS INT32_C(-2) |
| 42 | #define SPCI_NO_MEMORY INT32_C(-3) |
| 43 | #define SPCI_BUSY INT32_C(-4) |
| 44 | #define SPCI_INTERRUPTED INT32_C(-5) |
| 45 | #define SPCI_DENIED INT32_C(-6) |
| 46 | /* TODO: return code currently undefined in SPCI alpha2. */ |
| 47 | #define SPCI_RETRY INT32_C(-7) |
| 48 | |
| 49 | /* SPCI function specific constants. */ |
Andrew Scull | 1262ac2 | 2019-04-05 12:44:26 +0100 | [diff] [blame] | 50 | #define SPCI_MSG_RECV_BLOCK_MASK 0x1 |
Jose Marinho | 4e4e4d5 | 2019-02-22 16:23:51 +0000 | [diff] [blame] | 51 | #define SPCI_MSG_SEND_NOTIFY_MASK 0x1 |
| 52 | |
| 53 | #define SPCI_MESSAGE_IMPDEF_MASK 0x1 |
| 54 | |
| 55 | #define SPCI_MSG_SEND_NOTIFY 0x1 |
Andrew Scull | 1262ac2 | 2019-04-05 12:44:26 +0100 | [diff] [blame] | 56 | #define SPCI_MSG_RECV_BLOCK 0x1 |
| 57 | |
| 58 | /* The maximum length possible for a single message. */ |
| 59 | #define SPCI_MSG_PAYLOAD_MAX (HF_MAILBOX_SIZE - sizeof(struct spci_message)) |
Jose Marinho | 4e4e4d5 | 2019-02-22 16:23:51 +0000 | [diff] [blame] | 60 | |
| 61 | /* clang-format on */ |
| 62 | |
Andrew Walbran | 52d9967 | 2019-06-25 15:51:11 +0100 | [diff] [blame] | 63 | /** The ID of a VM. These are assigned sequentially. */ |
Jose Marinho | 4e4e4d5 | 2019-02-22 16:23:51 +0000 | [diff] [blame] | 64 | typedef uint16_t spci_vm_id_t; |
| 65 | |
Andrew Walbran | 52d9967 | 2019-06-25 15:51:11 +0100 | [diff] [blame] | 66 | /** |
| 67 | * A count of VMs. This has the same range as the VM IDs but we give it a |
| 68 | * different name to make the different semantics clear. |
| 69 | */ |
| 70 | typedef spci_vm_id_t spci_vm_count_t; |
Andrew Walbran | b037d5b | 2019-06-25 17:19:41 +0100 | [diff] [blame^] | 71 | typedef uint16_t spci_vcpu_index_t; |
Andrew Walbran | 52d9967 | 2019-06-25 15:51:11 +0100 | [diff] [blame] | 72 | |
Jose Marinho | 4e4e4d5 | 2019-02-22 16:23:51 +0000 | [diff] [blame] | 73 | /** SPCI common message header. */ |
| 74 | struct spci_message { |
| 75 | /* |
| 76 | * TODO: version is part of SPCI alpha2 but will be |
| 77 | * removed in the next spec revision hence we are not |
| 78 | * including it in the header. |
| 79 | */ |
| 80 | |
| 81 | /** |
| 82 | * flags[0]: |
| 83 | * 0: Architected message payload; |
| 84 | * 1: Implementation defined message payload. |
| 85 | * flags[15:1] reserved (MBZ). |
| 86 | */ |
| 87 | uint16_t flags; |
| 88 | |
| 89 | /* |
| 90 | * TODO: Padding is present to ensure controlled offset |
| 91 | * of the length field. SPCI spec must be updated |
| 92 | * to reflect this (TBD). |
| 93 | */ |
| 94 | uint16_t reserved_1; |
Andrew Scull | a1aa2ba | 2019-04-05 11:49:02 +0100 | [diff] [blame] | 95 | |
Jose Marinho | 4e4e4d5 | 2019-02-22 16:23:51 +0000 | [diff] [blame] | 96 | uint32_t length; |
Jose Marinho | 4e4e4d5 | 2019-02-22 16:23:51 +0000 | [diff] [blame] | 97 | spci_vm_id_t target_vm_id; |
Jose Marinho | 4e4e4d5 | 2019-02-22 16:23:51 +0000 | [diff] [blame] | 98 | spci_vm_id_t source_vm_id; |
| 99 | |
| 100 | /* |
| 101 | * TODO: Padding is present to ensure that the field |
| 102 | * payload alignment is 64B. SPCI spec must be updated |
| 103 | * to reflect this. |
| 104 | */ |
| 105 | uint32_t reserved_2; |
| 106 | |
| 107 | uint8_t payload[]; |
| 108 | }; |
| 109 | |
| 110 | /** |
| 111 | * Set the SPCI common message header fields. |
| 112 | */ |
| 113 | static inline void spci_message_init(struct spci_message *message, |
| 114 | uint32_t message_length, |
| 115 | spci_vm_id_t target_vm_id, |
| 116 | spci_vm_id_t source_vm_id) |
| 117 | { |
| 118 | message->flags = SPCI_MESSAGE_IMPDEF_MASK; |
| 119 | message->length = message_length; |
| 120 | message->target_vm_id = target_vm_id; |
| 121 | message->source_vm_id = source_vm_id; |
| 122 | |
| 123 | /* |
| 124 | * TODO: Reserved fields in the common message header will be |
| 125 | * defined as MBZ in next SPCI spec updates. |
| 126 | */ |
| 127 | message->reserved_1 = 0; |
| 128 | message->reserved_2 = 0; |
| 129 | } |