blob: c7c008d03a4ea7fb906e87a67e4ae419fc0a661d [file] [log] [blame]
Andrew Walbranbc342d42019-02-05 16:56:02 +00001/*
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 <stdalign.h>
18#include <stdint.h>
19
Andrew Walbran0fc4d412019-11-06 17:22:32 +000020#include "hf/arch/vm/interrupts.h"
21
David Brazdil711fbe92019-08-06 13:39:58 +010022#include "hf/mm.h"
Andrew Walbranbc342d42019-02-05 16:56:02 +000023
Andrew Walbranbc342d42019-02-05 16:56:02 +000024#include "hftest_common.h"
Andrew Walbran1e7c7742019-12-13 17:10:02 +000025#include "test/hftest.h"
Andrew Walbranbc342d42019-02-05 16:56:02 +000026
27alignas(4096) uint8_t kstack[4096];
28
29extern struct hftest_test hftest_begin[];
30extern struct hftest_test hftest_end[];
31
David Brazdilb856be62020-03-25 10:14:55 +000032void kmain(const void *fdt_ptr)
Andrew Walbranbc342d42019-02-05 16:56:02 +000033{
David Brazdilb856be62020-03-25 10:14:55 +000034 struct fdt fdt;
35 size_t fdt_len;
David Brazdil17e76652020-01-29 14:44:19 +000036 struct memiter command_line;
Andrew Walbranbc342d42019-02-05 16:56:02 +000037 struct memiter command;
38
David Brazdil711fbe92019-08-06 13:39:58 +010039 /*
40 * Initialize the stage-1 MMU and identity-map the entire address space.
41 */
42 if ((VM_TOOLCHAIN == 1) && !hftest_mm_init()) {
43 HFTEST_LOG("Memory initialization failed.");
David Brazdil17e76652020-01-29 14:44:19 +000044 goto out;
David Brazdil711fbe92019-08-06 13:39:58 +010045 }
46
Andrew Walbran0fc4d412019-11-06 17:22:32 +000047 /*
48 * Install the exception handler with no IRQ callback for now, so that
49 * exceptions are logged.
50 */
Fuad Tabba3e9b0222019-11-11 16:47:50 +000051 exception_setup(NULL, NULL);
Andrew Walbran0fc4d412019-11-06 17:22:32 +000052
Andrew Walbranbc342d42019-02-05 16:56:02 +000053 hftest_use_list(hftest_begin, hftest_end - hftest_begin);
54
David Brazdilb856be62020-03-25 10:14:55 +000055 if (!fdt_size_from_header(fdt_ptr, &fdt_len) ||
56 !fdt_init_from_ptr(&fdt, fdt_ptr, fdt_len)) {
57 HFTEST_LOG("Unable to init FDT.");
58 goto out;
59 }
60
61 if (!hftest_ctrl_start(&fdt, &command_line)) {
David Brazdil17e76652020-01-29 14:44:19 +000062 HFTEST_LOG("Unable to read the command line.");
63 goto out;
Andrew Walbranbc342d42019-02-05 16:56:02 +000064 }
65
David Brazdil17e76652020-01-29 14:44:19 +000066 if (!memiter_parse_str(&command_line, &command)) {
Andrew Walbranbc342d42019-02-05 16:56:02 +000067 HFTEST_LOG("Unable to parse command.");
David Brazdil17e76652020-01-29 14:44:19 +000068 goto out;
Andrew Walbranbc342d42019-02-05 16:56:02 +000069 }
70
David Brazdil88333cb2020-01-31 17:12:30 +000071 if (memiter_iseq(&command, "exit")) {
72 hftest_device_exit_test_environment();
73 goto out;
74 }
75
Andrew Walbranbc342d42019-02-05 16:56:02 +000076 if (memiter_iseq(&command, "json")) {
77 hftest_json();
David Brazdil17e76652020-01-29 14:44:19 +000078 goto out;
Andrew Walbranbc342d42019-02-05 16:56:02 +000079 }
80
81 if (memiter_iseq(&command, "run")) {
82 struct memiter suite_name;
83 struct memiter test_name;
84
David Brazdil17e76652020-01-29 14:44:19 +000085 if (!memiter_parse_str(&command_line, &suite_name)) {
Andrew Walbranbc342d42019-02-05 16:56:02 +000086 HFTEST_LOG("Unable to parse test suite.");
David Brazdil17e76652020-01-29 14:44:19 +000087 goto out;
Andrew Walbranbc342d42019-02-05 16:56:02 +000088 }
89
David Brazdil17e76652020-01-29 14:44:19 +000090 if (!memiter_parse_str(&command_line, &test_name)) {
Andrew Walbranbc342d42019-02-05 16:56:02 +000091 HFTEST_LOG("Unable to parse test.");
David Brazdil17e76652020-01-29 14:44:19 +000092 goto out;
Andrew Walbranbc342d42019-02-05 16:56:02 +000093 }
David Brazdilb856be62020-03-25 10:14:55 +000094 hftest_run(suite_name, test_name, &fdt);
David Brazdil17e76652020-01-29 14:44:19 +000095 goto out;
Andrew Walbranbc342d42019-02-05 16:56:02 +000096 }
97
98 hftest_help();
David Brazdil17e76652020-01-29 14:44:19 +000099
100out:
101 hftest_ctrl_finish();
Andrew Walbranbc342d42019-02-05 16:56:02 +0000102}