Jeff Dike | 8e36706 | 2006-03-27 01:14:32 -0800 | [diff] [blame] | 1 | /* |
Jeff Dike | c5d4bb1 | 2008-02-04 22:31:14 -0800 | [diff] [blame] | 2 | * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Licensed under the GPL |
| 4 | */ |
| 5 | |
Jeff Dike | c5d4bb1 | 2008-02-04 22:31:14 -0800 | [diff] [blame] | 6 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include "irq_kern.h" |
Jeff Dike | 8e36706 | 2006-03-27 01:14:32 -0800 | [diff] [blame] | 8 | #include "os.h" |
Jeff Dike | c5d4bb1 | 2008-02-04 22:31:14 -0800 | [diff] [blame] | 9 | #include "sigio.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | |
| 11 | /* Protected by sigio_lock() called from write_sigio_workaround */ |
| 12 | static int sigio_irq_fd = -1; |
| 13 | |
Al Viro | 7bea96f | 2006-10-08 22:49:34 +0100 | [diff] [blame] | 14 | static irqreturn_t sigio_interrupt(int irq, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | { |
Jeff Dike | 8e36706 | 2006-03-27 01:14:32 -0800 | [diff] [blame] | 16 | char c; |
| 17 | |
Jeff Dike | a6ea4cc | 2007-05-06 14:51:43 -0700 | [diff] [blame] | 18 | os_read_file(sigio_irq_fd, &c, sizeof(c)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | reactivate_fd(sigio_irq_fd, SIGIO_WRITE_IRQ); |
Jeff Dike | 4cffb7f | 2007-02-10 01:44:24 -0800 | [diff] [blame] | 20 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | int write_sigio_irq(int fd) |
| 24 | { |
| 25 | int err; |
| 26 | |
| 27 | err = um_request_irq(SIGIO_WRITE_IRQ, fd, IRQ_READ, sigio_interrupt, |
Theodore Ts'o | aab9446 | 2012-07-17 14:18:23 -0400 | [diff] [blame^] | 28 | 0, "write sigio", NULL); |
Jeff Dike | c5d4bb1 | 2008-02-04 22:31:14 -0800 | [diff] [blame] | 29 | if (err) { |
| 30 | printk(KERN_ERR "write_sigio_irq : um_request_irq failed, " |
| 31 | "err = %d\n", err); |
Jeff Dike | 4cffb7f | 2007-02-10 01:44:24 -0800 | [diff] [blame] | 32 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | } |
| 34 | sigio_irq_fd = fd; |
Jeff Dike | 4cffb7f | 2007-02-10 01:44:24 -0800 | [diff] [blame] | 35 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Jeff Dike | d9f9d319 | 2007-02-10 01:44:23 -0800 | [diff] [blame] | 38 | /* These are called from os-Linux/sigio.c to protect its pollfds arrays. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | static DEFINE_SPINLOCK(sigio_spinlock); |
| 40 | |
| 41 | void sigio_lock(void) |
| 42 | { |
| 43 | spin_lock(&sigio_spinlock); |
| 44 | } |
| 45 | |
| 46 | void sigio_unlock(void) |
| 47 | { |
| 48 | spin_unlock(&sigio_spinlock); |
| 49 | } |