proc.c 3.8 KB

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