proc.c 7.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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
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;

	if (!alloc_cpumask_var(&mask, GFP_KERNEL))
		return -ENOMEM;

	raw_spin_lock_irqsave(&desc->lock, flags);
	if (desc->affinity_hint)
		cpumask_copy(mask, desc->affinity_hint);
	else
		cpumask_setall(mask);
	raw_spin_unlock_irqrestore(&desc->lock, flags);

	seq_cpumask(m, mask);
	seq_putc(m, '\n');
	free_cpumask_var(mask);

	return 0;
}

58 59 60 61
#ifndef is_affinity_mask_valid
#define is_affinity_mask_valid(val) 1
#endif

L
Linus Torvalds 已提交
62
int no_irq_affinity;
63 64
static ssize_t irq_affinity_proc_write(struct file *file,
		const char __user *buffer, size_t count, loff_t *pos)
L
Linus Torvalds 已提交
65
{
66
	unsigned int irq = (int)(long)PDE(file->f_path.dentry->d_inode)->data;
67
	cpumask_var_t new_value;
68
	int err;
L
Linus Torvalds 已提交
69

70
	if (!irq_to_desc(irq)->chip->set_affinity || no_irq_affinity ||
71
	    irq_balancing_disabled(irq))
L
Linus Torvalds 已提交
72 73
		return -EIO;

74 75 76 77
	if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
		return -ENOMEM;

	err = cpumask_parse_user(buffer, count, new_value);
L
Linus Torvalds 已提交
78
	if (err)
79
		goto free_cpumask;
L
Linus Torvalds 已提交
80

81
	if (!is_affinity_mask_valid(new_value)) {
82 83 84
		err = -EINVAL;
		goto free_cpumask;
	}
85

L
Linus Torvalds 已提交
86 87 88 89 90
	/*
	 * 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.
	 */
91
	if (!cpumask_intersects(new_value, cpu_online_mask)) {
92 93
		/* Special case for empty set - allow the architecture
		   code to set default SMP affinity. */
94 95 96 97 98 99 100 101 102
		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 已提交
103 104
}

105
static int irq_affinity_proc_open(struct inode *inode, struct file *file)
106
{
107
	return single_open(file, irq_affinity_proc_show, PDE(inode)->data);
108 109
}

110 111 112 113 114
static int irq_affinity_hint_proc_open(struct inode *inode, struct file *file)
{
	return single_open(file, irq_affinity_hint_proc_show, PDE(inode)->data);
}

115 116 117 118 119 120 121 122
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,
};

123 124 125 126 127 128 129
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,
};

130 131
static int default_affinity_show(struct seq_file *m, void *v)
{
R
Rusty Russell 已提交
132
	seq_cpumask(m, irq_default_affinity);
133 134 135 136 137 138
	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)
139
{
R
Rusty Russell 已提交
140
	cpumask_var_t new_value;
141
	int err;
142

R
Rusty Russell 已提交
143 144 145 146
	if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
		return -ENOMEM;

	err = cpumask_parse_user(buffer, count, new_value);
147
	if (err)
R
Rusty Russell 已提交
148
		goto out;
149

R
Rusty Russell 已提交
150 151 152 153
	if (!is_affinity_mask_valid(new_value)) {
		err = -EINVAL;
		goto out;
	}
154 155 156 157 158 159

	/*
	 * 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 已提交
160 161 162 163
	if (!cpumask_intersects(new_value, cpu_online_mask)) {
		err = -EINVAL;
		goto out;
	}
164

R
Rusty Russell 已提交
165 166
	cpumask_copy(irq_default_affinity, new_value);
	err = count;
167

R
Rusty Russell 已提交
168 169 170
out:
	free_cpumask_var(new_value);
	return err;
171
}
172 173 174

static int default_affinity_open(struct inode *inode, struct file *file)
{
175
	return single_open(file, default_affinity_show, PDE(inode)->data);
176 177 178 179 180 181 182 183 184
}

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,
};
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204

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 已提交
205 206
#endif

207
static int irq_spurious_proc_show(struct seq_file *m, void *v)
208
{
209 210 211 212 213 214 215 216 217 218 219
	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);
220 221
}

222 223 224 225 226 227 228
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 已提交
229 230 231 232
#define MAX_NAMELEN 128

static int name_unique(unsigned int irq, struct irqaction *new_action)
{
233
	struct irq_desc *desc = irq_to_desc(irq);
L
Linus Torvalds 已提交
234
	struct irqaction *action;
235 236
	unsigned long flags;
	int ret = 1;
L
Linus Torvalds 已提交
237

238
	raw_spin_lock_irqsave(&desc->lock, flags);
239
	for (action = desc->action ; action; action = action->next) {
L
Linus Torvalds 已提交
240
		if ((action != new_action) && action->name &&
241 242 243 244 245
				!strcmp(new_action->name, action->name)) {
			ret = 0;
			break;
		}
	}
246
	raw_spin_unlock_irqrestore(&desc->lock, flags);
247
	return ret;
L
Linus Torvalds 已提交
248 249 250 251 252
}

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

255
	if (!desc->dir || action->dir || !action->name ||
L
Linus Torvalds 已提交
256 257 258 259 260 261 262
					!name_unique(irq, action))
		return;

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

	/* create /proc/irq/1234/handler/ */
263
	action->dir = proc_mkdir(name, desc->dir);
L
Linus Torvalds 已提交
264 265 266 267 268 269
}

#undef MAX_NAMELEN

#define MAX_NAMELEN 10

270
void register_irq_proc(unsigned int irq, struct irq_desc *desc)
L
Linus Torvalds 已提交
271 272 273
{
	char name [MAX_NAMELEN];

274
	if (!root_irq_dir || (desc->chip == &no_irq_chip) || desc->dir)
L
Linus Torvalds 已提交
275 276 277 278 279 280
		return;

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

	/* create /proc/irq/1234 */
281
	desc->dir = proc_mkdir(name, root_irq_dir);
282 283
	if (!desc->dir)
		return;
L
Linus Torvalds 已提交
284 285

#ifdef CONFIG_SMP
286
	/* create /proc/irq/<irq>/smp_affinity */
287
	proc_create_data("smp_affinity", 0600, desc->dir,
288
			 &irq_affinity_proc_fops, (void *)(long)irq);
289

290 291 292 293
	/* create /proc/irq/<irq>/affinity_hint */
	proc_create_data("affinity_hint", 0400, desc->dir,
			 &irq_affinity_hint_proc_fops, (void *)(long)irq);

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

298 299
	proc_create_data("spurious", 0444, desc->dir,
			 &irq_spurious_proc_fops, (void *)(long)irq);
L
Linus Torvalds 已提交
300 301 302 303 304 305
}

#undef MAX_NAMELEN

void unregister_handler_proc(unsigned int irq, struct irqaction *action)
{
306 307
	if (action->dir) {
		struct irq_desc *desc = irq_to_desc(irq);
308

309 310
		remove_proc_entry(action->dir->name, desc->dir);
	}
L
Linus Torvalds 已提交
311 312
}

R
roel kluin 已提交
313
static void register_default_affinity_proc(void)
314 315
{
#ifdef CONFIG_SMP
316 317
	proc_create("irq/default_smp_affinity", 0600, NULL,
		    &default_affinity_proc_fops);
318 319 320
#endif
}

L
Linus Torvalds 已提交
321 322
void init_irq_proc(void)
{
323 324
	unsigned int irq;
	struct irq_desc *desc;
L
Linus Torvalds 已提交
325 326 327 328 329 330

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

331 332
	register_default_affinity_proc();

L
Linus Torvalds 已提交
333 334 335
	/*
	 * Create entries for all existing IRQs.
	 */
336 337 338 339
	for_each_irq_desc(irq, desc) {
		if (!desc)
			continue;

340
		register_irq_proc(irq, desc);
341
	}
L
Linus Torvalds 已提交
342 343
}