Skip to content

Commit 1d54add

Browse files
committed
[sw] Add HW_ID platform check
Update the test framework smoketest to read the HW_ID register, validate it against known values, and fail on an unrecognised ID. Signed-off-by: martin-velay <mvelay@lowrisc.org>
1 parent 946b577 commit 1d54add

3 files changed

Lines changed: 36 additions & 2 deletions

File tree

sw/device/lib/hal/mocha.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
static const uintptr_t rom_base = 0x80000ul;
1515
static const uintptr_t mailbox_base = 0x20010000ul;
1616
static const uintptr_t dv_test_status_base = 0x20020000ul;
17+
static const uintptr_t dv_hw_id_base = 0x20020008ul;
1718
static const uintptr_t ethernet_base = 0x30000000ul;
1819
static const uintptr_t gpio_base = 0x40000000ul;
1920
static const uintptr_t clkmgr_base = 0x40020000ul;
@@ -201,3 +202,12 @@ void *mocha_system_dv_test_status(void)
201202
return (void *)dv_test_status_base;
202203
#endif /* defined(__riscv_zcherihybrid) */
203204
}
205+
206+
void *mocha_system_dv_hw_id(void)
207+
{
208+
#if defined(__riscv_zcherihybrid)
209+
return create_mmio_capability(dv_hw_id_base, 0x4u);
210+
#else /* !defined(__riscv_zcherihybrid) */
211+
return (void *)dv_hw_id_base;
212+
#endif /* defined(__riscv_zcherihybrid) */
213+
}

sw/device/lib/hal/mocha.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,10 @@ plic_t mocha_system_plic(void);
5252
void *mocha_system_dram(void);
5353

5454
void *mocha_system_dv_test_status(void);
55+
void *mocha_system_dv_hw_id(void);
56+
57+
typedef enum : uint32_t {
58+
HW_ID_FPGA_GENESYS2 = 0x0000000Au,
59+
HW_ID_SIM_VERILATOR = 0x0000001Au,
60+
HW_ID_SIM_UVM = 0x0000002Au,
61+
} dv_hw_platform_t;

sw/device/tests/test_framework/smoketest.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,28 @@
22
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
// SPDX-License-Identifier: Apache-2.0
44

5-
#include "hal/uart.h"
5+
#include "hal/mmio.h"
6+
#include "hal/mocha.h"
67
#include <stdbool.h>
78

89
bool test_main(uart_t console)
910
{
11+
dv_hw_platform_t hw_id = (dv_hw_platform_t)DEV_READ(mocha_system_dv_hw_id());
12+
1013
uart_puts(console, "Test framework smoketest\n");
11-
return true;
14+
15+
switch (hw_id) {
16+
case HW_ID_FPGA_GENESYS2:
17+
uart_puts(console, "Platform: FpgaGenesys2\n");
18+
return true;
19+
case HW_ID_SIM_VERILATOR:
20+
uart_puts(console, "Platform: SimVerilator\n");
21+
return true;
22+
case HW_ID_SIM_UVM:
23+
uart_puts(console, "Platform: SimUvm\n");
24+
return true;
25+
default:
26+
uart_puts(console, "Unknown HW_ID\n");
27+
return false;
28+
}
1229
}

0 commit comments

Comments
 (0)