[PATCH 27/32] leon, gr1553bm: SMP support by using spin-locks

Daniel Hellstrom daniel at gaisler.com
Thu May 11 14:26:12 UTC 2017


---
 c/src/lib/libbsp/sparc/shared/1553/gr1553bm.c | 53 ++++++++++++++++++++-------
 1 file changed, 39 insertions(+), 14 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/shared/1553/gr1553bm.c b/c/src/lib/libbsp/sparc/shared/1553/gr1553bm.c
index d1b208f..d63983b 100644
--- a/c/src/lib/libbsp/sparc/shared/1553/gr1553bm.c
+++ b/c/src/lib/libbsp/sparc/shared/1553/gr1553bm.c
@@ -23,21 +23,45 @@
 #define GR1553BM_WRITE_REG(adr, val) *(volatile uint32_t *)(adr) = (uint32_t)(val)
 #define GR1553BM_READ_REG(adr) (*(volatile uint32_t *)(adr))
 
-#ifndef IRQ_GLOBAL_PREPARE
- #define IRQ_GLOBAL_PREPARE(level) rtems_interrupt_level level
-#endif
-
-#ifndef IRQ_GLOBAL_DISABLE
- #define IRQ_GLOBAL_DISABLE(level) rtems_interrupt_disable(level)
+/* Use interrupt lock privmitives compatible with SMP defined in
+ * RTEMS 4.11.99 and higher.
+ */
+#if (((__RTEMS_MAJOR__ << 16) | (__RTEMS_MINOR__ << 8) | __RTEMS_REVISION__) >= 0x040b63)
+
+/* map via rtems_interrupt_lock_* API: */
+#define SPIN_DECLARE(lock) RTEMS_INTERRUPT_LOCK_MEMBER(lock)
+#define SPIN_INIT(lock, name) rtems_interrupt_lock_initialize(lock, name)
+#define SPIN_LOCK(lock, level) rtems_interrupt_lock_acquire_isr(lock, &level)
+#define SPIN_LOCK_IRQ(lock, level) rtems_interrupt_lock_acquire(lock, &level)
+#define SPIN_UNLOCK(lock, level) rtems_interrupt_lock_release_isr(lock, &level)
+#define SPIN_UNLOCK_IRQ(lock, level) rtems_interrupt_lock_release(lock, &level)
+#define SPIN_IRQFLAGS(k) rtems_interrupt_lock_context k
+#define SPIN_ISR_IRQFLAGS(k) SPIN_IRQFLAGS(k)
+#define SPIN_FREE(lock) rtems_interrupt_lock_destroy(lock)
+
+#else
+
+/* maintain single-core compatibility with older versions of RTEMS: */
+#define SPIN_DECLARE(name)
+#define SPIN_INIT(lock, name)
+#define SPIN_LOCK(lock, level)
+#define SPIN_LOCK_IRQ(lock, level) rtems_interrupt_disable(level)
+#define SPIN_UNLOCK(lock, level)
+#define SPIN_UNLOCK_IRQ(lock, level) rtems_interrupt_enable(level)
+#define SPIN_IRQFLAGS(k) rtems_interrupt_level k
+#define SPIN_ISR_IRQFLAGS(k)
+#define SPIN_FREE(lock)
+
+#ifdef RTEMS_SMP
+#error SMP mode not compatible with these interrupt lock primitives
 #endif
 
-#ifndef IRQ_GLOBAL_ENABLE
- #define IRQ_GLOBAL_ENABLE(level) rtems_interrupt_enable(level)
 #endif
 
 struct gr1553bm_priv {
 	struct drvmgr_dev **pdev;
 	struct gr1553b_regs *regs;
+	SPIN_DECLARE(devlock);
 
 	void *buffer;
 	unsigned int buffer_base_hw;
@@ -80,10 +104,10 @@ void gr1553bm_register(void)
 
 static void gr1553bm_hw_start(struct gr1553bm_priv *priv)
 {
-	IRQ_GLOBAL_PREPARE(oldLevel);
+	SPIN_IRQFLAGS(irqflags);
 
 	/* Enable IRQ source and mark running state */
-	IRQ_GLOBAL_DISABLE(oldLevel);
+	SPIN_LOCK_IRQ(&priv->devlock, irqflags);
 
 	priv->started = 1;
 
@@ -103,14 +127,14 @@ static void gr1553bm_hw_start(struct gr1553bm_priv *priv)
 		(GR1553B_BM_CTRL_MANL|GR1553B_BM_CTRL_UDWL|GR1553B_BM_CTRL_IMCL))
 		| GR1553B_BM_CTRL_BMEN;
 
-	IRQ_GLOBAL_ENABLE(oldLevel);
+	SPIN_UNLOCK_IRQ(&priv->devlock, irqflags);
 }
 
 static void gr1553bm_hw_stop(struct gr1553bm_priv *priv)
 {
-	IRQ_GLOBAL_PREPARE(oldLevel);
+	SPIN_IRQFLAGS(irqflags);
 
-	IRQ_GLOBAL_DISABLE(oldLevel);
+	SPIN_LOCK_IRQ(&priv->devlock, irqflags);
 
 	/* Stop Logging */
 	priv->regs->bm_ctrl = 0;
@@ -123,7 +147,7 @@ static void gr1553bm_hw_stop(struct gr1553bm_priv *priv)
 
 	priv->started = 0;
 
-	IRQ_GLOBAL_ENABLE(oldLevel);
+	SPIN_UNLOCK_IRQ(&priv->devlock, irqflags);
 }
 
 /* Open device by number */
@@ -152,6 +176,7 @@ void *gr1553bm_open(int minor)
 	ambadev = (struct amba_dev_info *)(*pdev)->businfo;
 	pnpinfo = &ambadev->info;
 	priv->regs = (struct gr1553b_regs *)pnpinfo->apb_slv->start;
+	SPIN_INIT(&priv->devlock, "gr1553bm");
 
 	/* Start with default configuration */
 	priv->cfg = gr1553bm_default_config;
-- 
2.7.4




More information about the devel mailing list