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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/gfp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/proc_fs.h> |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 12 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/interrupt.h> |
Thomas Gleixner | c78b9b6 | 2010-12-16 17:21:47 +0100 | [diff] [blame] | 14 | #include <linux/kernel_stat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
Adrian Bunk | 97a41e2 | 2006-01-08 01:02:17 -0800 | [diff] [blame] | 16 | #include "internals.h" |
| 17 | |
Ingo Molnar | 4a733ee | 2006-06-29 02:24:42 -0700 | [diff] [blame] | 18 | static struct proc_dir_entry *root_irq_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | #ifdef CONFIG_SMP |
| 21 | |
Mike Travis | 4b06042 | 2011-05-24 17:13:12 -0700 | [diff] [blame] | 22 | static int show_irq_affinity(int type, struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | { |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 24 | struct irq_desc *desc = irq_to_desc((long)m->private); |
Thomas Gleixner | 6b8ff31 | 2010-10-01 12:58:38 +0200 | [diff] [blame] | 25 | const struct cpumask *mask = desc->irq_data.affinity; |
Andi Kleen | 42ee2b7 | 2007-07-21 17:09:54 +0200 | [diff] [blame] | 26 | |
| 27 | #ifdef CONFIG_GENERIC_PENDING_IRQ |
Thomas Gleixner | f230b6d | 2011-02-05 15:20:04 +0100 | [diff] [blame] | 28 | if (irqd_is_setaffinity_pending(&desc->irq_data)) |
Mike Travis | 7f7ace0 | 2009-01-10 21:58:08 -0800 | [diff] [blame] | 29 | mask = desc->pending_mask; |
Andi Kleen | 42ee2b7 | 2007-07-21 17:09:54 +0200 | [diff] [blame] | 30 | #endif |
Mike Travis | 4b06042 | 2011-05-24 17:13:12 -0700 | [diff] [blame] | 31 | if (type) |
| 32 | seq_cpumask_list(m, mask); |
| 33 | else |
| 34 | seq_cpumask(m, mask); |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 35 | seq_putc(m, '\n'); |
| 36 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Peter P Waskiewicz Jr | e7a297b | 2010-04-30 14:44:50 -0700 | [diff] [blame] | 39 | static int irq_affinity_hint_proc_show(struct seq_file *m, void *v) |
| 40 | { |
| 41 | struct irq_desc *desc = irq_to_desc((long)m->private); |
| 42 | unsigned long flags; |
| 43 | cpumask_var_t mask; |
| 44 | |
Peter P Waskiewicz Jr | 4308ad8 | 2010-05-05 13:56:42 -0700 | [diff] [blame] | 45 | if (!zalloc_cpumask_var(&mask, GFP_KERNEL)) |
Peter P Waskiewicz Jr | e7a297b | 2010-04-30 14:44:50 -0700 | [diff] [blame] | 46 | return -ENOMEM; |
| 47 | |
| 48 | raw_spin_lock_irqsave(&desc->lock, flags); |
| 49 | if (desc->affinity_hint) |
| 50 | cpumask_copy(mask, desc->affinity_hint); |
Peter P Waskiewicz Jr | e7a297b | 2010-04-30 14:44:50 -0700 | [diff] [blame] | 51 | raw_spin_unlock_irqrestore(&desc->lock, flags); |
| 52 | |
| 53 | seq_cpumask(m, mask); |
| 54 | seq_putc(m, '\n'); |
| 55 | free_cpumask_var(mask); |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
John Keller | 25d6157 | 2007-05-10 22:42:44 -0700 | [diff] [blame] | 60 | #ifndef is_affinity_mask_valid |
| 61 | #define is_affinity_mask_valid(val) 1 |
| 62 | #endif |
| 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | int no_irq_affinity; |
Mike Travis | 4b06042 | 2011-05-24 17:13:12 -0700 | [diff] [blame] | 65 | static int irq_affinity_proc_show(struct seq_file *m, void *v) |
| 66 | { |
| 67 | return show_irq_affinity(0, m, v); |
| 68 | } |
| 69 | |
| 70 | static int irq_affinity_list_proc_show(struct seq_file *m, void *v) |
| 71 | { |
| 72 | return show_irq_affinity(1, m, v); |
| 73 | } |
| 74 | |
| 75 | |
| 76 | static ssize_t write_irq_affinity(int type, struct file *file, |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 77 | const char __user *buffer, size_t count, loff_t *pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | { |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 79 | unsigned int irq = (int)(long)PDE(file->f_path.dentry->d_inode)->data; |
Rusty Russell | 0de2652 | 2008-12-13 21:20:26 +1030 | [diff] [blame] | 80 | cpumask_var_t new_value; |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 81 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Thomas Gleixner | bce4303 | 2011-02-10 22:37:41 +0100 | [diff] [blame] | 83 | if (!irq_can_set_affinity(irq) || no_irq_affinity) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | return -EIO; |
| 85 | |
Rusty Russell | 0de2652 | 2008-12-13 21:20:26 +1030 | [diff] [blame] | 86 | if (!alloc_cpumask_var(&new_value, GFP_KERNEL)) |
| 87 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Mike Travis | 4b06042 | 2011-05-24 17:13:12 -0700 | [diff] [blame] | 89 | if (type) |
| 90 | err = cpumask_parselist_user(buffer, count, new_value); |
| 91 | else |
| 92 | err = cpumask_parse_user(buffer, count, new_value); |
Rusty Russell | 0de2652 | 2008-12-13 21:20:26 +1030 | [diff] [blame] | 93 | if (err) |
| 94 | goto free_cpumask; |
| 95 | |
Ingo Molnar | 6bdf197 | 2009-01-03 12:50:46 +0100 | [diff] [blame] | 96 | if (!is_affinity_mask_valid(new_value)) { |
Rusty Russell | 0de2652 | 2008-12-13 21:20:26 +1030 | [diff] [blame] | 97 | err = -EINVAL; |
| 98 | goto free_cpumask; |
| 99 | } |
John Keller | 25d6157 | 2007-05-10 22:42:44 -0700 | [diff] [blame] | 100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | /* |
| 102 | * Do not allow disabling IRQs completely - it's a too easy |
| 103 | * way to make the system unusable accidentally :-) At least |
| 104 | * one online CPU still has to be targeted. |
| 105 | */ |
Rusty Russell | 0de2652 | 2008-12-13 21:20:26 +1030 | [diff] [blame] | 106 | if (!cpumask_intersects(new_value, cpu_online_mask)) { |
Ivan Kokshaysky | eee4526 | 2006-01-06 00:12:21 -0800 | [diff] [blame] | 107 | /* Special case for empty set - allow the architecture |
| 108 | code to set default SMP affinity. */ |
Thomas Gleixner | 3b8249e | 2011-02-07 16:02:20 +0100 | [diff] [blame] | 109 | err = irq_select_affinity_usr(irq, new_value) ? -EINVAL : count; |
Rusty Russell | 0de2652 | 2008-12-13 21:20:26 +1030 | [diff] [blame] | 110 | } else { |
| 111 | irq_set_affinity(irq, new_value); |
| 112 | err = count; |
| 113 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Rusty Russell | 0de2652 | 2008-12-13 21:20:26 +1030 | [diff] [blame] | 115 | free_cpumask: |
| 116 | free_cpumask_var(new_value); |
| 117 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Mike Travis | 4b06042 | 2011-05-24 17:13:12 -0700 | [diff] [blame] | 120 | static ssize_t irq_affinity_proc_write(struct file *file, |
| 121 | const char __user *buffer, size_t count, loff_t *pos) |
| 122 | { |
| 123 | return write_irq_affinity(0, file, buffer, count, pos); |
| 124 | } |
| 125 | |
| 126 | static ssize_t irq_affinity_list_proc_write(struct file *file, |
| 127 | const char __user *buffer, size_t count, loff_t *pos) |
| 128 | { |
| 129 | return write_irq_affinity(1, file, buffer, count, pos); |
| 130 | } |
| 131 | |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 132 | static int irq_affinity_proc_open(struct inode *inode, struct file *file) |
Max Krasnyansky | 1840475 | 2008-05-29 11:02:52 -0700 | [diff] [blame] | 133 | { |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 134 | return single_open(file, irq_affinity_proc_show, PDE(inode)->data); |
Max Krasnyansky | 1840475 | 2008-05-29 11:02:52 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Mike Travis | 4b06042 | 2011-05-24 17:13:12 -0700 | [diff] [blame] | 137 | static int irq_affinity_list_proc_open(struct inode *inode, struct file *file) |
| 138 | { |
| 139 | return single_open(file, irq_affinity_list_proc_show, PDE(inode)->data); |
| 140 | } |
| 141 | |
Peter P Waskiewicz Jr | e7a297b | 2010-04-30 14:44:50 -0700 | [diff] [blame] | 142 | static int irq_affinity_hint_proc_open(struct inode *inode, struct file *file) |
| 143 | { |
| 144 | return single_open(file, irq_affinity_hint_proc_show, PDE(inode)->data); |
| 145 | } |
| 146 | |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 147 | static const struct file_operations irq_affinity_proc_fops = { |
| 148 | .open = irq_affinity_proc_open, |
| 149 | .read = seq_read, |
| 150 | .llseek = seq_lseek, |
| 151 | .release = single_release, |
| 152 | .write = irq_affinity_proc_write, |
| 153 | }; |
| 154 | |
Peter P Waskiewicz Jr | e7a297b | 2010-04-30 14:44:50 -0700 | [diff] [blame] | 155 | static const struct file_operations irq_affinity_hint_proc_fops = { |
| 156 | .open = irq_affinity_hint_proc_open, |
| 157 | .read = seq_read, |
| 158 | .llseek = seq_lseek, |
| 159 | .release = single_release, |
| 160 | }; |
| 161 | |
Mike Travis | 4b06042 | 2011-05-24 17:13:12 -0700 | [diff] [blame] | 162 | static const struct file_operations irq_affinity_list_proc_fops = { |
| 163 | .open = irq_affinity_list_proc_open, |
| 164 | .read = seq_read, |
| 165 | .llseek = seq_lseek, |
| 166 | .release = single_release, |
| 167 | .write = irq_affinity_list_proc_write, |
| 168 | }; |
| 169 | |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 170 | static int default_affinity_show(struct seq_file *m, void *v) |
Max Krasnyansky | 1840475 | 2008-05-29 11:02:52 -0700 | [diff] [blame] | 171 | { |
Rusty Russell | d036e67 | 2009-01-01 10:12:26 +1030 | [diff] [blame] | 172 | seq_cpumask(m, irq_default_affinity); |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 173 | seq_putc(m, '\n'); |
| 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | static ssize_t default_affinity_write(struct file *file, |
| 178 | const char __user *buffer, size_t count, loff_t *ppos) |
| 179 | { |
Rusty Russell | d036e67 | 2009-01-01 10:12:26 +1030 | [diff] [blame] | 180 | cpumask_var_t new_value; |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 181 | int err; |
Max Krasnyansky | 1840475 | 2008-05-29 11:02:52 -0700 | [diff] [blame] | 182 | |
Rusty Russell | d036e67 | 2009-01-01 10:12:26 +1030 | [diff] [blame] | 183 | if (!alloc_cpumask_var(&new_value, GFP_KERNEL)) |
| 184 | return -ENOMEM; |
Max Krasnyansky | 1840475 | 2008-05-29 11:02:52 -0700 | [diff] [blame] | 185 | |
Rusty Russell | d036e67 | 2009-01-01 10:12:26 +1030 | [diff] [blame] | 186 | err = cpumask_parse_user(buffer, count, new_value); |
| 187 | if (err) |
| 188 | goto out; |
| 189 | |
| 190 | if (!is_affinity_mask_valid(new_value)) { |
| 191 | err = -EINVAL; |
| 192 | goto out; |
| 193 | } |
Max Krasnyansky | 1840475 | 2008-05-29 11:02:52 -0700 | [diff] [blame] | 194 | |
| 195 | /* |
| 196 | * Do not allow disabling IRQs completely - it's a too easy |
| 197 | * way to make the system unusable accidentally :-) At least |
| 198 | * one online CPU still has to be targeted. |
| 199 | */ |
Rusty Russell | d036e67 | 2009-01-01 10:12:26 +1030 | [diff] [blame] | 200 | if (!cpumask_intersects(new_value, cpu_online_mask)) { |
| 201 | err = -EINVAL; |
| 202 | goto out; |
| 203 | } |
Max Krasnyansky | 1840475 | 2008-05-29 11:02:52 -0700 | [diff] [blame] | 204 | |
Rusty Russell | d036e67 | 2009-01-01 10:12:26 +1030 | [diff] [blame] | 205 | cpumask_copy(irq_default_affinity, new_value); |
| 206 | err = count; |
Max Krasnyansky | 1840475 | 2008-05-29 11:02:52 -0700 | [diff] [blame] | 207 | |
Rusty Russell | d036e67 | 2009-01-01 10:12:26 +1030 | [diff] [blame] | 208 | out: |
| 209 | free_cpumask_var(new_value); |
| 210 | return err; |
Max Krasnyansky | 1840475 | 2008-05-29 11:02:52 -0700 | [diff] [blame] | 211 | } |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 212 | |
| 213 | static int default_affinity_open(struct inode *inode, struct file *file) |
| 214 | { |
Thomas Gleixner | 3476994 | 2009-11-20 11:46:21 +0100 | [diff] [blame] | 215 | return single_open(file, default_affinity_show, PDE(inode)->data); |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | static const struct file_operations default_affinity_proc_fops = { |
| 219 | .open = default_affinity_open, |
| 220 | .read = seq_read, |
| 221 | .llseek = seq_lseek, |
| 222 | .release = single_release, |
| 223 | .write = default_affinity_write, |
| 224 | }; |
Dimitri Sivanich | 92d6b71 | 2010-03-11 14:08:56 -0800 | [diff] [blame] | 225 | |
| 226 | static int irq_node_proc_show(struct seq_file *m, void *v) |
| 227 | { |
| 228 | struct irq_desc *desc = irq_to_desc((long) m->private); |
| 229 | |
Thomas Gleixner | 6b8ff31 | 2010-10-01 12:58:38 +0200 | [diff] [blame] | 230 | seq_printf(m, "%d\n", desc->irq_data.node); |
Dimitri Sivanich | 92d6b71 | 2010-03-11 14:08:56 -0800 | [diff] [blame] | 231 | return 0; |
| 232 | } |
| 233 | |
| 234 | static int irq_node_proc_open(struct inode *inode, struct file *file) |
| 235 | { |
| 236 | return single_open(file, irq_node_proc_show, PDE(inode)->data); |
| 237 | } |
| 238 | |
| 239 | static const struct file_operations irq_node_proc_fops = { |
| 240 | .open = irq_node_proc_open, |
| 241 | .read = seq_read, |
| 242 | .llseek = seq_lseek, |
| 243 | .release = single_release, |
| 244 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | #endif |
| 246 | |
Alexey Dobriyan | a1afb63 | 2009-08-28 22:19:33 +0400 | [diff] [blame] | 247 | static int irq_spurious_proc_show(struct seq_file *m, void *v) |
Andi Kleen | 96d97cf | 2008-01-30 13:32:48 +0100 | [diff] [blame] | 248 | { |
Alexey Dobriyan | a1afb63 | 2009-08-28 22:19:33 +0400 | [diff] [blame] | 249 | struct irq_desc *desc = irq_to_desc((long) m->private); |
| 250 | |
| 251 | seq_printf(m, "count %u\n" "unhandled %u\n" "last_unhandled %u ms\n", |
| 252 | desc->irq_count, desc->irqs_unhandled, |
| 253 | jiffies_to_msecs(desc->last_unhandled)); |
| 254 | return 0; |
Andi Kleen | 96d97cf | 2008-01-30 13:32:48 +0100 | [diff] [blame] | 255 | } |
| 256 | |
Alexey Dobriyan | a1afb63 | 2009-08-28 22:19:33 +0400 | [diff] [blame] | 257 | static int irq_spurious_proc_open(struct inode *inode, struct file *file) |
| 258 | { |
Kenji Kaneshige | 25c9170 | 2010-11-30 17:36:08 +0900 | [diff] [blame] | 259 | return single_open(file, irq_spurious_proc_show, PDE(inode)->data); |
Alexey Dobriyan | a1afb63 | 2009-08-28 22:19:33 +0400 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | static const struct file_operations irq_spurious_proc_fops = { |
| 263 | .open = irq_spurious_proc_open, |
| 264 | .read = seq_read, |
| 265 | .llseek = seq_lseek, |
| 266 | .release = single_release, |
| 267 | }; |
| 268 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | #define MAX_NAMELEN 128 |
| 270 | |
| 271 | static int name_unique(unsigned int irq, struct irqaction *new_action) |
| 272 | { |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 273 | struct irq_desc *desc = irq_to_desc(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | struct irqaction *action; |
Dmitry Adamushko | d2d9433 | 2007-05-08 00:27:31 -0700 | [diff] [blame] | 275 | unsigned long flags; |
| 276 | int ret = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 278 | raw_spin_lock_irqsave(&desc->lock, flags); |
Dmitry Adamushko | d2d9433 | 2007-05-08 00:27:31 -0700 | [diff] [blame] | 279 | for (action = desc->action ; action; action = action->next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | if ((action != new_action) && action->name && |
Dmitry Adamushko | d2d9433 | 2007-05-08 00:27:31 -0700 | [diff] [blame] | 281 | !strcmp(new_action->name, action->name)) { |
| 282 | ret = 0; |
| 283 | break; |
| 284 | } |
| 285 | } |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 286 | raw_spin_unlock_irqrestore(&desc->lock, flags); |
Dmitry Adamushko | d2d9433 | 2007-05-08 00:27:31 -0700 | [diff] [blame] | 287 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | void register_handler_proc(unsigned int irq, struct irqaction *action) |
| 291 | { |
| 292 | char name [MAX_NAMELEN]; |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 293 | struct irq_desc *desc = irq_to_desc(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 295 | if (!desc->dir || action->dir || !action->name || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | !name_unique(irq, action)) |
| 297 | return; |
| 298 | |
| 299 | memset(name, 0, MAX_NAMELEN); |
| 300 | snprintf(name, MAX_NAMELEN, "%s", action->name); |
| 301 | |
| 302 | /* create /proc/irq/1234/handler/ */ |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 303 | action->dir = proc_mkdir(name, desc->dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | #undef MAX_NAMELEN |
| 307 | |
| 308 | #define MAX_NAMELEN 10 |
| 309 | |
Yinghai Lu | 2c6927a | 2008-08-19 20:50:11 -0700 | [diff] [blame] | 310 | void register_irq_proc(unsigned int irq, struct irq_desc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | { |
| 312 | char name [MAX_NAMELEN]; |
| 313 | |
Thomas Gleixner | 6b8ff31 | 2010-10-01 12:58:38 +0200 | [diff] [blame] | 314 | if (!root_irq_dir || (desc->irq_data.chip == &no_irq_chip) || desc->dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | return; |
| 316 | |
| 317 | memset(name, 0, MAX_NAMELEN); |
| 318 | sprintf(name, "%d", irq); |
| 319 | |
| 320 | /* create /proc/irq/1234 */ |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 321 | desc->dir = proc_mkdir(name, root_irq_dir); |
Cyrill Gorcunov | c82a43d | 2009-10-26 23:28:11 +0300 | [diff] [blame] | 322 | if (!desc->dir) |
| 323 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
| 325 | #ifdef CONFIG_SMP |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 326 | /* create /proc/irq/<irq>/smp_affinity */ |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 327 | proc_create_data("smp_affinity", 0600, desc->dir, |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 328 | &irq_affinity_proc_fops, (void *)(long)irq); |
Dimitri Sivanich | 92d6b71 | 2010-03-11 14:08:56 -0800 | [diff] [blame] | 329 | |
Peter P Waskiewicz Jr | e7a297b | 2010-04-30 14:44:50 -0700 | [diff] [blame] | 330 | /* create /proc/irq/<irq>/affinity_hint */ |
| 331 | proc_create_data("affinity_hint", 0400, desc->dir, |
| 332 | &irq_affinity_hint_proc_fops, (void *)(long)irq); |
| 333 | |
Mike Travis | 4b06042 | 2011-05-24 17:13:12 -0700 | [diff] [blame] | 334 | /* create /proc/irq/<irq>/smp_affinity_list */ |
| 335 | proc_create_data("smp_affinity_list", 0600, desc->dir, |
| 336 | &irq_affinity_list_proc_fops, (void *)(long)irq); |
| 337 | |
Dimitri Sivanich | 92d6b71 | 2010-03-11 14:08:56 -0800 | [diff] [blame] | 338 | proc_create_data("node", 0444, desc->dir, |
| 339 | &irq_node_proc_fops, (void *)(long)irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | #endif |
Andi Kleen | 96d97cf | 2008-01-30 13:32:48 +0100 | [diff] [blame] | 341 | |
Alexey Dobriyan | a1afb63 | 2009-08-28 22:19:33 +0400 | [diff] [blame] | 342 | proc_create_data("spurious", 0444, desc->dir, |
| 343 | &irq_spurious_proc_fops, (void *)(long)irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Thomas Gleixner | 13bfe99 | 2010-09-30 02:46:07 +0200 | [diff] [blame] | 346 | void unregister_irq_proc(unsigned int irq, struct irq_desc *desc) |
| 347 | { |
| 348 | char name [MAX_NAMELEN]; |
| 349 | |
| 350 | if (!root_irq_dir || !desc->dir) |
| 351 | return; |
| 352 | #ifdef CONFIG_SMP |
| 353 | remove_proc_entry("smp_affinity", desc->dir); |
| 354 | remove_proc_entry("affinity_hint", desc->dir); |
Yinghai Lu | def945e | 2011-05-25 22:09:40 -0700 | [diff] [blame] | 355 | remove_proc_entry("smp_affinity_list", desc->dir); |
Thomas Gleixner | 13bfe99 | 2010-09-30 02:46:07 +0200 | [diff] [blame] | 356 | remove_proc_entry("node", desc->dir); |
| 357 | #endif |
| 358 | remove_proc_entry("spurious", desc->dir); |
| 359 | |
| 360 | memset(name, 0, MAX_NAMELEN); |
| 361 | sprintf(name, "%u", irq); |
| 362 | remove_proc_entry(name, root_irq_dir); |
| 363 | } |
| 364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | #undef MAX_NAMELEN |
| 366 | |
| 367 | void unregister_handler_proc(unsigned int irq, struct irqaction *action) |
| 368 | { |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 369 | if (action->dir) { |
| 370 | struct irq_desc *desc = irq_to_desc(irq); |
Thomas Gleixner | d3c6004 | 2008-10-16 09:55:00 +0200 | [diff] [blame] | 371 | |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 372 | remove_proc_entry(action->dir->name, desc->dir); |
| 373 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | } |
| 375 | |
roel kluin | 3786fc7 | 2008-10-21 19:49:09 -0400 | [diff] [blame] | 376 | static void register_default_affinity_proc(void) |
Max Krasnyansky | 1840475 | 2008-05-29 11:02:52 -0700 | [diff] [blame] | 377 | { |
| 378 | #ifdef CONFIG_SMP |
Alexey Dobriyan | f18e439 | 2008-08-12 15:09:03 -0700 | [diff] [blame] | 379 | proc_create("irq/default_smp_affinity", 0600, NULL, |
| 380 | &default_affinity_proc_fops); |
Max Krasnyansky | 1840475 | 2008-05-29 11:02:52 -0700 | [diff] [blame] | 381 | #endif |
| 382 | } |
| 383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | void init_irq_proc(void) |
| 385 | { |
Yinghai Lu | 2c6927a | 2008-08-19 20:50:11 -0700 | [diff] [blame] | 386 | unsigned int irq; |
| 387 | struct irq_desc *desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | |
| 389 | /* create /proc/irq */ |
| 390 | root_irq_dir = proc_mkdir("irq", NULL); |
| 391 | if (!root_irq_dir) |
| 392 | return; |
| 393 | |
Max Krasnyansky | 1840475 | 2008-05-29 11:02:52 -0700 | [diff] [blame] | 394 | register_default_affinity_proc(); |
| 395 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | /* |
| 397 | * Create entries for all existing IRQs. |
| 398 | */ |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 399 | for_each_irq_desc(irq, desc) { |
| 400 | if (!desc) |
| 401 | continue; |
| 402 | |
Yinghai Lu | 2c6927a | 2008-08-19 20:50:11 -0700 | [diff] [blame] | 403 | register_irq_proc(irq, desc); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 404 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Thomas Gleixner | c78b9b6 | 2010-12-16 17:21:47 +0100 | [diff] [blame] | 407 | #ifdef CONFIG_GENERIC_IRQ_SHOW |
| 408 | |
| 409 | int __weak arch_show_interrupts(struct seq_file *p, int prec) |
| 410 | { |
| 411 | return 0; |
| 412 | } |
| 413 | |
Thomas Gleixner | a6e120e | 2011-03-25 22:20:51 +0100 | [diff] [blame] | 414 | #ifndef ACTUAL_NR_IRQS |
| 415 | # define ACTUAL_NR_IRQS nr_irqs |
| 416 | #endif |
| 417 | |
Thomas Gleixner | c78b9b6 | 2010-12-16 17:21:47 +0100 | [diff] [blame] | 418 | int show_interrupts(struct seq_file *p, void *v) |
| 419 | { |
| 420 | static int prec; |
| 421 | |
| 422 | unsigned long flags, any_count = 0; |
| 423 | int i = *(loff_t *) v, j; |
| 424 | struct irqaction *action; |
| 425 | struct irq_desc *desc; |
| 426 | |
Thomas Gleixner | a6e120e | 2011-03-25 22:20:51 +0100 | [diff] [blame] | 427 | if (i > ACTUAL_NR_IRQS) |
Thomas Gleixner | c78b9b6 | 2010-12-16 17:21:47 +0100 | [diff] [blame] | 428 | return 0; |
| 429 | |
Thomas Gleixner | a6e120e | 2011-03-25 22:20:51 +0100 | [diff] [blame] | 430 | if (i == ACTUAL_NR_IRQS) |
Thomas Gleixner | c78b9b6 | 2010-12-16 17:21:47 +0100 | [diff] [blame] | 431 | return arch_show_interrupts(p, prec); |
| 432 | |
| 433 | /* print header and calculate the width of the first column */ |
| 434 | if (i == 0) { |
| 435 | for (prec = 3, j = 1000; prec < 10 && j <= nr_irqs; ++prec) |
| 436 | j *= 10; |
| 437 | |
| 438 | seq_printf(p, "%*s", prec + 8, ""); |
| 439 | for_each_online_cpu(j) |
| 440 | seq_printf(p, "CPU%-8d", j); |
| 441 | seq_putc(p, '\n'); |
| 442 | } |
| 443 | |
| 444 | desc = irq_to_desc(i); |
| 445 | if (!desc) |
| 446 | return 0; |
| 447 | |
| 448 | raw_spin_lock_irqsave(&desc->lock, flags); |
| 449 | for_each_online_cpu(j) |
| 450 | any_count |= kstat_irqs_cpu(i, j); |
| 451 | action = desc->action; |
| 452 | if (!action && !any_count) |
| 453 | goto out; |
| 454 | |
| 455 | seq_printf(p, "%*d: ", prec, i); |
| 456 | for_each_online_cpu(j) |
| 457 | seq_printf(p, "%10u ", kstat_irqs_cpu(i, j)); |
Thomas Gleixner | ab7798f | 2011-03-25 16:48:50 +0100 | [diff] [blame] | 458 | |
| 459 | if (desc->irq_data.chip) { |
| 460 | if (desc->irq_data.chip->irq_print_chip) |
| 461 | desc->irq_data.chip->irq_print_chip(&desc->irq_data, p); |
| 462 | else if (desc->irq_data.chip->name) |
| 463 | seq_printf(p, " %8s", desc->irq_data.chip->name); |
| 464 | else |
| 465 | seq_printf(p, " %8s", "-"); |
| 466 | } else { |
| 467 | seq_printf(p, " %8s", "None"); |
| 468 | } |
Geert Uytterhoeven | 94b2c36 | 2011-04-30 22:56:20 +0200 | [diff] [blame] | 469 | #ifdef CONFIG_GENERIC_IRQ_SHOW_LEVEL |
Thomas Gleixner | ab7798f | 2011-03-25 16:48:50 +0100 | [diff] [blame] | 470 | seq_printf(p, " %-8s", irqd_is_level_type(&desc->irq_data) ? "Level" : "Edge"); |
| 471 | #endif |
Thomas Gleixner | ee0401e | 2011-03-17 13:36:57 +0100 | [diff] [blame] | 472 | if (desc->name) |
| 473 | seq_printf(p, "-%-8s", desc->name); |
Thomas Gleixner | c78b9b6 | 2010-12-16 17:21:47 +0100 | [diff] [blame] | 474 | |
| 475 | if (action) { |
| 476 | seq_printf(p, " %s", action->name); |
| 477 | while ((action = action->next) != NULL) |
| 478 | seq_printf(p, ", %s", action->name); |
| 479 | } |
| 480 | |
| 481 | seq_putc(p, '\n'); |
| 482 | out: |
| 483 | raw_spin_unlock_irqrestore(&desc->lock, flags); |
| 484 | return 0; |
| 485 | } |
| 486 | #endif |