Software APIs
dif_rv_dm.c
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
6 
7 #include "sw/device/lib/base/multibits.h"
8 
9 #include "rv_dm_regs.h" // Generated.
10 
11 static bool late_debug_enable_is_locked(const dif_rv_dm_t *rv_dm) {
12  uint32_t reg = mmio_region_read32(rv_dm->base_addr,
13  RV_DM_LATE_DEBUG_ENABLE_REGWEN_REG_OFFSET);
14  return !bitfield_bit32_read(
15  reg, RV_DM_LATE_DEBUG_ENABLE_REGWEN_LATE_DEBUG_ENABLE_REGWEN_BIT);
16 }
17 
19  dif_toggle_t enable) {
20  if (rv_dm == NULL || !dif_is_valid_toggle(enable)) {
21  return kDifBadArg;
22  }
23 
24  if (late_debug_enable_is_locked(rv_dm)) {
25  return kDifLocked;
26  }
27 
28  multi_bit_bool_t enable_value = kMultiBitBool32False;
29  if (enable == kDifToggleEnabled) {
30  enable_value = kMultiBitBool32True;
31  }
32 
33  mmio_region_write32(rv_dm->base_addr, RV_DM_LATE_DEBUG_ENABLE_REG_OFFSET,
34  enable_value);
35 
36  return kDifOk;
37 }
38 
40  if (rv_dm == NULL) {
41  return kDifBadArg;
42  }
43  mmio_region_write32(
44  rv_dm->base_addr, RV_DM_LATE_DEBUG_ENABLE_REGWEN_REG_OFFSET,
46  0, RV_DM_LATE_DEBUG_ENABLE_REGWEN_LATE_DEBUG_ENABLE_REGWEN_BIT,
47  false));
48  return kDifOk;
49 }
50 
52  bool *is_locked) {
53  if (rv_dm == NULL || is_locked == NULL) {
54  return kDifBadArg;
55  }
56 
57  *is_locked = late_debug_enable_is_locked(rv_dm);
58  return kDifOk;
59 }