Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/kernel/irq/proc.c |
| 3 | * |
| 4 | * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar |
| 5 | * |
| 6 | * This file contains the /proc/irq/ handling code. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/irq.h> |
| 10 | #include <linux/proc_fs.h> |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 11 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/interrupt.h> |
| 13 | |
Adrian Bunk | 97a41e2 | 2006-01-08 01:02:17 -0800 | [diff] [blame] | 14 | #include "internals.h" |
| 15 | |
Ingo Molnar | 4a733ee | 2006-06-29 02:24:42 -0700 | [diff] [blame] | 16 | static struct proc_dir_entry *root_irq_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | #ifdef CONFIG_SMP |
| 19 | |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 20 | static int irq_affinity_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | { |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 22 | struct irq_desc *desc = irq_to_desc((long)m->private); |
Andi Kleen | 42ee2b7 | 2007-07-21 17:09:54 +0200 | [diff] [blame] | 23 | cpumask_t *mask = &desc->affinity; |
Andi Kleen | 42ee2b7 | 2007-07-21 17:09:54 +0200 | [diff] [blame] | 24 | |
| 25 | #ifdef CONFIG_GENERIC_PENDING_IRQ |
| 26 | if (desc->status & IRQ_MOVE_PENDING) |
| 27 | mask = &desc->pending_mask; |
| 28 | #endif |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 29 | seq_cpumask(m, mask); |
| 30 | seq_putc(m, '\n'); |
| 31 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | } |
| 33 | |
John Keller | 25d6157 | 2007-05-10 22:42:44 -0700 | [diff] [blame] | 34 | #ifndef is_affinity_mask_valid |
| 35 | #define is_affinity_mask_valid(val) 1 |
| 36 | #endif |
| 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | int no_irq_affinity; |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 39 | static ssize_t irq_affinity_proc_write(struct file *file, |
| 40 | const char __user *buffer, size_t count, loff_t *pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | { |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 42 | unsigned int irq = (int)(long)PDE(file->f_path.dentry->d_inode)->data; |
Max Krasnyansky | 1840475 | 2008-05-29 11:02:52 -0700 | [diff] [blame] | 43 | cpumask_t new_value; |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 44 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 46 | if (!irq_to_desc(irq)->chip->set_affinity || no_irq_affinity || |
Thomas Gleixner | 950f442 | 2007-02-16 01:27:24 -0800 | [diff] [blame] | 47 | irq_balancing_disabled(irq)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | return -EIO; |
| 49 | |
Reinette Chatre | 01a3ee2 | 2006-10-11 01:21:55 -0700 | [diff] [blame] | 50 | err = cpumask_parse_user(buffer, count, new_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | if (err) |
| 52 | return err; |
| 53 | |
John Keller | 25d6157 | 2007-05-10 22:42:44 -0700 | [diff] [blame] | 54 | if (!is_affinity_mask_valid(new_value)) |
| 55 | return -EINVAL; |
| 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | /* |
| 58 | * Do not allow disabling IRQs completely - it's a too easy |
| 59 | * way to make the system unusable accidentally :-) At least |
| 60 | * one online CPU still has to be targeted. |
| 61 | */ |
Max Krasnyansky | 1840475 | 2008-05-29 11:02:52 -0700 | [diff] [blame] | 62 | if (!cpus_intersects(new_value, cpu_online_map)) |
Ivan Kokshaysky | eee4526 | 2006-01-06 00:12:21 -0800 | [diff] [blame] | 63 | /* Special case for empty set - allow the architecture |
| 64 | code to set default SMP affinity. */ |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 65 | return irq_select_affinity(irq) ? -EINVAL : count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Thomas Gleixner | 771ee3b | 2007-02-16 01:27:25 -0800 | [diff] [blame] | 67 | irq_set_affinity(irq, new_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 69 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 72 | static int irq_affinity_proc_open(struct inode *inode, struct file *file) |
Max Krasnyansky | 1840475 | 2008-05-29 11:02:52 -0700 | [diff] [blame] | 73 | { |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 74 | return single_open(file, irq_affinity_proc_show, PDE(inode)->data); |
Max Krasnyansky | 1840475 | 2008-05-29 11:02:52 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 77 | static const struct file_operations irq_affinity_proc_fops = { |
| 78 | .open = irq_affinity_proc_open, |
| 79 | .read = seq_read, |
| 80 | .llseek = seq_lseek, |
| 81 | .release = single_release, |
| 82 | .write = irq_affinity_proc_write, |
| 83 | }; |
| 84 | |
| 85 | static int default_affinity_show(struct seq_file *m, void *v) |
Max Krasnyansky | 1840475 | 2008-05-29 11:02:52 -0700 | [diff] [blame] | 86 | { |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 87 | seq_cpumask(m, &irq_default_affinity); |
| 88 | seq_putc(m, '\n'); |
| 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | static ssize_t default_affinity_write(struct file *file, |
| 93 | const char __user *buffer, size_t count, loff_t *ppos) |
| 94 | { |
Max Krasnyansky | 1840475 | 2008-05-29 11:02:52 -0700 | [diff] [blame] | 95 | cpumask_t new_value; |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 96 | int err; |
Max Krasnyansky | 1840475 | 2008-05-29 11:02:52 -0700 | [diff] [blame] | 97 | |
| 98 | err = cpumask_parse_user(buffer, count, new_value); |
| 99 | if (err) |
| 100 | return err; |
| 101 | |
| 102 | if (!is_affinity_mask_valid(new_value)) |
| 103 | return -EINVAL; |
| 104 | |
| 105 | /* |
| 106 | * Do not allow disabling IRQs completely - it's a too easy |
| 107 | * way to make the system unusable accidentally :-) At least |
| 108 | * one online CPU still has to be targeted. |
| 109 | */ |
| 110 | if (!cpus_intersects(new_value, cpu_online_map)) |
| 111 | return -EINVAL; |
| 112 | |
| 113 | irq_default_affinity = new_value; |
| 114 | |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 115 | return count; |
Max Krasnyansky | 1840475 | 2008-05-29 11:02:52 -0700 | [diff] [blame] | 116 | } |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 117 | |
| 118 | static int default_affinity_open(struct inode *inode, struct file *file) |
| 119 | { |
| 120 | return single_open(file, default_affinity_show, NULL); |
| 121 | } |
| 122 | |
| 123 | static const struct file_operations default_affinity_proc_fops = { |
| 124 | .open = default_affinity_open, |
| 125 | .read = seq_read, |
| 126 | .llseek = seq_lseek, |
| 127 | .release = single_release, |
| 128 | .write = default_affinity_write, |
| 129 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | #endif |
| 131 | |
Andi Kleen | 96d97cf | 2008-01-30 13:32:48 +0100 | [diff] [blame] | 132 | static int irq_spurious_read(char *page, char **start, off_t off, |
| 133 | int count, int *eof, void *data) |
| 134 | { |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 135 | struct irq_desc *desc = irq_to_desc((long) data); |
Andi Kleen | 96d97cf | 2008-01-30 13:32:48 +0100 | [diff] [blame] | 136 | return sprintf(page, "count %u\n" |
| 137 | "unhandled %u\n" |
| 138 | "last_unhandled %u ms\n", |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 139 | desc->irq_count, |
| 140 | desc->irqs_unhandled, |
| 141 | jiffies_to_msecs(desc->last_unhandled)); |
Andi Kleen | 96d97cf | 2008-01-30 13:32:48 +0100 | [diff] [blame] | 142 | } |
| 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | #define MAX_NAMELEN 128 |
| 145 | |
| 146 | static int name_unique(unsigned int irq, struct irqaction *new_action) |
| 147 | { |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 148 | struct irq_desc *desc = irq_to_desc(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | struct irqaction *action; |
Dmitry Adamushko | d2d9433 | 2007-05-08 00:27:31 -0700 | [diff] [blame] | 150 | unsigned long flags; |
| 151 | int ret = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
Dmitry Adamushko | d2d9433 | 2007-05-08 00:27:31 -0700 | [diff] [blame] | 153 | spin_lock_irqsave(&desc->lock, flags); |
| 154 | for (action = desc->action ; action; action = action->next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | if ((action != new_action) && action->name && |
Dmitry Adamushko | d2d9433 | 2007-05-08 00:27:31 -0700 | [diff] [blame] | 156 | !strcmp(new_action->name, action->name)) { |
| 157 | ret = 0; |
| 158 | break; |
| 159 | } |
| 160 | } |
| 161 | spin_unlock_irqrestore(&desc->lock, flags); |
| 162 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | void register_handler_proc(unsigned int irq, struct irqaction *action) |
| 166 | { |
| 167 | char name [MAX_NAMELEN]; |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 168 | struct irq_desc *desc = irq_to_desc(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 170 | if (!desc->dir || action->dir || !action->name || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | !name_unique(irq, action)) |
| 172 | return; |
| 173 | |
| 174 | memset(name, 0, MAX_NAMELEN); |
| 175 | snprintf(name, MAX_NAMELEN, "%s", action->name); |
| 176 | |
| 177 | /* create /proc/irq/1234/handler/ */ |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 178 | action->dir = proc_mkdir(name, desc->dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | #undef MAX_NAMELEN |
| 182 | |
| 183 | #define MAX_NAMELEN 10 |
| 184 | |
Yinghai Lu | 2c6927a | 2008-08-19 20:50:11 -0700 | [diff] [blame] | 185 | void register_irq_proc(unsigned int irq, struct irq_desc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | { |
| 187 | char name [MAX_NAMELEN]; |
Andi Kleen | 96d97cf | 2008-01-30 13:32:48 +0100 | [diff] [blame] | 188 | struct proc_dir_entry *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 190 | if (!root_irq_dir || (desc->chip == &no_irq_chip) || desc->dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | return; |
| 192 | |
| 193 | memset(name, 0, MAX_NAMELEN); |
| 194 | sprintf(name, "%d", irq); |
| 195 | |
| 196 | /* create /proc/irq/1234 */ |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 197 | desc->dir = proc_mkdir(name, root_irq_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | |
| 199 | #ifdef CONFIG_SMP |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 200 | /* create /proc/irq/<irq>/smp_affinity */ |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 201 | proc_create_data("smp_affinity", 0600, desc->dir, |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 202 | &irq_affinity_proc_fops, (void *)(long)irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | #endif |
Andi Kleen | 96d97cf | 2008-01-30 13:32:48 +0100 | [diff] [blame] | 204 | |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 205 | entry = create_proc_entry("spurious", 0444, desc->dir); |
Andi Kleen | 96d97cf | 2008-01-30 13:32:48 +0100 | [diff] [blame] | 206 | if (entry) { |
| 207 | entry->data = (void *)(long)irq; |
| 208 | entry->read_proc = irq_spurious_read; |
| 209 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | #undef MAX_NAMELEN |
| 213 | |
| 214 | void unregister_handler_proc(unsigned int irq, struct irqaction *action) |
| 215 | { |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 216 | if (action->dir) { |
| 217 | struct irq_desc *desc = irq_to_desc(irq); |
Thomas Gleixner | d3c6004 | 2008-10-16 09:55:00 +0200 | [diff] [blame] | 218 | |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 219 | remove_proc_entry(action->dir->name, desc->dir); |
| 220 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | } |
| 222 | |
roel kluin | 3786fc7 | 2008-10-21 19:49:09 -0400 | [diff] [blame] | 223 | static void register_default_affinity_proc(void) |
Max Krasnyansky | 1840475 | 2008-05-29 11:02:52 -0700 | [diff] [blame] | 224 | { |
| 225 | #ifdef CONFIG_SMP |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 226 | proc_create("irq/default_smp_affinity", 0600, NULL, |
| 227 | &default_affinity_proc_fops); |
Max Krasnyansky | 1840475 | 2008-05-29 11:02:52 -0700 | [diff] [blame] | 228 | #endif |
| 229 | } |
| 230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | void init_irq_proc(void) |
| 232 | { |
Yinghai Lu | 2c6927a | 2008-08-19 20:50:11 -0700 | [diff] [blame] | 233 | unsigned int irq; |
| 234 | struct irq_desc *desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | |
| 236 | /* create /proc/irq */ |
| 237 | root_irq_dir = proc_mkdir("irq", NULL); |
| 238 | if (!root_irq_dir) |
| 239 | return; |
| 240 | |
Max Krasnyansky | 1840475 | 2008-05-29 11:02:52 -0700 | [diff] [blame] | 241 | register_default_affinity_proc(); |
| 242 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | /* |
| 244 | * Create entries for all existing IRQs. |
| 245 | */ |
Yinghai Lu | 2c6927a | 2008-08-19 20:50:11 -0700 | [diff] [blame] | 246 | for_each_irq_desc(irq, desc) |
| 247 | register_irq_proc(irq, desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | } |
| 249 | |