summaryrefslogtreecommitdiff
path: root/zephyr/shim/core/cortex-m/mpu.c
blob: 8025227700a0e538839186e5c4701031d692b13c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* Copyright 2021 The ChromiumOS Authors
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include <zephyr/arch/arm/aarch32/cortex_m/cmsis.h>
#include <zephyr/arch/cpu.h>
#include <zephyr/init.h>

#include "config.h"
#include "mpu.h"

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(shim_mpu, LOG_LEVEL_ERR);

void mpu_enable(void)
{
	for (int index = 0; index < mpu_config.num_regions; index++) {
		MPU->RNR = index;
		MPU->RASR |= MPU_RASR_ENABLE_Msk;
		LOG_DBG("[%d] %08x %08x", index, MPU->RBAR, MPU->RASR);
	}
}

static int mpu_disable_fixed_regions(const struct device *dev)
{
	/* MPU is configured and enabled by the Zephyr init code, disable the
	 * fixed sections by default.
	 */
	for (int index = 0; index < mpu_config.num_regions; index++) {
		MPU->RNR = index;
		MPU->RASR &= ~MPU_RASR_ENABLE_Msk;
		LOG_DBG("[%d] %08x %08x", index, MPU->RBAR, MPU->RASR);
	}

	return 0;
}

SYS_INIT(mpu_disable_fixed_regions, PRE_KERNEL_1, 50);