[PATCH] i386: Clean up arch/i386/kernel/cpu/mcheck/p4.c
[linux-2.6/mini2440.git] / kernel / irq / proc.c
blob2db91eb54ad8bb539b2dccdcb059d6872c2191a4
1 /*
2 * linux/kernel/irq/proc.c
4 * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar
6 * This file contains the /proc/irq/ handling code.
7 */
9 #include <linux/irq.h>
10 #include <linux/proc_fs.h>
11 #include <linux/interrupt.h>
13 #include "internals.h"
15 static struct proc_dir_entry *root_irq_dir;
17 #ifdef CONFIG_SMP
19 static int irq_affinity_read_proc(char *page, char **start, off_t off,
20 int count, int *eof, void *data)
22 int len = cpumask_scnprintf(page, count, irq_desc[(long)data].affinity);
24 if (count - len < 2)
25 return -EINVAL;
26 len += sprintf(page + len, "\n");
27 return len;
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)
34 unsigned int irq = (int)(long)data, full_count = count, err;
35 cpumask_t new_value, tmp;
37 if (!irq_desc[irq].chip->set_affinity || no_irq_affinity ||
38 irq_balancing_disabled(irq))
39 return -EIO;
41 err = cpumask_parse_user(buffer, count, new_value);
42 if (err)
43 return err;
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.
50 cpus_and(tmp, new_value, cpu_online_map);
51 if (cpus_empty(tmp))
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;
56 irq_set_affinity(irq, new_value);
58 return full_count;
61 #endif
63 #define MAX_NAMELEN 128
65 static int name_unique(unsigned int irq, struct irqaction *new_action)
67 struct irq_desc *desc = irq_desc + irq;
68 struct irqaction *action;
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;
77 void register_handler_proc(unsigned int irq, struct irqaction *action)
79 char name [MAX_NAMELEN];
81 if (!irq_desc[irq].dir || action->dir || !action->name ||
82 !name_unique(irq, action))
83 return;
85 memset(name, 0, MAX_NAMELEN);
86 snprintf(name, MAX_NAMELEN, "%s", action->name);
88 /* create /proc/irq/1234/handler/ */
89 action->dir = proc_mkdir(name, irq_desc[irq].dir);
92 #undef MAX_NAMELEN
94 #define MAX_NAMELEN 10
96 void register_irq_proc(unsigned int irq)
98 char name [MAX_NAMELEN];
100 if (!root_irq_dir ||
101 (irq_desc[irq].chip == &no_irq_chip) ||
102 irq_desc[irq].dir)
103 return;
105 memset(name, 0, MAX_NAMELEN);
106 sprintf(name, "%d", irq);
108 /* create /proc/irq/1234 */
109 irq_desc[irq].dir = proc_mkdir(name, root_irq_dir);
111 #ifdef CONFIG_SMP
113 struct proc_dir_entry *entry;
115 /* create /proc/irq/<irq>/smp_affinity */
116 entry = create_proc_entry("smp_affinity", 0600, irq_desc[irq].dir);
118 if (entry) {
119 entry->data = (void *)(long)irq;
120 entry->read_proc = irq_affinity_read_proc;
121 entry->write_proc = irq_affinity_write_proc;
124 #endif
127 #undef MAX_NAMELEN
129 void unregister_handler_proc(unsigned int irq, struct irqaction *action)
131 if (action->dir)
132 remove_proc_entry(action->dir->name, irq_desc[irq].dir);
135 void init_irq_proc(void)
137 int i;
139 /* create /proc/irq */
140 root_irq_dir = proc_mkdir("irq", NULL);
141 if (!root_irq_dir)
142 return;
145 * Create entries for all existing IRQs.
147 for (i = 0; i < NR_IRQS; i++)
148 register_irq_proc(i);