source: rtems/c/src/lib/libbsp/sparc/leon3/include/leon.h @ 70eff78

4.115
Last change on this file since 70eff78 was 70eff78, checked in by Daniel Hellstrom <daniel@…>, on 05/26/14 at 15:08:34

LEON3: coding style clean bsp_irq_fixup()

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