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