Skip to content

Commit

Permalink
litex_serial: use small lock in arch/risc-v/src/litex/litex_serial.c
Browse files Browse the repository at this point in the history
reason:
We hope to remove all instances of spin_lock_irqsave(NULL).

Signed-off-by: hujun5 <[email protected]>
  • Loading branch information
hujun260 authored and xiaoxiang781216 committed Dec 10, 2024
1 parent 7e5088f commit 3063f2c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions arch/risc-v/src/litex/litex_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ struct up_dev_s
uintptr_t uartbase; /* Base address of UART registers */
uint32_t baud; /* Configured baud */
uint8_t irq; /* IRQ associated with this UART */
spinlock_t lock; /* Spinlock */
uint8_t im; /* Interrupt mask state */
};

Expand Down Expand Up @@ -190,6 +191,7 @@ static struct up_dev_s g_uart0priv =
.uartbase = LITEX_UART0_BASE,
.baud = CONFIG_UART0_BAUD,
.irq = LITEX_IRQ_UART0,
.lock = SP_UNLOCKED,
};

static uart_dev_t g_uart0port =
Expand Down Expand Up @@ -240,15 +242,15 @@ static void up_serialout(struct up_dev_s *priv, int offset, uint32_t value)

static void up_restoreuartint(struct up_dev_s *priv, uint8_t im)
{
irqstate_t flags = spin_lock_irqsave(NULL);
irqstate_t flags = spin_lock_irqsave(&priv->lock);

priv->im = im;

putreg8(getreg8(LITEX_CONSOLE_BASE + UART_EV_PENDING_OFFSET), \
LITEX_CONSOLE_BASE + UART_EV_PENDING_OFFSET);
up_serialout(priv, UART_EV_ENABLE_OFFSET, im);

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&priv->lock, flags);
}

/****************************************************************************
Expand All @@ -257,7 +259,7 @@ static void up_restoreuartint(struct up_dev_s *priv, uint8_t im)

static void up_disableuartint(struct up_dev_s *priv, uint8_t *im)
{
irqstate_t flags = spin_lock_irqsave(NULL);
irqstate_t flags = spin_lock_irqsave(&priv->lock);

/* Return the current interrupt mask value */

Expand All @@ -274,7 +276,7 @@ static void up_disableuartint(struct up_dev_s *priv, uint8_t *im)
LITEX_CONSOLE_BASE + UART_EV_PENDING_OFFSET);
up_serialout(priv, UART_EV_ENABLE_OFFSET, 0);

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&priv->lock, flags);
}

/****************************************************************************
Expand Down

0 comments on commit 3063f2c

Please sign in to comment.