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 | |
Ashok Raj | 54d5d42 | 2005-09-06 15:16:15 -0700 | [diff] [blame] | 19 | #ifdef CONFIG_GENERIC_PENDING_IRQ |
| 20 | void proc_set_irq_affinity(unsigned int irq, cpumask_t mask_val) |
| 21 | { |
Zhang Yanmin | 1b61b91 | 2006-06-23 02:04:22 -0700 | [diff] [blame] | 22 | set_balance_irq_affinity(irq, mask_val); |
| 23 | |
Ashok Raj | 54d5d42 | 2005-09-06 15:16:15 -0700 | [diff] [blame] | 24 | /* |
| 25 | * Save these away for later use. Re-progam when the |
| 26 | * interrupt is pending |
| 27 | */ |
| 28 | set_pending_irq(irq, mask_val); |
| 29 | } |
| 30 | #else |
| 31 | void proc_set_irq_affinity(unsigned int irq, cpumask_t mask_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | { |
Zhang Yanmin | 1b61b91 | 2006-06-23 02:04:22 -0700 | [diff] [blame] | 33 | set_balance_irq_affinity(irq, mask_val); |
Ingo Molnar | a53da52 | 2006-06-29 02:24:38 -0700 | [diff] [blame] | 34 | irq_desc[irq].affinity = mask_val; |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 35 | irq_desc[irq].chip->set_affinity(irq, mask_val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | } |
Ashok Raj | 54d5d42 | 2005-09-06 15:16:15 -0700 | [diff] [blame] | 37 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | static int irq_affinity_read_proc(char *page, char **start, off_t off, |
| 40 | int count, int *eof, void *data) |
| 41 | { |
Ingo Molnar | a53da52 | 2006-06-29 02:24:38 -0700 | [diff] [blame] | 42 | int len = cpumask_scnprintf(page, count, irq_desc[(long)data].affinity); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | if (count - len < 2) |
| 45 | return -EINVAL; |
| 46 | len += sprintf(page + len, "\n"); |
| 47 | return len; |
| 48 | } |
| 49 | |
| 50 | int no_irq_affinity; |
| 51 | static int irq_affinity_write_proc(struct file *file, const char __user *buffer, |
| 52 | unsigned long count, void *data) |
| 53 | { |
| 54 | unsigned int irq = (int)(long)data, full_count = count, err; |
| 55 | cpumask_t new_value, tmp; |
| 56 | |
Hidetoshi Seto | 6e2ac66 | 2006-12-08 02:35:58 -0800 | [diff] [blame] | 57 | if (!irq_desc[irq].chip->set_affinity || no_irq_affinity || |
| 58 | CHECK_IRQ_PER_CPU(irq_desc[irq].status)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | return -EIO; |
| 60 | |
Reinette Chatre | 01a3ee2 | 2006-10-11 01:21:55 -0700 | [diff] [blame] | 61 | err = cpumask_parse_user(buffer, count, new_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | if (err) |
| 63 | return err; |
| 64 | |
| 65 | /* |
| 66 | * Do not allow disabling IRQs completely - it's a too easy |
| 67 | * way to make the system unusable accidentally :-) At least |
| 68 | * one online CPU still has to be targeted. |
| 69 | */ |
| 70 | cpus_and(tmp, new_value, cpu_online_map); |
| 71 | if (cpus_empty(tmp)) |
Ivan Kokshaysky | eee4526 | 2006-01-06 00:12:21 -0800 | [diff] [blame] | 72 | /* Special case for empty set - allow the architecture |
| 73 | code to set default SMP affinity. */ |
| 74 | return select_smp_affinity(irq) ? -EINVAL : full_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | proc_set_irq_affinity(irq, new_value); |
| 77 | |
| 78 | return full_count; |
| 79 | } |
| 80 | |
| 81 | #endif |
| 82 | |
| 83 | #define MAX_NAMELEN 128 |
| 84 | |
| 85 | static int name_unique(unsigned int irq, struct irqaction *new_action) |
| 86 | { |
| 87 | struct irq_desc *desc = irq_desc + irq; |
| 88 | struct irqaction *action; |
| 89 | |
| 90 | for (action = desc->action ; action; action = action->next) |
| 91 | if ((action != new_action) && action->name && |
| 92 | !strcmp(new_action->name, action->name)) |
| 93 | return 0; |
| 94 | return 1; |
| 95 | } |
| 96 | |
| 97 | void register_handler_proc(unsigned int irq, struct irqaction *action) |
| 98 | { |
| 99 | char name [MAX_NAMELEN]; |
| 100 | |
Ingo Molnar | 4a733ee | 2006-06-29 02:24:42 -0700 | [diff] [blame] | 101 | if (!irq_desc[irq].dir || action->dir || !action->name || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | !name_unique(irq, action)) |
| 103 | return; |
| 104 | |
| 105 | memset(name, 0, MAX_NAMELEN); |
| 106 | snprintf(name, MAX_NAMELEN, "%s", action->name); |
| 107 | |
| 108 | /* create /proc/irq/1234/handler/ */ |
Ingo Molnar | 4a733ee | 2006-06-29 02:24:42 -0700 | [diff] [blame] | 109 | action->dir = proc_mkdir(name, irq_desc[irq].dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | #undef MAX_NAMELEN |
| 113 | |
| 114 | #define MAX_NAMELEN 10 |
| 115 | |
| 116 | void register_irq_proc(unsigned int irq) |
| 117 | { |
| 118 | char name [MAX_NAMELEN]; |
| 119 | |
| 120 | if (!root_irq_dir || |
Ingo Molnar | f1c2662 | 2006-06-29 02:24:57 -0700 | [diff] [blame] | 121 | (irq_desc[irq].chip == &no_irq_chip) || |
Ingo Molnar | 4a733ee | 2006-06-29 02:24:42 -0700 | [diff] [blame] | 122 | irq_desc[irq].dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | return; |
| 124 | |
| 125 | memset(name, 0, MAX_NAMELEN); |
| 126 | sprintf(name, "%d", irq); |
| 127 | |
| 128 | /* create /proc/irq/1234 */ |
Ingo Molnar | 4a733ee | 2006-06-29 02:24:42 -0700 | [diff] [blame] | 129 | irq_desc[irq].dir = proc_mkdir(name, root_irq_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | #ifdef CONFIG_SMP |
| 132 | { |
| 133 | struct proc_dir_entry *entry; |
| 134 | |
| 135 | /* create /proc/irq/<irq>/smp_affinity */ |
Ingo Molnar | 4a733ee | 2006-06-29 02:24:42 -0700 | [diff] [blame] | 136 | entry = create_proc_entry("smp_affinity", 0600, irq_desc[irq].dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
| 138 | if (entry) { |
| 139 | entry->nlink = 1; |
| 140 | entry->data = (void *)(long)irq; |
| 141 | entry->read_proc = irq_affinity_read_proc; |
| 142 | entry->write_proc = irq_affinity_write_proc; |
| 143 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } |
| 145 | #endif |
| 146 | } |
| 147 | |
| 148 | #undef MAX_NAMELEN |
| 149 | |
| 150 | void unregister_handler_proc(unsigned int irq, struct irqaction *action) |
| 151 | { |
| 152 | if (action->dir) |
Ingo Molnar | 4a733ee | 2006-06-29 02:24:42 -0700 | [diff] [blame] | 153 | remove_proc_entry(action->dir->name, irq_desc[irq].dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | void init_irq_proc(void) |
| 157 | { |
| 158 | int i; |
| 159 | |
| 160 | /* create /proc/irq */ |
| 161 | root_irq_dir = proc_mkdir("irq", NULL); |
| 162 | if (!root_irq_dir) |
| 163 | return; |
| 164 | |
| 165 | /* |
| 166 | * Create entries for all existing IRQs. |
| 167 | */ |
| 168 | for (i = 0; i < NR_IRQS; i++) |
| 169 | register_irq_proc(i); |
| 170 | } |
| 171 | |