proc.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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_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. err = cpumask_parse_user(buffer, count, new_value);
  41. if (err)
  42. return err;
  43. if (!is_affinity_mask_valid(new_value))
  44. return -EINVAL;
  45. /*
  46. * Do not allow disabling IRQs completely - it's a too easy
  47. * way to make the system unusable accidentally :-) At least
  48. * one online CPU still has to be targeted.
  49. */
  50. if (!cpus_intersects(new_value, cpu_online_map))
  51. /* Special case for empty set - allow the architecture
  52. code to set default SMP affinity. */
  53. return irq_select_affinity(irq) ? -EINVAL : count;
  54. irq_set_affinity(irq, new_value);
  55. return count;
  56. }
  57. static int irq_affinity_proc_open(struct inode *inode, struct file *file)
  58. {
  59. return single_open(file, irq_affinity_proc_show, PDE(inode)->data);
  60. }
  61. static const struct file_operations irq_affinity_proc_fops = {
  62. .open = irq_affinity_proc_open,
  63. .read = seq_read,
  64. .llseek = seq_lseek,
  65. .release = single_release,
  66. .write = irq_affinity_proc_write,
  67. };
  68. static int default_affinity_show(struct seq_file *m, void *v)
  69. {
  70. seq_cpumask(m, &irq_default_affinity);
  71. seq_putc(m, '\n');
  72. return 0;
  73. }
  74. static ssize_t default_affinity_write(struct file *file,
  75. const char __user *buffer, size_t count, loff_t *ppos)
  76. {
  77. cpumask_t new_value;
  78. int err;
  79. err = cpumask_parse_user(buffer, count, new_value);
  80. if (err)
  81. return err;
  82. if (!is_affinity_mask_valid(new_value))
  83. return -EINVAL;
  84. /*
  85. * Do not allow disabling IRQs completely - it's a too easy
  86. * way to make the system unusable accidentally :-) At least
  87. * one online CPU still has to be targeted.
  88. */
  89. if (!cpus_intersects(new_value, cpu_online_map))
  90. return -EINVAL;
  91. irq_default_affinity = new_value;
  92. return count;
  93. }
  94. static int default_affinity_open(struct inode *inode, struct file *file)
  95. {
  96. return single_open(file, default_affinity_show, NULL);
  97. }
  98. static const struct file_operations default_affinity_proc_fops = {
  99. .open = default_affinity_open,
  100. .read = seq_read,
  101. .llseek = seq_lseek,
  102. .release = single_release,
  103. .write = default_affinity_write,
  104. };
  105. #endif
  106. static int irq_spurious_read(char *page, char **start, off_t off,
  107. int count, int *eof, void *data)
  108. {
  109. struct irq_desc *desc = irq_to_desc((long) data);
  110. return sprintf(page, "count %u\n"
  111. "unhandled %u\n"
  112. "last_unhandled %u ms\n",
  113. desc->irq_count,
  114. desc->irqs_unhandled,
  115. jiffies_to_msecs(desc->last_unhandled));
  116. }
  117. #define MAX_NAMELEN 128
  118. static int name_unique(unsigned int irq, struct irqaction *new_action)
  119. {
  120. struct irq_desc *desc = irq_to_desc(irq);
  121. struct irqaction *action;
  122. unsigned long flags;
  123. int ret = 1;
  124. spin_lock_irqsave(&desc->lock, flags);
  125. for (action = desc->action ; action; action = action->next) {
  126. if ((action != new_action) && action->name &&
  127. !strcmp(new_action->name, action->name)) {
  128. ret = 0;
  129. break;
  130. }
  131. }
  132. spin_unlock_irqrestore(&desc->lock, flags);
  133. return ret;
  134. }
  135. void register_handler_proc(unsigned int irq, struct irqaction *action)
  136. {
  137. char name [MAX_NAMELEN];
  138. struct irq_desc *desc = irq_to_desc(irq);
  139. if (!desc->dir || action->dir || !action->name ||
  140. !name_unique(irq, action))
  141. return;
  142. memset(name, 0, MAX_NAMELEN);
  143. snprintf(name, MAX_NAMELEN, "%s", action->name);
  144. /* create /proc/irq/1234/handler/ */
  145. action->dir = proc_mkdir(name, desc->dir);
  146. }
  147. #undef MAX_NAMELEN
  148. #define MAX_NAMELEN 10
  149. void register_irq_proc(unsigned int irq, struct irq_desc *desc)
  150. {
  151. char name [MAX_NAMELEN];
  152. struct proc_dir_entry *entry;
  153. if (!root_irq_dir || (desc->chip == &no_irq_chip) || desc->dir)
  154. return;
  155. memset(name, 0, MAX_NAMELEN);
  156. sprintf(name, "%d", irq);
  157. /* create /proc/irq/1234 */
  158. desc->dir = proc_mkdir(name, root_irq_dir);
  159. #ifdef CONFIG_SMP
  160. /* create /proc/irq/<irq>/smp_affinity */
  161. proc_create_data("smp_affinity", 0600, desc->dir,
  162. &irq_affinity_proc_fops, (void *)(long)irq);
  163. #endif
  164. entry = create_proc_entry("spurious", 0444, desc->dir);
  165. if (entry) {
  166. entry->data = (void *)(long)irq;
  167. entry->read_proc = irq_spurious_read;
  168. }
  169. }
  170. #undef MAX_NAMELEN
  171. void unregister_handler_proc(unsigned int irq, struct irqaction *action)
  172. {
  173. if (action->dir) {
  174. struct irq_desc *desc = irq_to_desc(irq);
  175. remove_proc_entry(action->dir->name, desc->dir);
  176. }
  177. }
  178. static void register_default_affinity_proc(void)
  179. {
  180. #ifdef CONFIG_SMP
  181. proc_create("irq/default_smp_affinity", 0600, NULL,
  182. &default_affinity_proc_fops);
  183. #endif
  184. }
  185. void init_irq_proc(void)
  186. {
  187. unsigned int irq;
  188. struct irq_desc *desc;
  189. /* create /proc/irq */
  190. root_irq_dir = proc_mkdir("irq", NULL);
  191. if (!root_irq_dir)
  192. return;
  193. register_default_affinity_proc();
  194. /*
  195. * Create entries for all existing IRQs.
  196. */
  197. for_each_irq_desc(irq, desc)
  198. register_irq_proc(irq, desc);
  199. }