mpu.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
  4. * Author(s): Vikas Manocha, <vikas.manocha@st.com> for STMicroelectronics.
  5. */
  6. #include <linux/bitops.h>
  7. #include <asm/armv7m.h>
  8. #include <asm/armv7_mpu.h>
  9. #include <asm/io.h>
  10. #define V7M_MPU_CTRL_ENABLE BIT(0)
  11. #define V7M_MPU_CTRL_DISABLE (0 << 0)
  12. #define V7M_MPU_CTRL_HFNMIENA BIT(1)
  13. #define V7M_MPU_CTRL_PRIVDEFENA BIT(2)
  14. #define VALID_REGION BIT(4)
  15. void disable_mpu(void)
  16. {
  17. writel(0, &V7M_MPU->ctrl);
  18. }
  19. void enable_mpu(void)
  20. {
  21. writel(V7M_MPU_CTRL_ENABLE | V7M_MPU_CTRL_PRIVDEFENA, &V7M_MPU->ctrl);
  22. /* Make sure new mpu config is effective for next memory access */
  23. dsb();
  24. isb(); /* Make sure instruction stream sees it */
  25. }
  26. void mpu_config(struct mpu_region_config *reg_config)
  27. {
  28. uint32_t attr;
  29. attr = get_attr_encoding(reg_config->mr_attr);
  30. writel(reg_config->start_addr | VALID_REGION | reg_config->region_no,
  31. &V7M_MPU->rbar);
  32. writel(reg_config->xn << XN_SHIFT | reg_config->ap << AP_SHIFT | attr
  33. | reg_config->reg_size << REGION_SIZE_SHIFT | ENABLE_REGION
  34. , &V7M_MPU->rasr);
  35. }