proc.c 6.2 KB

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