source: rtems/c/src/lib/libbsp/sparc/leon3/include/cache_.h @ 62f373fb

4.115
Last change on this file since 62f373fb was 62f373fb, checked in by Daniel Cederman <cederman@…>, on 08/11/14 at 08:02:13

bsp/sparc: Flush only instruction cache

The flush instruction on LEON flushes both the data and the instruction
cache. Flushing of just the instruction cache can be done by setting
the "flush instruction cache" bit in the cache control register.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
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#ifndef LEON3_CACHE_H
16#define LEON3_CACHE_H
17
18#include <amba.h>
19#include <leon.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25#define CPU_CACHE_SUPPORT_PROVIDES_RANGE_FUNCTIONS
26
27#define CPU_CACHE_SUPPORT_PROVIDES_CACHE_SIZE_FUNCTIONS
28
29#define CPU_INSTRUCTION_CACHE_ALIGNMENT 64
30
31#define CPU_DATA_CACHE_ALIGNMENT 64
32
33static inline volatile struct l2c_regs *get_l2c_regs(void)
34{
35  volatile struct l2c_regs *l2c = NULL;
36  struct ambapp_dev *adev;
37
38  adev = (void *) ambapp_for_each(
39    &ambapp_plb,
40    OPTIONS_ALL | OPTIONS_AHB_SLVS,
41    VENDOR_GAISLER,
42    GAISLER_L2CACHE,
43    ambapp_find_by_idx,
44    NULL
45  );
46  if (adev != NULL) {
47    l2c = (volatile struct l2c_regs *) DEV_TO_AHB(adev)->start[1];
48  }
49
50  return l2c;
51}
52
53static inline size_t get_l2_size(void)
54{
55  size_t size = 0;
56  volatile struct l2c_regs *l2c = get_l2c_regs();
57
58  if (l2c != NULL) {
59    unsigned status = l2c->status;
60    unsigned ways = (status & 0x3) + 1;
61    unsigned set_size = ((status & 0x7ff) >> 2) * 1024;
62
63    size = ways * set_size;
64  }
65
66  return size;
67}
68
69static inline size_t get_l1_size(uint32_t l1_cfg)
70{
71  uint32_t ways = ((l1_cfg >> 24) & 0x7) + 1;
72  uint32_t wsize = UINT32_C(1) << (((l1_cfg >> 20) & 0xf) + 10);
73
74  return ways * wsize;
75}
76
77static inline size_t get_max_size(size_t a, size_t b)
78{
79  return a < b ? b : a;
80}
81
82static inline size_t get_cache_size(uint32_t level, uint32_t l1_cfg)
83{
84  size_t size;
85
86  switch (level) {
87    case 0:
88      size = get_max_size(get_l1_size(l1_cfg), get_l2_size());
89      break;
90    case 1:
91      size = get_l1_size(l1_cfg);
92      break;
93    case 2:
94      size = get_l2_size();
95      break;
96    default:
97      size = 0;
98      break;
99  }
100
101  return size;
102}
103
104static inline size_t _CPU_cache_get_data_cache_size(uint32_t level)
105{
106  return get_cache_size(level, leon3_get_data_cache_config_register());
107}
108
109static inline void _CPU_cache_flush_data_range(
110  const void *d_addr,
111  size_t n_bytes
112)
113{
114  /* TODO */
115}
116
117static inline void _CPU_cache_invalidate_data_range(
118  const void *d_addr,
119  size_t n_bytes
120)
121{
122  /* TODO */
123}
124
125static inline void _CPU_cache_freeze_data(void)
126{
127  /* TODO */
128}
129
130static inline void _CPU_cache_unfreeze_data(void)
131{
132  /* TODO */
133}
134
135static inline void _CPU_cache_invalidate_entire_instruction(void)
136{
137  uint32_t cache_reg = leon3_get_cache_control_register();
138
139  cache_reg |= LEON3_REG_CACHE_CTRL_FI;
140  leon3_set_cache_control_register(cache_reg);
141}
142
143static inline void _CPU_cache_invalidate_instruction_range(
144  const void *i_addr,
145  size_t n_bytes
146)
147{
148  _CPU_cache_invalidate_entire_instruction();
149}
150
151static inline void _CPU_cache_freeze_instruction(void)
152{
153  /* TODO */
154}
155
156static inline void _CPU_cache_unfreeze_instruction(void)
157{
158  /* TODO */
159}
160
161static inline void _CPU_cache_flush_entire_data(void)
162{
163  /* TODO */
164}
165
166static inline void _CPU_cache_invalidate_entire_data(void)
167{
168  /* TODO */
169}
170
171static inline void _CPU_cache_enable_data(void)
172{
173  /* TODO */
174}
175
176static inline void _CPU_cache_disable_data(void)
177{
178  /* TODO */
179}
180
181static inline size_t _CPU_cache_get_instruction_cache_size( uint32_t level )
182{
183  return get_cache_size(level, leon3_get_inst_cache_config_register());
184}
185
186static inline void _CPU_cache_enable_instruction(void)
187{
188  /* TODO */
189}
190
191static inline void _CPU_cache_disable_instruction(void)
192{
193  /* TODO */
194}
195
196#ifdef __cplusplus
197}
198#endif /* __cplusplus */
199
200#endif /* LEON3_CACHE_H */
Note: See TracBrowser for help on using the repository browser.