Skip to content

Commit fca6636

Browse files
sw: create DV register layout in HAL, adding hw_id
Co-authored-by: martin-velay <mvelay@lowrisc.org> Signed-off-by: Alice Ziuziakowska <a.ziuziakowska@lowrisc.org>
1 parent 9c0b32f commit fca6636

4 files changed

Lines changed: 60 additions & 16 deletions

File tree

sw/device/lib/hal/dv.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright lowRISC contributors (COSMIC project).
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
// Design Verification (DV) register window.
6+
7+
#pragma once
8+
9+
#include <stdint.h>
10+
11+
/* These values are written to the test_status register of the DV window
12+
* throughout a test to indicate test progression and outcome. */
13+
enum dv_test_status : uint32_t {
14+
/* Test code has begun. */
15+
dv_test_status_in_test = 0x4354u,
16+
/* The test has passed. */
17+
dv_test_status_passed = 0x900du,
18+
/* The test has failed. */
19+
dv_test_status_failed = 0xbaadu,
20+
};
21+
22+
/* These values are provided by the DV window from the hw_id register to
23+
* indicate the current test platform. */
24+
enum dv_hwid : uint32_t {
25+
/* Running on the Genesys2 FPGA. */
26+
dv_hwid_fpga_genesys2 = 0xau,
27+
/* Running in a Verilator simulation. */
28+
dv_hwid_sim_verilator = 0x1au,
29+
/* Running in a UVM simulation. */
30+
dv_hwid_sim_uvm = 0x2au,
31+
};
32+
33+
typedef volatile struct [[gnu::aligned(4)]] dv_window_memory_layout {
34+
/* test_status (0x0) */
35+
uint32_t test_status;
36+
37+
/* hw_id (0x4) */
38+
const uint32_t hw_id;
39+
40+
const uint8_t __reserved0[0x100 - 0x08];
41+
} *dv_window_t;
42+
43+
44+
_Static_assert(__builtin_offsetof(struct dv_window_memory_layout, test_status) == 0x0ul,
45+
"incorrect register test_status offset");
46+
_Static_assert(__builtin_offsetof(struct dv_window_memory_layout, hw_id) == 0x4ul,
47+
"incorrect register hw_id offset");

sw/device/lib/hal/mocha.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
static const uintptr_t rom_base = 0x80000ul;
1515
static const uintptr_t mailbox_base = 0x20010000ul;
16-
static const uintptr_t dv_test_status_base = 0x20020000ul;
16+
static const uintptr_t dv_window_base = 0x20020000ul;
1717
static const uintptr_t ethernet_base = 0x30000000ul;
1818
static const uintptr_t gpio_base = 0x40000000ul;
1919
static const uintptr_t clkmgr_base = 0x40020000ul;
@@ -193,11 +193,12 @@ void *mocha_system_dram(void)
193193
#endif /* defined(__riscv_zcherihybrid) */
194194
}
195195

196-
void *mocha_system_dv_test_status(void)
196+
dv_window_t mocha_system_dv_window(void)
197197
{
198198
#if defined(__riscv_zcherihybrid)
199-
return create_mmio_capability(dv_test_status_base, 0x100u);
199+
return (
200+
dv_window_t)create_mmio_capability(dv_window_base, sizeof(struct dv_window_memory_layout));
200201
#else /* !defined(__riscv_zcherihybrid) */
201-
return (void *)dv_test_status_base;
202+
return (dv_window_t)dv_window_base;
202203
#endif /* defined(__riscv_zcherihybrid) */
203204
}

sw/device/lib/hal/mocha.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#pragma once
88

99
#include "hal/clkmgr.h"
10+
#include "hal/dv.h"
1011
#include "hal/entropy_src.h"
1112
#include "hal/ethernet.h"
1213
#include "hal/gpio.h"
@@ -50,5 +51,4 @@ timer_t mocha_system_timer(void);
5051
spi_host_t mocha_system_spi_host(void);
5152
plic_t mocha_system_plic(void);
5253
void *mocha_system_dram(void);
53-
54-
void *mocha_system_dv_test_status(void);
54+
dv_window_t mocha_system_dv_window(void);

sw/device/lib/test_framework/main.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0
44

55
#include "boot/trap.h"
6+
#include "hal/dv.h"
67
#include "hal/hart.h"
78
#include "hal/mmio.h"
89
#include "hal/mocha.h"
@@ -12,12 +13,6 @@
1213
#include <stdbool.h>
1314
#include <stdint.h>
1415

15-
enum test_status {
16-
TEST_STATUS_IN_TEST = 0x4354u,
17-
TEST_STATUS_PASSED = 0x900du,
18-
TEST_STATUS_FAILED = 0xbaadu,
19-
};
20-
2116
/* magic byte string to terminate the verilator simulation */
2217
static const char magic[] = "\xd8\xaf\xfb\xa0\xc7\xe1\xa9\xd7";
2318

@@ -53,11 +48,11 @@ test_exception_handler(struct trap_registers *registers, struct trap_context *co
5348
[[noreturn]] void test_exit(bool success)
5449
{
5550
uart_t console = mocha_system_uart();
56-
void *dv_test_status = mocha_system_dv_test_status();
51+
dv_window_t dv_window = mocha_system_dv_window();
5752

5853
uart_puts(console, "TEST RESULT: ");
5954
uart_puts(console, success ? "PASSED" : "FAILED");
60-
DEV_WRITE(dv_test_status, success ? TEST_STATUS_PASSED : TEST_STATUS_FAILED);
55+
DEV_WRITE(&dv_window->test_status, success ? dv_test_status_passed : dv_test_status_failed);
6156

6257
uart_putchar(console, '\n');
6358
uart_puts(console, "Safe to exit simulator.");
@@ -75,12 +70,13 @@ test_exception_handler(struct trap_registers *registers, struct trap_context *co
7570
[[noreturn]] void main(void)
7671
{
7772
uart_t console = mocha_system_uart();
78-
void *dv_test_status = mocha_system_dv_test_status();
73+
dv_window_t dv_window = mocha_system_dv_window();
7974

8075
uart_init(console);
8176
// Flush the uart
8277
uart_wait_for(console, uart_status_txidle);
83-
DEV_WRITE(dv_test_status, TEST_STATUS_IN_TEST);
78+
79+
DEV_WRITE(&dv_window->test_status, dv_test_status_in_test);
8480

8581
bool result = test_main(console);
8682
// Flush the uart

0 commit comments

Comments
 (0)