proc.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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/interrupt.h>
  11. #include "internals.h"
  12. static struct proc_dir_entry *root_irq_dir, *irq_dir[NR_IRQS];
  13. #ifdef CONFIG_SMP
  14. /*
  15. * The /proc/irq/<irq>/smp_affinity values:
  16. */
  17. static struct proc_dir_entry *smp_affinity_entry[NR_IRQS];
  18. #ifdef CONFIG_GENERIC_PENDING_IRQ
  19. void proc_set_irq_affinity(unsigned int irq, cpumask_t mask_val)
  20. {
  21. /*
  22. * Save these away for later use. Re-progam when the
  23. * interrupt is pending
  24. */
  25. set_pending_irq(irq, mask_val);
  26. }
  27. #else
  28. void proc_set_irq_affinity(unsigned int irq, cpumask_t mask_val)
  29. {
  30. irq_affinity[irq] = mask_val;
  31. irq_desc[irq].handler->set_affinity(irq, mask_val);
  32. }
  33. #endif
  34. static int irq_affinity_read_proc(char *page, char **start, off_t off,
  35. int count, int *eof, void *data)
  36. {
  37. int len = cpumask_scnprintf(page, count, irq_affinity[(long)data]);
  38. if (count - len < 2)
  39. return -EINVAL;
  40. len += sprintf(page + len, "\n");
  41. return len;
  42. }
  43. int no_irq_affinity;
  44. static int irq_affinity_write_proc(struct file *file, const char __user *buffer,
  45. unsigned long count, void *data)
  46. {
  47. unsigned int irq = (int)(long)data, full_count = count, err;
  48. cpumask_t new_value, tmp;
  49. if (!irq_desc[irq].handler->set_affinity || no_irq_affinity)
  50. return -EIO;
  51. err = cpumask_parse(buffer, count, new_value);
  52. if (err)
  53. return err;
  54. /*
  55. * Do not allow disabling IRQs completely - it's a too easy
  56. * way to make the system unusable accidentally :-) At least
  57. * one online CPU still has to be targeted.
  58. */
  59. cpus_and(tmp, new_value, cpu_online_map);
  60. if (cpus_empty(tmp))
  61. /* Special case for empty set - allow the architecture
  62. code to set default SMP affinity. */
  63. return select_smp_affinity(irq) ? -EINVAL : full_count;
  64. proc_set_irq_affinity(irq, new_value);
  65. return full_count;
  66. }
  67. #endif
  68. #define MAX_NAMELEN 128
  69. static int name_unique(unsigned int irq, struct irqaction *new_action)
  70. {
  71. struct irq_desc *desc = irq_desc + irq;
  72. struct irqaction *action;
  73. for (action = desc->action ; action; action = action->next)
  74. if ((action != new_action) && action->name &&
  75. !strcmp(new_action->name, action->name))
  76. return 0;
  77. return 1;
  78. }
  79. void register_handler_proc(unsigned int irq, struct irqaction *action)
  80. {
  81. char name [MAX_NAMELEN];
  82. if (!irq_dir[irq] || action->dir || !action->name ||
  83. !name_unique(irq, action))
  84. return;
  85. memset(name, 0, MAX_NAMELEN);
  86. snprintf(name, MAX_NAMELEN, "%s", action->name);
  87. /* create /proc/irq/1234/handler/ */
  88. action->dir = proc_mkdir(name, irq_dir[irq]);
  89. }
  90. #undef MAX_NAMELEN
  91. #define MAX_NAMELEN 10
  92. void register_irq_proc(unsigned int irq)
  93. {
  94. char name [MAX_NAMELEN];
  95. if (!root_irq_dir ||
  96. (irq_desc[irq].handler == &no_irq_type) ||
  97. irq_dir[irq])
  98. return;
  99. memset(name, 0, MAX_NAMELEN);
  100. sprintf(name, "%d", irq);
  101. /* create /proc/irq/1234 */
  102. irq_dir[irq] = proc_mkdir(name, root_irq_dir);
  103. #ifdef CONFIG_SMP
  104. {
  105. struct proc_dir_entry *entry;
  106. /* create /proc/irq/<irq>/smp_affinity */
  107. entry = create_proc_entry("smp_affinity", 0600, irq_dir[irq]);
  108. if (entry) {
  109. entry->nlink = 1;
  110. entry->data = (void *)(long)irq;
  111. entry->read_proc = irq_affinity_read_proc;
  112. entry->write_proc = irq_affinity_write_proc;
  113. }
  114. smp_affinity_entry[irq] = entry;
  115. }
  116. #endif
  117. }
  118. #undef MAX_NAMELEN
  119. void unregister_handler_proc(unsigned int irq, struct irqaction *action)
  120. {
  121. if (action->dir)
  122. remove_proc_entry(action->dir->name, irq_dir[irq]);
  123. }
  124. void init_irq_proc(void)
  125. {
  126. int i;
  127. /* create /proc/irq */
  128. root_irq_dir = proc_mkdir("irq", NULL);
  129. if (!root_irq_dir)
  130. return;
  131. /*
  132. * Create entries for all existing IRQs.
  133. */
  134. for (i = 0; i < NR_IRQS; i++)
  135. register_irq_proc(i);
  136. }