Commit | Line | Data |
---|---|---|
1da177e4 LT |
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 | ||
97a41e26 AB |
13 | #include "internals.h" |
14 | ||
4a733ee1 | 15 | static struct proc_dir_entry *root_irq_dir; |
1da177e4 LT |
16 | |
17 | #ifdef CONFIG_SMP | |
18 | ||
1da177e4 LT |
19 | static int irq_affinity_read_proc(char *page, char **start, off_t off, |
20 | int count, int *eof, void *data) | |
21 | { | |
a53da52f | 22 | int len = cpumask_scnprintf(page, count, irq_desc[(long)data].affinity); |
1da177e4 LT |
23 | |
24 | if (count - len < 2) | |
25 | return -EINVAL; | |
26 | len += sprintf(page + len, "\n"); | |
27 | return len; | |
28 | } | |
29 | ||
30 | int no_irq_affinity; | |
31 | static int irq_affinity_write_proc(struct file *file, const char __user *buffer, | |
32 | unsigned long count, void *data) | |
33 | { | |
34 | unsigned int irq = (int)(long)data, full_count = count, err; | |
35 | cpumask_t new_value, tmp; | |
36 | ||
6e2ac664 | 37 | if (!irq_desc[irq].chip->set_affinity || no_irq_affinity || |
950f4427 | 38 | irq_balancing_disabled(irq)) |
1da177e4 LT |
39 | return -EIO; |
40 | ||
01a3ee2b | 41 | err = cpumask_parse_user(buffer, count, new_value); |
1da177e4 LT |
42 | if (err) |
43 | return err; | |
44 | ||
45 | /* | |
46 | * Do not allow disabling IRQs completely - it's a too easy | |
47 | * way to make the system unusable accidentally :-) At least | |
48 | * one online CPU still has to be targeted. | |
49 | */ | |
50 | cpus_and(tmp, new_value, cpu_online_map); | |
51 | if (cpus_empty(tmp)) | |
eee45269 IK |
52 | /* Special case for empty set - allow the architecture |
53 | code to set default SMP affinity. */ | |
54 | return select_smp_affinity(irq) ? -EINVAL : full_count; | |
1da177e4 | 55 | |
771ee3b0 | 56 | irq_set_affinity(irq, new_value); |
1da177e4 LT |
57 | |
58 | return full_count; | |
59 | } | |
60 | ||
61 | #endif | |
62 | ||
63 | #define MAX_NAMELEN 128 | |
64 | ||
65 | static int name_unique(unsigned int irq, struct irqaction *new_action) | |
66 | { | |
67 | struct irq_desc *desc = irq_desc + irq; | |
68 | struct irqaction *action; | |
d2d9433a DA |
69 | unsigned long flags; |
70 | int ret = 1; | |
1da177e4 | 71 | |
d2d9433a DA |
72 | spin_lock_irqsave(&desc->lock, flags); |
73 | for (action = desc->action ; action; action = action->next) { | |
1da177e4 | 74 | if ((action != new_action) && action->name && |
d2d9433a DA |
75 | !strcmp(new_action->name, action->name)) { |
76 | ret = 0; | |
77 | break; | |
78 | } | |
79 | } | |
80 | spin_unlock_irqrestore(&desc->lock, flags); | |
81 | return ret; | |
1da177e4 LT |
82 | } |
83 | ||
84 | void register_handler_proc(unsigned int irq, struct irqaction *action) | |
85 | { | |
86 | char name [MAX_NAMELEN]; | |
87 | ||
4a733ee1 | 88 | if (!irq_desc[irq].dir || action->dir || !action->name || |
1da177e4 LT |
89 | !name_unique(irq, action)) |
90 | return; | |
91 | ||
92 | memset(name, 0, MAX_NAMELEN); | |
93 | snprintf(name, MAX_NAMELEN, "%s", action->name); | |
94 | ||
95 | /* create /proc/irq/1234/handler/ */ | |
4a733ee1 | 96 | action->dir = proc_mkdir(name, irq_desc[irq].dir); |
1da177e4 LT |
97 | } |
98 | ||
99 | #undef MAX_NAMELEN | |
100 | ||
101 | #define MAX_NAMELEN 10 | |
102 | ||
103 | void register_irq_proc(unsigned int irq) | |
104 | { | |
105 | char name [MAX_NAMELEN]; | |
106 | ||
107 | if (!root_irq_dir || | |
f1c2662c | 108 | (irq_desc[irq].chip == &no_irq_chip) || |
4a733ee1 | 109 | irq_desc[irq].dir) |
1da177e4 LT |
110 | return; |
111 | ||
112 | memset(name, 0, MAX_NAMELEN); | |
113 | sprintf(name, "%d", irq); | |
114 | ||
115 | /* create /proc/irq/1234 */ | |
4a733ee1 | 116 | irq_desc[irq].dir = proc_mkdir(name, root_irq_dir); |
1da177e4 LT |
117 | |
118 | #ifdef CONFIG_SMP | |
119 | { | |
120 | struct proc_dir_entry *entry; | |
121 | ||
122 | /* create /proc/irq/<irq>/smp_affinity */ | |
4a733ee1 | 123 | entry = create_proc_entry("smp_affinity", 0600, irq_desc[irq].dir); |
1da177e4 LT |
124 | |
125 | if (entry) { | |
1da177e4 LT |
126 | entry->data = (void *)(long)irq; |
127 | entry->read_proc = irq_affinity_read_proc; | |
128 | entry->write_proc = irq_affinity_write_proc; | |
129 | } | |
1da177e4 LT |
130 | } |
131 | #endif | |
132 | } | |
133 | ||
134 | #undef MAX_NAMELEN | |
135 | ||
136 | void unregister_handler_proc(unsigned int irq, struct irqaction *action) | |
137 | { | |
138 | if (action->dir) | |
4a733ee1 | 139 | remove_proc_entry(action->dir->name, irq_desc[irq].dir); |
1da177e4 LT |
140 | } |
141 | ||
142 | void init_irq_proc(void) | |
143 | { | |
144 | int i; | |
145 | ||
146 | /* create /proc/irq */ | |
147 | root_irq_dir = proc_mkdir("irq", NULL); | |
148 | if (!root_irq_dir) | |
149 | return; | |
150 | ||
151 | /* | |
152 | * Create entries for all existing IRQs. | |
153 | */ | |
154 | for (i = 0; i < NR_IRQS; i++) | |
155 | register_irq_proc(i); | |
156 | } | |
157 |