-
Notifications
You must be signed in to change notification settings - Fork 13
[top,sw/dv] Clk pwr rst smoke tests #460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
5f5191d
0345940
7adf270
20e0f44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ static const uintptr_t dv_test_status_base = 0x20020000ul; | |
| static const uintptr_t gpio_base = 0x40000000ul; | ||
| static const uintptr_t clkmgr_base = 0x40020000ul; | ||
| static const uintptr_t rstmgr_base = 0x40030000ul; | ||
| static const uintptr_t pwrmgr_base = 0x40040000ul; | ||
| static const uintptr_t rom_ctrl_base = 0x40050000ul; | ||
| static const uintptr_t uart_base = 0x41000000ul; | ||
| static const uintptr_t i2c_base = 0x42000000ul; | ||
|
|
@@ -90,6 +91,15 @@ rstmgr_t mocha_system_rstmgr(void) | |
| #endif /* defined(__riscv_zcherihybrid) */ | ||
| } | ||
|
|
||
| pwrmgr_t mocha_system_pwrmgr(void) | ||
| { | ||
| #if defined(__riscv_zcherihybrid) | ||
| return (pwrmgr_t)create_mmio_capability(pwrmgr_base, 0x80u); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this length can be 0x44
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. The highest register used here is |
||
| #else /* !defined(__riscv_zcherihybrid) */ | ||
| return (pwrmgr_t)pwrmgr_base; | ||
| #endif /* defined(__riscv_zcherihybrid) */ | ||
| } | ||
|
|
||
| rom_ctrl_t mocha_system_rom_ctrl(void) | ||
| { | ||
| #if defined(__riscv_zcherihybrid) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // Copyright lowRISC contributors (COSMIC project). | ||
| // Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #include "hal/pwrmgr.h" | ||
| #include "hal/mmio.h" | ||
| #include <stdint.h> | ||
|
|
||
| static uint32_t pwrmgr_read(pwrmgr_t pwrmgr, uintptr_t reg) | ||
| { | ||
| return DEV_READ(pwrmgr + reg); | ||
| } | ||
|
|
||
| static void pwrmgr_write(pwrmgr_t pwrmgr, uintptr_t reg, uint32_t value) | ||
| { | ||
| DEV_WRITE(pwrmgr + reg, value); | ||
| } | ||
|
|
||
| uint32_t pwrmgr_control_get(pwrmgr_t pwrmgr) | ||
| { | ||
| return pwrmgr_read(pwrmgr, PWRMGR_CONTROL_REG); | ||
| } | ||
|
Comment on lines
+9
to
+22
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replicated from clock manager.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I copied the same style from clkmgr. I can keep both files like this, or I can remove these helpers and use |
||
|
|
||
| void pwrmgr_control_set(pwrmgr_t pwrmgr, uint32_t value) | ||
| { | ||
| pwrmgr_write(pwrmgr, PWRMGR_CONTROL_REG, value & PWRMGR_CONTROL_MASK); | ||
| } | ||
|
|
||
| void pwrmgr_cfg_sync(pwrmgr_t pwrmgr) | ||
| { | ||
| pwrmgr_write(pwrmgr, PWRMGR_CFG_CDC_SYNC_REG, 1u); | ||
| while ((pwrmgr_read(pwrmgr, PWRMGR_CFG_CDC_SYNC_REG) & 1u) != 0u) { | ||
| } | ||
| } | ||
|
|
||
| uint32_t pwrmgr_wakeup_enable_get(pwrmgr_t pwrmgr) | ||
| { | ||
| return pwrmgr_read(pwrmgr, PWRMGR_WAKEUP_EN_REG); | ||
| } | ||
|
|
||
| void pwrmgr_wakeup_enable_set(pwrmgr_t pwrmgr, uint32_t value) | ||
| { | ||
| pwrmgr_write(pwrmgr, PWRMGR_WAKEUP_EN_REG, value); | ||
| } | ||
|
|
||
| uint32_t pwrmgr_wakeup_status_get(pwrmgr_t pwrmgr) | ||
| { | ||
| return pwrmgr_read(pwrmgr, PWRMGR_WAKE_STATUS_REG); | ||
| } | ||
|
|
||
| uint32_t pwrmgr_reset_status_get(pwrmgr_t pwrmgr) | ||
| { | ||
| return pwrmgr_read(pwrmgr, PWRMGR_RESET_STATUS_REG); | ||
| } | ||
|
|
||
| uint32_t pwrmgr_escalate_reset_status_get(pwrmgr_t pwrmgr) | ||
| { | ||
| return pwrmgr_read(pwrmgr, PWRMGR_ESCALATE_RESET_STATUS_REG); | ||
| } | ||
|
|
||
| uint32_t pwrmgr_wake_info_get(pwrmgr_t pwrmgr) | ||
| { | ||
| return pwrmgr_read(pwrmgr, PWRMGR_WAKE_INFO_REG); | ||
| } | ||
|
|
||
| void pwrmgr_wake_info_clear(pwrmgr_t pwrmgr, uint32_t mask) | ||
| { | ||
| pwrmgr_write(pwrmgr, PWRMGR_WAKE_INFO_REG, mask); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Copyright lowRISC contributors (COSMIC project). | ||
| // Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| // Power manager interface. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| #define PWRMGR_CONTROL_REG (0x14) | ||
| #define PWRMGR_CFG_CDC_SYNC_REG (0x18) | ||
| #define PWRMGR_WAKEUP_EN_REG (0x20) | ||
| #define PWRMGR_WAKE_STATUS_REG (0x24) | ||
| #define PWRMGR_RESET_STATUS_REG (0x30) | ||
| #define PWRMGR_ESCALATE_RESET_STATUS_REG (0x34) | ||
| #define PWRMGR_WAKE_INFO_REG (0x3C) | ||
|
|
||
| #define PWRMGR_CONTROL_LOW_POWER_HINT_BIT (1u << 0) | ||
| #define PWRMGR_CONTROL_CORE_CLK_EN_BIT (1u << 4) | ||
| #define PWRMGR_CONTROL_IO_CLK_EN_BIT (1u << 5) | ||
| #define PWRMGR_CONTROL_MAIN_PD_N_BIT (1u << 6) | ||
| #define PWRMGR_CONTROL_MASK \ | ||
| (PWRMGR_CONTROL_LOW_POWER_HINT_BIT | PWRMGR_CONTROL_CORE_CLK_EN_BIT | \ | ||
| PWRMGR_CONTROL_IO_CLK_EN_BIT | PWRMGR_CONTROL_MAIN_PD_N_BIT) | ||
|
|
||
| #define PWRMGR_WAKEUP_EN_SOC_PROXY_EXT_WKUP_REQ_BIT (1u << 0) | ||
|
|
||
| #define PWRMGR_WAKE_INFO_REASONS_BIT (1u << 0) | ||
| #define PWRMGR_WAKE_INFO_FALL_THROUGH_BIT (1u << 1) | ||
| #define PWRMGR_WAKE_INFO_ABORT_BIT (1u << 2) | ||
|
|
||
| typedef void *pwrmgr_t; | ||
|
|
||
| #define PWRMGR_FROM_BASE_ADDR(addr) ((pwrmgr_t)(addr)) | ||
|
|
||
| uint32_t pwrmgr_control_get(pwrmgr_t pwrmgr); | ||
| void pwrmgr_control_set(pwrmgr_t pwrmgr, uint32_t value); | ||
|
|
||
| void pwrmgr_cfg_sync(pwrmgr_t pwrmgr); | ||
|
|
||
| uint32_t pwrmgr_wakeup_enable_get(pwrmgr_t pwrmgr); | ||
| void pwrmgr_wakeup_enable_set(pwrmgr_t pwrmgr, uint32_t value); | ||
|
|
||
| uint32_t pwrmgr_wakeup_status_get(pwrmgr_t pwrmgr); | ||
| uint32_t pwrmgr_reset_status_get(pwrmgr_t pwrmgr); | ||
| uint32_t pwrmgr_escalate_reset_status_get(pwrmgr_t pwrmgr); | ||
|
|
||
| uint32_t pwrmgr_wake_info_get(pwrmgr_t pwrmgr); | ||
| void pwrmgr_wake_info_clear(pwrmgr_t pwrmgr, uint32_t mask); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,19 +4,28 @@ | |
|
|
||
| #include "hal/rstmgr.h" | ||
| #include "hal/mmio.h" | ||
| #include "hal/mocha.h" | ||
| #include <stdint.h> | ||
|
|
||
| uint32_t rstmgr_reset_reason_get(rstmgr_t rstmgr) | ||
| { | ||
| return DEV_READ(rstmgr + RSTMGR_RESET_INFO_REG); | ||
| } | ||
|
|
||
| void rstmgr_reset_reason_clear(rstmgr_t rstmgr, uint32_t reason) | ||
| { | ||
| DEV_WRITE(rstmgr + RSTMGR_RESET_INFO_REG, reason); | ||
| } | ||
|
|
||
| void rstmgr_software_reset_request(rstmgr_t rstmgr) | ||
| { | ||
| DEV_WRITE(rstmgr + RSTMGR_RESET_REQ_REG, RSTMGR_RESET_REQ_TRUE); | ||
| } | ||
|
|
||
| bool rstmgr_software_reset_info_get(rstmgr_t rstmgr) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can now remove this function. I think it was only used in the software_reset test.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. The test now reads and clears the reset reason directly, so this function is not needed anymore. I will remove it from the HAL source and header. |
||
| { | ||
| if (DEV_READ(rstmgr + RSTMGR_RESET_INFO_REG) & RSTMGR_RESET_INFO_SW_RESET) { | ||
| if (rstmgr_reset_reason_get(rstmgr) & RSTMGR_RESET_INFO_SW_RESET) { | ||
| // Clear the info bit before returning. | ||
| DEV_WRITE(rstmgr + RSTMGR_RESET_INFO_REG, RSTMGR_RESET_INFO_SW_RESET); | ||
| rstmgr_reset_reason_clear(rstmgr, RSTMGR_RESET_INFO_SW_RESET); | ||
| return true; | ||
| } | ||
| return false; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // Copyright lowRISC contributors (COSMIC project). | ||
| // Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #include "hal/clkmgr.h" | ||
| #include "hal/mocha.h" | ||
| #include <stdbool.h> | ||
| #include <stdint.h> | ||
|
|
||
| static bool test_gateable_clock(clkmgr_t clkmgr) | ||
| { | ||
| bool initial = clkmgr_gateable_clock_get_enabled(clkmgr, CLKMGR_GATEABLE_CLOCK_IO_PERI); | ||
| bool toggled = !initial; | ||
|
|
||
| clkmgr_gateable_clock_set_enabled(clkmgr, CLKMGR_GATEABLE_CLOCK_IO_PERI, toggled); | ||
| if (clkmgr_gateable_clock_get_enabled(clkmgr, CLKMGR_GATEABLE_CLOCK_IO_PERI) != toggled) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any way that we can confirm that the peripherals are actually stopped? I'm not sure whether reading a register will cause a bus error or just hang the design.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this software smoke test can safely check that. If we read from a peripheral after stopping its clock, it may hang the design. This test only checks that the clkmgr registers can be written and read back correctly. I think checking that the clock really stops should be done in DV, where we can observe the clock signals directly. |
||
| return false; | ||
| } | ||
|
|
||
| clkmgr_gateable_clock_set_enabled(clkmgr, CLKMGR_GATEABLE_CLOCK_IO_PERI, initial); | ||
| return clkmgr_gateable_clock_get_enabled(clkmgr, CLKMGR_GATEABLE_CLOCK_IO_PERI) == initial; | ||
| } | ||
|
|
||
| static bool test_hintable_clock(clkmgr_t clkmgr) | ||
| { | ||
| bool initial = clkmgr_hintable_clock_get_hint(clkmgr, CLKMGR_HINTABLE_CLOCK_MAIN); | ||
| bool toggled = !initial; | ||
|
|
||
| clkmgr_hintable_clock_set_hint(clkmgr, CLKMGR_HINTABLE_CLOCK_MAIN, toggled); | ||
| if (clkmgr_hintable_clock_get_hint(clkmgr, CLKMGR_HINTABLE_CLOCK_MAIN) != toggled) { | ||
| return false; | ||
| } | ||
|
|
||
| if (toggled && !clkmgr_hintable_clock_get_enabled(clkmgr, CLKMGR_HINTABLE_CLOCK_MAIN)) { | ||
| return false; | ||
| } | ||
|
|
||
| clkmgr_hintable_clock_set_hint(clkmgr, CLKMGR_HINTABLE_CLOCK_MAIN, initial); | ||
| return clkmgr_hintable_clock_get_hint(clkmgr, CLKMGR_HINTABLE_CLOCK_MAIN) == initial; | ||
| } | ||
|
|
||
| bool test_main() | ||
| { | ||
| clkmgr_t clkmgr = mocha_system_clkmgr(); | ||
| return test_gateable_clock(clkmgr) && test_hintable_clock(clkmgr); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These don't look like clock manager specific functions. Do they already exist elsewhere in the repo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not find another helper for this, only the
DEV_READandDEV_WRITEmacros. I added these local helpers to avoid repeating the same code in this file. I can also remove them and useDEV_READ/DEV_WRITEdirectly if you prefer.