proc.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. static int irq_affinity_read_proc(char *page, char **start, off_t off,
  15. int count, int *eof, void *data)
  16. {
  17. struct irq_desc *desc = irq_desc + (long)data;
  18. cpumask_t *mask = &desc->affinity;
  19. int len;
  20. #ifdef CONFIG_GENERIC_PENDING_IRQ
  21. if (desc->status & IRQ_MOVE_PENDING)
  22. mask = &desc->pending_mask;
  23. #endif
  24. len = cpumask_scnprintf(page, count, *mask);
  25. if (count - len < 2)
  26. return -EINVAL;
  27. len += sprintf(page + len, "\n");
  28. return len;
  29. }
  30. #ifndef is_affinity_mask_valid
  31. #define is_affinity_mask_valid(val) 1
  32. #endif
  33. int no_irq_affinity;
  34. static int irq_affinity_write_proc(struct file *file, const char __user *buffer,
  35. unsigned long count, void *data)
  36. {
  37. unsigned int irq = (int)(long)data, full_count = count, err;
  38. cpumask_t new_value, tmp;
  39. if (!irq_desc[irq].chip->set_affinity || no_irq_affinity ||
  40. irq_balancing_disabled(irq))
  41. return -EIO;
  42. err = cpumask_parse_user(buffer, count, new_value);
  43. if (err)
  44. return err;
  45. if (!is_affinity_mask_valid(new_value))
  46. return -EINVAL;
  47. /*
  48. * Do not allow disabling IRQs completely - it's a too easy
  49. * way to make the system unusable accidentally :-) At least
  50. * one online CPU still has to be targeted.
  51. */
  52. cpus_and(tmp, new_value, cpu_online_map);
  53. if (cpus_empty(tmp))
  54. /* Special case for empty set - allow the architecture
  55. code to set default SMP affinity. */
  56. return select_smp_affinity(irq) ? -EINVAL : full_count;
  57. irq_set_affinity(irq, new_value);
  58. return full_count;
  59. }
  60. #endif
  61. #define MAX_NAMELEN 128
  62. static int name_unique(unsigned int irq, struct irqaction *new_action)
  63. {
  64. struct irq_desc *desc = irq_desc + irq;
  65. struct irqaction *action;
  66. unsigned long flags;
  67. int ret = 1;
  68. spin_lock_irqsave(&desc->lock, flags);
  69. for (action = desc->action ; action; action = action->next) {
  70. if ((action != new_action) && action->name &&
  71. !strcmp(new_action->name, action->name)) {
  72. ret = 0;
  73. break;
  74. }
  75. }
  76. spin_unlock_irqrestore(&desc->lock, flags);
  77. return ret;
  78. }
  79. void register_handler_proc(unsigned int irq, struct irqaction *action)
  80. {
  81. char name [MAX_NAMELEN];
  82. if (!irq_desc[irq].dir || 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_desc[irq].dir);
  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].chip == &no_irq_chip) ||
  97. irq_desc[irq].dir)
  98. return;
  99. memset(name, 0, MAX_NAMELEN);
  100. sprintf(name, "%d", irq);
  101. /* create /proc/irq/1234 */
  102. irq_desc[irq].dir = 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_desc[irq].dir);
  108. if (entry) {
  109. entry->data = (void *)(long)irq;
  110. entry->read_proc = irq_affinity_read_proc;
  111. entry->write_proc = irq_affinity_write_proc;
  112. }
  113. }
  114. #endif
  115. }
  116. #undef MAX_NAMELEN
  117. void unregister_handler_proc(unsigned int irq, struct irqaction *action)
  118. {
  119. if (action->dir)
  120. remove_proc_entry(action->dir->name, irq_desc[irq].dir);
  121. }
  122. void init_irq_proc(void)
  123. {
  124. int i;
  125. /* create /proc/irq */
  126. root_irq_dir = proc_mkdir("irq", NULL);
  127. if (!root_irq_dir)
  128. return;
  129. /*
  130. * Create entries for all existing IRQs.
  131. */
  132. for (i = 0; i < NR_IRQS; i++)
  133. register_irq_proc(i);
  134. }