[PATCH] bsp/leon3: Replace the define LEON3_MP_IRQ with a weakly linked variable

Daniel Cederman cederman at gaisler.com
Wed Oct 1 11:53:03 UTC 2014


The LEON3_MP_IRQ define is used to pick the IRQ to be used by the
shared memory driver and for inter-processor interrupts. On some LEON3
systems, for example the GR712RC, the default value of 14 is not suitable.
To make this value configurable from the application, it is replaced with
a weakly linked variable that can be overridden from the application.
---
 c/src/lib/libbsp/sparc/leon3/include/bsp.h     |  7 +++++++
 c/src/lib/libbsp/sparc/leon3/include/leon.h    |  2 --
 c/src/lib/libbsp/sparc/leon3/shmsupp/getcfg.c  |  4 ++--
 c/src/lib/libbsp/sparc/leon3/shmsupp/mpisr.c   |  4 ++--
 c/src/lib/libbsp/sparc/leon3/startup/bspsmp.c  | 13 +++++++++----
 c/src/lib/libbsp/sparc/shared/irq/irq-shared.c |  4 ++--
 6 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/leon3/include/bsp.h b/c/src/lib/libbsp/sparc/leon3/include/bsp.h
index cb15796..ceb7f2e 100644
--- a/c/src/lib/libbsp/sparc/leon3/include/bsp.h
+++ b/c/src/lib/libbsp/sparc/leon3/include/bsp.h
@@ -215,6 +215,13 @@ extern void BSP_shared_interrupt_unmask(int irq);
  */
 extern void BSP_shared_interrupt_mask(int irq);
 
+/* Irq used by the shared memory driver and for inter-processor interrupts.
+ * The variable is weakly linked. Redefine the variable in your application
+ * to override the BSP default.
+ * See startup/bspsmp.c for the default value.
+ */
+extern unsigned char LEON3_mp_irq;
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/c/src/lib/libbsp/sparc/leon3/include/leon.h b/c/src/lib/libbsp/sparc/leon3/include/leon.h
index 14cbc85..46e3071 100644
--- a/c/src/lib/libbsp/sparc/leon3/include/leon.h
+++ b/c/src/lib/libbsp/sparc/leon3/include/leon.h
@@ -119,8 +119,6 @@ static __inline__ int bsp_irq_fixup(int irq)
 
 /* Macros used for manipulating bits in LEON3 GP Timer Control Register */
 
-#define LEON3_MP_IRQ    14        /* Irq used by shared memory driver */
-
 #define LEON3_IRQMPSTATUS_CPUNR     28
 #define LEON3_IRQMPSTATUS_BROADCAST 27
 
diff --git a/c/src/lib/libbsp/sparc/leon3/shmsupp/getcfg.c b/c/src/lib/libbsp/sparc/leon3/shmsupp/getcfg.c
index 52bc0fd..e72eb64 100644
--- a/c/src/lib/libbsp/sparc/leon3/shmsupp/getcfg.c
+++ b/c/src/lib/libbsp/sparc/leon3/shmsupp/getcfg.c
@@ -60,7 +60,7 @@ shm_config_table BSP_shm_cfgtbl __attribute__((weak)) =
   Shm_Cause_interrupt,
   {
     NULL,
-    1 << LEON3_MP_IRQ,      /* USER OVERRIDABLE */
+    0,                      /* USER OVERRIDABLE - Uses default MP-IRQ if 0 */
     4,
   },
 };
@@ -93,7 +93,7 @@ void Shm_Get_configuration(
   BSP_shm_cfgtbl.Intr.address =
      (vol_u32 *) &(LEON3_IrqCtrl_Regs->force[LEON3_Cpu_Index]);
   if (BSP_shm_cfgtbl.Intr.value == 0)
-    BSP_shm_cfgtbl.Intr.value = 1 << LEON3_MP_IRQ; /* Use default MP-IRQ */
+    BSP_shm_cfgtbl.Intr.value = 1 << LEON3_mp_irq; /* Use default MP-IRQ */
   BSP_shm_cfgtbl.Intr.length  = 4;
 
   if (LEON3_Cpu_Index == 0) {
diff --git a/c/src/lib/libbsp/sparc/leon3/shmsupp/mpisr.c b/c/src/lib/libbsp/sparc/leon3/shmsupp/mpisr.c
index 194720a..cdf0529 100644
--- a/c/src/lib/libbsp/sparc/leon3/shmsupp/mpisr.c
+++ b/c/src/lib/libbsp/sparc/leon3/shmsupp/mpisr.c
@@ -45,6 +45,6 @@ void Shm_setvec( void )
    * Interrupt driven mode is not currently supported.
    * This is thought to be the interrupt to use.
    */
-  LEON_Unmask_interrupt(LEON3_MP_IRQ);
-  set_vector((rtems_isr_entry) Shm_isr, LEON_TRAP_TYPE(LEON3_MP_IRQ), 1);
+  LEON_Unmask_interrupt(LEON3_mp_irq);
+  set_vector((rtems_isr_entry) Shm_isr, LEON_TRAP_TYPE(LEON3_mp_irq), 1);
 }
diff --git a/c/src/lib/libbsp/sparc/leon3/startup/bspsmp.c b/c/src/lib/libbsp/sparc/leon3/startup/bspsmp.c
index b7c347e..567c971 100644
--- a/c/src/lib/libbsp/sparc/leon3/startup/bspsmp.c
+++ b/c/src/lib/libbsp/sparc/leon3/startup/bspsmp.c
@@ -21,6 +21,11 @@
 #include <rtems/score/smpimpl.h>
 #include <stdlib.h>
 
+/* Irq used by shared memory driver and for inter-processor interrupts.
+ * Can be overridden by being defined in the application.
+ */
+unsigned char LEON3_mp_irq __attribute__((weak)) = 14;
+
 #if !defined(__leon__) || defined(RTEMS_PARAVIRT)
 uint32_t _CPU_SMP_Get_current_processor( void )
 {
@@ -41,7 +46,7 @@ void bsp_start_on_secondary_processor()
 
   leon3_set_cache_control_register(0x80000F);
   /* Unmask IPI interrupts at Interrupt controller for this CPU */
-  LEON3_IrqCtrl_Regs->mask[cpu_index_self] |= 1U << LEON3_MP_IRQ;
+  LEON3_IrqCtrl_Regs->mask[cpu_index_self] |= 1U << LEON3_mp_irq;
 
   _SMP_Start_multitasking_on_secondary_processor();
 }
@@ -51,8 +56,8 @@ uint32_t _CPU_SMP_Initialize( void )
   leon3_set_cache_control_register(0x80000F);
 
   if ( rtems_configuration_get_maximum_processors() > 1 ) {
-    LEON_Unmask_interrupt(LEON3_MP_IRQ);
-    set_vector(bsp_inter_processor_interrupt, LEON_TRAP_TYPE(LEON3_MP_IRQ), 1);
+    LEON_Unmask_interrupt(LEON3_mp_irq);
+    set_vector(bsp_inter_processor_interrupt, LEON_TRAP_TYPE(LEON3_mp_irq), 1);
   }
 
   return leon3_get_cpu_count(LEON3_IrqCtrl_Regs);
@@ -79,7 +84,7 @@ void _CPU_SMP_Finalize_initialization( uint32_t cpu_count )
 void _CPU_SMP_Send_interrupt(uint32_t target_processor_index)
 {
   /* send interrupt to destination CPU */
-  LEON3_IrqCtrl_Regs->force[target_processor_index] = 1 << LEON3_MP_IRQ;
+  LEON3_IrqCtrl_Regs->force[target_processor_index] = 1 << LEON3_mp_irq;
 }
 
 void _LEON3_Start_multitasking(
diff --git a/c/src/lib/libbsp/sparc/shared/irq/irq-shared.c b/c/src/lib/libbsp/sparc/shared/irq/irq-shared.c
index ab2b4cf..b49621f 100644
--- a/c/src/lib/libbsp/sparc/shared/irq/irq-shared.c
+++ b/c/src/lib/libbsp/sparc/shared/irq/irq-shared.c
@@ -32,10 +32,10 @@ void BSP_shared_interrupt_init(void)
        int i;
 
        for (i=0; i <= BSP_INTERRUPT_VECTOR_MAX_STD; i++) {
-#if defined(LEON3_MP_IRQ) && \
+#if defined(LEON3) && \
     (defined(RTEMS_SMP) || defined(RTEMS_MULTIPROCESSING))
                /* Don't install IRQ handler on IPI interrupt */
-               if (i == LEON3_MP_IRQ)
+               if (i == LEON3_mp_irq)
                        continue;
 #endif
                vector = SPARC_ASYNCHRONOUS_TRAP(i) + 0x10;
-- 
2.1.0



More information about the devel mailing list