source: rtems/cpukit/score/cpu/nios2/nios2-mpu-add-region.c @ 255fe43

Last change on this file since 255fe43 was 255fe43, checked in by Joel Sherrill <joel@…>, on 03/01/22 at 20:40:44

cpukit/: Scripted embedded brains header file clean up

Updates #4625.

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 * Copyright (c) 2011 embedded brains GmbH.  All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifdef HAVE_CONFIG_H
29#include "config.h"
30#endif
31
32#include <rtems/score/nios2-utility.h>
33
34static bool _Nios2_MPU_Is_region_disabled(
35  const Nios2_MPU_Configuration *config,
36  uint32_t mpubase,
37  uint32_t mpuacc
38)
39{
40  bool disabled = false;
41
42  if ( config->region_uses_limit ) {
43    disabled = (mpubase & NIOS2_MPUBASE_BASE_MASK)
44      > (mpuacc & NIOS2_MPUACC_LIMIT_MASK);
45  } else {
46    disabled = (mpuacc & NIOS2_MPUACC_MASK_MASK) == 0;
47  }
48
49  return disabled;
50}
51
52int _Nios2_MPU_Get_disabled_region_index(
53  const Nios2_MPU_Configuration *config,
54  bool data,
55  int begin,
56  int end
57)
58{
59  int index = -1;
60  int count = _Nios2_MPU_Get_region_count( config, data );
61
62  if ( end < 0 || count < end ) {
63    end = count;
64  }
65
66  if ( begin >= 0 ) {
67    int i = 0;
68
69    for ( i = begin; i < end && index < 0; ++i ) {
70      uint32_t mpubase = 0;
71      uint32_t mpuacc = 0;
72
73      _Nios2_MPU_Get_region_registers( i, data, &mpubase, &mpuacc );
74
75      if ( _Nios2_MPU_Is_region_disabled( config, mpubase, mpuacc ) ) {
76        index = i;
77      }
78    }
79  }
80
81  return index;
82}
83
84bool _Nios2_MPU_Add_region(
85  const Nios2_MPU_Configuration *config,
86  const Nios2_MPU_Region_descriptor *desc,
87  bool force
88)
89{
90  bool ok = true;
91  int index = desc->index;
92  bool data = desc->data;
93  uint32_t mpubase = 0;
94  uint32_t mpuacc = 0;
95
96  if ( _Nios2_MPU_Is_valid_index( config, index, data ) ) {
97    if ( !force ) {
98      _Nios2_MPU_Get_region_registers( index, data, &mpubase, &mpuacc );
99      ok = _Nios2_MPU_Is_region_disabled( config, mpubase, mpuacc );
100    }
101
102    if ( ok ) {
103      ok = _Nios2_MPU_Setup_region_registers(
104        config,
105        desc,
106        &mpubase,
107        &mpuacc
108      );
109      if ( ok ) {
110        _Nios2_Set_ctlreg_mpubase(mpubase);
111        _Nios2_Set_ctlreg_mpuacc(mpuacc);
112      }
113    }
114  } else {
115    ok = false;
116  }
117
118  return ok;
119}
Note: See TracBrowser for help on using the repository browser.