1 | /** |
---|
2 | * @file |
---|
3 | * @ingroup sparc_leon3 |
---|
4 | * @brief LEON3 SMP BSP Support |
---|
5 | */ |
---|
6 | |
---|
7 | /* |
---|
8 | * COPYRIGHT (c) 1989-2011. |
---|
9 | * On-Line Applications Research Corporation (OAR). |
---|
10 | * |
---|
11 | * The license and distribution terms for this file may be |
---|
12 | * found in the file LICENSE in this distribution or at |
---|
13 | * http://www.rtems.com/license/LICENSE. |
---|
14 | */ |
---|
15 | |
---|
16 | #include <bsp.h> |
---|
17 | #include <leon.h> |
---|
18 | #include <rtems/bspIo.h> |
---|
19 | #include <rtems/bspsmp.h> |
---|
20 | #include <stdlib.h> |
---|
21 | |
---|
22 | #define RTEMS_DEBUG |
---|
23 | |
---|
24 | static inline void sparc_leon3_set_cctrl( unsigned int val ) |
---|
25 | { |
---|
26 | __asm__ volatile( "sta %0, [%%g0] 2" : : "r" (val) ); |
---|
27 | } |
---|
28 | |
---|
29 | static inline unsigned int sparc_leon3_get_cctrl( void ) |
---|
30 | { |
---|
31 | unsigned int v = 0; |
---|
32 | __asm__ volatile( "lda [%%g0] 2, %0" : "=r" (v) : "0" (v) ); |
---|
33 | return v; |
---|
34 | } |
---|
35 | |
---|
36 | static rtems_isr bsp_ap_ipi_isr( |
---|
37 | rtems_vector_number vector |
---|
38 | ) |
---|
39 | { |
---|
40 | rtems_smp_process_interrupt(); |
---|
41 | } |
---|
42 | |
---|
43 | void leon3_secondary_cpu_initialize(uint32_t cpu) |
---|
44 | { |
---|
45 | sparc_leon3_set_cctrl( 0x80000F ); |
---|
46 | LEON_Unmask_interrupt(LEON3_MP_IRQ); |
---|
47 | LEON3_IrqCtrl_Regs->mask[cpu] |= 1 << LEON3_MP_IRQ; |
---|
48 | |
---|
49 | rtems_smp_secondary_cpu_initialize(); |
---|
50 | } |
---|
51 | |
---|
52 | uint32_t bsp_smp_initialize( uint32_t configured_cpu_count ) |
---|
53 | { |
---|
54 | uint32_t cpu; |
---|
55 | uint32_t found_cpus = 0; |
---|
56 | |
---|
57 | sparc_leon3_set_cctrl( 0x80000F ); |
---|
58 | found_cpus = |
---|
59 | ((LEON3_IrqCtrl_Regs->mpstat >> LEON3_IRQMPSTATUS_CPUNR) & 0xf) + 1; |
---|
60 | |
---|
61 | #if defined(RTEMS_DEBUG) |
---|
62 | printk( "Found %d CPUs\n", found_cpus ); |
---|
63 | |
---|
64 | if ( found_cpus > configured_cpu_count ) { |
---|
65 | printk( |
---|
66 | "%d CPUs IS MORE THAN CONFIGURED -- ONLY USING %d\n", |
---|
67 | found_cpus, |
---|
68 | configured_cpu_count |
---|
69 | ); |
---|
70 | found_cpus = configured_cpu_count; |
---|
71 | } |
---|
72 | #endif |
---|
73 | |
---|
74 | if ( found_cpus > 1 ) { |
---|
75 | LEON_Unmask_interrupt(LEON3_MP_IRQ); |
---|
76 | set_vector(bsp_ap_ipi_isr, LEON_TRAP_TYPE(LEON3_MP_IRQ), 1); |
---|
77 | } |
---|
78 | |
---|
79 | for ( cpu = 1 ; cpu < found_cpus ; ++cpu ) { |
---|
80 | #if defined(RTEMS_DEBUG) |
---|
81 | printk( "Waking CPU %d\n", cpu ); |
---|
82 | #endif |
---|
83 | |
---|
84 | LEON3_IrqCtrl_Regs->mpstat = 1 << cpu; |
---|
85 | } |
---|
86 | |
---|
87 | return found_cpus; |
---|
88 | } |
---|
89 | |
---|
90 | void _CPU_SMP_Send_interrupt(uint32_t target_processor_index) |
---|
91 | { |
---|
92 | /* send interrupt to destination CPU */ |
---|
93 | LEON3_IrqCtrl_Regs->force[target_processor_index] = 1 << LEON3_MP_IRQ; |
---|
94 | } |
---|
95 | |
---|
96 | void bsp_smp_broadcast_interrupt(void) |
---|
97 | { |
---|
98 | uint32_t dest_cpu; |
---|
99 | uint32_t cpu; |
---|
100 | uint32_t max_cpus; |
---|
101 | |
---|
102 | cpu = rtems_smp_get_current_processor(); |
---|
103 | max_cpus = rtems_smp_get_processor_count(); |
---|
104 | |
---|
105 | for ( dest_cpu=0 ; dest_cpu < max_cpus ; dest_cpu++ ) { |
---|
106 | if ( cpu != dest_cpu ) { |
---|
107 | _CPU_SMP_Send_interrupt( dest_cpu ); |
---|
108 | } |
---|
109 | } |
---|
110 | } |
---|