1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
4 * Author(s): Vikas Manocha, <vikas.manocha@st.com> for STMicroelectronics.
7 #include <linux/bitops.h>
8 #include <asm/armv7m.h>
9 #include <asm/armv7_mpu.h>
12 #define V7M_MPU_CTRL_ENABLE BIT(0)
13 #define V7M_MPU_CTRL_DISABLE (0 << 0)
14 #define V7M_MPU_CTRL_HFNMIENA BIT(1)
15 #define V7M_MPU_CTRL_PRIVDEFENA BIT(2)
16 #define VALID_REGION BIT(4)
18 void disable_mpu(void)
20 writel(0, &V7M_MPU->ctrl);
25 writel(V7M_MPU_CTRL_ENABLE | V7M_MPU_CTRL_PRIVDEFENA, &V7M_MPU->ctrl);
27 /* Make sure new mpu config is effective for next memory access */
29 isb(); /* Make sure instruction stream sees it */
32 void mpu_config(struct mpu_region_config *reg_config)
36 attr = get_attr_encoding(reg_config->mr_attr);
38 writel(reg_config->start_addr | VALID_REGION | reg_config->region_no,
41 writel(reg_config->xn << XN_SHIFT | reg_config->ap << AP_SHIFT | attr
42 | reg_config->reg_size << REGION_SIZE_SHIFT | ENABLE_REGION