blob: 86eed7966069022aab00ea828bcd33bd4adde567 [file] [log] [blame]
/*
* Copyright 2018 The Hafnium Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "hf/std.h"
#include "vmapi/hf/call.h"
#include "hftest.h"
TEST_SERVICE(relay)
{
/*
* Loop, forward messages to the next VM.
*
* The first 32-bits of the message are the little-endian 32-bit ID of
* the VM to forward the message to. This ID will be dropped from the
* message so multiple IDs can be places at the start of the message.
*/
for (;;) {
spci_vm_id_t *chain;
spci_vm_id_t next_vm_id;
void *next_message;
uint32_t next_message_size;
/* Receive the message to relay. */
spci_msg_wait();
/* Prepare to relay the message. */
struct spci_message *recv_buf = SERVICE_RECV_BUFFER();
struct spci_message *send_buf = SERVICE_SEND_BUFFER();
ASSERT_GE(recv_buf->length, sizeof(spci_vm_id_t));
chain = (spci_vm_id_t *)recv_buf->payload;
next_vm_id = le16toh(*chain);
next_message = chain + 1;
next_message_size = recv_buf->length - sizeof(spci_vm_id_t);
/* Send the message to the next stage. */
memcpy_s(send_buf->payload, SPCI_MSG_PAYLOAD_MAX, next_message,
next_message_size);
spci_message_init(send_buf, next_message_size, next_vm_id,
hf_vm_get_id());
hf_mailbox_clear();
spci_msg_send(0);
}
}