source: rtems/cpukit/score/cpu/nios2/nios2-mpu-add-region.c @ 2afb22b

5
Last change on this file since 2afb22b was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2 * Copyright (c) 2011 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Obere Lagerstr. 30
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#ifdef HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include <rtems/score/nios2-utility.h>
20
21static bool _Nios2_MPU_Is_region_disabled(
22  const Nios2_MPU_Configuration *config,
23  uint32_t mpubase,
24  uint32_t mpuacc
25)
26{
27  bool disabled = false;
28
29  if ( config->region_uses_limit ) {
30    disabled = (mpubase & NIOS2_MPUBASE_BASE_MASK)
31      > (mpuacc & NIOS2_MPUACC_LIMIT_MASK);
32  } else {
33    disabled = (mpuacc & NIOS2_MPUACC_MASK_MASK) == 0;
34  }
35
36  return disabled;
37}
38
39int _Nios2_MPU_Get_disabled_region_index(
40  const Nios2_MPU_Configuration *config,
41  bool data,
42  int begin,
43  int end
44)
45{
46  int index = -1;
47  int count = _Nios2_MPU_Get_region_count( config, data );
48
49  if ( end < 0 || count < end ) {
50    end = count;
51  }
52
53  if ( begin >= 0 ) {
54    int i = 0;
55
56    for ( i = begin; i < end && index < 0; ++i ) {
57      uint32_t mpubase = 0;
58      uint32_t mpuacc = 0;
59
60      _Nios2_MPU_Get_region_registers( i, data, &mpubase, &mpuacc );
61
62      if ( _Nios2_MPU_Is_region_disabled( config, mpubase, mpuacc ) ) {
63        index = i;
64      }
65    }
66  }
67
68  return index;
69}
70
71bool _Nios2_MPU_Add_region(
72  const Nios2_MPU_Configuration *config,
73  const Nios2_MPU_Region_descriptor *desc,
74  bool force
75)
76{
77  bool ok = true;
78  int index = desc->index;
79  bool data = desc->data;
80  uint32_t mpubase = 0;
81  uint32_t mpuacc = 0;
82
83  if ( _Nios2_MPU_Is_valid_index( config, index, data ) ) {
84    if ( !force ) {
85      _Nios2_MPU_Get_region_registers( index, data, &mpubase, &mpuacc );
86      ok = _Nios2_MPU_Is_region_disabled( config, mpubase, mpuacc );
87    }
88
89    if ( ok ) {
90      ok = _Nios2_MPU_Setup_region_registers(
91        config,
92        desc,
93        &mpubase,
94        &mpuacc
95      );
96      if ( ok ) {
97        _Nios2_Set_ctlreg_mpubase(mpubase);
98        _Nios2_Set_ctlreg_mpuacc(mpuacc);
99      }
100    }
101  } else {
102    ok = false;
103  }
104
105  return ok;
106}
Note: See TracBrowser for help on using the repository browser.