blob: b4f1674fca7987d8f99fa707eb2655cd20f0bc37 [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
John Keller25d61572007-05-10 22:42:44 -070030#ifndef is_affinity_mask_valid
31#define is_affinity_mask_valid(val) 1
32#endif
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034int no_irq_affinity;
35static int irq_affinity_write_proc(struct file *file, const char __user *buffer,
36 unsigned long count, void *data)
37{
38 unsigned int irq = (int)(long)data, full_count = count, err;
39 cpumask_t new_value, tmp;
40
Hidetoshi Seto6e2ac662006-12-08 02:35:58 -080041 if (!irq_desc[irq].chip->set_affinity || no_irq_affinity ||
Thomas Gleixner950f4422007-02-16 01:27:24 -080042 irq_balancing_disabled(irq))
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 return -EIO;
44
Reinette Chatre01a3ee22006-10-11 01:21:55 -070045 err = cpumask_parse_user(buffer, count, new_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 if (err)
47 return err;
48
John Keller25d61572007-05-10 22:42:44 -070049 if (!is_affinity_mask_valid(new_value))
50 return -EINVAL;
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 /*
53 * Do not allow disabling IRQs completely - it's a too easy
54 * way to make the system unusable accidentally :-) At least
55 * one online CPU still has to be targeted.
56 */
57 cpus_and(tmp, new_value, cpu_online_map);
58 if (cpus_empty(tmp))
Ivan Kokshayskyeee45262006-01-06 00:12:21 -080059 /* Special case for empty set - allow the architecture
60 code to set default SMP affinity. */
61 return select_smp_affinity(irq) ? -EINVAL : full_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Thomas Gleixner771ee3b2007-02-16 01:27:25 -080063 irq_set_affinity(irq, new_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65 return full_count;
66}
67
68#endif
69
70#define MAX_NAMELEN 128
71
72static int name_unique(unsigned int irq, struct irqaction *new_action)
73{
74 struct irq_desc *desc = irq_desc + irq;
75 struct irqaction *action;
Dmitry Adamushkod2d94332007-05-08 00:27:31 -070076 unsigned long flags;
77 int ret = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Dmitry Adamushkod2d94332007-05-08 00:27:31 -070079 spin_lock_irqsave(&desc->lock, flags);
80 for (action = desc->action ; action; action = action->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 if ((action != new_action) && action->name &&
Dmitry Adamushkod2d94332007-05-08 00:27:31 -070082 !strcmp(new_action->name, action->name)) {
83 ret = 0;
84 break;
85 }
86 }
87 spin_unlock_irqrestore(&desc->lock, flags);
88 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089}
90
91void register_handler_proc(unsigned int irq, struct irqaction *action)
92{
93 char name [MAX_NAMELEN];
94
Ingo Molnar4a733ee2006-06-29 02:24:42 -070095 if (!irq_desc[irq].dir || action->dir || !action->name ||
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 !name_unique(irq, action))
97 return;
98
99 memset(name, 0, MAX_NAMELEN);
100 snprintf(name, MAX_NAMELEN, "%s", action->name);
101
102 /* create /proc/irq/1234/handler/ */
Ingo Molnar4a733ee2006-06-29 02:24:42 -0700103 action->dir = proc_mkdir(name, irq_desc[irq].dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104}
105
106#undef MAX_NAMELEN
107
108#define MAX_NAMELEN 10
109
110void register_irq_proc(unsigned int irq)
111{
112 char name [MAX_NAMELEN];
113
114 if (!root_irq_dir ||
Ingo Molnarf1c26622006-06-29 02:24:57 -0700115 (irq_desc[irq].chip == &no_irq_chip) ||
Ingo Molnar4a733ee2006-06-29 02:24:42 -0700116 irq_desc[irq].dir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 return;
118
119 memset(name, 0, MAX_NAMELEN);
120 sprintf(name, "%d", irq);
121
122 /* create /proc/irq/1234 */
Ingo Molnar4a733ee2006-06-29 02:24:42 -0700123 irq_desc[irq].dir = proc_mkdir(name, root_irq_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125#ifdef CONFIG_SMP
126 {
127 struct proc_dir_entry *entry;
128
129 /* create /proc/irq/<irq>/smp_affinity */
Ingo Molnar4a733ee2006-06-29 02:24:42 -0700130 entry = create_proc_entry("smp_affinity", 0600, irq_desc[irq].dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 if (entry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 entry->data = (void *)(long)irq;
134 entry->read_proc = irq_affinity_read_proc;
135 entry->write_proc = irq_affinity_write_proc;
136 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 }
138#endif
139}
140
141#undef MAX_NAMELEN
142
143void unregister_handler_proc(unsigned int irq, struct irqaction *action)
144{
145 if (action->dir)
Ingo Molnar4a733ee2006-06-29 02:24:42 -0700146 remove_proc_entry(action->dir->name, irq_desc[irq].dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147}
148
149void init_irq_proc(void)
150{
151 int i;
152
153 /* create /proc/irq */
154 root_irq_dir = proc_mkdir("irq", NULL);
155 if (!root_irq_dir)
156 return;
157
158 /*
159 * Create entries for all existing IRQs.
160 */
161 for (i = 0; i < NR_IRQS; i++)
162 register_irq_proc(i);
163}
164