-
Notifications
You must be signed in to change notification settings - Fork 977
[crypto] Prepare for alert management #29618
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
Open
siemen11
wants to merge
6
commits into
lowRISC:earlgrey_1.0.0
Choose a base branch
from
siemen11:cryptolib_config
base: earlgrey_1.0.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
66bdc81
[crypto/alert] Add functions to read/init alerts
siemen11 56fe455
[crypto] Rename security_config to config
siemen11 fd7418f
[crypto/config] Change to otcrypto_status_t
siemen11 d4e918a
[crypto/config] Add otcrypto_init
siemen11 8f5b773
[crypto/config] Add an exit function
siemen11 1ff72a7
[crypto] Implement otcrypto_eval_exit
siemen11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| // Copyright lowRISC contributors (OpenTitan project). | ||
| // Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #include "sw/device/lib/crypto/drivers/alert.h" | ||
|
|
||
| #include "sw/device/lib/base/abs_mmio.h" | ||
| #include "sw/device/lib/base/bitfield.h" | ||
| #include "sw/device/lib/base/hardened.h" | ||
| #include "sw/device/lib/base/macros.h" | ||
| #include "sw/device/lib/crypto/impl/status.h" | ||
|
|
||
| #include "alert_handler_regs.h" // Generated | ||
| #include "hw/top_earlgrey/sw/autogen/top_earlgrey.h" | ||
| #include "sensor_ctrl_regs.h" // Generated. | ||
|
|
||
| uint32_t read_alert_registers(void) { | ||
| // Read the sensors | ||
| uint32_t sensors_recov_alerts = | ||
| abs_mmio_read32(TOP_EARLGREY_SENSOR_CTRL_AON_BASE_ADDR + | ||
| SENSOR_CTRL_RECOV_ALERT_REG_OFFSET); | ||
| uint32_t sensors_fatal_alerts = | ||
| abs_mmio_read32(TOP_EARLGREY_SENSOR_CTRL_AON_BASE_ADDR + | ||
| SENSOR_CTRL_FATAL_ALERT_REG_OFFSET); | ||
| uint32_t combined_alerts = sensors_recov_alerts | sensors_fatal_alerts; | ||
|
|
||
| // Read out the alerts | ||
| for (uint32_t alert = 0; alert < ALERT_HANDLER_PARAM_N_ALERTS; alert++) { | ||
| uint32_t cause = abs_mmio_read32(TOP_EARLGREY_ALERT_HANDLER_BASE_ADDR + | ||
| (alert * sizeof(uint32_t)) + | ||
| ALERT_HANDLER_ALERT_CAUSE_0_REG_OFFSET); | ||
| combined_alerts |= cause; | ||
| } | ||
| // Read out the local alerts | ||
| for (uint32_t local_alert = 0; local_alert < ALERT_HANDLER_PARAM_N_LOC_ALERT; | ||
| local_alert++) { | ||
| uint32_t local_cause = | ||
| abs_mmio_read32(TOP_EARLGREY_ALERT_HANDLER_BASE_ADDR + | ||
| (local_alert * sizeof(uint32_t)) + | ||
| ALERT_HANDLER_LOC_ALERT_CAUSE_0_REG_OFFSET); | ||
| combined_alerts |= local_cause; | ||
| } | ||
| return combined_alerts; | ||
| } | ||
|
|
||
| status_t init_alert_registers(void) { | ||
| // Clear the sensors. | ||
| abs_mmio_write32(TOP_EARLGREY_SENSOR_CTRL_AON_BASE_ADDR + | ||
| SENSOR_CTRL_RECOV_ALERT_REG_OFFSET, | ||
| SENSOR_CTRL_RECOV_ALERT_REG_RESVAL); | ||
| abs_mmio_write32(TOP_EARLGREY_SENSOR_CTRL_AON_BASE_ADDR + | ||
| SENSOR_CTRL_FATAL_ALERT_REG_OFFSET, | ||
| SENSOR_CTRL_FATAL_ALERT_REG_RESVAL); | ||
| abs_mmio_write32(TOP_EARLGREY_SENSOR_CTRL_AON_BASE_ADDR + | ||
| SENSOR_CTRL_ALERT_TEST_REG_OFFSET, | ||
| SENSOR_CTRL_ALERT_TEST_REG_RESVAL); | ||
| abs_mmio_write32(TOP_EARLGREY_SENSOR_CTRL_AON_BASE_ADDR + | ||
| SENSOR_CTRL_ALERT_TRIG_REG_OFFSET, | ||
| SENSOR_CTRL_ALERT_TRIG_REG_RESVAL); | ||
| abs_mmio_write32(TOP_EARLGREY_SENSOR_CTRL_AON_BASE_ADDR + | ||
| SENSOR_CTRL_INTR_STATE_REG_OFFSET, | ||
| SENSOR_CTRL_INTR_STATE_REG_RESVAL); | ||
|
|
||
| // Clear the alerts. | ||
| for (uint32_t alert = 0; alert < ALERT_HANDLER_PARAM_N_ALERTS; alert++) { | ||
| abs_mmio_write32(TOP_EARLGREY_ALERT_HANDLER_BASE_ADDR + | ||
| (alert * sizeof(uint32_t)) + | ||
| ALERT_HANDLER_ALERT_CAUSE_0_REG_OFFSET, | ||
| 0x1); | ||
| } | ||
|
|
||
| // Clear the local alerts. | ||
| for (uint32_t local_alert = 0; local_alert < ALERT_HANDLER_PARAM_N_LOC_ALERT; | ||
| local_alert++) { | ||
| abs_mmio_write32(TOP_EARLGREY_ALERT_HANDLER_BASE_ADDR + | ||
| (local_alert * sizeof(uint32_t)) + | ||
| ALERT_HANDLER_LOC_ALERT_CAUSE_0_REG_OFFSET, | ||
| 0x1); | ||
| } | ||
|
|
||
| abs_mmio_write32(TOP_EARLGREY_ALERT_HANDLER_BASE_ADDR + | ||
| ALERT_HANDLER_INTR_STATE_REG_OFFSET, | ||
| 0xffffffff); | ||
| return OTCRYPTO_OK; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Copyright lowRISC contributors (OpenTitan project). | ||
| // Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #ifndef OPENTITAN_SW_DEVICE_LIB_CRYPTO_DRIVERS_ALERT_H_ | ||
| #define OPENTITAN_SW_DEVICE_LIB_CRYPTO_DRIVERS_ALERT_H_ | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| #include "sw/device/lib/crypto/include/datatypes.h" | ||
|
|
||
| /** | ||
| * Read the alert, the sensors, and the local alert registers. | ||
| * | ||
| * @return The OR of the alerts, sensors, and local alerts. | ||
| * Zero means no alerts were triggered. | ||
| */ | ||
| OT_WARN_UNUSED_RESULT | ||
| uint32_t read_alert_registers(void); | ||
|
|
||
| /** | ||
| * Clear the alert, the sensors, and the local alert registers. | ||
| * | ||
| * @return OK when the alerts are cleared. | ||
| */ | ||
| OT_WARN_UNUSED_RESULT | ||
| status_t init_alert_registers(void); | ||
|
|
||
| #endif // OPENTITAN_SW_DEVICE_LIB_CRYPTO_DRIVERS_ALERT_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Copyright lowRISC contributors (OpenTitan project). | ||
| // Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #include "sw/device/lib/crypto/drivers/alert.h" | ||
|
|
||
| #include "sw/device/lib/base/abs_mmio.h" | ||
| #include "sw/device/lib/base/memory.h" | ||
| #include "sw/device/lib/crypto/impl/status.h" | ||
| #include "sw/device/lib/runtime/log.h" | ||
| #include "sw/device/lib/testing/test_framework/check.h" | ||
| #include "sw/device/lib/testing/test_framework/ottf_alerts.h" | ||
| #include "sw/device/lib/testing/test_framework/ottf_main.h" | ||
|
|
||
| static status_t run_register_test(void) { | ||
| // Clear the alerts. | ||
| CHECK_STATUS_OK(init_alert_registers()); | ||
| // Read the alerts, expect there to be none. | ||
| CHECK(read_alert_registers() == 0); | ||
|
|
||
| return OTCRYPTO_OK; | ||
| } | ||
|
|
||
| OTTF_DEFINE_TEST_CONFIG(); | ||
|
|
||
| bool test_main(void) { | ||
| CHECK_STATUS_OK(run_register_test()); | ||
|
|
||
| return true; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.