Revert "use small lock in following files:"

This reverts commit bbaf1ff9fd.
This commit is contained in:
Xiang Xiao 2025-02-06 23:05:23 +08:00 committed by archer
parent 31e92f3bb5
commit 05ec313bc4
5 changed files with 42 additions and 68 deletions

View file

@ -44,7 +44,6 @@
#include <nuttx/i2c/i2c_master.h>
#include <nuttx/irq.h>
#include <nuttx/spinlock.h>
#include <arch/board/board.h>
#include "arm64_internal.h"
@ -167,7 +166,6 @@ struct a64_twi_priv_s
int refs; /* Reference count */
mutex_t lock; /* Mutual exclusion mutex */
spinlock_t spinlock; /* Spinlock */
sem_t waitsem; /* Wait for TWI transfer completion */
struct wdog_s timeout; /* Watchdog to recover from bus hangs */
volatile int result; /* The result of the transfer */
@ -290,7 +288,6 @@ static struct a64_twi_priv_s a64_twi0_priv =
.config = &a64_twi0_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
.waitsem = SEM_INITIALIZER(0),
.intstate = INTSTATE_IDLE,
.msgc = 0,
@ -327,7 +324,6 @@ static struct a64_twi_priv_s a64_twi1_priv =
.config = &a64_twi1_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
.waitsem = SEM_INITIALIZER(0),
.intstate = INTSTATE_IDLE,
.msgc = 0,
@ -364,7 +360,6 @@ static struct a64_twi_priv_s a64_twi2_priv =
.config = &a64_twi2_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
.waitsem = SEM_INITIALIZER(0),
.intstate = INTSTATE_IDLE,
.msgc = 0,
@ -401,7 +396,6 @@ static struct a64_twi_priv_s a64_rtwi_priv =
.config = &a64_rtwi_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
.waitsem = SEM_INITIALIZER(0),
.intstate = INTSTATE_IDLE,
.msgc = 0,
@ -1232,7 +1226,7 @@ static int a64_twi_isr_process(struct a64_twi_priv_s *priv)
*/
#ifdef CONFIG_I2C_POLLED
irqstate_t flags = spin_lock_irqsave(&priv->spinlock);
irqstate_t flags = enter_critical_section();
#endif
/* Transmit a byte */
@ -1241,7 +1235,7 @@ static int a64_twi_isr_process(struct a64_twi_priv_s *priv)
priv->dcnt--;
#ifdef CONFIG_I2C_POLLED
spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
#endif
break;
@ -1564,7 +1558,7 @@ static int twi_transfer(struct i2c_master_s *dev,
twi_setclock(priv, msgs->frequency);
flags = spin_lock_irqsave(&priv->spinlock);
flags = enter_critical_section();
/* Initiate the transfer. The rest will be handled from interrupt
* logic. Interrupts must be disabled to prevent re-entrance from the
@ -1618,7 +1612,7 @@ out:
/* Release the port for re-use by other clients */
spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
nxmutex_unlock(&priv->lock);
return ret;
}
@ -1826,7 +1820,7 @@ set_clk:
static void twi_hw_initialize(struct a64_twi_priv_s *priv)
{
irqstate_t flags = spin_lock_irqsave(&priv->spinlock);
irqstate_t flags = enter_critical_section();
i2cinfo("TWI%d Initializing\n", priv->config->twi);
@ -1862,7 +1856,7 @@ static void twi_hw_initialize(struct a64_twi_priv_s *priv)
twi_softreset(priv);
spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
}
/****************************************************************************

View file

@ -33,7 +33,6 @@
#include <nuttx/arch.h>
#include <nuttx/irq.h>
#include <nuttx/spinlock.h>
#include "arm64_internal.h"
#include "imx9_gpio.h"
@ -63,7 +62,6 @@ struct imx9_portisr_s
****************************************************************************/
static struct imx9_portisr_s g_isrtab[IMX9_GPIO_NPORTS];
static spinlock_t g_isrlock = SP_UNLOCKED;
/****************************************************************************
* Private Functions
@ -199,12 +197,12 @@ int imx9_gpioirq_attach(gpio_pinset_t pinset, xcpt_t isr, void *arg)
/* Atomically change the handler */
irqstate_t flags = spin_lock_irqsave(&g_isrlock);
irqstate_t flags = enter_critical_section();
g_isrtab[port].pins[pin].isr = isr;
g_isrtab[port].pins[pin].arg = arg;
spin_unlock_irqrestore(&g_isrlock, flags);
leave_critical_section(flags);
return OK;
}

View file

@ -38,7 +38,6 @@
#include <nuttx/arch.h>
#include <nuttx/irq.h>
#include <nuttx/spinlock.h>
#include <nuttx/clock.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
@ -207,7 +206,6 @@ struct imx9_lpi2c_priv_s
int refs; /* Reference count */
mutex_t lock; /* Mutual exclusion mutex */
spinlock_t spinlock; /* Spinlock */
#ifndef CONFIG_I2C_POLLED
sem_t sem_isr; /* Interrupt wait semaphore */
#endif
@ -366,7 +364,6 @@ static struct imx9_lpi2c_priv_s imx9_lpi2c1_priv =
.config = &imx9_lpi2c1_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
#ifndef CONFIG_I2C_POLLED
.sem_isr = SEM_INITIALIZER(0),
#endif
@ -415,7 +412,6 @@ static struct imx9_lpi2c_priv_s imx9_lpi2c2_priv =
.config = &imx9_lpi2c2_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
#ifndef CONFIG_I2C_POLLED
.sem_isr = SEM_INITIALIZER(0),
#endif
@ -464,7 +460,6 @@ static struct imx9_lpi2c_priv_s imx9_lpi2c3_priv =
.config = &imx9_lpi2c3_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
#ifndef CONFIG_I2C_POLLED
.sem_isr = SEM_INITIALIZER(0),
#endif
@ -513,7 +508,6 @@ static struct imx9_lpi2c_priv_s imx9_lpi2c4_priv =
.config = &imx9_lpi2c4_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
#ifndef CONFIG_I2C_POLLED
.sem_isr = SEM_INITIALIZER(0),
#endif
@ -562,7 +556,6 @@ static struct imx9_lpi2c_priv_s imx9_lpi2c5_priv =
.config = &imx9_lpi2c5_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
#ifndef CONFIG_I2C_POLLED
.sem_isr = SEM_INITIALIZER(0),
#endif
@ -611,7 +604,6 @@ static struct imx9_lpi2c_priv_s imx9_lpi2c6_priv =
.config = &imx9_lpi2c6_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
#ifndef CONFIG_I2C_POLLED
.sem_isr = SEM_INITIALIZER(0),
#endif
@ -660,7 +652,6 @@ static struct imx9_lpi2c_priv_s imx9_lpi2c7_priv =
.config = &imx9_lpi2c7_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
#ifndef CONFIG_I2C_POLLED
.sem_isr = SEM_INITIALIZER(0),
#endif
@ -709,7 +700,6 @@ static struct imx9_lpi2c_priv_s imx9_lpi2c8_priv =
.config = &imx9_lpi2c8_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
#ifndef CONFIG_I2C_POLLED
.sem_isr = SEM_INITIALIZER(0),
#endif
@ -1605,7 +1595,7 @@ static int imx9_lpi2c_isr_process(struct imx9_lpi2c_priv_s *priv)
*/
#ifdef CONFIG_I2C_POLLED
irqstate_t flags = spin_lock_irqsave(&priv->spinlock);
irqstate_t flags = enter_critical_section();
#endif
/* Receive a byte */
@ -1620,7 +1610,7 @@ static int imx9_lpi2c_isr_process(struct imx9_lpi2c_priv_s *priv)
}
#ifdef CONFIG_I2C_POLLED
spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
#endif
}
@ -2386,7 +2376,7 @@ struct i2c_master_s *imx9_i2cbus_initialize(int port)
* power-up hardware and configure GPIOs.
*/
flags = spin_lock_irqsave(&priv->spinlock);
flags = enter_critical_section();
if ((volatile int)priv->refs++ == 0)
{
@ -2407,7 +2397,7 @@ struct i2c_master_s *imx9_i2cbus_initialize(int port)
#endif
}
spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
return (struct i2c_master_s *)priv;
}
@ -2434,7 +2424,7 @@ int imx9_i2cbus_uninitialize(struct i2c_master_s *dev)
return ERROR;
}
flags = spin_lock_irqsave(&priv->spinlock);
flags = enter_critical_section();
if (--priv->refs > 0)
{
@ -2442,7 +2432,7 @@ int imx9_i2cbus_uninitialize(struct i2c_master_s *dev)
return OK;
}
spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
/* Disable power and other HW resource (GPIO's) */

View file

@ -42,7 +42,6 @@
#include <nuttx/usb/usbdev_trace.h>
#include <nuttx/irq.h>
#include <nuttx/spinlock.h>
#include <arch/barriers.h>
#include <arch/board/board.h>
@ -362,7 +361,6 @@ struct imx9_ep_s
*/
struct usbdev_ep_s ep; /* Standard endpoint structure */
spinlock_t spinlock; /* Spinlock */
/* IMX9XX-specific fields */
@ -393,7 +391,6 @@ struct imx9_usb_s
*/
struct usbdev_s usbdev;
spinlock_t spinlock; /* Spinlock */
/* The bound device class driver */
@ -2301,7 +2298,7 @@ static int imx9_epdisable(struct usbdev_ep_s *ep)
usbtrace(TRACE_EPDISABLE, privep->epphy);
flags = spin_lock_irqsave(&privep->spinlock);
flags = enter_critical_section();
/* Disable Endpoint */
@ -2320,7 +2317,7 @@ static int imx9_epdisable(struct usbdev_ep_s *ep)
/* Cancel any ongoing activity */
spin_unlock_irqrestore(&privep->spinlock, flags);
imx9_cancelrequests(privep, -ESHUTDOWN);
leave_critical_section(flags);
return OK;
@ -2479,7 +2476,7 @@ static int imx9_epsubmit(struct usbdev_ep_s *ep,
/* Disable Interrupts */
flags = spin_lock_irqsave(&privep->spinlock);
flags = enter_critical_section();
/* If we are stalled, then drop all requests on the floor */
@ -2506,7 +2503,7 @@ static int imx9_epsubmit(struct usbdev_ep_s *ep,
}
}
spin_unlock_irqrestore(&privep->spinlock, flags);
leave_critical_section(flags);
return ret;
}
@ -2534,7 +2531,7 @@ static int imx9_epcancel(struct usbdev_ep_s *ep,
usbtrace(TRACE_EPCANCEL, privep->epphy);
flags = spin_lock_irqsave(&privep->spinlock);
flags = enter_critical_section();
/* FIXME: if the request is the first, then we need to flush the EP
* otherwise just remove it from the list
@ -2543,7 +2540,7 @@ static int imx9_epcancel(struct usbdev_ep_s *ep,
*/
imx9_cancelrequests(privep, -ESHUTDOWN);
spin_unlock_irqrestore(&privep->spinlock, flags);
leave_critical_section(flags);
return OK;
}
@ -2563,7 +2560,7 @@ static int imx9_epstall(struct usbdev_ep_s *ep, bool resume)
/* STALL or RESUME the endpoint */
flags = spin_lock_irqsave(&privep->spinlock);
flags = enter_critical_section();
usbtrace(resume ? TRACE_EPRESUME : TRACE_EPSTALL, privep->epphy);
uint32_t offs = IMX9_USBDEV_ENDPTCTRL_OFFSET(privep->epphy >> 1);
@ -2587,7 +2584,7 @@ static int imx9_epstall(struct usbdev_ep_s *ep, bool resume)
imx9_modifyreg(priv, offs, 0, ctrl_xs);
}
spin_unlock_irqrestore(&privep->spinlock, flags);
leave_critical_section(flags);
return OK;
}
@ -2691,7 +2688,7 @@ static struct usbdev_ep_s *imx9_allocep(struct usbdev_s *dev,
{
/* Yes.. now see if any of the request endpoints are available */
flags = spin_lock_irqsave(&priv->spinlock);
flags = enter_critical_section();
epset &= priv->epavail;
if (epset)
{
@ -2707,7 +2704,7 @@ static struct usbdev_ep_s *imx9_allocep(struct usbdev_s *dev,
/* Mark endpoint no longer available */
priv->epavail &= ~bit;
spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
/* And return the pointer to the standard endpoint
* structure
@ -2720,7 +2717,7 @@ static struct usbdev_ep_s *imx9_allocep(struct usbdev_s *dev,
/* Shouldn't get here */
}
spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
}
usbtrace(TRACE_DEVERROR(IMX9_TRACEERR_NOEP), (uint16_t)eplog);
@ -2740,8 +2737,7 @@ static void imx9_freeep(struct usbdev_s *dev,
{
struct imx9_usb_s *priv = (struct imx9_usb_s *)dev;
struct imx9_ep_s *privep = (struct imx9_ep_s *)ep;
irqstate_t flags_1;
irqstate_t flags_2;
irqstate_t flags;
usbtrace(TRACE_DEVFREEEP, (uint16_t)privep->epphy);
@ -2749,11 +2745,9 @@ static void imx9_freeep(struct usbdev_s *dev,
{
/* Mark the endpoint as available */
flags_1 = spin_lock_irqsave(&priv->spinlock);
flags_2 = spin_lock_irqsave(&privep->spinlock);
flags = enter_critical_section();
priv->epavail |= (1 << privep->epphy);
spin_unlock_irqrestore(&privep->spinlock, flags_2);
spin_unlock_irqrestore(&priv->spinlock, flags_1);
leave_critical_section(flags);
}
}
@ -2802,9 +2796,9 @@ static int imx9_wakeup(struct usbdev_s *dev)
usbtrace(TRACE_DEVWAKEUP, 0);
flags = spin_lock_irqsave(&priv->spinlock);
flags = enter_critical_section();
imx9_modifyreg(priv, IMX9_USBDEV_PORTSC1_OFFSET, 0, USBDEV_PRTSC1_FPR);
spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
return OK;
}
@ -2848,7 +2842,7 @@ static int imx9_pullup(struct usbdev_s *dev, bool enable)
usbtrace(TRACE_DEVPULLUP, (uint16_t)enable);
irqstate_t flags = spin_lock_irqsave(&priv->spinlock);
irqstate_t flags = enter_critical_section();
if (enable)
{
imx9_modifyreg(priv, IMX9_USBDEV_USBCMD_OFFSET, 0, USBDEV_USBCMD_RS);
@ -2865,7 +2859,7 @@ static int imx9_pullup(struct usbdev_s *dev, bool enable)
imx9_modifyreg(priv, IMX9_USBDEV_USBCMD_OFFSET, USBDEV_USBCMD_RS, 0);
}
spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
return OK;
}
@ -2934,7 +2928,7 @@ void arm64_usbinitialize(void)
int i;
irqstate_t flags;
flags = spin_lock_irqsave(&priv->spinlock);
flags = enter_critical_section();
/* Initialize the device state structure */
@ -3022,7 +3016,7 @@ void arm64_usbinitialize(void)
irq_attach(IMX9_IRQ_USB1 + priv->id, imx9_usbinterrupt, priv);
up_enable_irq(IMX9_IRQ_USB1 + priv->id);
spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
/* Reset/Re-initialize the USB hardware */
@ -3046,7 +3040,7 @@ void arm64_usbuninitialize(void)
usbdev_unregister(priv->driver);
}
flags = spin_lock_irqsave(&priv->spinlock);
flags = enter_critical_section();
/* Disconnect device */
@ -3073,7 +3067,7 @@ void arm64_usbuninitialize(void)
imx9_ccm_gate_on(CCM_LPCG_USB_CONTROLLER, false);
spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
}
/****************************************************************************

View file

@ -43,7 +43,6 @@
#include <nuttx/mmcsd.h>
#include <nuttx/irq.h>
#include <nuttx/spinlock.h>
#include <arch/board/board.h>
#include "chip.h"
@ -178,7 +177,6 @@
struct imx9_dev_s
{
struct sdio_dev_s dev; /* Standard, base SDIO interface */
spinlock_t spinlock; /* Spinlock */
/* Imx9-specific extensions */
@ -564,7 +562,7 @@ static void imx9_configwaitints(struct imx9_dev_s *priv, uint32_t waitints,
* operation.
*/
flags = spin_lock_irqsave(&priv->spinlock);
flags = enter_critical_section();
priv->waitevents = waitevents;
priv->wkupevent = wkupevent;
priv->waitints = waitints;
@ -574,7 +572,7 @@ static void imx9_configwaitints(struct imx9_dev_s *priv, uint32_t waitints,
#endif
putreg32(priv->xfrints | priv->waitints | priv->cintints,
priv->addr + IMX9_USDHC_IRQSIGEN_OFFSET);
spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
}
/****************************************************************************
@ -596,11 +594,11 @@ static void imx9_configxfrints(struct imx9_dev_s *priv, uint32_t xfrints)
{
irqstate_t flags;
flags = spin_lock_irqsave(&priv->spinlock);
flags = enter_critical_section();
priv->xfrints = xfrints;
putreg32(priv->xfrints | priv->waitints | priv->cintints,
priv->addr + IMX9_USDHC_IRQSIGEN_OFFSET);
spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
}
/****************************************************************************
@ -3291,11 +3289,11 @@ void imx9_usdhc_set_sdio_card_isr(struct sdio_dev_s *dev,
}
#endif
flags = spin_lock_irqsave(&priv->spinlock);
flags = enter_critical_section();
regval = getreg32(priv->addr + IMX9_USDHC_IRQSIGEN_OFFSET);
regval = (regval & ~USDHC_INT_CINT) | priv->cintints;
putreg32(regval, priv->addr + IMX9_USDHC_IRQSIGEN_OFFSET);
spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
}
/****************************************************************************