source: rtems/c/src/lib/libbsp/sparc/leon3/include/leon.h @ 0d3b5d47

4.115
Last change on this file since 0d3b5d47 was 77a2226, checked in by Daniel Cederman <cederman@…>, on 09/10/14 at 11:39:53

bsp/sparc: Ensure that data cache snooping is enabled

Check that data cache snooping exists and is enabled on all cores.

  • Property mode set to 100644
File size: 11.2 KB
Line 
1/**
2 * @file
3 * @ingroup sparc_leon3
4 * @brief LEON3 BSP data types and macros
5 */
6
7/*  leon.h
8 *
9 *  LEON3 BSP data types and macros.
10 *
11 *  COPYRIGHT (c) 1989-1998.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  Modified for LEON3 BSP.
15 *  COPYRIGHT (c) 2004.
16 *  Gaisler Research.
17 *
18 *  The license and distribution terms for this file may be
19 *  found in the file LICENSE in this distribution or at
20 *  http://www.rtems.org/license/LICENSE.
21 */
22
23#ifndef _INCLUDE_LEON_h
24#define _INCLUDE_LEON_h
25
26#include <rtems.h>
27#include <amba.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#define LEON_INTERRUPT_EXTERNAL_1 5
34
35#ifndef ASM
36/*
37 *  Trap Types for on-chip peripherals
38 *
39 *  Source: Table 8 - Interrupt Trap Type and Default Priority Assignments
40 *
41 *  NOTE: The priority level for each source corresponds to the least
42 *        significant nibble of the trap type.
43 */
44
45#define LEON_TRAP_TYPE( _source ) SPARC_ASYNCHRONOUS_TRAP((_source) + 0x10)
46
47#define LEON_TRAP_SOURCE( _trap ) ((_trap) - 0x10)
48
49#define LEON_INT_TRAP( _trap ) \
50  ( (_trap) >= 0x11 && \
51    (_trap) <= 0x1F )
52
53/* /\* */
54/*  *  This is used to manipulate the on-chip registers. */
55/*  * */
56/*  *  The following symbol must be defined in the linkcmds file and point */
57/*  *  to the correct location. */
58/*  *\/ */
59/* Leon uses dynamic register mapping using amba configuration records */
60/* LEON_Register_Map is obsolete */
61/* extern LEON_Register_Map LEON_REG; */
62
63#endif
64
65/*
66 *  The following defines the bits in Memory Configuration Register 1.
67 */
68
69#define LEON_MEMORY_CONFIGURATION_PROM_SIZE_MASK  0x0003C000
70
71/*
72 *  The following defines the bits in Memory Configuration Register 1.
73 */
74
75#define LEON_MEMORY_CONFIGURATION_RAM_SIZE_MASK  0x00001E00
76
77
78/*
79 *  The following defines the bits in the Timer Control Register.
80 */
81
82#define LEON_REG_TIMER_CONTROL_EN    0x00000001  /* 1 = enable counting */
83                                              /* 0 = hold scalar and counter */
84#define LEON_REG_TIMER_CONTROL_RL    0x00000002  /* 1 = reload at 0 */
85                                              /* 0 = stop at 0 */
86#define LEON_REG_TIMER_CONTROL_LD    0x00000004  /* 1 = load counter */
87                                              /* 0 = no function */
88
89/*
90 *  The following defines the bits in the LEON Cache Control Register.
91 */
92#define LEON3_REG_CACHE_CTRL_FI      0x00200000 /* Flush instruction cache */
93#define LEON3_REG_CACHE_CTRL_DS      0x00800000 /* Data cache snooping */
94
95/* LEON3 Interrupt Controller */
96extern volatile struct irqmp_regs *LEON3_IrqCtrl_Regs;
97/* LEON3 GP Timer */
98extern volatile struct gptimer_regs *LEON3_Timer_Regs;
99
100/* LEON3 CPU Index of boot CPU */
101extern uint32_t LEON3_Cpu_Index;
102
103/* The external IRQ number, -1 if not external interrupts */
104extern int LEON3_IrqCtrl_EIrq;
105
106static __inline__ int bsp_irq_fixup(int irq)
107{
108  int eirq, cpu;
109
110  if (LEON3_IrqCtrl_EIrq != 0 && irq == LEON3_IrqCtrl_EIrq) {
111    /* Get interrupt number from IRQ controller */
112    cpu = _LEON3_Get_current_processor();
113    eirq = LEON3_IrqCtrl_Regs->intid[cpu] & 0x1f;
114    if (eirq & 0x10)
115      irq = eirq;
116  }
117
118  return irq;
119}
120
121/* Macros used for manipulating bits in LEON3 GP Timer Control Register */
122
123#define LEON3_IRQMPSTATUS_CPUNR     28
124#define LEON3_IRQMPSTATUS_BROADCAST 27
125
126
127#ifndef ASM
128
129/*
130 *  Macros to manipulate the Interrupt Clear, Interrupt Force, Interrupt Mask,
131 *  and the Interrupt Pending Registers.
132 *
133 *  NOTE: For operations which are not atomic, this code disables interrupts
134 *        to guarantee there are no intervening accesses to the same register.
135 *        The operations which read the register, modify the value and then
136 *        store the result back are vulnerable.
137 */
138
139extern rtems_interrupt_lock LEON3_IrqCtrl_Lock;
140
141#define LEON3_IRQCTRL_ACQUIRE( _lock_context ) \
142  rtems_interrupt_lock_acquire( &LEON3_IrqCtrl_Lock, _lock_context )
143
144#define LEON3_IRQCTRL_RELEASE( _lock_context ) \
145  rtems_interrupt_lock_release( &LEON3_IrqCtrl_Lock, _lock_context )
146
147#define LEON_Clear_interrupt( _source ) \
148  do { \
149    LEON3_IrqCtrl_Regs->iclear = (1 << (_source)); \
150  } while (0)
151
152#define LEON_Force_interrupt( _source ) \
153  do { \
154    LEON3_IrqCtrl_Regs->iforce = (1 << (_source)); \
155  } while (0)
156
157#define LEON_Is_interrupt_pending( _source ) \
158  (LEON3_IrqCtrl_Regs->ipend & (1 << (_source)))
159
160#define LEON_Cpu_Is_interrupt_masked( _source, _cpu ) \
161  do {\
162     (LEON3_IrqCtrl_Regs->mask[_cpu] & (1 << (_source))); \
163   } while (0)
164
165#define LEON_Cpu_Mask_interrupt( _source, _cpu ) \
166  do { \
167    rtems_interrupt_lock_context _lock_context; \
168    LEON3_IRQCTRL_ACQUIRE( &_lock_context ); \
169     LEON3_IrqCtrl_Regs->mask[_cpu]  &= ~(1 << (_source)); \
170    LEON3_IRQCTRL_RELEASE( &_lock_context ); \
171  } while (0)
172
173#define LEON_Cpu_Unmask_interrupt( _source, _cpu ) \
174  do { \
175    rtems_interrupt_lock_context _lock_context; \
176    LEON3_IRQCTRL_ACQUIRE( &_lock_context ); \
177    LEON3_IrqCtrl_Regs->mask[_cpu]  |= (1 << (_source)); \
178    LEON3_IRQCTRL_RELEASE( &_lock_context ); \
179  } while (0)
180
181#define LEON_Cpu_Disable_interrupt( _source, _previous, _cpu ) \
182  do { \
183    rtems_interrupt_lock_context _lock_context; \
184    uint32_t _mask = 1 << (_source); \
185    LEON3_IRQCTRL_ACQUIRE( &_lock_context ); \
186     (_previous) = LEON3_IrqCtrl_Regs->mask[_cpu]; \
187     LEON3_IrqCtrl_Regs->mask[_cpu] = _previous & ~_mask; \
188    LEON3_IRQCTRL_RELEASE( &_lock_context ); \
189    (_previous) &= _mask; \
190  } while (0)
191
192#define LEON_Cpu_Restore_interrupt( _source, _previous, _cpu ) \
193  do { \
194    rtems_interrupt_lock_context _lock_context; \
195    uint32_t _mask = 1 << (_source); \
196    LEON3_IRQCTRL_ACQUIRE( &_lock_context ); \
197      LEON3_IrqCtrl_Regs->mask[_cpu] = \
198        (LEON3_IrqCtrl_Regs->mask[_cpu] & ~_mask) | (_previous); \
199    LEON3_IRQCTRL_RELEASE( &_lock_context ); \
200  } while (0)
201
202/* Map single-cpu operations to local CPU */
203#define LEON_Is_interrupt_masked( _source ) \
204  LEON_Cpu_Is_interrupt_masked(_source, _LEON3_Get_current_processor())
205
206#define LEON_Mask_interrupt(_source) \
207  LEON_Cpu_Mask_interrupt(_source, _LEON3_Get_current_processor())
208
209#define LEON_Unmask_interrupt(_source) \
210  LEON_Cpu_Unmask_interrupt(_source, _LEON3_Get_current_processor())
211
212#define LEON_Disable_interrupt(_source, _previous) \
213  LEON_Cpu_Disable_interrupt(_source, _previous, _LEON3_Get_current_processor())
214
215#define LEON_Restore_interrupt(_source, _previous) \
216  LEON_Cpu_Restore_interrupt(_source, _previous, _LEON3_Get_current_processor())
217
218/* Make all SPARC BSPs have common macros for interrupt handling */
219#define BSP_Clear_interrupt(_source) LEON_Clear_interrupt(_source)
220#define BSP_Force_interrupt(_source) LEON_Force_interrupt(_source)
221#define BSP_Is_interrupt_pending(_source) LEON_Is_interrupt_pending(_source)
222#define BSP_Is_interrupt_masked(_source) LEON_Is_interrupt_masked(_source)
223#define BSP_Unmask_interrupt(_source) LEON_Unmask_interrupt(_source)
224#define BSP_Mask_interrupt(_source) LEON_Mask_interrupt(_source)
225#define BSP_Disable_interrupt(_source, _previous) \
226        LEON_Disable_interrupt(_source, _prev)
227#define BSP_Restore_interrupt(_source, _previous) \
228        LEON_Restore_interrupt(_source, _previous)
229
230/* Make all SPARC BSPs have common macros for interrupt handling on any CPU */
231#define BSP_Cpu_Is_interrupt_masked(_source, _cpu) \
232        LEON_Cpu_Is_interrupt_masked(_source, _cpu)
233#define BSP_Cpu_Unmask_interrupt(_source, _cpu) \
234        LEON_Cpu_Unmask_interrupt(_source, _cpu)
235#define BSP_Cpu_Mask_interrupt(_source, _cpu) \
236        LEON_Cpu_Mask_interrupt(_source, _cpu)
237#define BSP_Cpu_Disable_interrupt(_source, _previous, _cpu) \
238        LEON_Cpu_Disable_interrupt(_source, _prev, _cpu)
239#define BSP_Cpu_Restore_interrupt(_source, _previous, _cpu) \
240        LEON_Cpu_Restore_interrupt(_source, _previous, _cpu)
241
242/*
243 *  Each timer control register is organized as follows:
244 *
245 *    D0 - Enable
246 *          1 = enable counting
247 *          0 = hold scaler and counter
248 *
249 *    D1 - Counter Reload
250 *          1 = reload counter at zero and restart
251 *          0 = stop counter at zero
252 *
253 *    D2 - Counter Load
254 *          1 = load counter with preset value
255 *          0 = no function
256 *
257 */
258
259#define LEON_REG_TIMER_COUNTER_RELOAD_AT_ZERO     0x00000002
260#define LEON_REG_TIMER_COUNTER_STOP_AT_ZERO       0x00000000
261
262#define LEON_REG_TIMER_COUNTER_LOAD_COUNTER       0x00000004
263
264#define LEON_REG_TIMER_COUNTER_ENABLE_COUNTING    0x00000001
265#define LEON_REG_TIMER_COUNTER_DISABLE_COUNTING   0x00000000
266
267#define LEON_REG_TIMER_COUNTER_RELOAD_MASK        0x00000002
268#define LEON_REG_TIMER_COUNTER_ENABLE_MASK        0x00000001
269
270#define LEON_REG_TIMER_COUNTER_DEFINED_MASK       0x00000003
271#define LEON_REG_TIMER_COUNTER_CURRENT_MODE_MASK  0x00000003
272
273#if defined(RTEMS_MULTIPROCESSING)
274  #define LEON3_CLOCK_INDEX \
275   (rtems_configuration_get_user_multiprocessing_table() ? LEON3_Cpu_Index : 0)
276#else
277  #define LEON3_CLOCK_INDEX 0
278#endif
279
280/*
281 * We assume that a boot loader (usually GRMON) initialized the GPTIMER 0 to
282 * run with 1MHz.  This is used to determine all clock frequencies of the PnP
283 * devices.  See also ambapp_freq_init() and ambapp_freq_get().
284 */
285#define LEON3_GPTIMER_0_FREQUENCY_SET_BY_BOOT_LOADER 1000000
286
287/* Load 32-bit word by forcing a cache-miss */
288static inline unsigned int leon_r32_no_cache(uintptr_t addr)
289{
290  unsigned int tmp;
291  __asm__ volatile (" lda [%1] 1, %0\n" : "=r"(tmp) : "r"(addr));
292  return tmp;
293}
294
295/* Let user override which on-chip APBUART will be debug UART
296 * 0 = Default APBUART. On MP system CPU0=APBUART0, CPU1=APBUART1...
297 * 1 = APBUART[0]
298 * 2 = APBUART[1]
299 * 3 = APBUART[2]
300 * ...
301 */
302extern int syscon_uart_index;
303
304/* Let user override which on-chip APBUART will be debug UART
305 * 0 = Default APBUART. On MP system CPU0=APBUART0, CPU1=APBUART1...
306 * 1 = APBUART[0]
307 * 2 = APBUART[1]
308 * 3 = APBUART[2]
309 * ...
310 */
311extern int debug_uart_index;
312
313void leon3_cpu_counter_initialize(void);
314
315/* GRLIB extended IRQ controller register */
316void leon3_ext_irq_init(void);
317
318void bsp_debug_uart_init(void);
319
320void leon3_power_down_loop(void) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
321
322static inline uint32_t leon3_get_cpu_count(
323  volatile struct irqmp_regs *irqmp
324)
325{
326  uint32_t mpstat = irqmp->mpstat;
327
328  return ((mpstat >> LEON3_IRQMPSTATUS_CPUNR) & 0xf)  + 1;
329}
330
331static inline void leon3_set_system_register(uint32_t addr, uint32_t val)
332{
333  __asm__ volatile(
334    "sta %1, [%0] 2"
335    :
336    : "r" (addr), "r" (val)
337  );
338}
339
340static inline uint32_t leon3_get_system_register(uint32_t addr)
341{
342  uint32_t val;
343
344  __asm__ volatile(
345    "lda [%1] 2, %0"
346    : "=r" (val)
347    : "r" (addr)
348  );
349
350  return val;
351}
352
353static inline void leon3_set_cache_control_register(uint32_t val)
354{
355  leon3_set_system_register(0x0, val);
356}
357
358static inline uint32_t leon3_get_cache_control_register(void)
359{
360  return leon3_get_system_register(0x0);
361}
362
363static inline bool leon3_data_cache_snooping_enabled(void)
364{
365  return leon3_get_cache_control_register() & LEON3_REG_CACHE_CTRL_DS;
366}
367
368static inline uint32_t leon3_get_inst_cache_config_register(void)
369{
370  return leon3_get_system_register(0x8);
371}
372
373static inline uint32_t leon3_get_data_cache_config_register(void)
374{
375  return leon3_get_system_register(0xc);
376}
377
378static inline bool leon3_irqmp_has_timestamp(
379  volatile struct irqmp_timestamp_regs *irqmp_ts
380)
381{
382  return (irqmp_ts->control >> 27) > 0;
383}
384
385#endif /* !ASM */
386
387#ifdef __cplusplus
388}
389#endif
390
391#endif /* !_INCLUDE_LEON_h */
392/* end of include file */
393
Note: See TracBrowser for help on using the repository browser.