proc.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. cpumask_t *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_t new_value;
  87. int err;
  88. err = cpumask_parse_user(buffer, count, &new_value);
  89. if (err)
  90. return err;
  91. if (!is_affinity_mask_valid(new_value))
  92. return -EINVAL;
  93. /*
  94. * Do not allow disabling IRQs completely - it's a too easy
  95. * way to make the system unusable accidentally :-) At least
  96. * one online CPU still has to be targeted.
  97. */
  98. if (!cpus_intersects(new_value, cpu_online_map))
  99. return -EINVAL;
  100. irq_default_affinity = new_value;
  101. return count;
  102. }
  103. static int default_affinity_open(struct inode *inode, struct file *file)
  104. {
  105. return single_open(file, default_affinity_show, NULL);
  106. }
  107. static const struct file_operations default_affinity_proc_fops = {
  108. .open = default_affinity_open,
  109. .read = seq_read,
  110. .llseek = seq_lseek,
  111. .release = single_release,
  112. .write = default_affinity_write,
  113. };
  114. #endif
  115. static int irq_spurious_read(char *page, char **start, off_t off,
  116. int count, int *eof, void *data)
  117. {
  118. struct irq_desc *desc = irq_to_desc((long) data);
  119. return sprintf(page, "count %u\n"
  120. "unhandled %u\n"
  121. "last_unhandled %u ms\n",
  122. desc->irq_count,
  123. desc->irqs_unhandled,
  124. jiffies_to_msecs(desc->last_unhandled));
  125. }
  126. #define MAX_NAMELEN 128
  127. static int name_unique(unsigned int irq, struct irqaction *new_action)
  128. {
  129. struct irq_desc *desc = irq_to_desc(irq);
  130. struct irqaction *action;
  131. unsigned long flags;
  132. int ret = 1;
  133. spin_lock_irqsave(&desc->lock, flags);
  134. for (action = desc->action ; action; action = action->next) {
  135. if ((action != new_action) && action->name &&
  136. !strcmp(new_action->name, action->name)) {
  137. ret = 0;
  138. break;
  139. }
  140. }
  141. spin_unlock_irqrestore(&desc->lock, flags);
  142. return ret;
  143. }
  144. void register_handler_proc(unsigned int irq, struct irqaction *action)
  145. {
  146. char name [MAX_NAMELEN];
  147. struct irq_desc *desc = irq_to_desc(irq);
  148. if (!desc->dir || action->dir || !action->name ||
  149. !name_unique(irq, action))
  150. return;
  151. memset(name, 0, MAX_NAMELEN);
  152. snprintf(name, MAX_NAMELEN, "%s", action->name);
  153. /* create /proc/irq/1234/handler/ */
  154. action->dir = proc_mkdir(name, desc->dir);
  155. }
  156. #undef MAX_NAMELEN
  157. #define MAX_NAMELEN 10
  158. void register_irq_proc(unsigned int irq, struct irq_desc *desc)
  159. {
  160. char name [MAX_NAMELEN];
  161. struct proc_dir_entry *entry;
  162. if (!root_irq_dir || (desc->chip == &no_irq_chip) || desc->dir)
  163. return;
  164. memset(name, 0, MAX_NAMELEN);
  165. sprintf(name, "%d", irq);
  166. /* create /proc/irq/1234 */
  167. desc->dir = proc_mkdir(name, root_irq_dir);
  168. #ifdef CONFIG_SMP
  169. /* create /proc/irq/<irq>/smp_affinity */
  170. proc_create_data("smp_affinity", 0600, desc->dir,
  171. &irq_affinity_proc_fops, (void *)(long)irq);
  172. #endif
  173. entry = create_proc_entry("spurious", 0444, desc->dir);
  174. if (entry) {
  175. entry->data = (void *)(long)irq;
  176. entry->read_proc = irq_spurious_read;
  177. }
  178. }
  179. #undef MAX_NAMELEN
  180. void unregister_handler_proc(unsigned int irq, struct irqaction *action)
  181. {
  182. if (action->dir) {
  183. struct irq_desc *desc = irq_to_desc(irq);
  184. remove_proc_entry(action->dir->name, desc->dir);
  185. }
  186. }
  187. static void register_default_affinity_proc(void)
  188. {
  189. #ifdef CONFIG_SMP
  190. proc_create("irq/default_smp_affinity", 0600, NULL,
  191. &default_affinity_proc_fops);
  192. #endif
  193. }
  194. void init_irq_proc(void)
  195. {
  196. unsigned int irq;
  197. struct irq_desc *desc;
  198. /* create /proc/irq */
  199. root_irq_dir = proc_mkdir("irq", NULL);
  200. if (!root_irq_dir)
  201. return;
  202. register_default_affinity_proc();
  203. /*
  204. * Create entries for all existing IRQs.
  205. */
  206. for_each_irq_desc(irq, desc) {
  207. if (!desc)
  208. continue;
  209. register_irq_proc(irq, desc);
  210. }
  211. }