irq.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/arch/ia64/kernel/irq.c
  4. *
  5. * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
  6. *
  7. * This file contains the code used by various IRQ handling routines:
  8. * asking for different IRQs should be done through these routines
  9. * instead of just grabbing them. Thus setups with different IRQ numbers
  10. * shouldn't result in any weird surprises, and installing new handlers
  11. * should be easier.
  12. *
  13. * Copyright (C) Ashok Raj<[email protected]>, Intel Corporation 2004
  14. *
  15. * 4/14/2004: Added code to handle cpu migration and do safe irq
  16. * migration without losing interrupts for iosapic
  17. * architecture.
  18. */
  19. #include <asm/delay.h>
  20. #include <linux/uaccess.h>
  21. #include <linux/module.h>
  22. #include <linux/seq_file.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/kernel_stat.h>
  25. #include <asm/mca.h>
  26. #include <asm/xtp.h>
  27. /*
  28. * 'what should we do if we get a hw irq event on an illegal vector'.
  29. * each architecture has to answer this themselves.
  30. */
  31. void ack_bad_irq(unsigned int irq)
  32. {
  33. printk(KERN_ERR "Unexpected irq vector 0x%x on CPU %u!\n", irq, smp_processor_id());
  34. }
  35. /*
  36. * Interrupt statistics:
  37. */
  38. atomic_t irq_err_count;
  39. /*
  40. * /proc/interrupts printing:
  41. */
  42. int arch_show_interrupts(struct seq_file *p, int prec)
  43. {
  44. seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
  45. return 0;
  46. }
  47. #ifdef CONFIG_SMP
  48. static char irq_redir [NR_IRQS]; // = { [0 ... NR_IRQS-1] = 1 };
  49. void set_irq_affinity_info (unsigned int irq, int hwid, int redir)
  50. {
  51. if (irq < NR_IRQS) {
  52. irq_data_update_affinity(irq_get_irq_data(irq),
  53. cpumask_of(cpu_logical_id(hwid)));
  54. irq_redir[irq] = (char) (redir & 0xff);
  55. }
  56. }
  57. #endif /* CONFIG_SMP */
  58. int __init arch_early_irq_init(void)
  59. {
  60. ia64_mca_irq_init();
  61. return 0;
  62. }
  63. #ifdef CONFIG_HOTPLUG_CPU
  64. unsigned int vectors_in_migration[NR_IRQS];
  65. /*
  66. * Since cpu_online_mask is already updated, we just need to check for
  67. * affinity that has zeros
  68. */
  69. static void migrate_irqs(void)
  70. {
  71. int irq, new_cpu;
  72. for (irq=0; irq < NR_IRQS; irq++) {
  73. struct irq_desc *desc = irq_to_desc(irq);
  74. struct irq_data *data = irq_desc_get_irq_data(desc);
  75. struct irq_chip *chip = irq_data_get_irq_chip(data);
  76. if (irqd_irq_disabled(data))
  77. continue;
  78. /*
  79. * No handling for now.
  80. * TBD: Implement a disable function so we can now
  81. * tell CPU not to respond to these local intr sources.
  82. * such as ITV,CPEI,MCA etc.
  83. */
  84. if (irqd_is_per_cpu(data))
  85. continue;
  86. if (cpumask_any_and(irq_data_get_affinity_mask(data),
  87. cpu_online_mask) >= nr_cpu_ids) {
  88. /*
  89. * Save it for phase 2 processing
  90. */
  91. vectors_in_migration[irq] = irq;
  92. new_cpu = cpumask_any(cpu_online_mask);
  93. /*
  94. * Al three are essential, currently WARN_ON.. maybe panic?
  95. */
  96. if (chip && chip->irq_disable &&
  97. chip->irq_enable && chip->irq_set_affinity) {
  98. chip->irq_disable(data);
  99. chip->irq_set_affinity(data,
  100. cpumask_of(new_cpu), false);
  101. chip->irq_enable(data);
  102. } else {
  103. WARN_ON((!chip || !chip->irq_disable ||
  104. !chip->irq_enable ||
  105. !chip->irq_set_affinity));
  106. }
  107. }
  108. }
  109. }
  110. void fixup_irqs(void)
  111. {
  112. unsigned int irq;
  113. extern void ia64_process_pending_intr(void);
  114. extern volatile int time_keeper_id;
  115. /* Mask ITV to disable timer */
  116. ia64_set_itv(1 << 16);
  117. /*
  118. * Find a new timesync master
  119. */
  120. if (smp_processor_id() == time_keeper_id) {
  121. time_keeper_id = cpumask_first(cpu_online_mask);
  122. printk ("CPU %d is now promoted to time-keeper master\n", time_keeper_id);
  123. }
  124. /*
  125. * Phase 1: Locate IRQs bound to this cpu and
  126. * relocate them for cpu removal.
  127. */
  128. migrate_irqs();
  129. /*
  130. * Phase 2: Perform interrupt processing for all entries reported in
  131. * local APIC.
  132. */
  133. ia64_process_pending_intr();
  134. /*
  135. * Phase 3: Now handle any interrupts not captured in local APIC.
  136. * This is to account for cases that device interrupted during the time the
  137. * rte was being disabled and re-programmed.
  138. */
  139. for (irq=0; irq < NR_IRQS; irq++) {
  140. if (vectors_in_migration[irq]) {
  141. struct pt_regs *old_regs = set_irq_regs(NULL);
  142. vectors_in_migration[irq]=0;
  143. generic_handle_irq(irq);
  144. set_irq_regs(old_regs);
  145. }
  146. }
  147. /*
  148. * Now let processor die. We do irq disable and max_xtp() to
  149. * ensure there is no more interrupts routed to this processor.
  150. * But the local timer interrupt can have 1 pending which we
  151. * take care in timer_interrupt().
  152. */
  153. max_xtp();
  154. local_irq_disable();
  155. }
  156. #endif