RTEMS 6.1-rc6
Loading...
Searching...
No Matches
leon.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
9/* leon.h
10 *
11 * LEON3 BSP data types and macros.
12 *
13 * COPYRIGHT (c) 1989-1998.
14 * On-Line Applications Research Corporation (OAR).
15 *
16 * Modified for LEON3 BSP.
17 * COPYRIGHT (c) 2004.
18 * Gaisler Research.
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 * 1. Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
25 * 2. Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in the
27 * documentation and/or other materials provided with the distribution.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
33 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 * POSSIBILITY OF SUCH DAMAGE.
40 */
41
42#ifndef _INCLUDE_LEON_h
43#define _INCLUDE_LEON_h
44
45#include <rtems.h>
46#include <amba.h>
47#include <grlib/io.h>
48#include <bsp/leon3.h>
49
50#ifdef __cplusplus
51extern "C" {
52#endif
53
54#define LEON_INTERRUPT_EXTERNAL_1 5
55
56#ifndef ASM
57/*
58 * Trap Types for on-chip peripherals
59 *
60 * Source: Table 8 - Interrupt Trap Type and Default Priority Assignments
61 *
62 * NOTE: The priority level for each source corresponds to the least
63 * significant nibble of the trap type.
64 */
65
66#define LEON_TRAP_TYPE( _source ) SPARC_INTERRUPT_SOURCE_TO_TRAP( _source )
67
68#define LEON_TRAP_SOURCE( _trap ) SPARC_INTERRUPT_TRAP_TO_SOURCE( _trap )
69
70#define LEON_INT_TRAP( _trap ) SPARC_IS_INTERRUPT_TRAP( _trap )
71
72/* /\* */
73/* * This is used to manipulate the on-chip registers. */
74/* * */
75/* * The following symbol must be defined in the linkcmds file and point */
76/* * to the correct location. */
77/* *\/ */
78/* Leon uses dynamic register mapping using amba configuration records */
79/* LEON_Register_Map is obsolete */
80/* extern LEON_Register_Map LEON_REG; */
81
82#endif
83
84/*
85 * The following defines the bits in Memory Configuration Register 1.
86 */
87
88#define LEON_MEMORY_CONFIGURATION_PROM_SIZE_MASK 0x0003C000
89
90/*
91 * The following defines the bits in Memory Configuration Register 1.
92 */
93
94#define LEON_MEMORY_CONFIGURATION_RAM_SIZE_MASK 0x00001E00
95
96
97/*
98 * The following defines the bits in the Timer Control Register.
99 */
100
101#define LEON_REG_TIMER_CONTROL_EN 0x00000001 /* 1 = enable counting */
102 /* 0 = hold scalar and counter */
103#define LEON_REG_TIMER_CONTROL_RL 0x00000002 /* 1 = reload at 0 */
104 /* 0 = stop at 0 */
105#define LEON_REG_TIMER_CONTROL_LD 0x00000004 /* 1 = load counter */
106 /* 0 = no function */
107
108/*
109 * The following defines the bits in the UART Control Registers.
110 */
111
112#define LEON_REG_UART_CONTROL_RTD 0x000000FF /* RX/TX data */
113
114/*
115 * The following defines the bits in the LEON UART Status Register.
116 */
117
118#define LEON_REG_UART_STATUS_DR 0x00000001 /* Data Ready */
119#define LEON_REG_UART_STATUS_TSE 0x00000002 /* TX Send Register Empty */
120#define LEON_REG_UART_STATUS_THE 0x00000004 /* TX Hold Register Empty */
121#define LEON_REG_UART_STATUS_BR 0x00000008 /* Break Error */
122#define LEON_REG_UART_STATUS_OE 0x00000010 /* RX Overrun Error */
123#define LEON_REG_UART_STATUS_PE 0x00000020 /* RX Parity Error */
124#define LEON_REG_UART_STATUS_FE 0x00000040 /* RX Framing Error */
125#define LEON_REG_UART_STATUS_TF 0x00000200 /* FIFO Full */
126#define LEON_REG_UART_STATUS_ERR 0x00000078 /* Error Mask */
127
128/*
129 * The following defines the bits in the LEON UART Control Register.
130 */
131
132#define LEON_REG_UART_CTRL_RE 0x00000001 /* Receiver enable */
133#define LEON_REG_UART_CTRL_TE 0x00000002 /* Transmitter enable */
134#define LEON_REG_UART_CTRL_RI 0x00000004 /* Receiver interrupt enable */
135#define LEON_REG_UART_CTRL_TI 0x00000008 /* Transmitter interrupt enable */
136#define LEON_REG_UART_CTRL_PS 0x00000010 /* Parity select */
137#define LEON_REG_UART_CTRL_PE 0x00000020 /* Parity enable */
138#define LEON_REG_UART_CTRL_FL 0x00000040 /* Flow control enable */
139#define LEON_REG_UART_CTRL_LB 0x00000080 /* Loop Back enable */
140#define LEON_REG_UART_CTRL_DB 0x00000800 /* Debug FIFO enable */
141#define LEON_REG_UART_CTRL_SI 0x00004000 /* TX shift register empty IRQ enable */
142#define LEON_REG_UART_CTRL_FA 0x80000000 /* FIFO Available */
143#define LEON_REG_UART_CTRL_FA_BIT 31
144
145/* Macros used for manipulating bits in LEON3 GP Timer Control Register */
146
147#define LEON3_IRQMPSTATUS_CPUNR 28
148#define LEON3_IRQMPSTATUS_BROADCAST 27
149
150
151#ifndef ASM
152
153/*
154 * Macros to manipulate the Interrupt Clear, Interrupt Force, Interrupt Mask,
155 * and the Interrupt Pending Registers.
156 *
157 * NOTE: For operations which are not atomic, this code disables interrupts
158 * to guarantee there are no intervening accesses to the same register.
159 * The operations which read the register, modify the value and then
160 * store the result back are vulnerable.
161 */
162
163#define LEON_Clear_interrupt( _source ) \
164 grlib_store_32(&LEON3_IrqCtrl_Regs->iclear, 1U << (_source))
165
166#define LEON_Force_interrupt( _source ) \
167 grlib_store_32(&LEON3_IrqCtrl_Regs->iforce0, 1U << (_source))
168
169#define LEON_Enable_interrupt_broadcast( _source ) \
170 do { \
171 rtems_interrupt_lock_context _lock_context; \
172 uint32_t _mask = 1U << ( _source ); \
173 uint32_t _brdcst; \
174 LEON3_IRQCTRL_ACQUIRE( &_lock_context ); \
175 _brdcst = grlib_load_32(&LEON3_IrqCtrl_Regs->brdcst); \
176 _brdcst |= _mask; \
177 grlib_store_32(&LEON3_IrqCtrl_Regs->brdcst, _brdcst); \
178 LEON3_IRQCTRL_RELEASE( &_lock_context ); \
179 } while (0)
180
181#define LEON_Disable_interrupt_broadcast( _source ) \
182 do { \
183 rtems_interrupt_lock_context _lock_context; \
184 uint32_t _mask = 1U << ( _source ); \
185 uint32_t _brdcst; \
186 LEON3_IRQCTRL_ACQUIRE( &_lock_context ); \
187 _brdcst = grlib_load_32(&LEON3_IrqCtrl_Regs->brdcst); \
188 _brdcst &= ~_mask; \
189 grlib_store_32(&LEON3_IrqCtrl_Regs->brdcst, _brdcst); \
190 LEON3_IRQCTRL_RELEASE( &_lock_context ); \
191 } while (0)
192
193#define LEON_Is_interrupt_pending( _source ) \
194 (grlib_load_32(&LEON3_IrqCtrl_Regs->ipend) & (1U << (_source)))
195
196#define LEON_Cpu_Is_interrupt_masked( _source, _cpu ) \
197 (!(grlib_load_32(&LEON3_IrqCtrl_Regs->pimask[_cpu]) & (1U << (_source))))
198
199#define LEON_Cpu_Mask_interrupt( _source, _cpu ) \
200 do { \
201 rtems_interrupt_lock_context _lock_context; \
202 uint32_t _pimask; \
203 LEON3_IRQCTRL_ACQUIRE( &_lock_context ); \
204 _pimask = grlib_load_32(&LEON3_IrqCtrl_Regs->pimask[_cpu ]); \
205 _pimask &= ~(1U << (_source)); \
206 grlib_store_32(&LEON3_IrqCtrl_Regs->pimask[_cpu ], _pimask); \
207 LEON3_IRQCTRL_RELEASE( &_lock_context ); \
208 } while (0)
209
210#define LEON_Cpu_Unmask_interrupt( _source, _cpu ) \
211 do { \
212 rtems_interrupt_lock_context _lock_context; \
213 uint32_t _pimask; \
214 LEON3_IRQCTRL_ACQUIRE( &_lock_context ); \
215 _pimask = grlib_load_32(&LEON3_IrqCtrl_Regs->pimask[_cpu ]); \
216 _pimask |= 1U << (_source); \
217 grlib_store_32(&LEON3_IrqCtrl_Regs->pimask[_cpu ], _pimask); \
218 LEON3_IRQCTRL_RELEASE( &_lock_context ); \
219 } while (0)
220
221#define LEON_Cpu_Disable_interrupt( _source, _previous, _cpu ) \
222 do { \
223 rtems_interrupt_lock_context _lock_context; \
224 uint32_t _mask = 1U << (_source); \
225 LEON3_IRQCTRL_ACQUIRE( &_lock_context ); \
226 (_previous) = grlib_load_32(&LEON3_IrqCtrl_Regs->pimask[_cpu ]); \
227 grlib_store_32(&LEON3_IrqCtrl_Regs->pimask[_cpu ], (_previous) & ~_mask); \
228 LEON3_IRQCTRL_RELEASE( &_lock_context ); \
229 (_previous) &= _mask; \
230 } while (0)
231
232#define LEON_Cpu_Restore_interrupt( _source, _previous, _cpu ) \
233 do { \
234 rtems_interrupt_lock_context _lock_context; \
235 uint32_t _pimask; \
236 LEON3_IRQCTRL_ACQUIRE( &_lock_context ); \
237 _pimask = grlib_load_32(&LEON3_IrqCtrl_Regs->pimask[_cpu ]); \
238 _pimask &= ~(1U << (_source)); \
239 _pimask |= _previous; \
240 grlib_store_32(&LEON3_IrqCtrl_Regs->pimask[_cpu ], _pimask); \
241 LEON3_IRQCTRL_RELEASE( &_lock_context ); \
242 } while (0)
243
244/* Map single-cpu operations to local CPU */
245#define LEON_Is_interrupt_masked( _source ) \
246 LEON_Cpu_Is_interrupt_masked(_source, _LEON3_Get_current_processor())
247
248#define LEON_Mask_interrupt(_source) \
249 LEON_Cpu_Mask_interrupt(_source, _LEON3_Get_current_processor())
250
251#define LEON_Unmask_interrupt(_source) \
252 LEON_Cpu_Unmask_interrupt(_source, _LEON3_Get_current_processor())
253
254#define LEON_Disable_interrupt(_source, _previous) \
255 LEON_Cpu_Disable_interrupt(_source, _previous, _LEON3_Get_current_processor())
256
257#define LEON_Restore_interrupt(_source, _previous) \
258 LEON_Cpu_Restore_interrupt(_source, _previous, _LEON3_Get_current_processor())
259
260/* Make all SPARC BSPs have common macros for interrupt handling */
261#define BSP_Clear_interrupt(_source) LEON_Clear_interrupt(_source)
262#define BSP_Force_interrupt(_source) LEON_Force_interrupt(_source)
263#define BSP_Is_interrupt_pending(_source) LEON_Is_interrupt_pending(_source)
264#define BSP_Is_interrupt_masked(_source) LEON_Is_interrupt_masked(_source)
265#define BSP_Unmask_interrupt(_source) LEON_Unmask_interrupt(_source)
266#define BSP_Mask_interrupt(_source) LEON_Mask_interrupt(_source)
267#define BSP_Disable_interrupt(_source, _previous) \
268 LEON_Disable_interrupt(_source, _prev)
269#define BSP_Restore_interrupt(_source, _previous) \
270 LEON_Restore_interrupt(_source, _previous)
271
272/* Make all SPARC BSPs have common macros for interrupt handling on any CPU */
273#define BSP_Cpu_Is_interrupt_masked(_source, _cpu) \
274 LEON_Cpu_Is_interrupt_masked(_source, _cpu)
275#define BSP_Cpu_Unmask_interrupt(_source, _cpu) \
276 LEON_Cpu_Unmask_interrupt(_source, _cpu)
277#define BSP_Cpu_Mask_interrupt(_source, _cpu) \
278 LEON_Cpu_Mask_interrupt(_source, _cpu)
279#define BSP_Cpu_Disable_interrupt(_source, _previous, _cpu) \
280 LEON_Cpu_Disable_interrupt(_source, _prev, _cpu)
281#define BSP_Cpu_Restore_interrupt(_source, _previous, _cpu) \
282 LEON_Cpu_Restore_interrupt(_source, _previous, _cpu)
283
284/*
285 * Each timer control register is organized as follows:
286 *
287 * D0 - Enable
288 * 1 = enable counting
289 * 0 = hold scaler and counter
290 *
291 * D1 - Counter Reload
292 * 1 = reload counter at zero and restart
293 * 0 = stop counter at zero
294 *
295 * D2 - Counter Load
296 * 1 = load counter with preset value
297 * 0 = no function
298 *
299 */
300
301#define LEON_REG_TIMER_COUNTER_RELOAD_AT_ZERO 0x00000002
302#define LEON_REG_TIMER_COUNTER_STOP_AT_ZERO 0x00000000
303
304#define LEON_REG_TIMER_COUNTER_LOAD_COUNTER 0x00000004
305
306#define LEON_REG_TIMER_COUNTER_ENABLE_COUNTING 0x00000001
307#define LEON_REG_TIMER_COUNTER_DISABLE_COUNTING 0x00000000
308
309#define LEON_REG_TIMER_COUNTER_RELOAD_MASK 0x00000002
310#define LEON_REG_TIMER_COUNTER_ENABLE_MASK 0x00000001
311
312#define LEON_REG_TIMER_COUNTER_DEFINED_MASK 0x00000003
313#define LEON_REG_TIMER_COUNTER_CURRENT_MODE_MASK 0x00000003
314
315/* Load 32-bit word by forcing a cache-miss */
316static inline unsigned int leon_r32_no_cache(uintptr_t addr)
317{
318 unsigned int tmp;
319 __asm__ volatile (" lda [%1] 1, %0\n" : "=r"(tmp) : "r"(addr));
320 return tmp;
321}
322
323/* Let user override which on-chip APBUART will be debug UART
324 * 0 = Default APBUART. On MP system CPU0=APBUART0, CPU1=APBUART1...
325 * 1 = APBUART[0]
326 * 2 = APBUART[1]
327 * 3 = APBUART[2]
328 * ...
329 */
330extern int syscon_uart_index;
331
332#if !defined(LEON3_APBUART_BASE)
333/* Let user override which on-chip APBUART will be debug UART
334 * 0 = Default APBUART. On MP system CPU0=APBUART0, CPU1=APBUART1...
335 * 1 = APBUART[0]
336 * 2 = APBUART[1]
337 * 3 = APBUART[2]
338 * ...
339 */
340extern int leon3_debug_uart_index;
341#endif
342
343#endif /* !ASM */
344
345#ifdef __cplusplus
346}
347#endif
348
349#endif /* !_INCLUDE_LEON_h */
350/* end of include file */
351
This header file provides interfaces used by the BSP implementation.
This header file defines the RTEMS Classic API.