Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 1 | /* |
Andrew Walbran | 692b325 | 2019-03-07 15:51:31 +0000 | [diff] [blame] | 2 | * Copyright 2019 The Hafnium Authors. |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 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 <stdint.h> |
| 18 | |
Andrew Scull | 8d9e121 | 2019-04-05 13:52:55 +0100 | [diff] [blame] | 19 | #include "hf/std.h" |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 20 | |
| 21 | #include "vmapi/hf/call.h" |
| 22 | |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 23 | #include "primary_with_secondary.h" |
Andrew Walbran | 1e7c774 | 2019-12-13 17:10:02 +0000 | [diff] [blame] | 24 | #include "test/hftest.h" |
Andrew Walbran | 0e7a1c3 | 2019-12-13 17:24:35 +0000 | [diff] [blame] | 25 | #include "test/vmapi/spci.h" |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 26 | |
Andrew Walbran | a0168d5 | 2019-12-16 11:55:06 +0000 | [diff] [blame^] | 27 | TEAR_DOWN(interrupts) |
| 28 | { |
| 29 | EXPECT_SPCI_ERROR(spci_rx_release(), SPCI_DENIED); |
| 30 | } |
| 31 | |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 32 | /** |
| 33 | * Send a message to the interruptible VM, which will interrupt itself to send a |
| 34 | * response back. |
| 35 | */ |
| 36 | TEST(interrupts, interrupt_self) |
| 37 | { |
| 38 | const char message[] = "Ping"; |
| 39 | const char expected_response[] = "Got IRQ 05."; |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 40 | struct spci_value run_res; |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 41 | struct mailbox_buffers mb = set_up_mailbox(); |
| 42 | |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 43 | SERVICE_SELECT(SERVICE_VM1, "interruptible", mb.send); |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 44 | |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 45 | run_res = spci_run(SERVICE_VM1, 0); |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 46 | EXPECT_EQ(run_res.func, SPCI_MSG_WAIT_32); |
| 47 | EXPECT_EQ(run_res.arg2, SPCI_SLEEP_INDEFINITE); |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 48 | |
| 49 | /* Set the message, echo it and wait for a response. */ |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 50 | memcpy_s(mb.send, SPCI_MSG_PAYLOAD_MAX, message, sizeof(message)); |
| 51 | EXPECT_EQ( |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 52 | spci_msg_send(HF_PRIMARY_VM_ID, SERVICE_VM1, sizeof(message), 0) |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 53 | .func, |
| 54 | SPCI_SUCCESS_32); |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 55 | run_res = spci_run(SERVICE_VM1, 0); |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 56 | EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32); |
| 57 | EXPECT_EQ(spci_msg_send_size(run_res), sizeof(expected_response)); |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 58 | EXPECT_EQ(memcmp(mb.recv, expected_response, sizeof(expected_response)), |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 59 | 0); |
Andrew Walbran | 8a0f5ca | 2019-11-05 13:12:23 +0000 | [diff] [blame] | 60 | EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32); |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Inject an interrupt to the interrupt VM, which will send a message back. |
| 65 | * Repeat this twice to make sure it doesn't get into a bad state after the |
| 66 | * first one. |
| 67 | */ |
| 68 | TEST(interrupts, inject_interrupt_twice) |
| 69 | { |
| 70 | const char expected_response[] = "Got IRQ 07."; |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 71 | struct spci_value run_res; |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 72 | struct mailbox_buffers mb = set_up_mailbox(); |
| 73 | |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 74 | SERVICE_SELECT(SERVICE_VM1, "interruptible", mb.send); |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 75 | |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 76 | run_res = spci_run(SERVICE_VM1, 0); |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 77 | EXPECT_EQ(run_res.func, SPCI_MSG_WAIT_32); |
| 78 | EXPECT_EQ(run_res.arg2, SPCI_SLEEP_INDEFINITE); |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 79 | |
| 80 | /* Inject the interrupt and wait for a message. */ |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 81 | hf_interrupt_inject(SERVICE_VM1, 0, EXTERNAL_INTERRUPT_ID_A); |
| 82 | run_res = spci_run(SERVICE_VM1, 0); |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 83 | EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32); |
| 84 | EXPECT_EQ(spci_msg_send_size(run_res), sizeof(expected_response)); |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 85 | EXPECT_EQ(memcmp(mb.recv, expected_response, sizeof(expected_response)), |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 86 | 0); |
Andrew Walbran | 8a0f5ca | 2019-11-05 13:12:23 +0000 | [diff] [blame] | 87 | EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32); |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 88 | |
| 89 | /* Inject the interrupt again, and wait for the same message. */ |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 90 | hf_interrupt_inject(SERVICE_VM1, 0, EXTERNAL_INTERRUPT_ID_A); |
| 91 | run_res = spci_run(SERVICE_VM1, 0); |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 92 | EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32); |
| 93 | EXPECT_EQ(spci_msg_send_size(run_res), sizeof(expected_response)); |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 94 | EXPECT_EQ(memcmp(mb.recv, expected_response, sizeof(expected_response)), |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 95 | 0); |
Andrew Walbran | 8a0f5ca | 2019-11-05 13:12:23 +0000 | [diff] [blame] | 96 | EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32); |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Inject two different interrupts to the interrupt VM, which will send a |
| 101 | * message back each time. |
| 102 | */ |
| 103 | TEST(interrupts, inject_two_interrupts) |
| 104 | { |
| 105 | const char expected_response[] = "Got IRQ 07."; |
| 106 | const char expected_response_2[] = "Got IRQ 08."; |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 107 | struct spci_value run_res; |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 108 | struct mailbox_buffers mb = set_up_mailbox(); |
| 109 | |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 110 | SERVICE_SELECT(SERVICE_VM1, "interruptible", mb.send); |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 111 | |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 112 | run_res = spci_run(SERVICE_VM1, 0); |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 113 | EXPECT_EQ(run_res.func, SPCI_MSG_WAIT_32); |
| 114 | EXPECT_EQ(run_res.arg2, SPCI_SLEEP_INDEFINITE); |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 115 | |
| 116 | /* Inject the interrupt and wait for a message. */ |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 117 | hf_interrupt_inject(SERVICE_VM1, 0, EXTERNAL_INTERRUPT_ID_A); |
| 118 | run_res = spci_run(SERVICE_VM1, 0); |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 119 | EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32); |
| 120 | EXPECT_EQ(spci_msg_send_size(run_res), sizeof(expected_response)); |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 121 | EXPECT_EQ(memcmp(mb.recv, expected_response, sizeof(expected_response)), |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 122 | 0); |
Andrew Walbran | 8a0f5ca | 2019-11-05 13:12:23 +0000 | [diff] [blame] | 123 | EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32); |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 124 | |
| 125 | /* Inject a different interrupt and wait for a different message. */ |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 126 | hf_interrupt_inject(SERVICE_VM1, 0, EXTERNAL_INTERRUPT_ID_B); |
| 127 | run_res = spci_run(SERVICE_VM1, 0); |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 128 | EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32); |
| 129 | EXPECT_EQ(spci_msg_send_size(run_res), sizeof(expected_response_2)); |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 130 | EXPECT_EQ(memcmp(mb.recv, expected_response_2, |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 131 | sizeof(expected_response_2)), |
| 132 | 0); |
Andrew Walbran | 8a0f5ca | 2019-11-05 13:12:23 +0000 | [diff] [blame] | 133 | EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32); |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Inject an interrupt then send a message to the interrupt VM, which will send |
| 138 | * a message back each time. This is to test that interrupt injection doesn't |
| 139 | * interfere with message reception. |
| 140 | */ |
| 141 | TEST(interrupts, inject_interrupt_message) |
| 142 | { |
| 143 | const char expected_response[] = "Got IRQ 07."; |
| 144 | const char message[] = "Ping"; |
| 145 | const char expected_response_2[] = "Got IRQ 05."; |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 146 | struct spci_value run_res; |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 147 | struct mailbox_buffers mb = set_up_mailbox(); |
| 148 | |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 149 | SERVICE_SELECT(SERVICE_VM1, "interruptible", mb.send); |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 150 | |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 151 | run_res = spci_run(SERVICE_VM1, 0); |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 152 | EXPECT_EQ(run_res.func, SPCI_MSG_WAIT_32); |
| 153 | EXPECT_EQ(run_res.arg2, SPCI_SLEEP_INDEFINITE); |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 154 | |
| 155 | /* Inject the interrupt and wait for a message. */ |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 156 | hf_interrupt_inject(SERVICE_VM1, 0, EXTERNAL_INTERRUPT_ID_A); |
| 157 | run_res = spci_run(SERVICE_VM1, 0); |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 158 | EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32); |
| 159 | EXPECT_EQ(spci_msg_send_size(run_res), sizeof(expected_response)); |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 160 | EXPECT_EQ(memcmp(mb.recv, expected_response, sizeof(expected_response)), |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 161 | 0); |
Andrew Walbran | 8a0f5ca | 2019-11-05 13:12:23 +0000 | [diff] [blame] | 162 | EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32); |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 163 | |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 164 | run_res = spci_run(SERVICE_VM1, 0); |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 165 | EXPECT_EQ(run_res.func, SPCI_MSG_WAIT_32); |
| 166 | EXPECT_EQ(run_res.arg2, SPCI_SLEEP_INDEFINITE); |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 167 | |
| 168 | /* Now send a message to the secondary. */ |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 169 | memcpy_s(mb.send, SPCI_MSG_PAYLOAD_MAX, message, sizeof(message)); |
| 170 | EXPECT_EQ( |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 171 | spci_msg_send(HF_PRIMARY_VM_ID, SERVICE_VM1, sizeof(message), 0) |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 172 | .func, |
| 173 | SPCI_SUCCESS_32); |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 174 | run_res = spci_run(SERVICE_VM1, 0); |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 175 | EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32); |
| 176 | EXPECT_EQ(spci_msg_send_size(run_res), sizeof(expected_response_2)); |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 177 | EXPECT_EQ(memcmp(mb.recv, expected_response_2, |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 178 | sizeof(expected_response_2)), |
| 179 | 0); |
Andrew Walbran | 8a0f5ca | 2019-11-05 13:12:23 +0000 | [diff] [blame] | 180 | EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32); |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Inject an interrupt which the target VM has not enabled, and then send a |
| 185 | * message telling it to enable that interrupt ID. It should then (and only |
| 186 | * then) send a message back. |
| 187 | */ |
| 188 | TEST(interrupts, inject_interrupt_disabled) |
| 189 | { |
| 190 | const char expected_response[] = "Got IRQ 09."; |
| 191 | const char message[] = "Enable interrupt C"; |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 192 | struct spci_value run_res; |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 193 | struct mailbox_buffers mb = set_up_mailbox(); |
| 194 | |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 195 | SERVICE_SELECT(SERVICE_VM1, "interruptible", mb.send); |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 196 | |
| 197 | /* Inject the interrupt and expect not to get a message. */ |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 198 | hf_interrupt_inject(SERVICE_VM1, 0, EXTERNAL_INTERRUPT_ID_C); |
| 199 | run_res = spci_run(SERVICE_VM1, 0); |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 200 | EXPECT_EQ(run_res.func, SPCI_MSG_WAIT_32); |
| 201 | EXPECT_EQ(run_res.arg2, SPCI_SLEEP_INDEFINITE); |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 202 | |
| 203 | /* |
| 204 | * Now send a message to the secondary to enable the interrupt ID, and |
| 205 | * expect the response from the interrupt we sent before. |
| 206 | */ |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 207 | memcpy_s(mb.send, SPCI_MSG_PAYLOAD_MAX, message, sizeof(message)); |
| 208 | EXPECT_EQ( |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 209 | spci_msg_send(HF_PRIMARY_VM_ID, SERVICE_VM1, sizeof(message), 0) |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 210 | .func, |
| 211 | SPCI_SUCCESS_32); |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 212 | run_res = spci_run(SERVICE_VM1, 0); |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 213 | EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32); |
| 214 | EXPECT_EQ(spci_msg_send_size(run_res), sizeof(expected_response)); |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 215 | EXPECT_EQ(memcmp(mb.recv, expected_response, sizeof(expected_response)), |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 216 | 0); |
Andrew Walbran | 8a0f5ca | 2019-11-05 13:12:23 +0000 | [diff] [blame] | 217 | EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32); |
Andrew Scull | 2e7a76d | 2019-01-24 11:47:26 +0000 | [diff] [blame] | 218 | } |
Andrew Walbran | 9311c9a | 2019-03-12 16:59:04 +0000 | [diff] [blame] | 219 | |
| 220 | /** |
| 221 | * If a secondary VM has an enabled and pending interrupt, even if interrupts |
| 222 | * are disabled globally via PSTATE, then hf_mailbox_receive should not block |
| 223 | * even if `block` is true. |
| 224 | */ |
| 225 | TEST(interrupts, pending_interrupt_no_blocking_receive) |
| 226 | { |
| 227 | const char expected_response[] = "Done waiting"; |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 228 | struct spci_value run_res; |
Andrew Walbran | 9311c9a | 2019-03-12 16:59:04 +0000 | [diff] [blame] | 229 | struct mailbox_buffers mb = set_up_mailbox(); |
| 230 | |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 231 | SERVICE_SELECT(SERVICE_VM1, "receive_block", mb.send); |
Andrew Walbran | 9311c9a | 2019-03-12 16:59:04 +0000 | [diff] [blame] | 232 | |
| 233 | /* |
| 234 | * Inject the interrupt and run the VM. It should disable interrupts |
| 235 | * globally, enable the specific interrupt, and then send us a message |
| 236 | * back after failing to receive a message a few times. |
| 237 | */ |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 238 | hf_interrupt_inject(SERVICE_VM1, 0, EXTERNAL_INTERRUPT_ID_A); |
| 239 | run_res = spci_run(SERVICE_VM1, 0); |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 240 | EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32); |
| 241 | EXPECT_EQ(spci_msg_send_size(run_res), sizeof(expected_response)); |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 242 | EXPECT_EQ(memcmp(mb.recv, expected_response, sizeof(expected_response)), |
Andrew Walbran | 9311c9a | 2019-03-12 16:59:04 +0000 | [diff] [blame] | 243 | 0); |
Andrew Walbran | 8a0f5ca | 2019-11-05 13:12:23 +0000 | [diff] [blame] | 244 | EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32); |
Andrew Walbran | 9311c9a | 2019-03-12 16:59:04 +0000 | [diff] [blame] | 245 | } |
Andrew Walbran | 2d10e88 | 2019-03-14 18:17:42 +0000 | [diff] [blame] | 246 | |
| 247 | /** |
| 248 | * If a secondary VM has an enabled and pending interrupt, even if interrupts |
| 249 | * are disabled globally via PSTATE, then WFI should be treated as a no-op and |
| 250 | * not return to the primary. |
| 251 | */ |
| 252 | TEST(interrupts, pending_interrupt_wfi_not_trapped) |
| 253 | { |
| 254 | const char expected_response[] = "Done waiting"; |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 255 | struct spci_value run_res; |
Andrew Walbran | 2d10e88 | 2019-03-14 18:17:42 +0000 | [diff] [blame] | 256 | struct mailbox_buffers mb = set_up_mailbox(); |
| 257 | |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 258 | SERVICE_SELECT(SERVICE_VM1, "wfi", mb.send); |
Andrew Walbran | 2d10e88 | 2019-03-14 18:17:42 +0000 | [diff] [blame] | 259 | |
| 260 | /* |
| 261 | * Inject the interrupt and run the VM. It should disable interrupts |
| 262 | * globally, enable the specific interrupt, and then send us a message |
| 263 | * back after running WFI a few times. |
| 264 | */ |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 265 | hf_interrupt_inject(SERVICE_VM1, 0, EXTERNAL_INTERRUPT_ID_A); |
| 266 | run_res = spci_run(SERVICE_VM1, 0); |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 267 | EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32); |
| 268 | EXPECT_EQ(spci_msg_send_size(run_res), sizeof(expected_response)); |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 269 | EXPECT_EQ(memcmp(mb.recv, expected_response, sizeof(expected_response)), |
Andrew Walbran | 2d10e88 | 2019-03-14 18:17:42 +0000 | [diff] [blame] | 270 | 0); |
Andrew Walbran | 8a0f5ca | 2019-11-05 13:12:23 +0000 | [diff] [blame] | 271 | EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32); |
Andrew Walbran | 2d10e88 | 2019-03-14 18:17:42 +0000 | [diff] [blame] | 272 | } |
Andrew Scull | b06d175 | 2019-02-04 10:15:48 +0000 | [diff] [blame] | 273 | |
| 274 | /* |
| 275 | * Deliver an interrupt and a message to the same vCPU and check that both are |
| 276 | * delivered the next time the vCPU is run. |
| 277 | */ |
| 278 | TEST(interrupts, deliver_interrupt_and_message) |
| 279 | { |
| 280 | const char message[] = "I\'ll see you again."; |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 281 | struct spci_value run_res; |
Andrew Scull | b06d175 | 2019-02-04 10:15:48 +0000 | [diff] [blame] | 282 | struct mailbox_buffers mb = set_up_mailbox(); |
| 283 | |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 284 | SERVICE_SELECT(SERVICE_VM1, "interruptible_echo", mb.send); |
Andrew Scull | b06d175 | 2019-02-04 10:15:48 +0000 | [diff] [blame] | 285 | |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 286 | run_res = spci_run(SERVICE_VM1, 0); |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 287 | EXPECT_EQ(run_res.func, SPCI_MSG_WAIT_32); |
| 288 | EXPECT_EQ(run_res.arg2, SPCI_SLEEP_INDEFINITE); |
Andrew Scull | b06d175 | 2019-02-04 10:15:48 +0000 | [diff] [blame] | 289 | |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 290 | memcpy_s(mb.send, SPCI_MSG_PAYLOAD_MAX, message, sizeof(message)); |
| 291 | EXPECT_EQ( |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 292 | spci_msg_send(HF_PRIMARY_VM_ID, SERVICE_VM1, sizeof(message), 0) |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 293 | .func, |
| 294 | SPCI_SUCCESS_32); |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame] | 295 | hf_interrupt_inject(SERVICE_VM1, 0, EXTERNAL_INTERRUPT_ID_A); |
| 296 | run_res = spci_run(SERVICE_VM1, 0); |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 297 | EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32); |
| 298 | EXPECT_EQ(spci_msg_send_size(run_res), sizeof(message)); |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 299 | EXPECT_EQ(memcmp(mb.recv, message, sizeof(message)), 0); |
Andrew Walbran | 8a0f5ca | 2019-11-05 13:12:23 +0000 | [diff] [blame] | 300 | EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32); |
Andrew Scull | b06d175 | 2019-02-04 10:15:48 +0000 | [diff] [blame] | 301 | } |