source: rtems/cpukit/score/cpu/nios2/rtems/score/nios2-utility.h @ 43e0599

4.115
Last change on this file since 43e0599 was 43e0599, checked in by Mathew Kallada <matkallada@…>, on 12/02/12 at 21:23:57

score misc: Clean up Doxygen #13 (GCI 2012)

This patch is a task from GCI 2012 which improves the Doxygen
comments in the RTEMS source.

http://www.google-melange.com/gci/task/view/google/gci2012/8013205

  • Property mode set to 100644
File size: 14.0 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.com/license/LICENSE.
13 */
14
15#ifndef _RTEMS_SCORE_NIOS2_UTILITY_H
16#define _RTEMS_SCORE_NIOS2_UTILITY_H
17
18#define NIOS2_CTLREG_INDEX_STATUS 0
19#define NIOS2_CTLREG_INDEX_ESTATUS 1
20#define NIOS2_CTLREG_INDEX_BSTATUS 2
21#define NIOS2_CTLREG_INDEX_IENABLE 3
22#define NIOS2_CTLREG_INDEX_IPENDING 4
23#define NIOS2_CTLREG_INDEX_CPUID 5
24#define NIOS2_CTLREG_INDEX_EXCEPTION 7
25#define NIOS2_CTLREG_INDEX_PTEADDR 8
26#define NIOS2_CTLREG_INDEX_TLBACC 9
27#define NIOS2_CTLREG_INDEX_TLBMISC 10
28#define NIOS2_CTLREG_INDEX_BADADDR 12
29#define NIOS2_CTLREG_INDEX_CONFIG 13
30#define NIOS2_CTLREG_INDEX_MPUBASE 14
31#define NIOS2_CTLREG_INDEX_MPUACC 15
32
33#define NIOS2_CONTEXT_OFFSET_R16 0
34#define NIOS2_CONTEXT_OFFSET_R17 4
35#define NIOS2_CONTEXT_OFFSET_R18 8
36#define NIOS2_CONTEXT_OFFSET_R19 12
37#define NIOS2_CONTEXT_OFFSET_R20 16
38#define NIOS2_CONTEXT_OFFSET_R21 20
39#define NIOS2_CONTEXT_OFFSET_R22 24
40#define NIOS2_CONTEXT_OFFSET_R23 28
41#define NIOS2_CONTEXT_OFFSET_FP 32
42#define NIOS2_CONTEXT_OFFSET_STATUS 36
43#define NIOS2_CONTEXT_OFFSET_SP 40
44#define NIOS2_CONTEXT_OFFSET_RA 44
45#define NIOS2_CONTEXT_OFFSET_THREAD_DISPATCH_DISABLED 48
46#define NIOS2_CONTEXT_OFFSET_STACK_MPUBASE 52
47#define NIOS2_CONTEXT_OFFSET_STACK_MPUACC 56
48
49#define NIOS2_ISR_STATUS_MASK_IIC 0xfffffffe
50#define NIOS2_ISR_STATUS_BITS_IIC 0x00000000
51
52#define NIOS2_ISR_STATUS_MASK_EIC_IL 0xfffffc0f
53#define NIOS2_ISR_STATUS_BITS_EIC_IL 0x000003f0
54
55#define NIOS2_ISR_STATUS_MASK_EIC_RSIE 0xf7ffffff
56#define NIOS2_ISR_STATUS_BITS_EIC_RSIE 0x00000000
57
58#define NIOS2_STATUS_RSIE (1 << 23)
59#define NIOS2_STATUS_NMI (1 << 22)
60#define NIOS2_STATUS_PRS_OFFSET 16
61#define NIOS2_STATUS_PRS_MASK (0x3f << NIOS2_STATUS_PRS_OFFSET)
62#define NIOS2_STATUS_CRS_OFFSET 10
63#define NIOS2_STATUS_CRS_MASK (0x3f << NIOS2_STATUS_CRS_OFFSET)
64#define NIOS2_STATUS_IL_OFFSET 4
65#define NIOS2_STATUS_IL_MASK (0x3f << NIOS2_STATUS_IL_OFFSET)
66#define NIOS2_STATUS_IH (1 << 3)
67#define NIOS2_STATUS_EH (1 << 2)
68#define NIOS2_STATUS_U (1 << 1)
69#define NIOS2_STATUS_PIE (1 << 0)
70
71#define NIOS2_EXCEPTION_CAUSE_OFFSET 2
72#define NIOS2_EXCEPTION_CAUSE_MASK (0x1f << NIOS2_EXCEPTION_CAUSE_OFFSET)
73
74#define NIOS2_PTEADDR_PTBASE_OFFSET 22
75#define NIOS2_PTEADDR_PTBASE_MASK (0x3ff << NIOS2_PTEADDR_PTBASE_OFFSET)
76#define NIOS2_PTEADDR_VPN_OFFSET 2
77#define NIOS2_PTEADDR_VPN_MASK (0xfffff << NIOS2_PTEADDR_VPN_OFFSET)
78
79#define NIOS2_TLBACC_IG_OFFSET 25
80#define NIOS2_TLBACC_IG_MASK (0x3ff << NIOS2_TLBACC_IG_OFFSET)
81#define NIOS2_TLBACC_C (1 << 24)
82#define NIOS2_TLBACC_R (1 << 23)
83#define NIOS2_TLBACC_W (1 << 22)
84#define NIOS2_TLBACC_X (1 << 21)
85#define NIOS2_TLBACC_G (1 << 20)
86#define NIOS2_TLBACC_PFN_OFFSET 2
87#define NIOS2_TLBACC_PFN_MASK (0xfffff << NIOS2_TLBACC_PFN_OFFSET)
88
89#define NIOS2_TLBMISC_WAY_OFFSET 20
90#define NIOS2_TLBMISC_WAY_MASK (0xf << NIOS2_TLBMISC_WAY_OFFSET)
91#define NIOS2_TLBMISC_RD (1 << 19)
92#define NIOS2_TLBMISC_WE (1 << 18)
93#define NIOS2_TLBMISC_PID_OFFSET 5
94#define NIOS2_TLBMISC_PID_MASK (0x3fff << NIOS2_TLBMISC_PID_OFFSET)
95#define NIOS2_TLBMISC_DBL (1 << 3)
96#define NIOS2_TLBMISC_BAD (1 << 2)
97#define NIOS2_TLBMISC_PERM (1 << 1)
98#define NIOS2_TLBMISC_D (1 << 0)
99
100#define NIOS2_CONFIG_ANI (1 << 1)
101#define NIOS2_CONFIG_PE (1 << 0)
102
103#define NIOS2_MPUBASE_BASE_OFFSET 6
104#define NIOS2_MPUBASE_BASE_MASK (0x1ffffff << NIOS2_MPUBASE_BASE_OFFSET)
105#define NIOS2_MPUBASE_INDEX_OFFSET 1
106
107/* Avoid redefines with Altera HAL */
108#define NIOS2_MPUBASE_INDEX_MASK (0x0000003e)
109
110#define NIOS2_MPUBASE_D (1 << 0)
111
112#define NIOS2_MPUACC_MASK_OFFSET 6
113
114/* Avoid redefines with Altera HAL */
115#define NIOS2_MPUACC_MASK_MASK (0x7fffffc0)
116
117#define NIOS2_MPUACC_LIMIT_OFFSET 6
118
119/* Avoid redefines with Altera HAL */
120#define NIOS2_MPUACC_LIMIT_MASK (0xffffffc0)
121
122#define NIOS2_MPUACC_C (1 << 5)
123#define NIOS2_MPUACC_PERM_OFFSET 2
124
125/* Avoid redefines with Altera HAL */
126#define NIOS2_MPUACC_PERM_MASK (0x0000001c)
127
128#define NIOS2_MPUACC_RD (1 << 1)
129#define NIOS2_MPUACC_WR (1 << 0)
130
131#ifndef ASM
132
133#include <stddef.h>
134#include <stdint.h>
135#include <stdbool.h>
136
137#ifdef __cplusplus
138extern "C" {
139#endif /* __cplusplus */
140
141/**
142 * @brief Nios II specific thread dispatch disabled indicator.
143 *
144 * This global variable is used by the interrupt dispatch support for the
145 * external interrupt controller (EIC) with shadow registers.  This makes it
146 * possible to do the thread dispatch after an interrupt without disabled
147 * interrupts and thus probably reduce the maximum interrupt latency.  Its
148 * purpose is to prevent unbounded stack usage of the interrupted thread.
149 */
150extern uint32_t _Nios2_Thread_dispatch_disabled;
151
152/**
153 * @brief This global symbol specifies the status register mask used to disable
154 * interrupts.
155 *
156 * The board support package must provide a global symbol with this name to
157 * specifiy the status register mask used in _CPU_ISR_Disable().
158 */
159extern char _Nios2_ISR_Status_mask [];
160
161/**
162 * @brief This symbol specifies the status register bits used to disable
163 * interrupts.
164 *
165 * The board support package must provide a global symbol with this name to
166 * specifiy the status register bits used in _CPU_ISR_Disable().
167 */
168extern char _Nios2_ISR_Status_bits [];
169
170static inline void _Nios2_Flush_pipeline( void )
171{
172  __asm__ volatile ("flushp");
173}
174
175static inline uint32_t _Nios2_Get_ctlreg_status( void )
176{
177  return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_STATUS );
178}
179
180static inline void _Nios2_Set_ctlreg_status( uint32_t value )
181{
182  __builtin_wrctl( NIOS2_CTLREG_INDEX_STATUS, (int) value );
183}
184
185static inline uint32_t _Nios2_Get_ctlreg_estatus( void )
186{
187  return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_ESTATUS );
188}
189
190static inline void _Nios2_Set_ctlreg_estatus( uint32_t value )
191{
192  __builtin_wrctl( NIOS2_CTLREG_INDEX_ESTATUS, (int) value );
193}
194
195static inline uint32_t _Nios2_Get_ctlreg_bstatus( void )
196{
197  return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_BSTATUS );
198}
199
200static inline void _Nios2_Set_ctlreg_bstatus( uint32_t value )
201{
202  __builtin_wrctl( NIOS2_CTLREG_INDEX_BSTATUS, (int) value );
203}
204
205static inline uint32_t _Nios2_Get_ctlreg_ienable( void )
206{
207  return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_IENABLE );
208}
209
210static inline void _Nios2_Set_ctlreg_ienable( uint32_t value )
211{
212  __builtin_wrctl( NIOS2_CTLREG_INDEX_IENABLE, (int) value );
213}
214
215static inline uint32_t _Nios2_Get_ctlreg_ipending( void )
216{
217  return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_IPENDING );
218}
219
220static inline uint32_t _Nios2_Get_ctlreg_cpuid( void )
221{
222  return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_CPUID );
223}
224
225static inline uint32_t _Nios2_Get_ctlreg_exception( void )
226{
227  return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_EXCEPTION );
228}
229
230static inline uint32_t _Nios2_Get_ctlreg_pteaddr( void )
231{
232  return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_PTEADDR );
233}
234
235static inline void _Nios2_Set_ctlreg_pteaddr( uint32_t value )
236{
237  __builtin_wrctl( NIOS2_CTLREG_INDEX_PTEADDR, (int) value );
238}
239
240static inline uint32_t _Nios2_Get_ctlreg_tlbacc( void )
241{
242  return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_TLBACC );
243}
244
245static inline void _Nios2_Set_ctlreg_tlbacc( uint32_t value )
246{
247  __builtin_wrctl( NIOS2_CTLREG_INDEX_TLBACC, (int) value );
248}
249
250static inline uint32_t _Nios2_Get_ctlreg_tlbmisc( void )
251{
252  return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_TLBMISC );
253}
254
255static inline void _Nios2_Set_ctlreg_tlbmisc( uint32_t value )
256{
257  __builtin_wrctl( NIOS2_CTLREG_INDEX_TLBMISC, (int) value );
258}
259
260static inline uint32_t _Nios2_Get_ctlreg_badaddr( void )
261{
262  return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_BADADDR );
263}
264
265static inline uint32_t _Nios2_Get_ctlreg_config( void )
266{
267  return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_CONFIG );
268}
269
270static inline void _Nios2_Set_ctlreg_config( uint32_t value )
271{
272  __builtin_wrctl( NIOS2_CTLREG_INDEX_CONFIG, (int) value );
273}
274
275static inline uint32_t _Nios2_Get_ctlreg_mpubase( void )
276{
277  return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_MPUBASE );
278}
279
280static inline void _Nios2_Set_ctlreg_mpubase( uint32_t value )
281{
282  __builtin_wrctl( NIOS2_CTLREG_INDEX_MPUBASE, (int) value );
283}
284
285static inline uint32_t _Nios2_Get_ctlreg_mpuacc( void )
286{
287  return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_MPUACC );
288}
289
290static inline void _Nios2_Set_ctlreg_mpuacc( uint32_t value )
291{
292  __builtin_wrctl( NIOS2_CTLREG_INDEX_MPUACC, (int) value );
293}
294
295static inline uint32_t _Nios2_ISR_Get_status_mask( void )
296{
297  return (uint32_t) &_Nios2_ISR_Status_mask [0];
298}
299
300static inline uint32_t _Nios2_ISR_Get_status_bits( void )
301{
302  return (uint32_t) &_Nios2_ISR_Status_bits [0];
303}
304
305static inline bool _Nios2_Has_internal_interrupt_controller( void )
306{
307  return _Nios2_ISR_Get_status_mask() == NIOS2_ISR_STATUS_MASK_IIC;
308}
309
310/*
311 *  @brief Nios2 ISR Set level
312 *
313 */
314uint32_t _Nios2_ISR_Set_level( uint32_t new_level, uint32_t status );
315
316typedef struct {
317  int data_address_width;
318  int instruction_address_width;
319  int data_region_size_log2;
320  int instruction_region_size_log2;
321  int data_region_count;
322  int instruction_region_count;
323  int data_index_for_stack_protection;
324  bool region_uses_limit;
325  bool enable_data_cache_for_stack;
326} Nios2_MPU_Configuration;
327
328void _Nios2_MPU_Set_configuration( const Nios2_MPU_Configuration *config );
329
330const Nios2_MPU_Configuration *_Nios2_MPU_Get_configuration( void );
331
332typedef enum {
333  NIOS2_MPU_INST_PERM_SVR_NONE_USER_NONE = 0,
334  NIOS2_MPU_INST_PERM_SVR_EXECUTE_USER_NONE,
335  NIOS2_MPU_INST_PERM_SVR_EXECUTE_USER_EXECUTE,
336  NIOS2_MPU_DATA_PERM_SVR_NONE_USER_NONE = 0,
337  NIOS2_MPU_DATA_PERM_SVR_READONLY_USER_NONE,
338  NIOS2_MPU_DATA_PERM_SVR_READONLY_USER_READONLY,
339  NIOS2_MPU_DATA_PERM_SVR_READWRITE_USER_NONE = 4,
340  NIOS2_MPU_DATA_PERM_SVR_READWRITE_USER_READONLY,
341  NIOS2_MPU_DATA_PERM_SVR_READWRITE_USER_READWRITE
342} Nios2_MPU_Region_permissions;
343
344typedef struct {
345  int index;
346  const void *base;
347  const void *end;
348  Nios2_MPU_Region_permissions perm;
349  bool data;
350  bool cacheable;
351  bool read;
352  bool write;
353} Nios2_MPU_Region_descriptor;
354
355#define NIOS2_MPU_REGION_DESC_INST( index, base, end ) \
356  { \
357    (index), (base), (end), NIOS2_MPU_INST_PERM_SVR_EXECUTE_USER_NONE, \
358    false, false, false, true \
359  }
360
361#define NIOS2_MPU_REGION_DESC_DATA_RO( index, base, end ) \
362  { \
363    (index), (base), (end), NIOS2_MPU_DATA_PERM_SVR_READONLY_USER_NONE, \
364    true, true, false, true \
365  }
366
367#define NIOS2_MPU_REGION_DESC_DATA_RW( index, base, end ) \
368  { \
369    (index), (base), (end), NIOS2_MPU_DATA_PERM_SVR_READWRITE_USER_NONE, \
370    true, true, false, true \
371  }
372
373#define NIOS2_MPU_REGION_DESC_DATA_IO( index, base, end ) \
374  { \
375    (index), (base), (end), NIOS2_MPU_DATA_PERM_SVR_READWRITE_USER_NONE, \
376    true, false, false, true \
377  }
378
379static inline int _Nios2_MPU_Get_region_count(
380  const Nios2_MPU_Configuration *config,
381  bool data
382)
383{
384  return data ?
385    config->data_region_count
386      : config->instruction_region_count;
387}
388
389static inline bool _Nios2_MPU_Is_valid_index(
390  const Nios2_MPU_Configuration *config,
391  int index,
392  bool data
393)
394{
395  return 0 <= index
396    && index < _Nios2_MPU_Get_region_count( config, data );
397}
398
399bool _Nios2_MPU_Setup_region_registers(
400  const Nios2_MPU_Configuration *config,
401  const Nios2_MPU_Region_descriptor *desc,
402  uint32_t *mpubase,
403  uint32_t *mpuacc
404);
405
406/**
407 * @brief Nios2 MPU Get region descriptor.
408 *
409 */
410bool _Nios2_MPU_Get_region_descriptor(
411  const Nios2_MPU_Configuration *config,
412  int index,
413  bool data,
414  Nios2_MPU_Region_descriptor *desc
415);
416
417/**
418 * @brief Seaches the region table part for a disabled region.
419 *
420 * The table will be searched between indices @a begin and @a end.  The @a end
421 * index is not part of the search range.  If @a end is negative, then the
422 * region count will be used.  Thus a @a begin of 0 and a @a end of -1 will
423 * specifiy the complete table.
424 *
425 * @retval -1 No disabled region is available.
426 * @retval other Index of disabled region.
427 */
428int _Nios2_MPU_Get_disabled_region_index(
429  const Nios2_MPU_Configuration *config,
430  bool data,
431  int begin,
432  int end
433);
434
435/**
436 * @brief Adds a region according to region descriptor @a desc.
437 *
438 * If @a force is true, then an enabled region will be overwritten.
439 *
440 * @retval true Successful operation.
441 * @retval false Invalid region descriptor or region already in use.
442 */
443bool _Nios2_MPU_Add_region(
444  const Nios2_MPU_Configuration *config,
445  const Nios2_MPU_Region_descriptor *desc,
446  bool force
447);
448
449static inline void _Nios2_MPU_Get_region_registers(
450  int index,
451  bool data,
452  uint32_t *mpubase,
453  uint32_t *mpuacc
454)
455{
456  uint32_t base = (uint32_t)
457    (((index << NIOS2_MPUBASE_INDEX_OFFSET) & NIOS2_MPUBASE_INDEX_MASK)
458      | (data ? NIOS2_MPUBASE_D : 0));
459
460  _Nios2_Set_ctlreg_mpubase( base );
461  _Nios2_Set_ctlreg_mpuacc( NIOS2_MPUACC_RD );
462  _Nios2_Flush_pipeline();
463  *mpubase = _Nios2_Get_ctlreg_mpubase() | base;
464  *mpuacc = _Nios2_Get_ctlreg_mpuacc();
465}
466
467static inline void _Nios2_MPU_Set_region_registers(
468  uint32_t mpubase,
469  uint32_t mpuacc
470)
471{
472  _Nios2_Set_ctlreg_mpubase( mpubase );
473  _Nios2_Set_ctlreg_mpuacc( mpuacc );
474  _Nios2_Flush_pipeline();
475}
476
477static inline void _Nios2_MPU_Enable( void )
478{
479  uint32_t config = _Nios2_Get_ctlreg_config();
480
481  _Nios2_Set_ctlreg_config( config | NIOS2_CONFIG_PE );
482}
483
484static inline uint32_t _Nios2_MPU_Disable( void )
485{
486  uint32_t config = _Nios2_Get_ctlreg_config();
487  uint32_t config_pe = NIOS2_CONFIG_PE;
488
489  _Nios2_Set_ctlreg_config( config & ~config_pe );
490
491  return config;
492}
493
494static inline void _Nios2_MPU_Restore( uint32_t config )
495{
496  _Nios2_Set_ctlreg_config( config );
497}
498
499/*
500 *  @brief Nios2 MPU Disable Protected
501 *
502 */
503uint32_t _Nios2_MPU_Disable_protected( void );
504
505void _Nios2_MPU_Reset( const Nios2_MPU_Configuration *config );
506
507#ifdef __cplusplus
508}
509#endif /* __cplusplus */
510
511#else /* ASM */
512
513        .macro  NIOS2_ASM_DISABLE_INTERRUPTS new_status, current_status
514        movhi   \new_status, %hiadj(_Nios2_ISR_Status_mask)
515        addi    \new_status, \new_status, %lo(_Nios2_ISR_Status_mask)
516        and     \new_status, \current_status, \new_status
517        ori     \new_status, \new_status, %lo(_Nios2_ISR_Status_bits)
518        wrctl   status, \new_status
519        .endm
520
521#endif /* ASM */
522
523#endif /* _RTEMS_SCORE_NIOS2_UTILITY_H */
Note: See TracBrowser for help on using the repository browser.