blob: 586b3b3294067ebd3395688b0a7686ef48ada456 [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
Andrew Walbranbc342d42019-02-05 16:56:02 +000022#include "hf/fdt.h"
23#include "hf/memiter.h"
David Brazdil711fbe92019-08-06 13:39:58 +010024#include "hf/mm.h"
Andrew Walbranbc342d42019-02-05 16:56:02 +000025
Andrew Walbranbc342d42019-02-05 16:56:02 +000026#include "hftest_common.h"
Andrew Walbran1e7c7742019-12-13 17:10:02 +000027#include "test/hftest.h"
Andrew Walbranbc342d42019-02-05 16:56:02 +000028
29alignas(4096) uint8_t kstack[4096];
30
31extern struct hftest_test hftest_begin[];
32extern struct hftest_test hftest_end[];
33
34void kmain(const struct fdt_header *fdt)
35{
36 struct fdt_node n;
37 const char *bootargs;
38 uint32_t bootargs_size;
39 struct memiter bootargs_iter;
40 struct memiter command;
41
David Brazdil711fbe92019-08-06 13:39:58 +010042 /*
43 * Initialize the stage-1 MMU and identity-map the entire address space.
44 */
45 if ((VM_TOOLCHAIN == 1) && !hftest_mm_init()) {
46 HFTEST_LOG("Memory initialization failed.");
47 return;
48 }
49
Andrew Walbran0fc4d412019-11-06 17:22:32 +000050 /*
51 * Install the exception handler with no IRQ callback for now, so that
52 * exceptions are logged.
53 */
Fuad Tabba3e9b0222019-11-11 16:47:50 +000054 exception_setup(NULL, NULL);
Andrew Walbran0fc4d412019-11-06 17:22:32 +000055
Andrew Walbranbc342d42019-02-05 16:56:02 +000056 hftest_use_list(hftest_begin, hftest_end - hftest_begin);
57
58 if (!fdt_root_node(&n, fdt)) {
59 HFTEST_LOG("FDT failed validation.");
60 return;
61 }
62
63 if (!fdt_find_child(&n, "")) {
64 HFTEST_LOG("Unable to find root node in FDT.");
65 return;
66 }
67
68 if (!fdt_find_child(&n, "chosen")) {
69 HFTEST_LOG("Unable to find 'chosen' node in FDT.");
70 return;
71 }
72
73 if (!fdt_read_property(&n, "bootargs", &bootargs, &bootargs_size)) {
74 HFTEST_LOG("Unable to read bootargs.");
75 return;
76 }
77
78 /* Remove null terminator. */
79 memiter_init(&bootargs_iter, bootargs, bootargs_size - 1);
80
81 if (!memiter_parse_str(&bootargs_iter, &command)) {
82 HFTEST_LOG("Unable to parse command.");
83 return;
84 }
85
86 if (memiter_iseq(&command, "json")) {
87 hftest_json();
88 return;
89 }
90
91 if (memiter_iseq(&command, "run")) {
92 struct memiter suite_name;
93 struct memiter test_name;
94
95 if (!memiter_parse_str(&bootargs_iter, &suite_name)) {
96 HFTEST_LOG("Unable to parse test suite.");
97 return;
98 }
99
100 if (!memiter_parse_str(&bootargs_iter, &test_name)) {
101 HFTEST_LOG("Unable to parse test.");
102 return;
103 }
Andrew Walbranafabe852019-03-20 17:55:11 +0000104 hftest_run(suite_name, test_name, fdt);
Andrew Walbranbc342d42019-02-05 16:56:02 +0000105 return;
106 }
107
108 hftest_help();
109}