Blame view

kernel/irq/proc.c 12.3 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
  /*
   * linux/kernel/irq/proc.c
   *
   * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar
   *
   * This file contains the /proc/irq/ handling code.
   */
  
  #include <linux/irq.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
10
  #include <linux/gfp.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
11
  #include <linux/proc_fs.h>
f18e439d1   Alexey Dobriyan   genirq: switch /p...
12
  #include <linux/seq_file.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
  #include <linux/interrupt.h>
c78b9b65f   Thomas Gleixner   genirq: Implement...
14
  #include <linux/kernel_stat.h>
0cf68c236   Ben Hutchings   genirq: Fix race ...
15
  #include <linux/mutex.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
16

97a41e261   Adrian Bunk   [PATCH] kernel/: ...
17
  #include "internals.h"
c291ee622   Thomas Gleixner   genirq: Prevent p...
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  /*
   * Access rules:
   *
   * procfs protects read/write of /proc/irq/N/ files against a
   * concurrent free of the interrupt descriptor. remove_proc_entry()
   * immediately prevents new read/writes to happen and waits for
   * already running read/write functions to complete.
   *
   * We remove the proc entries first and then delete the interrupt
   * descriptor from the radix tree and free it. So it is guaranteed
   * that irq_to_desc(N) is valid as long as the read/writes are
   * permitted by procfs.
   *
   * The read from /proc/interrupts is a different problem because there
   * is no protection. So the lookup and the access to irqdesc
   * information must be protected by sparse_irq_lock.
   */
4a733ee12   Ingo Molnar   [PATCH] genirq: c...
35
  static struct proc_dir_entry *root_irq_dir;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
36
37
  
  #ifdef CONFIG_SMP
4b060420a   Mike Travis   bitmap, irq: add ...
38
  static int show_irq_affinity(int type, struct seq_file *m, void *v)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
39
  {
08678b084   Yinghai Lu   generic: sparse i...
40
  	struct irq_desc *desc = irq_to_desc((long)m->private);
6b8ff3120   Thomas Gleixner   genirq: Convert c...
41
  	const struct cpumask *mask = desc->irq_data.affinity;
42ee2b741   Andi Kleen   x86_64: Report th...
42
43
  
  #ifdef CONFIG_GENERIC_PENDING_IRQ
f230b6d5c   Thomas Gleixner   genirq: Add IRQ_M...
44
  	if (irqd_is_setaffinity_pending(&desc->irq_data))
7f7ace0cd   Mike Travis   cpumask: update i...
45
  		mask = desc->pending_mask;
42ee2b741   Andi Kleen   x86_64: Report th...
46
  #endif
4b060420a   Mike Travis   bitmap, irq: add ...
47
  	if (type)
c1d7f03fd   Tejun Heo   irq: use %*pb[l] ...
48
49
  		seq_printf(m, "%*pbl
  ", cpumask_pr_args(mask));
4b060420a   Mike Travis   bitmap, irq: add ...
50
  	else
c1d7f03fd   Tejun Heo   irq: use %*pb[l] ...
51
52
  		seq_printf(m, "%*pb
  ", cpumask_pr_args(mask));
f18e439d1   Alexey Dobriyan   genirq: switch /p...
53
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
54
  }
e7a297b0d   Peter P Waskiewicz Jr   genirq: Add CPU m...
55
56
57
58
59
  static int irq_affinity_hint_proc_show(struct seq_file *m, void *v)
  {
  	struct irq_desc *desc = irq_to_desc((long)m->private);
  	unsigned long flags;
  	cpumask_var_t mask;
4308ad801   Peter P Waskiewicz Jr   genirq: Clear CPU...
60
  	if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
e7a297b0d   Peter P Waskiewicz Jr   genirq: Add CPU m...
61
62
63
64
65
  		return -ENOMEM;
  
  	raw_spin_lock_irqsave(&desc->lock, flags);
  	if (desc->affinity_hint)
  		cpumask_copy(mask, desc->affinity_hint);
e7a297b0d   Peter P Waskiewicz Jr   genirq: Add CPU m...
66
  	raw_spin_unlock_irqrestore(&desc->lock, flags);
c1d7f03fd   Tejun Heo   irq: use %*pb[l] ...
67
68
  	seq_printf(m, "%*pb
  ", cpumask_pr_args(mask));
e7a297b0d   Peter P Waskiewicz Jr   genirq: Add CPU m...
69
70
71
72
  	free_cpumask_var(mask);
  
  	return 0;
  }
25d61578d   John Keller   [IA64] SN: valida...
73
74
75
  #ifndef is_affinity_mask_valid
  #define is_affinity_mask_valid(val) 1
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
76
  int no_irq_affinity;
4b060420a   Mike Travis   bitmap, irq: add ...
77
78
79
80
81
82
83
84
85
86
87
88
  static int irq_affinity_proc_show(struct seq_file *m, void *v)
  {
  	return show_irq_affinity(0, m, v);
  }
  
  static int irq_affinity_list_proc_show(struct seq_file *m, void *v)
  {
  	return show_irq_affinity(1, m, v);
  }
  
  
  static ssize_t write_irq_affinity(int type, struct file *file,
f18e439d1   Alexey Dobriyan   genirq: switch /p...
89
  		const char __user *buffer, size_t count, loff_t *pos)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
90
  {
d9dda78ba   Al Viro   procfs: new helpe...
91
  	unsigned int irq = (int)(long)PDE_DATA(file_inode(file));
0de26520c   Rusty Russell   cpumask: make irq...
92
  	cpumask_var_t new_value;
f18e439d1   Alexey Dobriyan   genirq: switch /p...
93
  	int err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
94

bce43032a   Thomas Gleixner   genirq: Reuse exi...
95
  	if (!irq_can_set_affinity(irq) || no_irq_affinity)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
96
  		return -EIO;
0de26520c   Rusty Russell   cpumask: make irq...
97
98
  	if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
  		return -ENOMEM;
4b060420a   Mike Travis   bitmap, irq: add ...
99
100
101
102
  	if (type)
  		err = cpumask_parselist_user(buffer, count, new_value);
  	else
  		err = cpumask_parse_user(buffer, count, new_value);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
103
  	if (err)
0de26520c   Rusty Russell   cpumask: make irq...
104
  		goto free_cpumask;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
105

6bdf197b0   Ingo Molnar   ia64: cpumask fix...
106
  	if (!is_affinity_mask_valid(new_value)) {
0de26520c   Rusty Russell   cpumask: make irq...
107
108
109
  		err = -EINVAL;
  		goto free_cpumask;
  	}
25d61578d   John Keller   [IA64] SN: valida...
110

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
111
112
113
114
115
  	/*
  	 * Do not allow disabling IRQs completely - it's a too easy
  	 * way to make the system unusable accidentally :-) At least
  	 * one online CPU still has to be targeted.
  	 */
0de26520c   Rusty Russell   cpumask: make irq...
116
  	if (!cpumask_intersects(new_value, cpu_online_mask)) {
eee45269b   Ivan Kokshaysky   [PATCH] Alpha: co...
117
118
  		/* Special case for empty set - allow the architecture
  		   code to set default SMP affinity. */
3b8249e75   Thomas Gleixner   genirq: Do not co...
119
  		err = irq_select_affinity_usr(irq, new_value) ? -EINVAL : count;
0de26520c   Rusty Russell   cpumask: make irq...
120
121
122
123
124
125
126
127
  	} else {
  		irq_set_affinity(irq, new_value);
  		err = count;
  	}
  
  free_cpumask:
  	free_cpumask_var(new_value);
  	return err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
128
  }
4b060420a   Mike Travis   bitmap, irq: add ...
129
130
131
132
133
134
135
136
137
138
139
  static ssize_t irq_affinity_proc_write(struct file *file,
  		const char __user *buffer, size_t count, loff_t *pos)
  {
  	return write_irq_affinity(0, file, buffer, count, pos);
  }
  
  static ssize_t irq_affinity_list_proc_write(struct file *file,
  		const char __user *buffer, size_t count, loff_t *pos)
  {
  	return write_irq_affinity(1, file, buffer, count, pos);
  }
f18e439d1   Alexey Dobriyan   genirq: switch /p...
140
  static int irq_affinity_proc_open(struct inode *inode, struct file *file)
184047567   Max Krasnyansky   genirq: Expose de...
141
  {
d9dda78ba   Al Viro   procfs: new helpe...
142
  	return single_open(file, irq_affinity_proc_show, PDE_DATA(inode));
184047567   Max Krasnyansky   genirq: Expose de...
143
  }
4b060420a   Mike Travis   bitmap, irq: add ...
144
145
  static int irq_affinity_list_proc_open(struct inode *inode, struct file *file)
  {
d9dda78ba   Al Viro   procfs: new helpe...
146
  	return single_open(file, irq_affinity_list_proc_show, PDE_DATA(inode));
4b060420a   Mike Travis   bitmap, irq: add ...
147
  }
e7a297b0d   Peter P Waskiewicz Jr   genirq: Add CPU m...
148
149
  static int irq_affinity_hint_proc_open(struct inode *inode, struct file *file)
  {
d9dda78ba   Al Viro   procfs: new helpe...
150
  	return single_open(file, irq_affinity_hint_proc_show, PDE_DATA(inode));
e7a297b0d   Peter P Waskiewicz Jr   genirq: Add CPU m...
151
  }
f18e439d1   Alexey Dobriyan   genirq: switch /p...
152
153
154
155
156
157
158
  static const struct file_operations irq_affinity_proc_fops = {
  	.open		= irq_affinity_proc_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
  	.release	= single_release,
  	.write		= irq_affinity_proc_write,
  };
e7a297b0d   Peter P Waskiewicz Jr   genirq: Add CPU m...
159
160
161
162
163
164
  static const struct file_operations irq_affinity_hint_proc_fops = {
  	.open		= irq_affinity_hint_proc_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
  	.release	= single_release,
  };
4b060420a   Mike Travis   bitmap, irq: add ...
165
166
167
168
169
170
171
  static const struct file_operations irq_affinity_list_proc_fops = {
  	.open		= irq_affinity_list_proc_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
  	.release	= single_release,
  	.write		= irq_affinity_list_proc_write,
  };
f18e439d1   Alexey Dobriyan   genirq: switch /p...
172
173
  static int default_affinity_show(struct seq_file *m, void *v)
  {
c1d7f03fd   Tejun Heo   irq: use %*pb[l] ...
174
175
  	seq_printf(m, "%*pb
  ", cpumask_pr_args(irq_default_affinity));
f18e439d1   Alexey Dobriyan   genirq: switch /p...
176
177
178
179
180
  	return 0;
  }
  
  static ssize_t default_affinity_write(struct file *file,
  		const char __user *buffer, size_t count, loff_t *ppos)
184047567   Max Krasnyansky   genirq: Expose de...
181
  {
d036e67b4   Rusty Russell   cpumask: convert ...
182
  	cpumask_var_t new_value;
f18e439d1   Alexey Dobriyan   genirq: switch /p...
183
  	int err;
184047567   Max Krasnyansky   genirq: Expose de...
184

d036e67b4   Rusty Russell   cpumask: convert ...
185
186
187
188
  	if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
  		return -ENOMEM;
  
  	err = cpumask_parse_user(buffer, count, new_value);
184047567   Max Krasnyansky   genirq: Expose de...
189
  	if (err)
d036e67b4   Rusty Russell   cpumask: convert ...
190
  		goto out;
184047567   Max Krasnyansky   genirq: Expose de...
191

d036e67b4   Rusty Russell   cpumask: convert ...
192
193
194
195
  	if (!is_affinity_mask_valid(new_value)) {
  		err = -EINVAL;
  		goto out;
  	}
184047567   Max Krasnyansky   genirq: Expose de...
196
197
198
199
200
201
  
  	/*
  	 * Do not allow disabling IRQs completely - it's a too easy
  	 * way to make the system unusable accidentally :-) At least
  	 * one online CPU still has to be targeted.
  	 */
d036e67b4   Rusty Russell   cpumask: convert ...
202
203
204
205
  	if (!cpumask_intersects(new_value, cpu_online_mask)) {
  		err = -EINVAL;
  		goto out;
  	}
184047567   Max Krasnyansky   genirq: Expose de...
206

d036e67b4   Rusty Russell   cpumask: convert ...
207
208
  	cpumask_copy(irq_default_affinity, new_value);
  	err = count;
184047567   Max Krasnyansky   genirq: Expose de...
209

d036e67b4   Rusty Russell   cpumask: convert ...
210
211
212
  out:
  	free_cpumask_var(new_value);
  	return err;
184047567   Max Krasnyansky   genirq: Expose de...
213
  }
f18e439d1   Alexey Dobriyan   genirq: switch /p...
214
215
216
  
  static int default_affinity_open(struct inode *inode, struct file *file)
  {
d9dda78ba   Al Viro   procfs: new helpe...
217
  	return single_open(file, default_affinity_show, PDE_DATA(inode));
f18e439d1   Alexey Dobriyan   genirq: switch /p...
218
219
220
221
222
223
224
225
226
  }
  
  static const struct file_operations default_affinity_proc_fops = {
  	.open		= default_affinity_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
  	.release	= single_release,
  	.write		= default_affinity_write,
  };
92d6b71ab   Dimitri Sivanich   genirq: Expose ir...
227
228
229
230
  
  static int irq_node_proc_show(struct seq_file *m, void *v)
  {
  	struct irq_desc *desc = irq_to_desc((long) m->private);
6b8ff3120   Thomas Gleixner   genirq: Convert c...
231
232
  	seq_printf(m, "%d
  ", desc->irq_data.node);
92d6b71ab   Dimitri Sivanich   genirq: Expose ir...
233
234
235
236
237
  	return 0;
  }
  
  static int irq_node_proc_open(struct inode *inode, struct file *file)
  {
d9dda78ba   Al Viro   procfs: new helpe...
238
  	return single_open(file, irq_node_proc_show, PDE_DATA(inode));
92d6b71ab   Dimitri Sivanich   genirq: Expose ir...
239
240
241
242
243
244
245
246
  }
  
  static const struct file_operations irq_node_proc_fops = {
  	.open		= irq_node_proc_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
  	.release	= single_release,
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
247
  #endif
a1afb6371   Alexey Dobriyan   genirq: switch /p...
248
  static int irq_spurious_proc_show(struct seq_file *m, void *v)
96d97cf03   Andi Kleen   x86: add /proc/ir...
249
  {
a1afb6371   Alexey Dobriyan   genirq: switch /p...
250
251
252
253
254
255
256
257
258
259
260
261
262
  	struct irq_desc *desc = irq_to_desc((long) m->private);
  
  	seq_printf(m, "count %u
  " "unhandled %u
  " "last_unhandled %u ms
  ",
  		   desc->irq_count, desc->irqs_unhandled,
  		   jiffies_to_msecs(desc->last_unhandled));
  	return 0;
  }
  
  static int irq_spurious_proc_open(struct inode *inode, struct file *file)
  {
d9dda78ba   Al Viro   procfs: new helpe...
263
  	return single_open(file, irq_spurious_proc_show, PDE_DATA(inode));
96d97cf03   Andi Kleen   x86: add /proc/ir...
264
  }
a1afb6371   Alexey Dobriyan   genirq: switch /p...
265
266
267
268
269
270
  static const struct file_operations irq_spurious_proc_fops = {
  	.open		= irq_spurious_proc_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
  	.release	= single_release,
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
271
272
273
274
  #define MAX_NAMELEN 128
  
  static int name_unique(unsigned int irq, struct irqaction *new_action)
  {
08678b084   Yinghai Lu   generic: sparse i...
275
  	struct irq_desc *desc = irq_to_desc(irq);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
276
  	struct irqaction *action;
d2d9433a4   Dmitry Adamushko   kernel/irq/proc.c...
277
278
  	unsigned long flags;
  	int ret = 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
279

239007b84   Thomas Gleixner   genirq: Convert i...
280
  	raw_spin_lock_irqsave(&desc->lock, flags);
d2d9433a4   Dmitry Adamushko   kernel/irq/proc.c...
281
  	for (action = desc->action ; action; action = action->next) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
282
  		if ((action != new_action) && action->name &&
d2d9433a4   Dmitry Adamushko   kernel/irq/proc.c...
283
284
285
286
287
  				!strcmp(new_action->name, action->name)) {
  			ret = 0;
  			break;
  		}
  	}
239007b84   Thomas Gleixner   genirq: Convert i...
288
  	raw_spin_unlock_irqrestore(&desc->lock, flags);
d2d9433a4   Dmitry Adamushko   kernel/irq/proc.c...
289
  	return ret;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
290
291
292
293
294
  }
  
  void register_handler_proc(unsigned int irq, struct irqaction *action)
  {
  	char name [MAX_NAMELEN];
08678b084   Yinghai Lu   generic: sparse i...
295
  	struct irq_desc *desc = irq_to_desc(irq);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
296

08678b084   Yinghai Lu   generic: sparse i...
297
  	if (!desc->dir || action->dir || !action->name ||
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
298
299
300
301
302
303
304
  					!name_unique(irq, action))
  		return;
  
  	memset(name, 0, MAX_NAMELEN);
  	snprintf(name, MAX_NAMELEN, "%s", action->name);
  
  	/* create /proc/irq/1234/handler/ */
08678b084   Yinghai Lu   generic: sparse i...
305
  	action->dir = proc_mkdir(name, desc->dir);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
306
307
308
309
310
  }
  
  #undef MAX_NAMELEN
  
  #define MAX_NAMELEN 10
2c6927a38   Yinghai Lu   irq: replace loop...
311
  void register_irq_proc(unsigned int irq, struct irq_desc *desc)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
312
  {
0cf68c236   Ben Hutchings   genirq: Fix race ...
313
  	static DEFINE_MUTEX(register_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
314
  	char name [MAX_NAMELEN];
0cf68c236   Ben Hutchings   genirq: Fix race ...
315
  	if (!root_irq_dir || (desc->irq_data.chip == &no_irq_chip))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
316
  		return;
0cf68c236   Ben Hutchings   genirq: Fix race ...
317
318
319
320
321
322
323
324
325
  	/*
  	 * irq directories are registered only when a handler is
  	 * added, not when the descriptor is created, so multiple
  	 * tasks might try to register at the same time.
  	 */
  	mutex_lock(&register_lock);
  
  	if (desc->dir)
  		goto out_unlock;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
326
327
328
329
  	memset(name, 0, MAX_NAMELEN);
  	sprintf(name, "%d", irq);
  
  	/* create /proc/irq/1234 */
08678b084   Yinghai Lu   generic: sparse i...
330
  	desc->dir = proc_mkdir(name, root_irq_dir);
c82a43d40   Cyrill Gorcunov   irq: Do not attem...
331
  	if (!desc->dir)
0cf68c236   Ben Hutchings   genirq: Fix race ...
332
  		goto out_unlock;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
333
334
  
  #ifdef CONFIG_SMP
f18e439d1   Alexey Dobriyan   genirq: switch /p...
335
  	/* create /proc/irq/<irq>/smp_affinity */
bab5c790c   Chema Gonzalez   genirq: procfs: M...
336
  	proc_create_data("smp_affinity", 0644, desc->dir,
f18e439d1   Alexey Dobriyan   genirq: switch /p...
337
  			 &irq_affinity_proc_fops, (void *)(long)irq);
92d6b71ab   Dimitri Sivanich   genirq: Expose ir...
338

e7a297b0d   Peter P Waskiewicz Jr   genirq: Add CPU m...
339
  	/* create /proc/irq/<irq>/affinity_hint */
bab5c790c   Chema Gonzalez   genirq: procfs: M...
340
  	proc_create_data("affinity_hint", 0444, desc->dir,
e7a297b0d   Peter P Waskiewicz Jr   genirq: Add CPU m...
341
  			 &irq_affinity_hint_proc_fops, (void *)(long)irq);
4b060420a   Mike Travis   bitmap, irq: add ...
342
  	/* create /proc/irq/<irq>/smp_affinity_list */
bab5c790c   Chema Gonzalez   genirq: procfs: M...
343
  	proc_create_data("smp_affinity_list", 0644, desc->dir,
4b060420a   Mike Travis   bitmap, irq: add ...
344
  			 &irq_affinity_list_proc_fops, (void *)(long)irq);
92d6b71ab   Dimitri Sivanich   genirq: Expose ir...
345
346
  	proc_create_data("node", 0444, desc->dir,
  			 &irq_node_proc_fops, (void *)(long)irq);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
347
  #endif
96d97cf03   Andi Kleen   x86: add /proc/ir...
348

a1afb6371   Alexey Dobriyan   genirq: switch /p...
349
350
  	proc_create_data("spurious", 0444, desc->dir,
  			 &irq_spurious_proc_fops, (void *)(long)irq);
0cf68c236   Ben Hutchings   genirq: Fix race ...
351
352
353
  
  out_unlock:
  	mutex_unlock(&register_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
354
  }
13bfe99e0   Thomas Gleixner   genirq: Prepare p...
355
356
357
358
359
360
361
362
363
  void unregister_irq_proc(unsigned int irq, struct irq_desc *desc)
  {
  	char name [MAX_NAMELEN];
  
  	if (!root_irq_dir || !desc->dir)
  		return;
  #ifdef CONFIG_SMP
  	remove_proc_entry("smp_affinity", desc->dir);
  	remove_proc_entry("affinity_hint", desc->dir);
def945eeb   Yinghai Lu   irq: Remove smp_a...
364
  	remove_proc_entry("smp_affinity_list", desc->dir);
13bfe99e0   Thomas Gleixner   genirq: Prepare p...
365
366
367
368
369
370
371
372
  	remove_proc_entry("node", desc->dir);
  #endif
  	remove_proc_entry("spurious", desc->dir);
  
  	memset(name, 0, MAX_NAMELEN);
  	sprintf(name, "%u", irq);
  	remove_proc_entry(name, root_irq_dir);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
373
374
375
376
  #undef MAX_NAMELEN
  
  void unregister_handler_proc(unsigned int irq, struct irqaction *action)
  {
a8ca16ea7   David Howells   proc: Supply a fu...
377
  	proc_remove(action->dir);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
378
  }
3786fc710   roel kluin   irq: make variabl...
379
  static void register_default_affinity_proc(void)
184047567   Max Krasnyansky   genirq: Expose de...
380
381
  {
  #ifdef CONFIG_SMP
bab5c790c   Chema Gonzalez   genirq: procfs: M...
382
  	proc_create("irq/default_smp_affinity", 0644, NULL,
f18e439d1   Alexey Dobriyan   genirq: switch /p...
383
  		    &default_affinity_proc_fops);
184047567   Max Krasnyansky   genirq: Expose de...
384
385
  #endif
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
386
387
  void init_irq_proc(void)
  {
2c6927a38   Yinghai Lu   irq: replace loop...
388
389
  	unsigned int irq;
  	struct irq_desc *desc;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
390
391
392
393
394
  
  	/* create /proc/irq */
  	root_irq_dir = proc_mkdir("irq", NULL);
  	if (!root_irq_dir)
  		return;
184047567   Max Krasnyansky   genirq: Expose de...
395
  	register_default_affinity_proc();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
396
397
398
  	/*
  	 * Create entries for all existing IRQs.
  	 */
0b8f1efad   Yinghai Lu   sparse irq_desc[]...
399
400
401
  	for_each_irq_desc(irq, desc) {
  		if (!desc)
  			continue;
2c6927a38   Yinghai Lu   irq: replace loop...
402
  		register_irq_proc(irq, desc);
0b8f1efad   Yinghai Lu   sparse irq_desc[]...
403
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
404
  }
c78b9b65f   Thomas Gleixner   genirq: Implement...
405
406
407
408
409
410
  #ifdef CONFIG_GENERIC_IRQ_SHOW
  
  int __weak arch_show_interrupts(struct seq_file *p, int prec)
  {
  	return 0;
  }
a6e120ed4   Thomas Gleixner   alpha: Use generi...
411
412
413
  #ifndef ACTUAL_NR_IRQS
  # define ACTUAL_NR_IRQS nr_irqs
  #endif
c78b9b65f   Thomas Gleixner   genirq: Implement...
414
415
416
417
418
419
420
421
  int show_interrupts(struct seq_file *p, void *v)
  {
  	static int prec;
  
  	unsigned long flags, any_count = 0;
  	int i = *(loff_t *) v, j;
  	struct irqaction *action;
  	struct irq_desc *desc;
a6e120ed4   Thomas Gleixner   alpha: Use generi...
422
  	if (i > ACTUAL_NR_IRQS)
c78b9b65f   Thomas Gleixner   genirq: Implement...
423
  		return 0;
a6e120ed4   Thomas Gleixner   alpha: Use generi...
424
  	if (i == ACTUAL_NR_IRQS)
c78b9b65f   Thomas Gleixner   genirq: Implement...
425
426
427
428
429
430
431
432
433
434
435
436
437
  		return arch_show_interrupts(p, prec);
  
  	/* print header and calculate the width of the first column */
  	if (i == 0) {
  		for (prec = 3, j = 1000; prec < 10 && j <= nr_irqs; ++prec)
  			j *= 10;
  
  		seq_printf(p, "%*s", prec + 8, "");
  		for_each_online_cpu(j)
  			seq_printf(p, "CPU%-8d", j);
  		seq_putc(p, '
  ');
  	}
c291ee622   Thomas Gleixner   genirq: Prevent p...
438
  	irq_lock_sparse();
c78b9b65f   Thomas Gleixner   genirq: Implement...
439
440
  	desc = irq_to_desc(i);
  	if (!desc)
c291ee622   Thomas Gleixner   genirq: Prevent p...
441
  		goto outsparse;
c78b9b65f   Thomas Gleixner   genirq: Implement...
442
443
444
445
446
447
448
449
450
451
452
  
  	raw_spin_lock_irqsave(&desc->lock, flags);
  	for_each_online_cpu(j)
  		any_count |= kstat_irqs_cpu(i, j);
  	action = desc->action;
  	if (!action && !any_count)
  		goto out;
  
  	seq_printf(p, "%*d: ", prec, i);
  	for_each_online_cpu(j)
  		seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));
ab7798ffc   Thomas Gleixner   genirq: Expand ge...
453
454
455
456
457
458
459
460
461
462
463
  
  	if (desc->irq_data.chip) {
  		if (desc->irq_data.chip->irq_print_chip)
  			desc->irq_data.chip->irq_print_chip(&desc->irq_data, p);
  		else if (desc->irq_data.chip->name)
  			seq_printf(p, " %8s", desc->irq_data.chip->name);
  		else
  			seq_printf(p, " %8s", "-");
  	} else {
  		seq_printf(p, " %8s", "None");
  	}
c12d2f42a   Grant Likely   irqdomain: Includ...
464
465
  	if (desc->irq_data.domain)
  		seq_printf(p, " %*d", prec, (int) desc->irq_data.hwirq);
94b2c363d   Geert Uytterhoeven   genirq: Fix typo ...
466
  #ifdef CONFIG_GENERIC_IRQ_SHOW_LEVEL
ab7798ffc   Thomas Gleixner   genirq: Expand ge...
467
468
  	seq_printf(p, " %-8s", irqd_is_level_type(&desc->irq_data) ? "Level" : "Edge");
  #endif
ee0401ec1   Thomas Gleixner   genirq: show_inte...
469
470
  	if (desc->name)
  		seq_printf(p, "-%-8s", desc->name);
c78b9b65f   Thomas Gleixner   genirq: Implement...
471
472
473
474
475
476
477
478
479
480
481
  
  	if (action) {
  		seq_printf(p, "  %s", action->name);
  		while ((action = action->next) != NULL)
  			seq_printf(p, ", %s", action->name);
  	}
  
  	seq_putc(p, '
  ');
  out:
  	raw_spin_unlock_irqrestore(&desc->lock, flags);
c291ee622   Thomas Gleixner   genirq: Prevent p...
482
483
  outsparse:
  	irq_unlock_sparse();
c78b9b65f   Thomas Gleixner   genirq: Implement...
484
485
486
  	return 0;
  }
  #endif