Jeff Dike | 8e36706 | 2006-03-27 01:14:32 -0800 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Copyright (C) 2002 - 2003 Jeff Dike (jdike@addtoit.com) |
| 3 | * Licensed under the GPL |
| 4 | */ |
| 5 | |
| 6 | #include "linux/kernel.h" |
| 7 | #include "linux/list.h" |
| 8 | #include "linux/slab.h" |
| 9 | #include "linux/signal.h" |
| 10 | #include "linux/interrupt.h" |
| 11 | #include "init.h" |
| 12 | #include "sigio.h" |
| 13 | #include "irq_user.h" |
| 14 | #include "irq_kern.h" |
Jeff Dike | 8e36706 | 2006-03-27 01:14:32 -0800 | [diff] [blame] | 15 | #include "os.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | /* Protected by sigio_lock() called from write_sigio_workaround */ |
| 18 | static int sigio_irq_fd = -1; |
| 19 | |
Al Viro | 7bea96f | 2006-10-08 22:49:34 +0100 | [diff] [blame] | 20 | static irqreturn_t sigio_interrupt(int irq, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | { |
Jeff Dike | 8e36706 | 2006-03-27 01:14:32 -0800 | [diff] [blame] | 22 | char c; |
| 23 | |
| 24 | os_read_file(sigio_irq_fd, &c, sizeof(c)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | reactivate_fd(sigio_irq_fd, SIGIO_WRITE_IRQ); |
Jeff Dike | 4cffb7f | 2007-02-10 01:44:24 -0800 | [diff] [blame^] | 26 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | int write_sigio_irq(int fd) |
| 30 | { |
| 31 | int err; |
| 32 | |
| 33 | err = um_request_irq(SIGIO_WRITE_IRQ, fd, IRQ_READ, sigio_interrupt, |
Jeff Dike | 1d3468a | 2006-07-10 04:45:13 -0700 | [diff] [blame] | 34 | IRQF_DISABLED|IRQF_SAMPLE_RANDOM, "write sigio", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | NULL); |
| 36 | if(err){ |
| 37 | printk("write_sigio_irq : um_request_irq failed, err = %d\n", |
| 38 | err); |
Jeff Dike | 4cffb7f | 2007-02-10 01:44:24 -0800 | [diff] [blame^] | 39 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | } |
| 41 | sigio_irq_fd = fd; |
Jeff Dike | 4cffb7f | 2007-02-10 01:44:24 -0800 | [diff] [blame^] | 42 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Jeff Dike | d9f9d319 | 2007-02-10 01:44:23 -0800 | [diff] [blame] | 45 | /* 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] | 46 | static DEFINE_SPINLOCK(sigio_spinlock); |
| 47 | |
| 48 | void sigio_lock(void) |
| 49 | { |
| 50 | spin_lock(&sigio_spinlock); |
| 51 | } |
| 52 | |
| 53 | void sigio_unlock(void) |
| 54 | { |
| 55 | spin_unlock(&sigio_spinlock); |
| 56 | } |