[fdcd80e] | 1 | /** |
---|
| 2 | * @file |
---|
| 3 | * |
---|
| 4 | * 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 <rtems.h> |
---|
| 17 | #include <bsp.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 | |
---|
[2f6108f9] | 36 | static rtems_isr bsp_ap_ipi_isr( |
---|
[fdcd80e] | 37 | rtems_vector_number vector |
---|
| 38 | ) |
---|
| 39 | { |
---|
| 40 | LEON_Clear_interrupt(LEON3_MP_IRQ); |
---|
| 41 | rtems_smp_process_interrupt(); |
---|
| 42 | } |
---|
| 43 | |
---|
[8cacceb] | 44 | static void leon3_secondary_cpu_initialize(void) |
---|
[fdcd80e] | 45 | { |
---|
[8cacceb] | 46 | int cpu = bsp_smp_processor_id(); |
---|
| 47 | |
---|
[fdcd80e] | 48 | sparc_leon3_set_cctrl( 0x80000F ); |
---|
| 49 | LEON_Unmask_interrupt(LEON3_MP_IRQ); |
---|
| 50 | LEON3_IrqCtrl_Regs->mask[cpu] |= 1 << LEON3_MP_IRQ; |
---|
[8cacceb] | 51 | |
---|
| 52 | rtems_smp_secondary_cpu_initialize(); |
---|
[fdcd80e] | 53 | } |
---|
| 54 | |
---|
| 55 | /* |
---|
| 56 | * Used to pass information to start.S when bringing secondary CPUs |
---|
| 57 | * out of reset. |
---|
| 58 | */ |
---|
| 59 | void *bsp_ap_stack; |
---|
| 60 | void *bsp_ap_entry; |
---|
| 61 | |
---|
| 62 | static void bsp_smp_delay( int ); |
---|
| 63 | |
---|
[baf8f4d] | 64 | uint32_t bsp_smp_initialize( uint32_t configured_cpu_count ) |
---|
[fdcd80e] | 65 | { |
---|
[baf8f4d] | 66 | uint32_t cpu; |
---|
| 67 | uint32_t found_cpus = 0; |
---|
[fdcd80e] | 68 | |
---|
| 69 | sparc_leon3_set_cctrl( 0x80000F ); |
---|
| 70 | found_cpus = |
---|
| 71 | ((LEON3_IrqCtrl_Regs->mpstat >> LEON3_IRQMPSTATUS_CPUNR) & 0xf) + 1; |
---|
| 72 | #if defined(RTEMS_DEBUG) |
---|
| 73 | printk( "Found %d CPUs\n", found_cpus ); |
---|
| 74 | #endif |
---|
| 75 | |
---|
[baf8f4d] | 76 | if ( found_cpus > configured_cpu_count ) { |
---|
[fdcd80e] | 77 | printk( |
---|
| 78 | "%d CPUs IS MORE THAN CONFIGURED -- ONLY USING %d\n", |
---|
| 79 | found_cpus, |
---|
[baf8f4d] | 80 | configured_cpu_count |
---|
[fdcd80e] | 81 | ); |
---|
[baf8f4d] | 82 | found_cpus = configured_cpu_count; |
---|
[fdcd80e] | 83 | } |
---|
| 84 | |
---|
| 85 | if ( found_cpus == 1 ) |
---|
| 86 | return 1; |
---|
| 87 | |
---|
| 88 | for ( cpu=1 ; cpu < found_cpus ; cpu++ ) { |
---|
| 89 | |
---|
| 90 | #if defined(RTEMS_DEBUG) |
---|
| 91 | printk( "Waking CPU %d\n", cpu ); |
---|
| 92 | #endif |
---|
| 93 | |
---|
| 94 | bsp_ap_stack = _Per_CPU_Information[cpu].interrupt_stack_high - |
---|
| 95 | CPU_MINIMUM_STACK_FRAME_SIZE; |
---|
[8cacceb] | 96 | bsp_ap_entry = leon3_secondary_cpu_initialize; |
---|
[fdcd80e] | 97 | |
---|
| 98 | LEON3_IrqCtrl_Regs->mpstat = 1 << cpu; |
---|
| 99 | bsp_smp_delay( 1000000 ); |
---|
| 100 | #if defined(RTEMS_DEBUG) |
---|
| 101 | printk( |
---|
[2f6108f9] | 102 | "CPU %d is %s\n", |
---|
| 103 | cpu, |
---|
| 104 | _Per_CPU_Information[cpu].state |
---|
| 105 | == PER_CPU_STATE_READY_TO_BEGIN_MULTITASKING ? |
---|
| 106 | "online" : "offline" |
---|
[fdcd80e] | 107 | ); |
---|
| 108 | #endif |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | if ( found_cpus > 1 ) { |
---|
| 112 | LEON_Unmask_interrupt(LEON3_MP_IRQ); |
---|
| 113 | set_vector(bsp_ap_ipi_isr, LEON_TRAP_TYPE(LEON3_MP_IRQ), 1); |
---|
| 114 | } |
---|
| 115 | return found_cpus; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | void bsp_smp_interrupt_cpu( |
---|
| 119 | int cpu |
---|
| 120 | ) |
---|
| 121 | { |
---|
| 122 | /* send interrupt to destination CPU */ |
---|
| 123 | LEON3_IrqCtrl_Regs->force[cpu] = 1 << LEON3_MP_IRQ; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | void bsp_smp_broadcast_interrupt(void) |
---|
| 127 | { |
---|
| 128 | int dest_cpu; |
---|
| 129 | int cpu; |
---|
| 130 | int max_cpus; |
---|
| 131 | |
---|
| 132 | cpu = bsp_smp_processor_id(); |
---|
| 133 | max_cpus = rtems_smp_get_number_of_processors(); |
---|
| 134 | |
---|
| 135 | for ( dest_cpu=0 ; dest_cpu < max_cpus ; dest_cpu++ ) { |
---|
| 136 | if ( cpu == dest_cpu ) |
---|
| 137 | continue; |
---|
| 138 | bsp_smp_interrupt_cpu( dest_cpu ); |
---|
| 139 | /* this is likely needed due to the ISR code not being SMP aware yet */ |
---|
| 140 | bsp_smp_delay( 100000 ); |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | extern __inline__ void __delay(unsigned long loops) |
---|
| 145 | { |
---|
| 146 | __asm__ __volatile__("cmp %0, 0\n\t" |
---|
| 147 | "1: bne 1b\n\t" |
---|
| 148 | "subcc %0, 1, %0\n" : |
---|
| 149 | "=&r" (loops) : |
---|
| 150 | "0" (loops) : |
---|
| 151 | "cc" |
---|
| 152 | ); |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | /* |
---|
| 156 | * Kill time without depending on the timer being present or programmed. |
---|
| 157 | * |
---|
| 158 | * This is not very sophisticated. |
---|
| 159 | */ |
---|
| 160 | void bsp_smp_delay( int max ) |
---|
| 161 | { |
---|
| 162 | __delay( max ); |
---|
| 163 | } |
---|