source: rtems/c/src/lib/libbsp/sparc/leon3/include/leon.h @ 8448a4d

4.115
Last change on this file since 8448a4d was 8448a4d, checked in by Christian Mauderer <Christian.Mauderer@…>, on 07/01/14 at 13:09:49

bsps/sparc: Move APBUART printk support

  • Property mode set to 100644
File size: 9.7 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/* LEON3 Interrupt Controller */
90extern volatile struct irqmp_regs *LEON3_IrqCtrl_Regs;
91/* LEON3 GP Timer */
92extern volatile struct gptimer_regs *LEON3_Timer_Regs;
93
94/* LEON3 CPU Index of boot CPU */
95extern uint32_t LEON3_Cpu_Index;
96
97/* The external IRQ number, -1 if not external interrupts */
98extern int LEON3_IrqCtrl_EIrq;
99
100static __inline__ int bsp_irq_fixup(int irq)
101{
102  int eirq, cpu;
103
104  if (LEON3_IrqCtrl_EIrq != 0 && irq == LEON3_IrqCtrl_EIrq) {
105    /* Get interrupt number from IRQ controller */
106    cpu = _LEON3_Get_current_processor();
107    eirq = LEON3_IrqCtrl_Regs->intid[cpu] & 0x1f;
108    if (eirq & 0x10)
109      irq = eirq;
110  }
111
112  return irq;
113}
114
115/* Macros used for manipulating bits in LEON3 GP Timer Control Register */
116
117#define LEON3_MP_IRQ    14        /* Irq used by shared memory driver */
118
119#define LEON3_IRQMPSTATUS_CPUNR     28
120#define LEON3_IRQMPSTATUS_BROADCAST 27
121
122
123#ifndef ASM
124
125/*
126 *  Macros to manipulate the Interrupt Clear, Interrupt Force, Interrupt Mask,
127 *  and the Interrupt Pending Registers.
128 *
129 *  NOTE: For operations which are not atomic, this code disables interrupts
130 *        to guarantee there are no intervening accesses to the same register.
131 *        The operations which read the register, modify the value and then
132 *        store the result back are vulnerable.
133 */
134
135extern rtems_interrupt_lock LEON3_IrqCtrl_Lock;
136
137#define LEON3_IRQCTRL_ACQUIRE( _lock_context ) \
138  rtems_interrupt_lock_acquire( &LEON3_IrqCtrl_Lock, _lock_context )
139
140#define LEON3_IRQCTRL_RELEASE( _lock_context ) \
141  rtems_interrupt_lock_release( &LEON3_IrqCtrl_Lock, _lock_context )
142
143#define LEON_Clear_interrupt( _source ) \
144  do { \
145    LEON3_IrqCtrl_Regs->iclear = (1 << (_source)); \
146  } while (0)
147
148#define LEON_Force_interrupt( _source ) \
149  do { \
150    LEON3_IrqCtrl_Regs->iforce = (1 << (_source)); \
151  } while (0)
152
153#define LEON_Is_interrupt_pending( _source ) \
154  (LEON3_IrqCtrl_Regs->ipend & (1 << (_source)))
155
156#define LEON_Is_interrupt_masked( _source ) \
157  do {\
158     (LEON3_IrqCtrl_Regs->mask[LEON3_Cpu_Index] & (1 << (_source))); \
159   } while (0)
160
161#define LEON_Mask_interrupt( _source ) \
162  do { \
163    rtems_interrupt_lock_context _lock_context; \
164    LEON3_IRQCTRL_ACQUIRE( &_lock_context ); \
165     LEON3_IrqCtrl_Regs->mask[LEON3_Cpu_Index]  &= ~(1 << (_source)); \
166    LEON3_IRQCTRL_RELEASE( &_lock_context ); \
167  } while (0)
168
169#define LEON_Unmask_interrupt( _source ) \
170  do { \
171    rtems_interrupt_lock_context _lock_context; \
172    LEON3_IRQCTRL_ACQUIRE( &_lock_context ); \
173    LEON3_IrqCtrl_Regs->mask[LEON3_Cpu_Index]  |= (1 << (_source)); \
174    LEON3_IRQCTRL_RELEASE( &_lock_context ); \
175  } while (0)
176
177#define LEON_Disable_interrupt( _source, _previous ) \
178  do { \
179    rtems_interrupt_lock_context _lock_context; \
180    uint32_t _mask = 1 << (_source); \
181    LEON3_IRQCTRL_ACQUIRE( &_lock_context ); \
182     (_previous) = LEON3_IrqCtrl_Regs->mask[LEON3_Cpu_Index]; \
183     LEON3_IrqCtrl_Regs->mask[LEON3_Cpu_Index] = _previous & ~_mask; \
184    LEON3_IRQCTRL_RELEASE( &_lock_context ); \
185    (_previous) &= _mask; \
186  } while (0)
187
188#define LEON_Restore_interrupt( _source, _previous ) \
189  do { \
190    rtems_interrupt_lock_context _lock_context; \
191    uint32_t _mask = 1 << (_source); \
192    LEON3_IRQCTRL_ACQUIRE( &_lock_context ); \
193      LEON3_IrqCtrl_Regs->mask[LEON3_Cpu_Index] = \
194        (LEON3_IrqCtrl_Regs->mask[LEON3_Cpu_Index] & ~_mask) | (_previous); \
195    LEON3_IRQCTRL_RELEASE( &_lock_context ); \
196  } while (0)
197
198/* Make all SPARC BSPs have common macros for interrupt handling */
199#define BSP_Clear_interrupt(_source) LEON_Clear_interrupt(_source)
200#define BSP_Force_interrupt(_source) LEON_Force_interrupt(_source)
201#define BSP_Is_interrupt_pending(_source) LEON_Is_interrupt_pending(_source)
202#define BSP_Is_interrupt_masked(_source) LEON_Is_interrupt_masked(_source)
203#define BSP_Unmask_interrupt(_source) LEON_Unmask_interrupt(_source)
204#define BSP_Mask_interrupt(_source) LEON_Mask_interrupt(_source)
205#define BSP_Disable_interrupt(_source, _previous) \
206        LEON_Disable_interrupt(_source, _prev)
207#define BSP_Restore_interrupt(_source, _previous) \
208        LEON_Restore_interrupt(_source, _previous)
209
210/*
211 *  Each timer control register is organized as follows:
212 *
213 *    D0 - Enable
214 *          1 = enable counting
215 *          0 = hold scaler and counter
216 *
217 *    D1 - Counter Reload
218 *          1 = reload counter at zero and restart
219 *          0 = stop counter at zero
220 *
221 *    D2 - Counter Load
222 *          1 = load counter with preset value
223 *          0 = no function
224 *
225 */
226
227#define LEON_REG_TIMER_COUNTER_RELOAD_AT_ZERO     0x00000002
228#define LEON_REG_TIMER_COUNTER_STOP_AT_ZERO       0x00000000
229
230#define LEON_REG_TIMER_COUNTER_LOAD_COUNTER       0x00000004
231
232#define LEON_REG_TIMER_COUNTER_ENABLE_COUNTING    0x00000001
233#define LEON_REG_TIMER_COUNTER_DISABLE_COUNTING   0x00000000
234
235#define LEON_REG_TIMER_COUNTER_RELOAD_MASK        0x00000002
236#define LEON_REG_TIMER_COUNTER_ENABLE_MASK        0x00000001
237
238#define LEON_REG_TIMER_COUNTER_DEFINED_MASK       0x00000003
239#define LEON_REG_TIMER_COUNTER_CURRENT_MODE_MASK  0x00000003
240
241#if defined(RTEMS_MULTIPROCESSING)
242  #define LEON3_CLOCK_INDEX \
243   (rtems_configuration_get_user_multiprocessing_table() ? LEON3_Cpu_Index : 0)
244#else
245  #define LEON3_CLOCK_INDEX 0
246#endif
247
248/*
249 * We assume that a boot loader (usually GRMON) initialized the GPTIMER 0 to
250 * run with 1MHz.  This is used to determine all clock frequencies of the PnP
251 * devices.  See also ambapp_freq_init() and ambapp_freq_get().
252 */
253#define LEON3_GPTIMER_0_FREQUENCY_SET_BY_BOOT_LOADER 1000000
254
255/* Load 32-bit word by forcing a cache-miss */
256static inline unsigned int leon_r32_no_cache(uintptr_t addr)
257{
258  unsigned int tmp;
259  __asm__ volatile (" lda [%1] 1, %0\n" : "=r"(tmp) : "r"(addr));
260  return tmp;
261}
262
263/* Let user override which on-chip APBUART will be debug UART
264 * 0 = Default APBUART. On MP system CPU0=APBUART0, CPU1=APBUART1...
265 * 1 = APBUART[0]
266 * 2 = APBUART[1]
267 * 3 = APBUART[2]
268 * ...
269 */
270extern int syscon_uart_index;
271
272/* Let user override which on-chip APBUART will be debug UART
273 * 0 = Default APBUART. On MP system CPU0=APBUART0, CPU1=APBUART1...
274 * 1 = APBUART[0]
275 * 2 = APBUART[1]
276 * 3 = APBUART[2]
277 * ...
278 */
279extern int debug_uart_index;
280
281void leon3_cpu_counter_initialize(void);
282
283/* GRLIB extended IRQ controller register */
284void leon3_ext_irq_init(void);
285
286void bsp_debug_uart_init(void);
287
288void leon3_power_down_loop(void) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
289
290static inline uint32_t leon3_get_cpu_count(
291  volatile struct irqmp_regs *irqmp
292)
293{
294  uint32_t mpstat = irqmp->mpstat;
295
296  return ((mpstat >> LEON3_IRQMPSTATUS_CPUNR) & 0xf)  + 1;
297}
298
299static inline void leon3_set_system_register(uint32_t addr, uint32_t val)
300{
301  __asm__ volatile(
302    "sta %1, [%0] 2"
303    :
304    : "r" (addr), "r" (val)
305  );
306}
307
308static inline uint32_t leon3_get_system_register(uint32_t addr)
309{
310  uint32_t val;
311
312  __asm__ volatile(
313    "lda [%1] 2, %0"
314    : "=r" (val)
315    : "r" (addr)
316  );
317
318  return val;
319}
320
321static inline void leon3_set_cache_control_register(uint32_t val)
322{
323  leon3_set_system_register(0x0, val);
324}
325
326static inline uint32_t leon3_get_cache_control_register(void)
327{
328  return leon3_get_system_register(0x0);
329}
330
331static inline uint32_t leon3_get_inst_cache_config_register(void)
332{
333  return leon3_get_system_register(0x8);
334}
335
336static inline uint32_t leon3_get_data_cache_config_register(void)
337{
338  return leon3_get_system_register(0xc);
339}
340
341static inline bool leon3_irqmp_has_timestamp(
342  volatile struct irqmp_timestamp_regs *irqmp_ts
343)
344{
345  return (irqmp_ts->control >> 27) > 0;
346}
347
348#endif /* !ASM */
349
350#ifdef __cplusplus
351}
352#endif
353
354#endif /* !_INCLUDE_LEON_h */
355/* end of include file */
356
Note: See TracBrowser for help on using the repository browser.