blob: 81e7492f1c866e908bb0bf05e9dfedb87ef35f4f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Vikas Manocha29645ec2017-05-03 16:38:55 -07002/*
Patrice Chotard789ee0e2017-10-23 09:53:58 +02003 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
4 * Author(s): Vikas Manocha, <vikas.manocha@st.com> for STMicroelectronics.
Vikas Manocha29645ec2017-05-03 16:38:55 -07005 */
6
7#include <linux/bitops.h>
8#include <asm/armv7m.h>
Lokesh Vutla076ee452018-04-26 18:21:30 +05309#include <asm/armv7_mpu.h>
Vikas Manocha29645ec2017-05-03 16:38:55 -070010#include <asm/io.h>
11
Patrice Chotard574f4572018-02-28 17:15:00 +010012#define V7M_MPU_CTRL_ENABLE BIT(0)
Vikas Manocha29645ec2017-05-03 16:38:55 -070013#define V7M_MPU_CTRL_DISABLE (0 << 0)
Patrice Chotard574f4572018-02-28 17:15:00 +010014#define V7M_MPU_CTRL_HFNMIENA BIT(1)
15#define V7M_MPU_CTRL_PRIVDEFENA BIT(2)
16#define VALID_REGION BIT(4)
Vikas Manocha29645ec2017-05-03 16:38:55 -070017
Vikas Manocha29645ec2017-05-03 16:38:55 -070018void disable_mpu(void)
19{
20 writel(0, &V7M_MPU->ctrl);
21}
22
23void enable_mpu(void)
24{
Patrice Chotard574f4572018-02-28 17:15:00 +010025 writel(V7M_MPU_CTRL_ENABLE | V7M_MPU_CTRL_PRIVDEFENA, &V7M_MPU->ctrl);
Vikas Manocha29645ec2017-05-03 16:38:55 -070026
27 /* Make sure new mpu config is effective for next memory access */
28 dsb();
29 isb(); /* Make sure instruction stream sees it */
30}
31
32void mpu_config(struct mpu_region_config *reg_config)
33{
34 uint32_t attr;
35
Lokesh Vutla076ee452018-04-26 18:21:30 +053036 attr = get_attr_encoding(reg_config->mr_attr);
Vikas Manocha29645ec2017-05-03 16:38:55 -070037
38 writel(reg_config->start_addr | VALID_REGION | reg_config->region_no,
39 &V7M_MPU->rbar);
40
41 writel(reg_config->xn << XN_SHIFT | reg_config->ap << AP_SHIFT | attr
42 | reg_config->reg_size << REGION_SIZE_SHIFT | ENABLE_REGION
43 , &V7M_MPU->rasr);
44}