mirror of
https://github.com/apache/nuttx.git
synced 2026-05-29 04:19:37 +08:00
Revert "Use small lock to protect usbdev and endpoint in sim."
This reverts commit 4558db18e4.
This commit is contained in:
@@ -36,11 +36,9 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
#include <sched.h>
|
|
||||||
|
|
||||||
#include <nuttx/arch.h>
|
#include <nuttx/arch.h>
|
||||||
#include <nuttx/kmalloc.h>
|
#include <nuttx/kmalloc.h>
|
||||||
#include <nuttx/spinlock.h>
|
|
||||||
#include <nuttx/usb/usb.h>
|
#include <nuttx/usb/usb.h>
|
||||||
#include <nuttx/usb/usbdev.h>
|
#include <nuttx/usb/usbdev.h>
|
||||||
#include <nuttx/usb/usbdev_trace.h>
|
#include <nuttx/usb/usbdev_trace.h>
|
||||||
@@ -158,7 +156,6 @@ struct sim_usbdev_s
|
|||||||
uint8_t selfpowered:1; /* 1: Device is self powered */
|
uint8_t selfpowered:1; /* 1: Device is self powered */
|
||||||
uint16_t epavail; /* Bitset of available endpoints */
|
uint16_t epavail; /* Bitset of available endpoints */
|
||||||
struct sim_ep_s eps[SIM_USB_EPNUM];
|
struct sim_ep_s eps[SIM_USB_EPNUM];
|
||||||
spinlock_t lock; /* Spinlock */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sim_req_s
|
struct sim_req_s
|
||||||
@@ -350,9 +347,9 @@ static void sim_reqcomplete(struct sim_ep_s *privep, int16_t result)
|
|||||||
|
|
||||||
/* Remove the completed request at the head of the endpoint request list */
|
/* Remove the completed request at the head of the endpoint request list */
|
||||||
|
|
||||||
flags = spin_lock_irqsave(&privep->dev->lock);
|
flags = enter_critical_section();
|
||||||
privreq = sim_rqdequeue(&privep->reqq);
|
privreq = sim_rqdequeue(&privep->reqq);
|
||||||
spin_unlock_irqrestore(&privep->dev->lock, flags);
|
leave_critical_section(flags);
|
||||||
|
|
||||||
if (privreq)
|
if (privreq)
|
||||||
{
|
{
|
||||||
@@ -643,8 +640,7 @@ static int sim_ep_disable(struct usbdev_ep_s *ep)
|
|||||||
|
|
||||||
/* Cancel any ongoing activity */
|
/* Cancel any ongoing activity */
|
||||||
|
|
||||||
flags = spin_lock_irqsave(&privep->dev->lock);
|
flags = enter_critical_section();
|
||||||
sched_lock();
|
|
||||||
|
|
||||||
/* Disable TX; disable RX */
|
/* Disable TX; disable RX */
|
||||||
|
|
||||||
@@ -652,8 +648,7 @@ static int sim_ep_disable(struct usbdev_ep_s *ep)
|
|||||||
|
|
||||||
privep->epstate = SIM_EPSTATE_DISABLED;
|
privep->epstate = SIM_EPSTATE_DISABLED;
|
||||||
|
|
||||||
spin_unlock_irqrestore(&privep->dev->lock, flags);
|
leave_critical_section(flags);
|
||||||
sched_unlock();
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -708,16 +703,14 @@ static int sim_ep_stall(struct usbdev_ep_s *ep, bool resume)
|
|||||||
|
|
||||||
/* STALL or RESUME the endpoint */
|
/* STALL or RESUME the endpoint */
|
||||||
|
|
||||||
flags = spin_lock_irqsave(&privep->dev->lock);
|
flags = enter_critical_section();
|
||||||
sched_lock();
|
|
||||||
usbtrace(resume ? TRACE_EPRESUME : TRACE_EPSTALL, epno);
|
usbtrace(resume ? TRACE_EPRESUME : TRACE_EPSTALL, epno);
|
||||||
|
|
||||||
ret = host_usbdev_epstall(epno, resume);
|
ret = host_usbdev_epstall(epno, resume);
|
||||||
|
|
||||||
privep->epstate = SIM_EPSTATE_STALLED;
|
privep->epstate = SIM_EPSTATE_STALLED;
|
||||||
|
|
||||||
spin_unlock_irqrestore(&privep->dev->lock, flags);
|
leave_critical_section(flags);
|
||||||
sched_unlock();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -745,14 +738,12 @@ static int sim_ep_submit(struct usbdev_ep_s *ep, struct usbdev_req_s *req)
|
|||||||
epno = USB_EPNO(ep->eplog);
|
epno = USB_EPNO(ep->eplog);
|
||||||
req->result = -EINPROGRESS;
|
req->result = -EINPROGRESS;
|
||||||
req->xfrd = 0;
|
req->xfrd = 0;
|
||||||
flags = spin_lock_irqsave(&priv->lock);
|
flags = enter_critical_section();
|
||||||
sched_lock();
|
|
||||||
|
|
||||||
if (privep->epstate == SIM_EPSTATE_STALLED)
|
if (privep->epstate == SIM_EPSTATE_STALLED)
|
||||||
{
|
{
|
||||||
sim_reqabort(privep, privreq, -EBUSY);
|
sim_reqabort(privep, privreq, -EBUSY);
|
||||||
spin_unlock_irqrestore(&priv->lock, flags);
|
leave_critical_section(flags);
|
||||||
sched_unlock();
|
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -787,8 +778,7 @@ static int sim_ep_submit(struct usbdev_ep_s *ep, struct usbdev_req_s *req)
|
|||||||
sim_rqenqueue(&privep->reqq, privreq);
|
sim_rqenqueue(&privep->reqq, privreq);
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_unlock_irqrestore(&priv->lock, flags);
|
leave_critical_section(flags);
|
||||||
sched_unlock();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -798,14 +788,13 @@ static int sim_ep_submit(struct usbdev_ep_s *ep, struct usbdev_req_s *req)
|
|||||||
|
|
||||||
static int sim_ep_cancel(struct usbdev_ep_s *ep, struct usbdev_req_s *req)
|
static int sim_ep_cancel(struct usbdev_ep_s *ep, struct usbdev_req_s *req)
|
||||||
{
|
{
|
||||||
struct sim_ep_s *privep = (struct sim_ep_s *)ep;
|
|
||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
|
|
||||||
usbtrace(TRACE_EPCANCEL, USB_EPNO(ep->eplog));
|
usbtrace(TRACE_EPCANCEL, USB_EPNO(ep->eplog));
|
||||||
|
|
||||||
flags = spin_lock_irqsave(&privep->dev->lock);
|
flags = enter_critical_section();
|
||||||
host_usbdev_epcancel(USB_EPNO(ep->eplog));
|
host_usbdev_epcancel(USB_EPNO(ep->eplog));
|
||||||
spin_unlock_irqrestore(&privep->dev->lock, flags);
|
leave_critical_section(flags);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -829,7 +818,7 @@ static struct sim_ep_s *sim_ep_reserve(struct sim_usbdev_s *priv,
|
|||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
int epndx = 0;
|
int epndx = 0;
|
||||||
|
|
||||||
flags = spin_lock_irqsave(&priv->lock);
|
flags = enter_critical_section();
|
||||||
epset &= priv->epavail;
|
epset &= priv->epavail;
|
||||||
if (epset)
|
if (epset)
|
||||||
{
|
{
|
||||||
@@ -854,7 +843,7 @@ static struct sim_ep_s *sim_ep_reserve(struct sim_usbdev_s *priv,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_unlock_irqrestore(&priv->lock, flags);
|
leave_critical_section(flags);
|
||||||
return privep;
|
return privep;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -871,9 +860,9 @@ static struct sim_ep_s *sim_ep_reserve(struct sim_usbdev_s *priv,
|
|||||||
static void sim_ep_unreserve(struct sim_usbdev_s *priv,
|
static void sim_ep_unreserve(struct sim_usbdev_s *priv,
|
||||||
struct sim_ep_s *privep)
|
struct sim_ep_s *privep)
|
||||||
{
|
{
|
||||||
irqstate_t flags = spin_lock_irqsave(&priv->lock);
|
irqstate_t flags = enter_critical_section();
|
||||||
priv->epavail |= SIM_EP_BIT(USB_EPNO(privep->ep.eplog));
|
priv->epavail |= SIM_EP_BIT(USB_EPNO(privep->ep.eplog));
|
||||||
spin_unlock_irqrestore(&priv->lock, flags);
|
leave_critical_section(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -1015,14 +1004,13 @@ static int sim_usbdev_selfpowered(struct usbdev_s *dev, bool selfpowered)
|
|||||||
|
|
||||||
static int sim_usbdev_pullup(struct usbdev_s *dev, bool enable)
|
static int sim_usbdev_pullup(struct usbdev_s *dev, bool enable)
|
||||||
{
|
{
|
||||||
struct sim_usbdev_s *priv = (struct sim_usbdev_s *)dev;
|
|
||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
|
|
||||||
usbtrace(TRACE_DEVPULLUP, (uint16_t)enable);
|
usbtrace(TRACE_DEVPULLUP, (uint16_t)enable);
|
||||||
|
|
||||||
flags = spin_lock_irqsave(&priv->lock);
|
flags = enter_critical_section();
|
||||||
host_usbdev_pullup(enable);
|
host_usbdev_pullup(enable);
|
||||||
spin_unlock_irqrestore(&priv->lock, flags);
|
leave_critical_section(flags);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1071,9 +1059,6 @@ static void sim_usbdev_devinit(struct sim_usbdev_s *dev)
|
|||||||
|
|
||||||
void sim_usbdev_initialize(void)
|
void sim_usbdev_initialize(void)
|
||||||
{
|
{
|
||||||
/* Initialize driver lock */
|
|
||||||
|
|
||||||
spin_lock_init(&g_sim_usbdev.lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -1147,9 +1132,9 @@ int usbdev_unregister(struct usbdevclass_driver_s *driver)
|
|||||||
* canceled while the class driver is still bound.
|
* canceled while the class driver is still bound.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
flags = spin_lock_irqsave(&priv->lock);
|
flags = enter_critical_section();
|
||||||
CLASS_DISCONNECT(driver, &priv->usbdev);
|
CLASS_DISCONNECT(driver, &priv->usbdev);
|
||||||
spin_unlock_irqrestore(&priv->lock, flags);
|
leave_critical_section(flags);
|
||||||
|
|
||||||
/* Unbind the class driver */
|
/* Unbind the class driver */
|
||||||
|
|
||||||
@@ -1157,7 +1142,7 @@ int usbdev_unregister(struct usbdevclass_driver_s *driver)
|
|||||||
|
|
||||||
/* Disable USB controller interrupts */
|
/* Disable USB controller interrupts */
|
||||||
|
|
||||||
flags = spin_lock_irqsave(&priv->lock);
|
flags = enter_critical_section();
|
||||||
|
|
||||||
/* Disconnect device */
|
/* Disconnect device */
|
||||||
|
|
||||||
@@ -1167,7 +1152,7 @@ int usbdev_unregister(struct usbdevclass_driver_s *driver)
|
|||||||
/* Unhook the driver */
|
/* Unhook the driver */
|
||||||
|
|
||||||
priv->driver = NULL;
|
priv->driver = NULL;
|
||||||
spin_unlock_irqrestore(&priv->lock, flags);
|
leave_critical_section(flags);
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user