source: rtems/c/src/lib/libbsp/sparc/leon3/smp/smp_leon3.c @ fe52e7c0

4.115
Last change on this file since fe52e7c0 was fe52e7c0, checked in by Sebastian Huber <sebastian.huber@…>, on 07/26/13 at 12:10:25

smp: Add and use _Per_CPU_Get()

Add and use _Per_CPU_Get_by_index() and _Per_CPU_Get_index(). Add
_Per_CPU_Send_interrupt(). This avoids direct access of
_Per_CPU_Information.

  • Property mode set to 100644
File size: 3.6 KB
Line 
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
24static inline void sparc_leon3_set_cctrl( unsigned int val )
25{
26  __asm__ volatile( "sta %0, [%%g0] 2" : : "r" (val) );
27}
28
29static 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
36static rtems_isr bsp_ap_ipi_isr(
37  rtems_vector_number vector
38)
39{
40  LEON_Clear_interrupt(LEON3_MP_IRQ);
41  rtems_smp_process_interrupt();
42}
43
44static void leon3_secondary_cpu_initialize(void)
45{
46  uint32_t cpu = rtems_smp_get_current_processor();
47
48  sparc_leon3_set_cctrl( 0x80000F );
49  LEON_Unmask_interrupt(LEON3_MP_IRQ);
50  LEON3_IrqCtrl_Regs->mask[cpu] |= 1 << LEON3_MP_IRQ;
51
52  rtems_smp_secondary_cpu_initialize();
53}
54
55/*
56 *  Used to pass information to start.S when bringing secondary CPUs
57 *  out of reset.
58 */
59void *bsp_ap_stack;
60void *bsp_ap_entry;
61
62static void bsp_smp_delay( int );
63
64uint32_t bsp_smp_initialize( uint32_t configured_cpu_count )
65{
66  uint32_t cpu;
67  uint32_t found_cpus = 0;
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
76  if ( found_cpus > configured_cpu_count ) {
77    printk(
78      "%d CPUs IS MORE THAN CONFIGURED -- ONLY USING %d\n",
79      found_cpus,
80      configured_cpu_count
81    );
82    found_cpus = configured_cpu_count;
83  }
84
85  if ( found_cpus == 1 )
86    return 1;
87
88  for ( cpu=1 ; cpu < found_cpus ; cpu++ ) {
89    const Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( cpu );
90
91    #if defined(RTEMS_DEBUG)
92      printk( "Waking CPU %d\n", cpu );
93    #endif
94
95    bsp_ap_stack = per_cpu->interrupt_stack_high -
96                      CPU_MINIMUM_STACK_FRAME_SIZE;
97    bsp_ap_entry = leon3_secondary_cpu_initialize;
98
99    LEON3_IrqCtrl_Regs->mpstat = 1 << cpu;
100    bsp_smp_delay( 1000000 );
101    #if defined(RTEMS_DEBUG)
102      printk(
103        "CPU %d is %s\n",
104        cpu,
105        per_cpu->state == PER_CPU_STATE_READY_TO_BEGIN_MULTITASKING ?
106          "online" : "offline"
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
118void _CPU_SMP_Send_interrupt(uint32_t target_processor_index)
119{
120  /* send interrupt to destination CPU */
121  LEON3_IrqCtrl_Regs->force[target_processor_index] = 1 << LEON3_MP_IRQ;
122}
123
124void bsp_smp_broadcast_interrupt(void)
125{
126  uint32_t dest_cpu;
127  uint32_t cpu;
128  uint32_t max_cpus;
129
130  cpu = rtems_smp_get_current_processor();
131  max_cpus = rtems_smp_get_processor_count();
132
133  for ( dest_cpu=0 ; dest_cpu < max_cpus ; dest_cpu++ ) {
134    if ( cpu == dest_cpu )
135      continue;
136    _CPU_SMP_Send_interrupt( dest_cpu );
137    /* this is likely needed due to the ISR code not being SMP aware yet */
138    bsp_smp_delay( 100000 );
139  }
140}
141
142extern __inline__ void __delay(unsigned long loops)
143{
144   __asm__ __volatile__("cmp %0, 0\n\t"
145     "1: bne 1b\n\t"
146     "subcc %0, 1, %0\n" :
147     "=&r" (loops) :
148     "0" (loops) :
149     "cc"
150  );
151}
152
153/*
154 *  Kill time without depending on the timer being present or programmed.
155 *
156 *  This is not very sophisticated.
157 */
158void bsp_smp_delay( int max )
159{
160   __delay( max );
161}
Note: See TracBrowser for help on using the repository browser.