Skip to content

Commit

Permalink
risc-v/mpfs: ddr: lock segmentation registers
Browse files Browse the repository at this point in the history
Set the LOCKED bit when the final ddr segmentatition is
in place. Otherwise the system is prone to potential
security issues if the config is altered later. Once the
LOCKED bit is set, the register may no longer be changed.

Signed-off-by: Eero Nurkkala <[email protected]>
  • Loading branch information
eenurkka committed Dec 19, 2023
1 parent 71764e1 commit 0c5fb78
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion arch/risc-v/src/mpfs/mpfs_ddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,8 @@ static int mpfs_ddr_pll_lock_scb(void)
#define INIT_SETTING_SEG1_6 0x00000000
#define INIT_SETTING_SEG1_7 0x00000000

#define SEG_LOCKED (1 << 31)

/****************************************************************************
* Name: mpfs_setup_ddr_segments
*
Expand Down Expand Up @@ -755,30 +757,43 @@ void mpfs_setup_ddr_segments(enum seg_setup_e option)
}
else
{
/* This is the final configuration that cannot be changed after being
* locked.
*/

/* Segment 0 */

val_l = LIBERO_SETTING_SEG0_0 & 0x7fff;
val_h = LIBERO_SETTING_SEG0_1 & 0x7fff;

val_l |= SEG_LOCKED;
val_h |= SEG_LOCKED;

putreg64((((uint64_t)val_h) << 32) | val_l, MPFS_MPUCFG_SEG0_REG0);

/* Segment 1 */

val_l = LIBERO_SETTING_SEG1_2 & 0x7fff;
val_h = LIBERO_SETTING_SEG1_3 & 0x7fff;

val_l |= SEG_LOCKED;
val_h |= SEG_LOCKED;

putreg64((((uint64_t)val_h) << 32) | val_l, MPFS_MPUCFG_SEG1_REG1);

val_l = LIBERO_SETTING_SEG1_4 & 0x7fff;
val_h = LIBERO_SETTING_SEG1_5 & 0x7fff;

val_l |= SEG_LOCKED;
val_h |= SEG_LOCKED;

putreg64((((uint64_t)val_h) << 32) | val_l, MPFS_MPUCFG_SEG1_REG2);
}

/* Disable ddr blocker: cleared at reset. When written to '1' disables
* the blocker function allowing the L2 cache controller to access the
* DDRC. Once written to '1' the register cannot be written to 0, only
* an devie reset will clear the register.
* an device reset will clear the register.
*/

putreg64((((uint64_t)0x01) << 32) , MPFS_MPUCFG_SEG0_REG3);
Expand Down

0 comments on commit 0c5fb78

Please sign in to comment.