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

4.115
Last change on this file since 0a2096b was 0a2096b, checked in by Sebastian Huber <sebastian.huber@…>, on 02/24/14 at 16:06:52

bsp/leon3: Use ambapp_freq_get() for CPU counter

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