forked from joninvski/ts_7500_kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcavium-userspace-irq.patch
More file actions
204 lines (190 loc) · 5.09 KB
/
cavium-userspace-irq.patch
File metadata and controls
204 lines (190 loc) · 5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
User-mode IRQ handling for linux: generic code.
This patch adds a new file to /proc/irq/<nnn>/ called irq. Suitably
privileged processes can open this file. Reading the file returns the
number of interrupts (if any) that have occurred since the last read.
If the file is opened in blocking mode, reading it blocks until
an interrupt occurs. poll(2) and select(2) work as one would expect, to
allow interrupts to be one of many events to wait for.
Interrupts are usually masked; while a thread is in poll(2) or read(2) on the
file they are unmasked.
All architectures that use CONFIG_GENERIC_HARDIRQ are supported by this patch.
Signed-off-by: Peter Chubb <peterc@gelato.unsw.edu.au>
kernel/irq/proc.c | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 139 insertions(+), 5 deletions(-)
Index: linux-2.6-usrdrv/kernel/irq/proc.c
===================================================================
--- linux-2.6-usrdrv.orig/kernel/irq/proc.c 2006-08-10 10:32:16.040765830 +1000
+++ linux-2.6-usrdrv/kernel/irq/proc.c 2006-08-10 11:03:26.253628340 +1000
@@ -9,6 +9,7 @@
#include <linux/irq.h>
#include <linux/proc_fs.h>
#include <linux/interrupt.h>
+#include <linux/poll.h>
#include "internals.h"
@@ -112,21 +113,165 @@ void register_handler_proc(unsigned int
#define MAX_NAMELEN 10
+struct irq_proc {
+ unsigned long irq;
+ wait_queue_head_t q;
+ atomic_t count;
+ char devname[TASK_COMM_LEN];
+};
+
+static irqreturn_t irq_proc_irq_handler(int irq, void *vidp)
+{
+ struct irq_proc *idp = (struct irq_proc *)vidp;
+ unsigned long stamp;
+
+ BUG_ON(idp->irq != irq);
+
+ disable_irq_nosync(irq);
+ atomic_inc(&idp->count);
+
+ wake_up(&idp->q);
+ return IRQ_HANDLED;
+}
+
+
+/*
+ * Signal to userspace an interrupt has occured.
+ */
+static ssize_t irq_proc_read(struct file *filp, char __user *bufp, size_t len, loff_t *ppos)
+{
+ struct irq_proc *ip = (struct irq_proc *)filp->private_data;
+ irq_desc_t *idp = irq_desc + ip->irq;
+ int pending;
+
+ DEFINE_WAIT(wait);
+
+ if (len < sizeof(int))
+ return -EINVAL;
+
+ pending = atomic_read(&ip->count);
+ if (pending == 0) {
+ if (idp->status & IRQ_DISABLED)
+ enable_irq(ip->irq);
+ if (filp->f_flags & O_NONBLOCK)
+ return -EWOULDBLOCK;
+ }
+
+ while (pending == 0) {
+ prepare_to_wait(&ip->q, &wait, TASK_INTERRUPTIBLE);
+ pending = atomic_read(&ip->count);
+ if (pending == 0)
+ schedule();
+ finish_wait(&ip->q, &wait);
+ if (signal_pending(current))
+ return -ERESTARTSYS;
+ }
+
+ if (copy_to_user(bufp, &pending, sizeof pending))
+ return -EFAULT;
+
+ *ppos += sizeof pending;
+
+ atomic_sub(pending, &ip->count);
+ return sizeof pending;
+}
+
+
+static int irq_proc_open(struct inode *inop, struct file *filp)
+{
+ struct irq_proc *ip;
+ struct proc_dir_entry *ent = PDE(inop);
+ int error;
+
+ ip = kmalloc(sizeof *ip, GFP_KERNEL);
+ if (ip == NULL)
+ return -ENOMEM;
+
+ memset(ip, 0, sizeof(*ip));
+ strcpy(ip->devname, current->comm);
+ init_waitqueue_head(&ip->q);
+ atomic_set(&ip->count, 0);
+ ip->irq = (unsigned long)ent->data;
+
+ error = request_irq(ip->irq,
+ irq_proc_irq_handler,
+ 0,
+ ip->devname,
+ ip);
+ if (error < 0) {
+ kfree(ip);
+ return error;
+ }
+ filp->private_data = (void *)ip;
+
+ return 0;
+}
+
+static int irq_proc_release(struct inode *inop, struct file *filp)
+{
+ struct irq_proc *ip = (struct irq_proc *)filp->private_data;
+
+ free_irq(ip->irq, ip);
+ filp->private_data = NULL;
+ kfree(ip);
+ return 0;
+}
+
+static unsigned int irq_proc_poll(struct file *filp, struct poll_table_struct *wait)
+{
+ struct irq_proc *ip = (struct irq_proc *)filp->private_data;
+ irq_desc_t *idp = irq_desc + ip->irq;
+
+ if (atomic_read(&ip->count) > 0)
+ return POLLIN | POLLRDNORM; /* readable */
+
+ /* if interrupts disabled and we don't have one to process... */
+ if (idp->status & IRQ_DISABLED)
+ enable_irq(ip->irq);
+
+ poll_wait(filp, &ip->q, wait);
+
+ if (atomic_read(&ip->count) > 0)
+ return POLLIN | POLLRDNORM; /* readable */
+
+ return 0;
+}
+
+static struct file_operations irq_proc_file_operations = {
+ .read = irq_proc_read,
+ .open = irq_proc_open,
+ .release = irq_proc_release,
+ .poll = irq_proc_poll,
+};
+
+
void register_irq_proc(unsigned int irq)
{
+ struct proc_dir_entry *entry;
char name [MAX_NAMELEN];
- if (!root_irq_dir ||
- (irq_desc[irq].chip == &no_irq_chip) ||
- irq_desc[irq].dir)
+ if (!root_irq_dir)
return;
memset(name, 0, MAX_NAMELEN);
sprintf(name, "%d", irq);
- /* create /proc/irq/1234 */
- irq_desc[irq].dir = proc_mkdir(name, root_irq_dir);
-
+ if (!irq_desc[irq].dir) {
+ /* create /proc/irq/1234 */
+ irq_desc[irq].dir = proc_mkdir(name, root_irq_dir);
+
+ /*
+ * Create handles for user-mode interrupt handlers
+ * if the kernel hasn't already grabbed the IRQ
+ */
+ entry = create_proc_entry("irq", 0600, irq_desc[irq].dir);
+ if (entry) {
+ entry->data = (void *)(unsigned long)irq;
+ entry->read_proc = NULL;
+ entry->write_proc = NULL;
+ entry->proc_fops = &irq_proc_file_operations;
+ }
+ }
#ifdef CONFIG_SMP
{
struct proc_dir_entry *entry;