proc.c 3.5 KB

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