proc.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /*
  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. #include <linux/irq.h>
  9. #include <linux/gfp.h>
  10. #include <linux/proc_fs.h>
  11. #include <linux/seq_file.h>
  12. #include <linux/interrupt.h>
  13. #include "internals.h"
  14. static struct proc_dir_entry *root_irq_dir;
  15. #ifdef CONFIG_SMP
  16. static int irq_affinity_proc_show(struct seq_file *m, void *v)
  17. {
  18. struct irq_desc *desc = irq_to_desc((long)m->private);
  19. const struct cpumask *mask = desc->affinity;
  20. #ifdef CONFIG_GENERIC_PENDING_IRQ
  21. if (desc->status & IRQ_MOVE_PENDING)
  22. mask = desc->pending_mask;
  23. #endif
  24. seq_cpumask(m, mask);
  25. seq_putc(m, '\n');
  26. return 0;
  27. }
  28. #ifndef is_affinity_mask_valid
  29. #define is_affinity_mask_valid(val) 1
  30. #endif
  31. int no_irq_affinity;
  32. static ssize_t irq_affinity_proc_write(struct file *file,
  33. const char __user *buffer, size_t count, loff_t *pos)
  34. {
  35. unsigned int irq = (int)(long)PDE(file->f_path.dentry->d_inode)->data;
  36. cpumask_var_t new_value;
  37. int err;
  38. if (!irq_to_desc(irq)->chip->set_affinity || no_irq_affinity ||
  39. irq_balancing_disabled(irq))
  40. return -EIO;
  41. if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
  42. return -ENOMEM;
  43. err = cpumask_parse_user(buffer, count, new_value);
  44. if (err)
  45. goto free_cpumask;
  46. if (!is_affinity_mask_valid(new_value)) {
  47. err = -EINVAL;
  48. goto free_cpumask;
  49. }
  50. /*
  51. * Do not allow disabling IRQs completely - it's a too easy
  52. * way to make the system unusable accidentally :-) At least
  53. * one online CPU still has to be targeted.
  54. */
  55. if (!cpumask_intersects(new_value, cpu_online_mask)) {
  56. /* Special case for empty set - allow the architecture
  57. code to set default SMP affinity. */
  58. err = irq_select_affinity_usr(irq) ? -EINVAL : count;
  59. } else {
  60. irq_set_affinity(irq, new_value);
  61. err = count;
  62. }
  63. free_cpumask:
  64. free_cpumask_var(new_value);
  65. return err;
  66. }
  67. static int irq_affinity_proc_open(struct inode *inode, struct file *file)
  68. {
  69. return single_open(file, irq_affinity_proc_show, PDE(inode)->data);
  70. }
  71. static const struct file_operations irq_affinity_proc_fops = {
  72. .open = irq_affinity_proc_open,
  73. .read = seq_read,
  74. .llseek = seq_lseek,
  75. .release = single_release,
  76. .write = irq_affinity_proc_write,
  77. };
  78. static int default_affinity_show(struct seq_file *m, void *v)
  79. {
  80. seq_cpumask(m, irq_default_affinity);
  81. seq_putc(m, '\n');
  82. return 0;
  83. }
  84. static ssize_t default_affinity_write(struct file *file,
  85. const char __user *buffer, size_t count, loff_t *ppos)
  86. {
  87. cpumask_var_t new_value;
  88. int err;
  89. if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
  90. return -ENOMEM;
  91. err = cpumask_parse_user(buffer, count, new_value);
  92. if (err)
  93. goto out;
  94. if (!is_affinity_mask_valid(new_value)) {
  95. err = -EINVAL;
  96. goto out;
  97. }
  98. /*
  99. * Do not allow disabling IRQs completely - it's a too easy
  100. * way to make the system unusable accidentally :-) At least
  101. * one online CPU still has to be targeted.
  102. */
  103. if (!cpumask_intersects(new_value, cpu_online_mask)) {
  104. err = -EINVAL;
  105. goto out;
  106. }
  107. cpumask_copy(irq_default_affinity, new_value);
  108. err = count;
  109. out:
  110. free_cpumask_var(new_value);
  111. return err;
  112. }
  113. static int default_affinity_open(struct inode *inode, struct file *file)
  114. {
  115. return single_open(file, default_affinity_show, PDE(inode)->data);
  116. }
  117. static const struct file_operations default_affinity_proc_fops = {
  118. .open = default_affinity_open,
  119. .read = seq_read,
  120. .llseek = seq_lseek,
  121. .release = single_release,
  122. .write = default_affinity_write,
  123. };
  124. #endif
  125. static int irq_spurious_proc_show(struct seq_file *m, void *v)
  126. {
  127. struct irq_desc *desc = irq_to_desc((long) m->private);
  128. seq_printf(m, "count %u\n" "unhandled %u\n" "last_unhandled %u ms\n",
  129. desc->irq_count, desc->irqs_unhandled,
  130. jiffies_to_msecs(desc->last_unhandled));
  131. return 0;
  132. }
  133. static int irq_spurious_proc_open(struct inode *inode, struct file *file)
  134. {
  135. return single_open(file, irq_spurious_proc_show, NULL);
  136. }
  137. static const struct file_operations irq_spurious_proc_fops = {
  138. .open = irq_spurious_proc_open,
  139. .read = seq_read,
  140. .llseek = seq_lseek,
  141. .release = single_release,
  142. };
  143. #define MAX_NAMELEN 128
  144. static int name_unique(unsigned int irq, struct irqaction *new_action)
  145. {
  146. struct irq_desc *desc = irq_to_desc(irq);
  147. struct irqaction *action;
  148. unsigned long flags;
  149. int ret = 1;
  150. raw_spin_lock_irqsave(&desc->lock, flags);
  151. for (action = desc->action ; action; action = action->next) {
  152. if ((action != new_action) && action->name &&
  153. !strcmp(new_action->name, action->name)) {
  154. ret = 0;
  155. break;
  156. }
  157. }
  158. raw_spin_unlock_irqrestore(&desc->lock, flags);
  159. return ret;
  160. }
  161. void register_handler_proc(unsigned int irq, struct irqaction *action)
  162. {
  163. char name [MAX_NAMELEN];
  164. struct irq_desc *desc = irq_to_desc(irq);
  165. if (!desc->dir || action->dir || !action->name ||
  166. !name_unique(irq, action))
  167. return;
  168. memset(name, 0, MAX_NAMELEN);
  169. snprintf(name, MAX_NAMELEN, "%s", action->name);
  170. /* create /proc/irq/1234/handler/ */
  171. action->dir = proc_mkdir(name, desc->dir);
  172. }
  173. #undef MAX_NAMELEN
  174. #define MAX_NAMELEN 10
  175. void register_irq_proc(unsigned int irq, struct irq_desc *desc)
  176. {
  177. char name [MAX_NAMELEN];
  178. if (!root_irq_dir || (desc->chip == &no_irq_chip) || desc->dir)
  179. return;
  180. memset(name, 0, MAX_NAMELEN);
  181. sprintf(name, "%d", irq);
  182. /* create /proc/irq/1234 */
  183. desc->dir = proc_mkdir(name, root_irq_dir);
  184. if (!desc->dir)
  185. return;
  186. #ifdef CONFIG_SMP
  187. /* create /proc/irq/<irq>/smp_affinity */
  188. proc_create_data("smp_affinity", 0600, desc->dir,
  189. &irq_affinity_proc_fops, (void *)(long)irq);
  190. #endif
  191. proc_create_data("spurious", 0444, desc->dir,
  192. &irq_spurious_proc_fops, (void *)(long)irq);
  193. }
  194. #undef MAX_NAMELEN
  195. void unregister_handler_proc(unsigned int irq, struct irqaction *action)
  196. {
  197. if (action->dir) {
  198. struct irq_desc *desc = irq_to_desc(irq);
  199. remove_proc_entry(action->dir->name, desc->dir);
  200. }
  201. }
  202. static void register_default_affinity_proc(void)
  203. {
  204. #ifdef CONFIG_SMP
  205. proc_create("irq/default_smp_affinity", 0600, NULL,
  206. &default_affinity_proc_fops);
  207. #endif
  208. }
  209. void init_irq_proc(void)
  210. {
  211. unsigned int irq;
  212. struct irq_desc *desc;
  213. /* create /proc/irq */
  214. root_irq_dir = proc_mkdir("irq", NULL);
  215. if (!root_irq_dir)
  216. return;
  217. register_default_affinity_proc();
  218. /*
  219. * Create entries for all existing IRQs.
  220. */
  221. for_each_irq_desc(irq, desc) {
  222. if (!desc)
  223. continue;
  224. register_irq_proc(irq, desc);
  225. }
  226. }