Skip to content

Commit

Permalink
Use small lock to protect resources related to irq in arch ARM.
Browse files Browse the repository at this point in the history
Signed-off-by: wangzhi16 <[email protected]>
  • Loading branch information
wangzhi-art committed Jan 22, 2025
1 parent 0e1214d commit 85c4971
Show file tree
Hide file tree
Showing 54 changed files with 790 additions and 237 deletions.
53 changes: 37 additions & 16 deletions arch/arm/src/a1x/a1x_irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include <sched.h>

#include <nuttx/irq.h>
#include <nuttx/spinlock.h>
#include <nuttx/arch.h>

#include "arm_internal.h"
Expand All @@ -40,6 +41,12 @@
#include "a1x_pio.h"
#include "a1x_irq.h"

/****************************************************************************
* Private Data
****************************************************************************/

static spinlock_t g_irq_lock = SP_UNLOCKED;

/****************************************************************************
* Private Functions
****************************************************************************/
Expand All @@ -53,14 +60,10 @@
****************************************************************************/

#if defined(CONFIG_DEBUG_IRQ_INFO)
static void a1x_dumpintc(const char *msg, int irq)
static void a1x_dumpintc_nolock(const char *msg, int irq)
{
irqstate_t flags;

/* Dump some relevant ARMv7 register contents */

flags = enter_critical_section();

irqinfo("ARMv7 (%s, irq=%d):\n", msg, irq);
irqinfo(" CPSR: %08x SCTLR: %08x\n", flags, cp15_rdsctlr());

Expand Down Expand Up @@ -95,10 +98,22 @@ static void a1x_dumpintc(const char *msg, int irq)
getreg32(A1X_INTC_PRIO0), getreg32(A1X_INTC_PRIO1),
getreg32(A1X_INTC_PRIO2), getreg32(A1X_INTC_PRIO3),
getreg32(A1X_INTC_PRIO4));
}

static void a1x_dumpintc(const char *msg, int irq)
{
irqstate_t flags;

flags = spin_lock_irqsave(&g_irq_lock);
sched_lock();

a1x_dumpintc_nolock(msg, irq);

leave_critical_section(flags);
spin_unlock_irqrestore(&g_irq_lock, flags);
sched_unlock();
}
#else
# define a1x_dumpintc_nolock(msg, irq)
# define a1x_dumpintc(msg, irq)
#endif

Expand Down Expand Up @@ -297,7 +312,8 @@ void up_disable_irq(int irq)
{
/* These operations must be atomic */

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_irq_lock);
sched_lock();

/* Make sure that the interrupt is disabled. */

Expand All @@ -313,8 +329,9 @@ void up_disable_irq(int irq)
regval |= INTC_MASK(irq);
putreg32(regval, regaddr);

a1x_dumpintc("disable", irq);
leave_critical_section(flags);
a1x_dumpintc_nolock("disable", irq);
spin_unlock_irqrestore(&g_irq_lock, flags);
sched_unlock();
}

#ifdef CONFIG_A1X_PIO_IRQ
Expand Down Expand Up @@ -345,7 +362,8 @@ void up_enable_irq(int irq)
{
/* These operations must be atomic */

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_irq_lock);
sched_lock();

/* Make sure that the interrupt is enabled. */

Expand All @@ -361,8 +379,9 @@ void up_enable_irq(int irq)
regval &= ~INTC_MASK(irq);
putreg32(regval, regaddr);

a1x_dumpintc("enable", irq);
leave_critical_section(flags);
a1x_dumpintc_nolock("enable", irq);
spin_unlock_irqrestore(&g_irq_lock, flags);
sched_unlock();
}

#ifdef CONFIG_A1X_PIO_IRQ
Expand Down Expand Up @@ -398,7 +417,8 @@ int up_prioritize_irq(int irq, int priority)
{
/* These operations must be atomic */

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_irq_lock);
sched_lock();

/* Set the new priority */

Expand All @@ -408,8 +428,9 @@ int up_prioritize_irq(int irq, int priority)
regval |= INTC_PRIO(irq, priority);
putreg32(regval, regaddr);

a1x_dumpintc("prioritize", irq);
leave_critical_section(flags);
a1x_dumpintc_nolock("prioritize", irq);
spin_unlock_irqrestore(&g_irq_lock, flags);
sched_unlock();
return OK;
}

Expand Down
2 changes: 2 additions & 0 deletions arch/arm/src/am335x/am335x_irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@
* Private Data
****************************************************************************/
#ifdef CONFIG_ARCH_IRQPRIO
#if defined(CONFIG_DEBUG_IRQ_INFO)
static spinlock_t g_irq_lock = SP_UNLOCKED;
#endif
#endif

/****************************************************************************
* Public Data
Expand Down
17 changes: 14 additions & 3 deletions arch/arm/src/at32/at32_irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
#include <stdint.h>
#include <assert.h>
#include <debug.h>
#include <sched.h>

#include <nuttx/irq.h>
#include <nuttx/spinlock.h>
#include <nuttx/arch.h>
#include <arch/irq.h>
#include <arch/armv7-m/nvicpri.h>
Expand Down Expand Up @@ -62,6 +63,14 @@
#define NVIC_ENA_OFFSET (0)
#define NVIC_CLRENA_OFFSET (NVIC_IRQ0_31_CLEAR - NVIC_IRQ0_31_ENABLE)

/****************************************************************************
* Private Data
****************************************************************************/

#if defined(CONFIG_DEBUG_IRQ_INFO)
static spinlock_t g_irq_lock = SP_UNLOCKED;
#endif

/****************************************************************************
* Private Functions
****************************************************************************/
Expand All @@ -79,7 +88,8 @@ static void at32_dumpnvic(const char *msg, int irq)
{
irqstate_t flags;

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_irq_lock);
sched_lock();

irqinfo("NVIC (%s, irq=%d):\n", msg, irq);
irqinfo(" INTCTRL: %08x VECTAB: %08x\n",
Expand Down Expand Up @@ -123,7 +133,8 @@ static void at32_dumpnvic(const char *msg, int irq)
irqinfo(" %08x\n",
getreg32(NVIC_IRQ64_67_PRIORITY));

leave_critical_section(flags);
spin_unlock_irqrestore(&g_irq_lock, flags);
sched_unlock();
}
#else
# define at32_dumpnvic(msg, irq)
Expand Down
24 changes: 15 additions & 9 deletions arch/arm/src/efm32/efm32_gpioirq.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <assert.h>

#include <nuttx/arch.h>
#include <nuttx/irq.h>
#include <nuttx/spinlock.h>

#include "arm_internal.h"
#include "hardware/efm32_gpio.h"
Expand All @@ -44,6 +44,12 @@
* Pre-processor Definitions
****************************************************************************/

/****************************************************************************
* Private Data
****************************************************************************/

static spinlock_t g_gpioirq_lock = SP_UNLOCKED;

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -198,7 +204,7 @@ void efm32_gpioirq(gpio_pinset_t pinset)

/* Make sure that the pin interrupt is disabled */

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_gpioirq_lock);
regval = getreg32(EFM32_GPIO_IEN);
regval &= ~bit;
putreg32(regval, EFM32_GPIO_IEN);
Expand Down Expand Up @@ -248,7 +254,7 @@ void efm32_gpioirq(gpio_pinset_t pinset)
}

putreg32(regval, EFM32_GPIO_EXTIFALL);
leave_critical_section(flags);
spin_unlock_irqrestore(&g_gpioirq_lock, flags);
}

/****************************************************************************
Expand All @@ -270,11 +276,11 @@ void efm32_gpioirqenable(int irq)
uint32_t regval;
uint32_t bit;
bit = ((uint32_t)1 << (irq - EFM32_IRQ_EXTI0));
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_gpioirq_lock);
regval = getreg32(EFM32_GPIO_IEN);
regval |= bit;
putreg32(regval, EFM32_GPIO_IEN);
leave_critical_section(flags);
spin_unlock_irqrestore(&g_gpioirq_lock, flags);
#else
bitband_set_peripheral(EFM32_GPIO_IEN, (irq - EFM32_IRQ_EXTI0), 1);
#endif
Expand All @@ -301,11 +307,11 @@ void efm32_gpioirqdisable(int irq)
uint32_t bit;

bit = ((uint32_t)1 << (irq - EFM32_IRQ_EXTI0));
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_gpioirq_lock);
regval = getreg32(EFM32_GPIO_IEN);
regval &= ~bit;
putreg32(regval, EFM32_GPIO_IEN);
leave_critical_section(flags);
spin_unlock_irqrestore(&g_gpioirq_lock, flags);
#else
bitband_set_peripheral(EFM32_GPIO_IEN, (irq - EFM32_IRQ_EXTI0), 0);
#endif
Expand All @@ -332,11 +338,11 @@ void efm32_gpioirqclear(int irq)
uint32_t bit;

bit = ((uint32_t)1 << (irq - EFM32_IRQ_EXTI0));
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_gpioirq_lock);
regval = getreg32(EFM32_GPIO_IFC);
regval |= bit;
putreg32(regval, EFM32_GPIO_IFC);
leave_critical_section(flags);
spin_unlock_irqrestore(&g_gpioirq_lock, flags);
#else
bitband_set_peripheral(EFM32_GPIO_IFC, (irq - EFM32_IRQ_EXTI0), 1);
#endif
Expand Down
17 changes: 14 additions & 3 deletions arch/arm/src/efm32/efm32_irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include <sched.h>

#include <nuttx/irq.h>
#include <nuttx/spinlock.h>
#include <nuttx/arch.h>
#include <arch/armv7-m/nvicpri.h>

Expand Down Expand Up @@ -61,6 +62,14 @@
#define NVIC_ENA_OFFSET (0)
#define NVIC_CLRENA_OFFSET (NVIC_IRQ0_31_CLEAR - NVIC_IRQ0_31_ENABLE)

/****************************************************************************
* Private Data
****************************************************************************/

#if defined(CONFIG_DEBUG_IRQ_INFO)
static spinlock_t g_irq_lock = SP_UNLOCKED;
#endif

/****************************************************************************
* Private Function
****************************************************************************/
Expand All @@ -78,7 +87,8 @@ static void efm32_dumpnvic(const char *msg, int irq)
{
irqstate_t flags;

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_irq_lock);
sched_lock();

irqinfo("NVIC (%s, irq=%d):\n", msg, irq);
irqinfo(" INTCTRL: %08x VECTAB: %08x\n",
Expand Down Expand Up @@ -126,7 +136,8 @@ static void efm32_dumpnvic(const char *msg, int irq)
#endif
#endif

leave_critical_section(flags);
spin_unlock_irqrestore(&g_irq_lock, flags);
sched_unlock();
}
#else
# define efm32_dumpnvic(msg, irq)
Expand Down
17 changes: 14 additions & 3 deletions arch/arm/src/eoss3/eoss3_irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include <sched.h>

#include <nuttx/irq.h>
#include <nuttx/spinlock.h>
#include <nuttx/arch.h>
#include <arch/armv7-m/nvicpri.h>

Expand Down Expand Up @@ -60,6 +61,14 @@
#define NVIC_ENA_OFFSET (0)
#define NVIC_CLRENA_OFFSET (NVIC_IRQ0_31_CLEAR - NVIC_IRQ0_31_ENABLE)

/****************************************************************************
* Private Data
****************************************************************************/

#if defined(CONFIG_DEBUG_IRQ_INFO)
static spinlock_t g_irq_lock = SP_UNLOCKED;
#endif

/****************************************************************************
* Private Functions
****************************************************************************/
Expand All @@ -77,7 +86,8 @@ static void eoss3_dumpnvic(const char *msg, int irq)
{
irqstate_t flags;

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_irq_lock);
sched_lock();

irqinfo("NVIC (%s, irq=%d):\n", msg, irq);
irqinfo(" INTCTRL: %08x VECTAB: %08x\n",
Expand Down Expand Up @@ -107,7 +117,8 @@ static void eoss3_dumpnvic(const char *msg, int irq)
getreg32(NVIC_IRQ24_27_PRIORITY),
getreg32(NVIC_IRQ28_31_PRIORITY));

leave_critical_section(flags);
spin_unlock_irqrestore(&g_irq_lock, flags);
sched_unlock();
}
#else
# define eoss3_dumpnvic(msg, irq)
Expand Down
Loading

0 comments on commit 85c4971

Please sign in to comment.