blob: b110cb50388579889f5949f075eea792aadf5722 [file] [log] [blame]
Andrew Scullf0551c82018-12-15 20:38:47 +00001/*
Andrew Walbran692b3252019-03-07 15:51:31 +00002 * Copyright 2018 The Hafnium Authors.
Andrew Scullf0551c82018-12-15 20:38:47 +00003 *
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 <stdalign.h>
18#include <stdint.h>
19
20#include "hf/memiter.h"
Jose Marinhoa1dfeda2019-02-27 16:46:03 +000021#include "hf/spci.h"
Andrew Scull8d9e1212019-04-05 13:52:55 +010022#include "hf/std.h"
Andrew Scullf0551c82018-12-15 20:38:47 +000023
24#include "vmapi/hf/call.h"
25
26#include "hftest.h"
27
28alignas(4096) uint8_t kstack[4096];
29
30HFTEST_ENABLE();
31
32extern struct hftest_test hftest_begin[];
33extern struct hftest_test hftest_end[];
34
35static alignas(HF_MAILBOX_SIZE) uint8_t send[HF_MAILBOX_SIZE];
36static alignas(HF_MAILBOX_SIZE) uint8_t recv[HF_MAILBOX_SIZE];
37
38static hf_ipaddr_t send_addr = (hf_ipaddr_t)send;
39static hf_ipaddr_t recv_addr = (hf_ipaddr_t)recv;
40
41static struct hftest_context global_context;
42
43struct hftest_context *hftest_get_context(void)
44{
45 return &global_context;
46}
47
48/** Find the service with the name passed in the arguments. */
49static hftest_test_fn find_service(struct memiter *args)
50{
51 struct memiter service_name;
52 struct hftest_test *test;
53
54 if (!memiter_parse_str(args, &service_name)) {
55 return NULL;
56 }
57
58 for (test = hftest_begin; test < hftest_end; ++test) {
59 if (test->kind == HFTEST_KIND_SERVICE &&
60 memiter_iseq(&service_name, test->name)) {
61 return test->fn;
62 }
63 }
64
65 return NULL;
66}
67
Andrew Sculla59f9bc2019-04-03 15:24:35 +010068noreturn void abort(void)
Andrew Scullf0551c82018-12-15 20:38:47 +000069{
70 HFTEST_LOG("Service contained failures.");
71 for (;;) {
72 /*
73 * Hang if the service aborts as a secondary can't power down
74 * the machine.
75 */
76 }
77}
78
79noreturn void kmain(void)
80{
81 struct memiter args;
82 hftest_test_fn service;
Andrew Scullf0551c82018-12-15 20:38:47 +000083 struct hftest_context *ctx;
84
Jose Marinhoa1dfeda2019-02-27 16:46:03 +000085 struct spci_message *recv_msg = (struct spci_message *)recv;
86
Andrew Scullf0551c82018-12-15 20:38:47 +000087 /* Prepare the context. */
88
89 /* Set up the mailbox. */
90 hf_vm_configure(send_addr, recv_addr);
91
92 /* Receive the name of the service to run. */
Jose Marinho3e2442f2019-03-12 13:30:37 +000093 spci_msg_recv(SPCI_MSG_RECV_BLOCK);
Jose Marinhoa1dfeda2019-02-27 16:46:03 +000094 memiter_init(&args, recv_msg->payload, recv_msg->length);
Andrew Scullf0551c82018-12-15 20:38:47 +000095 service = find_service(&args);
96 hf_mailbox_clear();
97
98 /* Check the service was found. */
99 if (service == NULL) {
100 HFTEST_LOG_FAILURE();
101 HFTEST_LOG(HFTEST_LOG_INDENT
102 "Unable to find requested service");
103 for (;;) {
104 /* Hang if the service was unknown. */
105 }
106 }
107
108 /* Clean the context. */
109 ctx = hftest_get_context();
110 memset(ctx, 0, sizeof(*ctx));
111 ctx->abort = abort;
Jose Marinhoa1dfeda2019-02-27 16:46:03 +0000112 ctx->send = (struct spci_message *)send;
113 ctx->recv = (struct spci_message *)recv;
Andrew Scullf0551c82018-12-15 20:38:47 +0000114
115 /* Pause so the next time cycles are given the service will be run. */
116 hf_vcpu_yield();
117
118 /* Let the service run. */
119 service();
120
121 /* Cleanly handle it if the service returns. */
122 if (ctx->failures) {
123 abort();
124 }
125
126 for (;;) {
127 /* Hang if the service returns. */
128 }
129}