blob: 2db91eb54ad8bb539b2dccdcb059d6872c2191a4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Bunk97a41e22006-01-08 01:02:17 -080013#include "internals.h"
14
Ingo Molnar4a733ee2006-06-29 02:24:42 -070015static struct proc_dir_entry *root_irq_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17#ifdef CONFIG_SMP
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019static int irq_affinity_read_proc(char *page, char **start, off_t off,
20 int count, int *eof, void *data)
21{
Ingo Molnara53da522006-06-29 02:24:38 -070022 int len = cpumask_scnprintf(page, count, irq_desc[(long)data].affinity);
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24 if (count - len < 2)
25 return -EINVAL;
26 len += sprintf(page + len, "\n");
27 return len;
28}
29
30int no_irq_affinity;
31static 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
Hidetoshi Seto6e2ac662006-12-08 02:35:58 -080037 if (!irq_desc[irq].chip->set_affinity || no_irq_affinity ||
Thomas Gleixner950f4422007-02-16 01:27:24 -080038 irq_balancing_disabled(irq))
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 return -EIO;
40
Reinette Chatre01a3ee22006-10-11 01:21:55 -070041 err = cpumask_parse_user(buffer, count, new_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 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))
Ivan Kokshayskyeee45262006-01-06 00:12:21 -080052 /* Special case for empty set - allow the architecture
53 code to set default SMP affinity. */
54 return select_smp_affinity(irq) ? -EINVAL : full_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Thomas Gleixner771ee3b2007-02-16 01:27:25 -080056 irq_set_affinity(irq, new_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58 return full_count;
59}
60
61#endif
62
63#define MAX_NAMELEN 128
64
65static int name_unique(unsigned int irq, struct irqaction *new_action)
66{
67 struct irq_desc *desc = irq_desc + irq;
68 struct irqaction *action;
69
70 for (action = desc->action ; action; action = action->next)
71 if ((action != new_action) && action->name &&
72 !strcmp(new_action->name, action->name))
73 return 0;
74 return 1;
75}
76
77void register_handler_proc(unsigned int irq, struct irqaction *action)
78{
79 char name [MAX_NAMELEN];
80
Ingo Molnar4a733ee2006-06-29 02:24:42 -070081 if (!irq_desc[irq].dir || action->dir || !action->name ||
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 !name_unique(irq, action))
83 return;
84
85 memset(name, 0, MAX_NAMELEN);
86 snprintf(name, MAX_NAMELEN, "%s", action->name);
87
88 /* create /proc/irq/1234/handler/ */
Ingo Molnar4a733ee2006-06-29 02:24:42 -070089 action->dir = proc_mkdir(name, irq_desc[irq].dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
92#undef MAX_NAMELEN
93
94#define MAX_NAMELEN 10
95
96void register_irq_proc(unsigned int irq)
97{
98 char name [MAX_NAMELEN];
99
100 if (!root_irq_dir ||
Ingo Molnarf1c26622006-06-29 02:24:57 -0700101 (irq_desc[irq].chip == &no_irq_chip) ||
Ingo Molnar4a733ee2006-06-29 02:24:42 -0700102 irq_desc[irq].dir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 return;
104
105 memset(name, 0, MAX_NAMELEN);
106 sprintf(name, "%d", irq);
107
108 /* create /proc/irq/1234 */
Ingo Molnar4a733ee2006-06-29 02:24:42 -0700109 irq_desc[irq].dir = proc_mkdir(name, root_irq_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111#ifdef CONFIG_SMP
112 {
113 struct proc_dir_entry *entry;
114
115 /* create /proc/irq/<irq>/smp_affinity */
Ingo Molnar4a733ee2006-06-29 02:24:42 -0700116 entry = create_proc_entry("smp_affinity", 0600, irq_desc[irq].dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118 if (entry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 entry->data = (void *)(long)irq;
120 entry->read_proc = irq_affinity_read_proc;
121 entry->write_proc = irq_affinity_write_proc;
122 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 }
124#endif
125}
126
127#undef MAX_NAMELEN
128
129void unregister_handler_proc(unsigned int irq, struct irqaction *action)
130{
131 if (action->dir)
Ingo Molnar4a733ee2006-06-29 02:24:42 -0700132 remove_proc_entry(action->dir->name, irq_desc[irq].dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133}
134
135void init_irq_proc(void)
136{
137 int i;
138
139 /* create /proc/irq */
140 root_irq_dir = proc_mkdir("irq", NULL);
141 if (!root_irq_dir)
142 return;
143
144 /*
145 * Create entries for all existing IRQs.
146 */
147 for (i = 0; i < NR_IRQS; i++)
148 register_irq_proc(i);
149}
150