blob: d73bfb5f1123d7e9173e8b258c08c89618ff7213 [file] [log] [blame]
Andrew Walbranbc342d42019-02-05 16:56:02 +00001/*
2 * Copyright 2019 The Hafnium Authors.
3 *
Andrew Walbrane959ec12020-06-17 15:01:09 +01004 * Use of this source code is governed by a BSD-style
5 * license that can be found in the LICENSE file or at
6 * https://opensource.org/licenses/BSD-3-Clause.
Andrew Walbranbc342d42019-02-05 16:56:02 +00007 */
8
9#include <stdalign.h>
10#include <stdint.h>
11
Andrew Walbran0fc4d412019-11-06 17:22:32 +000012#include "hf/arch/vm/interrupts.h"
13
David Brazdil711fbe92019-08-06 13:39:58 +010014#include "hf/mm.h"
Andrew Walbranbc342d42019-02-05 16:56:02 +000015
Andrew Walbranbc342d42019-02-05 16:56:02 +000016#include "hftest_common.h"
Andrew Walbran1e7c7742019-12-13 17:10:02 +000017#include "test/hftest.h"
Andrew Walbranbc342d42019-02-05 16:56:02 +000018
19alignas(4096) uint8_t kstack[4096];
20
21extern struct hftest_test hftest_begin[];
22extern struct hftest_test hftest_end[];
23
David Brazdilb856be62020-03-25 10:14:55 +000024void kmain(const void *fdt_ptr)
Andrew Walbranbc342d42019-02-05 16:56:02 +000025{
David Brazdilb856be62020-03-25 10:14:55 +000026 struct fdt fdt;
27 size_t fdt_len;
David Brazdil17e76652020-01-29 14:44:19 +000028 struct memiter command_line;
Andrew Walbranbc342d42019-02-05 16:56:02 +000029 struct memiter command;
30
David Brazdil711fbe92019-08-06 13:39:58 +010031 /*
32 * Initialize the stage-1 MMU and identity-map the entire address space.
33 */
34 if ((VM_TOOLCHAIN == 1) && !hftest_mm_init()) {
35 HFTEST_LOG("Memory initialization failed.");
David Brazdil17e76652020-01-29 14:44:19 +000036 goto out;
David Brazdil711fbe92019-08-06 13:39:58 +010037 }
38
Andrew Walbran0fc4d412019-11-06 17:22:32 +000039 /*
40 * Install the exception handler with no IRQ callback for now, so that
41 * exceptions are logged.
42 */
Fuad Tabba3e9b0222019-11-11 16:47:50 +000043 exception_setup(NULL, NULL);
Andrew Walbran0fc4d412019-11-06 17:22:32 +000044
Andrew Walbranbc342d42019-02-05 16:56:02 +000045 hftest_use_list(hftest_begin, hftest_end - hftest_begin);
46
David Brazdilb856be62020-03-25 10:14:55 +000047 if (!fdt_size_from_header(fdt_ptr, &fdt_len) ||
48 !fdt_init_from_ptr(&fdt, fdt_ptr, fdt_len)) {
49 HFTEST_LOG("Unable to init FDT.");
50 goto out;
51 }
52
53 if (!hftest_ctrl_start(&fdt, &command_line)) {
David Brazdil17e76652020-01-29 14:44:19 +000054 HFTEST_LOG("Unable to read the command line.");
55 goto out;
Andrew Walbranbc342d42019-02-05 16:56:02 +000056 }
57
David Brazdil17e76652020-01-29 14:44:19 +000058 if (!memiter_parse_str(&command_line, &command)) {
Andrew Walbranbc342d42019-02-05 16:56:02 +000059 HFTEST_LOG("Unable to parse command.");
David Brazdil17e76652020-01-29 14:44:19 +000060 goto out;
Andrew Walbranbc342d42019-02-05 16:56:02 +000061 }
62
David Brazdil88333cb2020-01-31 17:12:30 +000063 if (memiter_iseq(&command, "exit")) {
64 hftest_device_exit_test_environment();
65 goto out;
66 }
67
Andrew Walbranbc342d42019-02-05 16:56:02 +000068 if (memiter_iseq(&command, "json")) {
69 hftest_json();
David Brazdil17e76652020-01-29 14:44:19 +000070 goto out;
Andrew Walbranbc342d42019-02-05 16:56:02 +000071 }
72
73 if (memiter_iseq(&command, "run")) {
74 struct memiter suite_name;
75 struct memiter test_name;
76
David Brazdil17e76652020-01-29 14:44:19 +000077 if (!memiter_parse_str(&command_line, &suite_name)) {
Andrew Walbranbc342d42019-02-05 16:56:02 +000078 HFTEST_LOG("Unable to parse test suite.");
David Brazdil17e76652020-01-29 14:44:19 +000079 goto out;
Andrew Walbranbc342d42019-02-05 16:56:02 +000080 }
81
David Brazdil17e76652020-01-29 14:44:19 +000082 if (!memiter_parse_str(&command_line, &test_name)) {
Andrew Walbranbc342d42019-02-05 16:56:02 +000083 HFTEST_LOG("Unable to parse test.");
David Brazdil17e76652020-01-29 14:44:19 +000084 goto out;
Andrew Walbranbc342d42019-02-05 16:56:02 +000085 }
David Brazdilb856be62020-03-25 10:14:55 +000086 hftest_run(suite_name, test_name, &fdt);
David Brazdil17e76652020-01-29 14:44:19 +000087 goto out;
Andrew Walbranbc342d42019-02-05 16:56:02 +000088 }
89
90 hftest_help();
David Brazdil17e76652020-01-29 14:44:19 +000091
92out:
93 hftest_ctrl_finish();
Andrew Walbranbc342d42019-02-05 16:56:02 +000094}