Commit 487e0a60 authored by Jens Taprogge's avatar Jens Taprogge Committed by Greg Kroah-Hartman

Staging: ipack/bridges/tpci200: Protect device registers with spinlock.

Some of the device registers are accessed from both interrupt and
non-interrupt context.  To ensure proper read-modify-write modification
of these registers we can not use the  "global" tpci200 mutex.  Instead
a spin-lock is used.
Signed-off-by: default avatarJens Taprogge <jens.taprogge@taprogge.org>
Signed-off-by: default avatarSamuel Iglesias Gonsalvez <siglesias@igalia.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent b8d61d49
...@@ -53,30 +53,22 @@ static struct tpci200_board *check_slot(struct ipack_device *dev) ...@@ -53,30 +53,22 @@ static struct tpci200_board *check_slot(struct ipack_device *dev)
return tpci200; return tpci200;
} }
static void __tpci200_clear_mask(__le16 __iomem *addr, u16 mask)
{
iowrite16(ioread16(addr) & (~mask), addr);
}
static void tpci200_clear_mask(struct tpci200_board *tpci200, static void tpci200_clear_mask(struct tpci200_board *tpci200,
__le16 __iomem *addr, u16 mask) __le16 __iomem *addr, u16 mask)
{ {
mutex_lock(&tpci200->mutex); unsigned long flags;
__tpci200_clear_mask(addr, mask); spin_lock_irqsave(&tpci200->regs_lock, flags);
mutex_unlock(&tpci200->mutex); iowrite16(ioread16(addr) & (~mask), addr);
} spin_unlock_irqrestore(&tpci200->regs_lock, flags);
static void __tpci200_set_mask(__le16 __iomem *addr, u16 mask)
{
iowrite16(ioread16(addr) | mask, addr);
} }
static void tpci200_set_mask(struct tpci200_board *tpci200, static void tpci200_set_mask(struct tpci200_board *tpci200,
__le16 __iomem *addr, u16 mask) __le16 __iomem *addr, u16 mask)
{ {
mutex_lock(&tpci200->mutex); unsigned long flags;
__tpci200_set_mask(addr, mask); spin_lock_irqsave(&tpci200->regs_lock, flags);
mutex_unlock(&tpci200->mutex); iowrite16(ioread16(addr) | mask, addr);
spin_unlock_irqrestore(&tpci200->regs_lock, flags);
} }
static void tpci200_unregister(struct tpci200_board *tpci200) static void tpci200_unregister(struct tpci200_board *tpci200)
...@@ -143,7 +135,7 @@ static irqreturn_t tpci200_interrupt(int irq, void *dev_id) ...@@ -143,7 +135,7 @@ static irqreturn_t tpci200_interrupt(int irq, void *dev_id)
dev_info(&tpci200->info->pdev->dev, dev_info(&tpci200->info->pdev->dev,
"No registered ISR for slot [%d:%d]!. IRQ will be disabled.\n", "No registered ISR for slot [%d:%d]!. IRQ will be disabled.\n",
tpci200->number, i); tpci200->number, i);
__tpci200_clear_mask( tpci200_clear_mask(tpci200,
&tpci200->info->interface_regs->control[i], &tpci200->info->interface_regs->control[i],
TPCI200_INT0_EN | TPCI200_INT1_EN); TPCI200_INT0_EN | TPCI200_INT1_EN);
} }
...@@ -213,6 +205,9 @@ static int tpci200_register(struct tpci200_board *tpci200) ...@@ -213,6 +205,9 @@ static int tpci200_register(struct tpci200_board *tpci200)
TPCI200_MEM8_SPACE_BAR), TPCI200_MEM8_SPACE_BAR),
TPCI200_MEM8_SIZE); TPCI200_MEM8_SIZE);
/* Initialize lock that protects interface_regs */
spin_lock_init(&tpci200->regs_lock);
ioidint_base = pci_resource_start(tpci200->info->pdev, ioidint_base = pci_resource_start(tpci200->info->pdev,
TPCI200_IO_ID_INT_SPACES_BAR); TPCI200_IO_ID_INT_SPACES_BAR);
mem_base = pci_resource_start(tpci200->info->pdev, mem_base = pci_resource_start(tpci200->info->pdev,
...@@ -272,7 +267,7 @@ static int tpci200_register(struct tpci200_board *tpci200) ...@@ -272,7 +267,7 @@ static int tpci200_register(struct tpci200_board *tpci200)
static int __tpci200_request_irq(struct tpci200_board *tpci200, static int __tpci200_request_irq(struct tpci200_board *tpci200,
struct ipack_device *dev) struct ipack_device *dev)
{ {
__tpci200_set_mask( tpci200_set_mask(tpci200,
&tpci200->info->interface_regs->control[dev->slot], &tpci200->info->interface_regs->control[dev->slot],
TPCI200_INT0_EN | TPCI200_INT1_EN); TPCI200_INT0_EN | TPCI200_INT1_EN);
return 0; return 0;
...@@ -281,7 +276,7 @@ static int __tpci200_request_irq(struct tpci200_board *tpci200, ...@@ -281,7 +276,7 @@ static int __tpci200_request_irq(struct tpci200_board *tpci200,
static void __tpci200_free_irq(struct tpci200_board *tpci200, static void __tpci200_free_irq(struct tpci200_board *tpci200,
struct ipack_device *dev) struct ipack_device *dev)
{ {
__tpci200_clear_mask( tpci200_clear_mask(tpci200,
&tpci200->info->interface_regs->control[dev->slot], &tpci200->info->interface_regs->control[dev->slot],
TPCI200_INT0_EN | TPCI200_INT1_EN); TPCI200_INT0_EN | TPCI200_INT1_EN);
} }
......
...@@ -163,6 +163,7 @@ struct tpci200_infos { ...@@ -163,6 +163,7 @@ struct tpci200_infos {
struct tpci200_board { struct tpci200_board {
unsigned int number; unsigned int number;
struct mutex mutex; struct mutex mutex;
spinlock_t regs_lock;
struct tpci200_slot *slots; struct tpci200_slot *slots;
struct tpci200_infos *info; struct tpci200_infos *info;
}; };
......
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