Commit 91cac0b0 authored by Dmitry Torokhov's avatar Dmitry Torokhov

Input: add serio_pause_rx and serio_continue_rx so drivers can protect

       their critical sections from port's interrupt handler
Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
parent a3938700
...@@ -541,15 +541,14 @@ void serio_unregister_driver(struct serio_driver *drv) ...@@ -541,15 +541,14 @@ void serio_unregister_driver(struct serio_driver *drv)
/* called from serio_driver->connect/disconnect methods under serio_sem */ /* called from serio_driver->connect/disconnect methods under serio_sem */
int serio_open(struct serio *serio, struct serio_driver *drv) int serio_open(struct serio *serio, struct serio_driver *drv)
{ {
unsigned long flags; serio_pause_rx(serio);
spin_lock_irqsave(&serio->lock, flags);
serio->drv = drv; serio->drv = drv;
spin_unlock_irqrestore(&serio->lock, flags); serio_continue_rx(serio);
if (serio->open && serio->open(serio)) { if (serio->open && serio->open(serio)) {
spin_lock_irqsave(&serio->lock, flags); serio_pause_rx(serio);
serio->drv = NULL; serio->drv = NULL;
spin_unlock_irqrestore(&serio->lock, flags); serio_continue_rx(serio);
return -1; return -1;
} }
return 0; return 0;
...@@ -558,13 +557,12 @@ int serio_open(struct serio *serio, struct serio_driver *drv) ...@@ -558,13 +557,12 @@ int serio_open(struct serio *serio, struct serio_driver *drv)
/* called from serio_driver->connect/disconnect methods under serio_sem */ /* called from serio_driver->connect/disconnect methods under serio_sem */
void serio_close(struct serio *serio) void serio_close(struct serio *serio)
{ {
unsigned long flags;
if (serio->close) if (serio->close)
serio->close(serio); serio->close(serio);
spin_lock_irqsave(&serio->lock, flags);
serio_pause_rx(serio);
serio->drv = NULL; serio->drv = NULL;
spin_unlock_irqrestore(&serio->lock, flags); serio_continue_rx(serio);
} }
irqreturn_t serio_interrupt(struct serio *serio, irqreturn_t serio_interrupt(struct serio *serio,
......
...@@ -35,7 +35,7 @@ struct serio { ...@@ -35,7 +35,7 @@ struct serio {
unsigned long type; unsigned long type;
unsigned long event; unsigned long event;
spinlock_t lock; spinlock_t lock; /* protects critical sections from port's interrupt handler */
int (*write)(struct serio *, unsigned char); int (*write)(struct serio *, unsigned char);
int (*open)(struct serio *); int (*open)(struct serio *);
...@@ -43,7 +43,7 @@ struct serio { ...@@ -43,7 +43,7 @@ struct serio {
struct serio *parent, *child; struct serio *parent, *child;
struct serio_driver *drv; /* Accessed from interrupt, writes must be protected by serio_lock */ struct serio_driver *drv; /* accessed from interrupt, must be protected by serio->lock */
struct device dev; struct device dev;
...@@ -81,6 +81,7 @@ void serio_register_port(struct serio *serio); ...@@ -81,6 +81,7 @@ void serio_register_port(struct serio *serio);
void serio_register_port_delayed(struct serio *serio); void serio_register_port_delayed(struct serio *serio);
void serio_unregister_port(struct serio *serio); void serio_unregister_port(struct serio *serio);
void serio_unregister_port_delayed(struct serio *serio); void serio_unregister_port_delayed(struct serio *serio);
void serio_register_driver(struct serio_driver *drv); void serio_register_driver(struct serio_driver *drv);
void serio_unregister_driver(struct serio_driver *drv); void serio_unregister_driver(struct serio_driver *drv);
...@@ -104,6 +105,22 @@ static __inline__ void serio_cleanup(struct serio *serio) ...@@ -104,6 +105,22 @@ static __inline__ void serio_cleanup(struct serio *serio)
serio->drv->cleanup(serio); serio->drv->cleanup(serio);
} }
/*
* Use the following fucntions to protect critical sections in
* driver code from port's interrupt handler
*/
static __inline__ void serio_pause_rx(struct serio *serio)
{
spin_lock_irq(&serio->lock);
}
static __inline__ void serio_continue_rx(struct serio *serio)
{
spin_unlock_irq(&serio->lock);
}
#endif #endif
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment