Skip to content

Commit

Permalink
macintosh/via-macii: Simplify locking
Browse files Browse the repository at this point in the history
Modifying the request queue or changing the current state requires
mutual exclusion. Use local_irq_disable() consistently for this
rather than disabling the ADB interrupt. This simplifies the locking
scheme and brings via-macii into line with the other ADB drivers.

Tested-by: Stan Johnson <userm57@yahoo.com>
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
  • Loading branch information
Finn Thain authored and Michael Ellerman committed Oct 8, 2018
1 parent 5f93d70 commit 5ce6185
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions drivers/macintosh/via-macii.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,22 +216,23 @@ static void macii_queue_poll(void)
static int macii_send_request(struct adb_request *req, int sync)
{
int err;
unsigned long flags;

local_irq_save(flags);
err = macii_write(req);
local_irq_restore(flags);
if (err)
return err;

if (!err && sync)
if (sync)
while (!req->complete)
macii_poll();

return err;
return 0;
}

/* Send an ADB request (append to request queue) */
static int macii_write(struct adb_request *req)
{
unsigned long flags;

if (req->nbytes < 2 || req->data[0] != ADB_PACKET || req->nbytes > 15) {
req->complete = 1;
return -EINVAL;
Expand All @@ -242,6 +243,8 @@ static int macii_write(struct adb_request *req)
req->complete = 0;
req->reply_len = 0;

local_irq_save(flags);

if (current_req != NULL) {
last_req->next = req;
last_req = req;
Expand All @@ -250,6 +253,9 @@ static int macii_write(struct adb_request *req)
last_req = req;
if (macii_state == idle) macii_start();
}

local_irq_restore(flags);

return 0;
}

Expand Down Expand Up @@ -293,9 +299,7 @@ static inline int need_autopoll(void) {
/* Prod the chip without interrupts */
static void macii_poll(void)
{
disable_irq(IRQ_MAC_ADB);
macii_interrupt(0, NULL);
enable_irq(IRQ_MAC_ADB);
}

/* Reset the bus */
Expand Down Expand Up @@ -358,13 +362,18 @@ static irqreturn_t macii_interrupt(int irq, void *arg)
{
int x;
struct adb_request *req;
unsigned long flags;

local_irq_save(flags);

if (!arg) {
/* Clear the SR IRQ flag when polling. */
if (via[IFR] & SR_INT)
via[IFR] = SR_INT;
else
else {
local_irq_restore(flags);
return IRQ_NONE;
}
}

last_status = status;
Expand Down Expand Up @@ -512,5 +521,6 @@ static irqreturn_t macii_interrupt(int irq, void *arg)
break;
}

local_irq_restore(flags);
return IRQ_HANDLED;
}

0 comments on commit 5ce6185

Please sign in to comment.