proc.c 3.7 KB

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