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

4.115
Last change on this file since 8cacceb was 8cacceb, checked in by Sebastian Huber <sebastian.huber@…>, on May 14, 2013 at 11:23:10 AM

smp: Delete bsp_smp_secondary_cpu_initialize()

Do not call bsp_smp_secondary_cpu_initialize() in
rtems_smp_secondary_cpu_initialize(). This allows more flexibilty in
the BSP low-level code. Specify context requirements for a call to
rtems_smp_secondary_cpu_initialize().

  • Property mode set to 100644
File size: 3.7 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
36rtems_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  int cpu = bsp_smp_processor_id();
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   
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;
96    bsp_ap_entry = leon3_secondary_cpu_initialize;
97
98    LEON3_IrqCtrl_Regs->mpstat = 1 << cpu;
99    bsp_smp_delay( 1000000 );
100    #if defined(RTEMS_DEBUG)
101      printk(
102        "CPU %d is %s\n",
103        cpu,
104        ((_Per_CPU_Information[cpu].state == RTEMS_BSP_SMP_CPU_INITIALIZED) ?
105           "online" : "offline")
106      );
107    #endif
108  }
109
110  if ( found_cpus > 1 ) {
111    LEON_Unmask_interrupt(LEON3_MP_IRQ);
112    set_vector(bsp_ap_ipi_isr, LEON_TRAP_TYPE(LEON3_MP_IRQ), 1);
113  }
114  return found_cpus;
115}
116
117void bsp_smp_interrupt_cpu(
118  int cpu
119)
120{
121  /* send interrupt to destination CPU */
122  LEON3_IrqCtrl_Regs->force[cpu] = 1 << LEON3_MP_IRQ;
123}
124
125void bsp_smp_broadcast_interrupt(void)
126{
127  int dest_cpu;
128  int cpu;
129  int max_cpus;
130
131  cpu = bsp_smp_processor_id();
132  max_cpus = rtems_smp_get_number_of_processors();
133
134  for ( dest_cpu=0 ; dest_cpu < max_cpus ; dest_cpu++ ) {
135    if ( cpu == dest_cpu )
136      continue;
137    bsp_smp_interrupt_cpu( dest_cpu );
138    /* this is likely needed due to the ISR code not being SMP aware yet */
139    bsp_smp_delay( 100000 );
140  }
141}
142
143extern __inline__ void __delay(unsigned long loops)
144{
145   __asm__ __volatile__("cmp %0, 0\n\t"
146     "1: bne 1b\n\t"
147     "subcc %0, 1, %0\n" :
148     "=&r" (loops) :
149     "0" (loops) :
150     "cc"
151  );
152}
153
154/*
155 *  Kill time without depending on the timer being present or programmed.
156 *
157 *  This is not very sophisticated.
158 */
159void bsp_smp_delay( int max )
160{
161   __delay( max );
162}
163
164void bsp_smp_wait_for(
165  volatile unsigned int *address,
166  unsigned int           desired,
167  int                    maximum_usecs
168)
169{
170  int iterations;
171  volatile unsigned int *p = address;
172
173  for (iterations=0 ;  iterations < maximum_usecs ; iterations++ ) {
174    if ( *p == desired )
175      break;
176    bsp_smp_delay( 5000 );
177  }
178}
179
180
Note: See TracBrowser for help on using the repository browser.