[PATCH 15/17] riscv: Add dummy SMP support

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Jun 22 11:59:12 UTC 2018


Update #3433.
---
 bsps/riscv/riscv/start/start.S                     |  10 ++
 c/src/lib/libbsp/riscv/riscv/Makefile.am           |   3 +
 cpukit/score/cpu/riscv/include/rtems/score/cpu.h   | 101 +++------------------
 .../score/cpu/riscv/include/rtems/score/cpuimpl.h  |   6 ++
 4 files changed, 33 insertions(+), 87 deletions(-)

diff --git a/bsps/riscv/riscv/start/start.S b/bsps/riscv/riscv/start/start.S
index 1f6b3f96f5..2c560cea35 100644
--- a/bsps/riscv/riscv/start/start.S
+++ b/bsps/riscv/riscv/start/start.S
@@ -52,6 +52,11 @@ SYM(_start):
 	la	gp, __global_pointer$
 	.option	pop
 
+#ifdef RTEMS_SMP
+	csrr	s0, mhartid
+	bnez	s0, .Lloop_forever
+#endif
+
 	la	t0, ISR_Handler
 	csrw	mtvec, t0
 
@@ -70,6 +75,11 @@ SYM(_start):
 
 	j	boot_card
 
+#ifdef RTEMS_SMP
+.Lloop_forever:
+	j	.Lloop_forever
+#endif
+
 	.align	4
 bsp_start_vector_table_begin:
 	.word	_RISCV_Exception_default /* User int */
diff --git a/c/src/lib/libbsp/riscv/riscv/Makefile.am b/c/src/lib/libbsp/riscv/riscv/Makefile.am
index 3d819f758b..0830b4f639 100644
--- a/c/src/lib/libbsp/riscv/riscv/Makefile.am
+++ b/c/src/lib/libbsp/riscv/riscv/Makefile.am
@@ -61,6 +61,9 @@ librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/cache/nocache.c
 # debugio
 librtemsbsp_a_SOURCES += ../../../../../../bsps/riscv/riscv/console/console-io.c
 
+if HAS_SMP
+librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/start/bspsmp-dummy.c
+endif
 
 include $(top_srcdir)/../../../../automake/local.am
 include $(srcdir)/../../../../../../bsps/shared/irq-sources.am
diff --git a/cpukit/score/cpu/riscv/include/rtems/score/cpu.h b/cpukit/score/cpu/riscv/include/rtems/score/cpu.h
index 83686267fb..290d6e74ad 100644
--- a/cpukit/score/cpu/riscv/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/riscv/include/rtems/score/cpu.h
@@ -480,102 +480,35 @@ static inline CPU_Counter_ticks _CPU_Counter_difference(
 }
 
 #ifdef RTEMS_SMP
-/**
- * @brief Performs CPU specific SMP initialization in the context of the boot
- * processor.
- *
- * This function is invoked on the boot processor during system
- * initialization.  All interrupt stacks are allocated at this point in case
- * the CPU port allocates the interrupt stacks.  This function is called
- * before _CPU_SMP_Start_processor() or _CPU_SMP_Finalize_initialization() is
- * used.
- *
- * @return The count of physically or virtually available processors.
- * Depending on the configuration the application may use not all processors.
- */
 uint32_t _CPU_SMP_Initialize( void );
 
-/**
- * @brief Starts a processor specified by its index.
- *
- * This function is invoked on the boot processor during system
- * initialization.
- *
- * This function will be called after _CPU_SMP_Initialize().
- *
- * @param[in] cpu_index The processor index.
- *
- * @retval true Successful operation.
- * @retval false Unable to start this processor.
- */
 bool _CPU_SMP_Start_processor( uint32_t cpu_index );
 
-/**
- * @brief Performs final steps of CPU specific SMP initialization in the
- * context of the boot processor.
- *
- * This function is invoked on the boot processor during system
- * initialization.
- *
- * This function will be called after all processors requested by the
- * application have been started.
- *
- * @param[in] cpu_count The minimum value of the count of processors
- * requested by the application configuration and the count of physically or
- * virtually available processors.
- */
 void _CPU_SMP_Finalize_initialization( uint32_t cpu_count );
 
-/**
- * @brief Returns the index of the current processor.
- *
- * An architecture specific method must be used to obtain the index of the
- * current processor in the system.  The set of processor indices is the
- * range of integers starting with zero up to the processor count minus one.
- */
-uint32_t _CPU_SMP_Get_current_processor( void );
+void _CPU_SMP_Prepare_start_multitasking( void );
+
+static inline uint32_t _CPU_SMP_Get_current_processor( void )
+{
+  long mhartid;
+
+  __asm__ volatile ( "csrr %0, mhartid" : "=&r" ( mhartid ) );
+
+  return mhartid;
+}
 
-/**
- * @brief Sends an inter-processor interrupt to the specified target
- * processor.
- *
- * This operation is undefined for target processor indices out of range.
- *
- * @param[in] target_processor_index The target processor index.
- */
 void _CPU_SMP_Send_interrupt( uint32_t target_processor_index );
 
-/**
- * @brief Broadcasts a processor event.
- *
- * Some architectures provide a low-level synchronization primitive for
- * processors in a multi-processor environment.  Processors waiting for this
- * event may go into a low-power state and stop generating system bus
- * transactions.  This function must ensure that preceding store operations
- * can be observed by other processors.
- *
- * @see _CPU_SMP_Processor_event_receive().
- */
-void _CPU_SMP_Processor_event_broadcast( void );
+static inline void _CPU_SMP_Processor_event_broadcast( void )
+{
+  __asm__ volatile ( "" : : : "memory" );
+}
 
-/**
- * @brief Receives a processor event.
- *
- * This function will wait for the processor event and may wait forever if no
- * such event arrives.
- *
- * @see _CPU_SMP_Processor_event_broadcast().
- */
 static inline void _CPU_SMP_Processor_event_receive( void )
 {
   __asm__ volatile ( "" : : : "memory" );
 }
 
-/**
- * @brief Gets the is executing indicator of the thread context.
- *
- * @param[in] context The context.
- */
 static inline bool _CPU_Context_Get_is_executing(
   const Context_Control *context
 )
@@ -583,12 +516,6 @@ static inline bool _CPU_Context_Get_is_executing(
   return context->is_executing;
 }
 
-/**
- * @brief Sets the is executing indicator of the thread context.
- *
- * @param[in] context The context.
- * @param[in] is_executing The new value for the is executing indicator.
- */
 static inline void _CPU_Context_Set_is_executing(
   Context_Control *context,
   bool is_executing
diff --git a/cpukit/score/cpu/riscv/include/rtems/score/cpuimpl.h b/cpukit/score/cpu/riscv/include/rtems/score/cpuimpl.h
index 3904c84bf9..3096f5258b 100644
--- a/cpukit/score/cpu/riscv/include/rtems/score/cpuimpl.h
+++ b/cpukit/score/cpu/riscv/include/rtems/score/cpuimpl.h
@@ -36,6 +36,12 @@
 
 #define CPU_PER_CPU_CONTROL_SIZE 0
 
+#if __riscv_xlen == 64
+#define CPU_INTERRUPT_FRAME_SIZE 288
+#else
+#define CPU_INTERRUPT_FRAME_SIZE 144
+#endif
+
 #ifndef ASM
 
 #ifdef __cplusplus
-- 
2.13.7



More information about the devel mailing list