proc.c 3.4 KB

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