proc.c 6.8 KB
Newer Older
L
Linus Torvalds 已提交
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>
10
#include <linux/gfp.h>
L
Linus Torvalds 已提交
11
#include <linux/proc_fs.h>
12
#include <linux/seq_file.h>
L
Linus Torvalds 已提交
13 14
#include <linux/interrupt.h>

A
Adrian Bunk 已提交
15 16
#include "internals.h"

17
static struct proc_dir_entry *root_irq_dir;
L
Linus Torvalds 已提交
18 19 20

#ifdef CONFIG_SMP

21
static int irq_affinity_proc_show(struct seq_file *m, void *v)
L
Linus Torvalds 已提交
22
{
23
	struct irq_desc *desc = irq_to_desc((long)m->private);
24
	const struct cpumask *mask = desc->affinity;
25 26 27

#ifdef CONFIG_GENERIC_PENDING_IRQ
	if (desc->status & IRQ_MOVE_PENDING)
28
		mask = desc->pending_mask;
29
#endif
30 31 32
	seq_cpumask(m, mask);
	seq_putc(m, '\n');
	return 0;
L
Linus Torvalds 已提交
33 34
}

35 36 37 38
#ifndef is_affinity_mask_valid
#define is_affinity_mask_valid(val) 1
#endif

L
Linus Torvalds 已提交
39
int no_irq_affinity;
40 41
static ssize_t irq_affinity_proc_write(struct file *file,
		const char __user *buffer, size_t count, loff_t *pos)
L
Linus Torvalds 已提交
42
{
43
	unsigned int irq = (int)(long)PDE(file->f_path.dentry->d_inode)->data;
44
	cpumask_var_t new_value;
45
	int err;
L
Linus Torvalds 已提交
46

47
	if (!irq_to_desc(irq)->chip->set_affinity || no_irq_affinity ||
48
	    irq_balancing_disabled(irq))
L
Linus Torvalds 已提交
49 50
		return -EIO;

51 52 53 54
	if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
		return -ENOMEM;

	err = cpumask_parse_user(buffer, count, new_value);
L
Linus Torvalds 已提交
55
	if (err)
56
		goto free_cpumask;
L
Linus Torvalds 已提交
57

58
	if (!is_affinity_mask_valid(new_value)) {
59 60 61
		err = -EINVAL;
		goto free_cpumask;
	}
62

L
Linus Torvalds 已提交
63 64 65 66 67
	/*
	 * 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.
	 */
68
	if (!cpumask_intersects(new_value, cpu_online_mask)) {
69 70
		/* Special case for empty set - allow the architecture
		   code to set default SMP affinity. */
71 72 73 74 75 76 77 78 79
		err = irq_select_affinity_usr(irq) ? -EINVAL : count;
	} else {
		irq_set_affinity(irq, new_value);
		err = count;
	}

free_cpumask:
	free_cpumask_var(new_value);
	return err;
L
Linus Torvalds 已提交
80 81
}

82
static int irq_affinity_proc_open(struct inode *inode, struct file *file)
83
{
84
	return single_open(file, irq_affinity_proc_show, PDE(inode)->data);
85 86
}

87 88 89 90 91 92 93 94 95 96
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,
};

static int default_affinity_show(struct seq_file *m, void *v)
{
R
Rusty Russell 已提交
97
	seq_cpumask(m, irq_default_affinity);
98 99 100 101 102 103
	seq_putc(m, '\n');
	return 0;
}

static ssize_t default_affinity_write(struct file *file,
		const char __user *buffer, size_t count, loff_t *ppos)
104
{
R
Rusty Russell 已提交
105
	cpumask_var_t new_value;
106
	int err;
107

R
Rusty Russell 已提交
108 109 110 111
	if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
		return -ENOMEM;

	err = cpumask_parse_user(buffer, count, new_value);
112
	if (err)
R
Rusty Russell 已提交
113
		goto out;
114

R
Rusty Russell 已提交
115 116 117 118
	if (!is_affinity_mask_valid(new_value)) {
		err = -EINVAL;
		goto out;
	}
119 120 121 122 123 124

	/*
	 * 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.
	 */
R
Rusty Russell 已提交
125 126 127 128
	if (!cpumask_intersects(new_value, cpu_online_mask)) {
		err = -EINVAL;
		goto out;
	}
129

R
Rusty Russell 已提交
130 131
	cpumask_copy(irq_default_affinity, new_value);
	err = count;
132

R
Rusty Russell 已提交
133 134 135
out:
	free_cpumask_var(new_value);
	return err;
136
}
137 138 139

static int default_affinity_open(struct inode *inode, struct file *file)
{
140
	return single_open(file, default_affinity_show, PDE(inode)->data);
141 142 143 144 145 146 147 148 149
}

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,
};
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169

static int irq_node_proc_show(struct seq_file *m, void *v)
{
	struct irq_desc *desc = irq_to_desc((long) m->private);

	seq_printf(m, "%d\n", desc->node);
	return 0;
}

static int irq_node_proc_open(struct inode *inode, struct file *file)
{
	return single_open(file, irq_node_proc_show, PDE(inode)->data);
}

static const struct file_operations irq_node_proc_fops = {
	.open		= irq_node_proc_open,
	.read		= seq_read,
	.llseek		= seq_lseek,
	.release	= single_release,
};
L
Linus Torvalds 已提交
170 171
#endif

172
static int irq_spurious_proc_show(struct seq_file *m, void *v)
173
{
174 175 176 177 178 179 180 181 182 183 184
	struct irq_desc *desc = irq_to_desc((long) m->private);

	seq_printf(m, "count %u\n" "unhandled %u\n" "last_unhandled %u ms\n",
		   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)
{
	return single_open(file, irq_spurious_proc_show, NULL);
185 186
}

187 188 189 190 191 192 193
static const struct file_operations irq_spurious_proc_fops = {
	.open		= irq_spurious_proc_open,
	.read		= seq_read,
	.llseek		= seq_lseek,
	.release	= single_release,
};

L
Linus Torvalds 已提交
194 195 196 197
#define MAX_NAMELEN 128

static int name_unique(unsigned int irq, struct irqaction *new_action)
{
198
	struct irq_desc *desc = irq_to_desc(irq);
L
Linus Torvalds 已提交
199
	struct irqaction *action;
200 201
	unsigned long flags;
	int ret = 1;
L
Linus Torvalds 已提交
202

203
	raw_spin_lock_irqsave(&desc->lock, flags);
204
	for (action = desc->action ; action; action = action->next) {
L
Linus Torvalds 已提交
205
		if ((action != new_action) && action->name &&
206 207 208 209 210
				!strcmp(new_action->name, action->name)) {
			ret = 0;
			break;
		}
	}
211
	raw_spin_unlock_irqrestore(&desc->lock, flags);
212
	return ret;
L
Linus Torvalds 已提交
213 214 215 216 217
}

void register_handler_proc(unsigned int irq, struct irqaction *action)
{
	char name [MAX_NAMELEN];
218
	struct irq_desc *desc = irq_to_desc(irq);
L
Linus Torvalds 已提交
219

220
	if (!desc->dir || action->dir || !action->name ||
L
Linus Torvalds 已提交
221 222 223 224 225 226 227
					!name_unique(irq, action))
		return;

	memset(name, 0, MAX_NAMELEN);
	snprintf(name, MAX_NAMELEN, "%s", action->name);

	/* create /proc/irq/1234/handler/ */
228
	action->dir = proc_mkdir(name, desc->dir);
L
Linus Torvalds 已提交
229 230 231 232 233 234
}

#undef MAX_NAMELEN

#define MAX_NAMELEN 10

235
void register_irq_proc(unsigned int irq, struct irq_desc *desc)
L
Linus Torvalds 已提交
236 237 238
{
	char name [MAX_NAMELEN];

239
	if (!root_irq_dir || (desc->chip == &no_irq_chip) || desc->dir)
L
Linus Torvalds 已提交
240 241 242 243 244 245
		return;

	memset(name, 0, MAX_NAMELEN);
	sprintf(name, "%d", irq);

	/* create /proc/irq/1234 */
246
	desc->dir = proc_mkdir(name, root_irq_dir);
247 248
	if (!desc->dir)
		return;
L
Linus Torvalds 已提交
249 250

#ifdef CONFIG_SMP
251
	/* create /proc/irq/<irq>/smp_affinity */
252
	proc_create_data("smp_affinity", 0600, desc->dir,
253
			 &irq_affinity_proc_fops, (void *)(long)irq);
254 255 256

	proc_create_data("node", 0444, desc->dir,
			 &irq_node_proc_fops, (void *)(long)irq);
L
Linus Torvalds 已提交
257
#endif
258

259 260
	proc_create_data("spurious", 0444, desc->dir,
			 &irq_spurious_proc_fops, (void *)(long)irq);
L
Linus Torvalds 已提交
261 262 263 264 265 266
}

#undef MAX_NAMELEN

void unregister_handler_proc(unsigned int irq, struct irqaction *action)
{
267 268
	if (action->dir) {
		struct irq_desc *desc = irq_to_desc(irq);
269

270 271
		remove_proc_entry(action->dir->name, desc->dir);
	}
L
Linus Torvalds 已提交
272 273
}

R
roel kluin 已提交
274
static void register_default_affinity_proc(void)
275 276
{
#ifdef CONFIG_SMP
277 278
	proc_create("irq/default_smp_affinity", 0600, NULL,
		    &default_affinity_proc_fops);
279 280 281
#endif
}

L
Linus Torvalds 已提交
282 283
void init_irq_proc(void)
{
284 285
	unsigned int irq;
	struct irq_desc *desc;
L
Linus Torvalds 已提交
286 287 288 289 290 291

	/* create /proc/irq */
	root_irq_dir = proc_mkdir("irq", NULL);
	if (!root_irq_dir)
		return;

292 293
	register_default_affinity_proc();

L
Linus Torvalds 已提交
294 295 296
	/*
	 * Create entries for all existing IRQs.
	 */
297 298 299 300
	for_each_irq_desc(irq, desc) {
		if (!desc)
			continue;

301
		register_irq_proc(irq, desc);
302
	}
L
Linus Torvalds 已提交
303 304
}