Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:04

0001 /**
0002  * @file
0003  *
0004  * @ingroup lpc32xx_mmu
0005  *
0006  * @brief MMU support implementation.
0007  */
0008 
0009 /*
0010  * Copyright (c) 2010-2011 embedded brains GmbH.  All rights reserved.
0011  *
0012  *  embedded brains GmbH
0013  *  Obere Lagerstr. 30
0014  *  82178 Puchheim
0015  *  Germany
0016  *  <rtems@embedded-brains.de>
0017  *
0018  * The license and distribution terms for this file may be
0019  * found in the file LICENSE in this distribution or at
0020  * http://www.rtems.com/license/LICENSE.
0021  */
0022 
0023 #include <bsp/mmu.h>
0024 
0025 static uint32_t disable_mmu(void)
0026 {
0027   uint32_t ctrl = 0;
0028 
0029   arm_cp15_data_cache_test_and_clean_and_invalidate();
0030 
0031   ctrl = arm_cp15_get_control();
0032   arm_cp15_set_control(ctrl & ~ARM_CP15_CTRL_M);
0033 
0034   arm_cp15_tlb_invalidate();
0035 
0036   return ctrl;
0037 }
0038 
0039 static void restore_mmu_control(uint32_t ctrl)
0040 {
0041   arm_cp15_set_control(ctrl);
0042 }
0043 
0044 static uint32_t set_translation_table_entries(
0045   const void *begin,
0046   const void *end,
0047   uint32_t section_flags
0048 )
0049 {
0050   uint32_t *ttb = arm_cp15_get_translation_table_base();
0051   uint32_t i = ARM_MMU_SECT_GET_INDEX(begin);
0052   uint32_t iend = ARM_MMU_SECT_GET_INDEX(ARM_MMU_SECT_MVA_ALIGN_UP(end));
0053   uint32_t ctrl = disable_mmu();
0054   uint32_t section_flags_of_first_entry = ttb [i];
0055 
0056   while (i < iend) {
0057     ttb [i] = (i << ARM_MMU_SECT_BASE_SHIFT) | section_flags;
0058     ++i;
0059   }
0060 
0061   restore_mmu_control(ctrl);
0062 
0063   return section_flags_of_first_entry;
0064 }
0065 
0066 uint32_t lpc32xx_set_translation_table_entries(
0067   const void *begin,
0068   const void *end,
0069   uint32_t section_flags
0070 )
0071 {
0072   rtems_interrupt_level level;
0073   uint32_t section_flags_of_first_entry = 0;
0074 
0075   rtems_interrupt_disable(level);
0076   section_flags_of_first_entry =
0077     set_translation_table_entries(begin, end, section_flags);
0078   rtems_interrupt_enable(level);
0079 
0080   return section_flags_of_first_entry;
0081 }