Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 1 | /* |
| 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 Walbran | 0fc4d41 | 2019-11-06 17:22:32 +0000 | [diff] [blame] | 20 | #include "hf/arch/vm/interrupts.h" |
| 21 | |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 22 | #include "hf/fdt.h" |
| 23 | #include "hf/memiter.h" |
David Brazdil | 711fbe9 | 2019-08-06 13:39:58 +0100 | [diff] [blame] | 24 | #include "hf/mm.h" |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 25 | |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 26 | #include "hftest_common.h" |
Andrew Walbran | 1e7c774 | 2019-12-13 17:10:02 +0000 | [diff] [blame^] | 27 | #include "test/hftest.h" |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 28 | |
| 29 | alignas(4096) uint8_t kstack[4096]; |
| 30 | |
| 31 | extern struct hftest_test hftest_begin[]; |
| 32 | extern struct hftest_test hftest_end[]; |
| 33 | |
| 34 | void 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 Brazdil | 711fbe9 | 2019-08-06 13:39:58 +0100 | [diff] [blame] | 42 | /* |
| 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 Walbran | 0fc4d41 | 2019-11-06 17:22:32 +0000 | [diff] [blame] | 50 | /* |
| 51 | * Install the exception handler with no IRQ callback for now, so that |
| 52 | * exceptions are logged. |
| 53 | */ |
Fuad Tabba | 3e9b022 | 2019-11-11 16:47:50 +0000 | [diff] [blame] | 54 | exception_setup(NULL, NULL); |
Andrew Walbran | 0fc4d41 | 2019-11-06 17:22:32 +0000 | [diff] [blame] | 55 | |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 56 | 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 Walbran | afabe85 | 2019-03-20 17:55:11 +0000 | [diff] [blame] | 104 | hftest_run(suite_name, test_name, fdt); |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 105 | return; |
| 106 | } |
| 107 | |
| 108 | hftest_help(); |
| 109 | } |