proc.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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, NULL);
  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_read(char *page, char **start, off_t off,
  125. int count, int *eof, void *data)
  126. {
  127. struct irq_desc *desc = irq_to_desc((long) data);
  128. return sprintf(page, "count %u\n"
  129. "unhandled %u\n"
  130. "last_unhandled %u ms\n",
  131. desc->irq_count,
  132. desc->irqs_unhandled,
  133. jiffies_to_msecs(desc->last_unhandled));
  134. }
  135. #define MAX_NAMELEN 128
  136. static int name_unique(unsigned int irq, struct irqaction *new_action)
  137. {
  138. struct irq_desc *desc = irq_to_desc(irq);
  139. struct irqaction *action;
  140. unsigned long flags;
  141. int ret = 1;
  142. spin_lock_irqsave(&desc->lock, flags);
  143. for (action = desc->action ; action; action = action->next) {
  144. if ((action != new_action) && action->name &&
  145. !strcmp(new_action->name, action->name)) {
  146. ret = 0;
  147. break;
  148. }
  149. }
  150. spin_unlock_irqrestore(&desc->lock, flags);
  151. return ret;
  152. }
  153. void register_handler_proc(unsigned int irq, struct irqaction *action)
  154. {
  155. char name [MAX_NAMELEN];
  156. struct irq_desc *desc = irq_to_desc(irq);
  157. if (!desc->dir || action->dir || !action->name ||
  158. !name_unique(irq, action))
  159. return;
  160. memset(name, 0, MAX_NAMELEN);
  161. snprintf(name, MAX_NAMELEN, "%s", action->name);
  162. /* create /proc/irq/1234/handler/ */
  163. action->dir = proc_mkdir(name, desc->dir);
  164. }
  165. #undef MAX_NAMELEN
  166. #define MAX_NAMELEN 10
  167. void register_irq_proc(unsigned int irq, struct irq_desc *desc)
  168. {
  169. char name [MAX_NAMELEN];
  170. struct proc_dir_entry *entry;
  171. if (!root_irq_dir || (desc->chip == &no_irq_chip) || desc->dir)
  172. return;
  173. memset(name, 0, MAX_NAMELEN);
  174. sprintf(name, "%d", irq);
  175. /* create /proc/irq/1234 */
  176. desc->dir = proc_mkdir(name, root_irq_dir);
  177. #ifdef CONFIG_SMP
  178. /* create /proc/irq/<irq>/smp_affinity */
  179. proc_create_data("smp_affinity", 0600, desc->dir,
  180. &irq_affinity_proc_fops, (void *)(long)irq);
  181. #endif
  182. entry = create_proc_entry("spurious", 0444, desc->dir);
  183. if (entry) {
  184. entry->data = (void *)(long)irq;
  185. entry->read_proc = irq_spurious_read;
  186. }
  187. }
  188. #undef MAX_NAMELEN
  189. void unregister_handler_proc(unsigned int irq, struct irqaction *action)
  190. {
  191. if (action->dir) {
  192. struct irq_desc *desc = irq_to_desc(irq);
  193. remove_proc_entry(action->dir->name, desc->dir);
  194. }
  195. }
  196. static void register_default_affinity_proc(void)
  197. {
  198. #ifdef CONFIG_SMP
  199. proc_create("irq/default_smp_affinity", 0600, NULL,
  200. &default_affinity_proc_fops);
  201. #endif
  202. }
  203. void init_irq_proc(void)
  204. {
  205. unsigned int irq;
  206. struct irq_desc *desc;
  207. /* create /proc/irq */
  208. root_irq_dir = proc_mkdir("irq", NULL);
  209. if (!root_irq_dir)
  210. return;
  211. register_default_affinity_proc();
  212. /*
  213. * Create entries for all existing IRQs.
  214. */
  215. for_each_irq_desc(irq, desc) {
  216. if (!desc)
  217. continue;
  218. register_irq_proc(irq, desc);
  219. }
  220. }