irq.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Based on arch/arm/kernel/irq.c
  4. *
  5. * Copyright (C) 1992 Linus Torvalds
  6. * Modifications for ARM processor Copyright (C) 1995-2000 Russell King.
  7. * Support for Dynamic Tick Timer Copyright (C) 2004-2005 Nokia Corporation.
  8. * Dynamic Tick Timer written by Tony Lindgren <tony@atomide.com> and
  9. * Tuukka Tikkanen <tuukka.tikkanen@elektrobit.com>.
  10. * Copyright (C) 2012 ARM Ltd.
  11. */
  12. #include <linux/hardirq.h>
  13. #include <linux/init.h>
  14. #include <linux/irq.h>
  15. #include <linux/irqchip.h>
  16. #include <linux/kprobes.h>
  17. #include <linux/memory.h>
  18. #include <linux/scs.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/smp.h>
  21. #include <linux/vmalloc.h>
  22. #include <asm/daifflags.h>
  23. #include <asm/exception.h>
  24. #include <asm/numa.h>
  25. #include <asm/softirq_stack.h>
  26. #include <asm/stacktrace.h>
  27. #include <asm/vmap_stack.h>
  28. /* Only access this in an NMI enter/exit */
  29. DEFINE_PER_CPU(struct nmi_ctx, nmi_contexts);
  30. DEFINE_PER_CPU(unsigned long *, irq_stack_ptr);
  31. DECLARE_PER_CPU(unsigned long *, irq_shadow_call_stack_ptr);
  32. #ifdef CONFIG_SHADOW_CALL_STACK
  33. DEFINE_PER_CPU(unsigned long *, irq_shadow_call_stack_ptr);
  34. #endif
  35. static void init_irq_scs(void)
  36. {
  37. int cpu;
  38. if (!scs_is_enabled())
  39. return;
  40. for_each_possible_cpu(cpu)
  41. per_cpu(irq_shadow_call_stack_ptr, cpu) =
  42. scs_alloc(early_cpu_to_node(cpu));
  43. }
  44. #ifdef CONFIG_VMAP_STACK
  45. static void __init init_irq_stacks(void)
  46. {
  47. int cpu;
  48. unsigned long *p;
  49. for_each_possible_cpu(cpu) {
  50. p = arch_alloc_vmap_stack(IRQ_STACK_SIZE, early_cpu_to_node(cpu));
  51. per_cpu(irq_stack_ptr, cpu) = p;
  52. }
  53. }
  54. #else
  55. /* irq stack only needs to be 16 byte aligned - not IRQ_STACK_SIZE aligned. */
  56. DEFINE_PER_CPU_ALIGNED(unsigned long [IRQ_STACK_SIZE/sizeof(long)], irq_stack);
  57. static void init_irq_stacks(void)
  58. {
  59. int cpu;
  60. for_each_possible_cpu(cpu)
  61. per_cpu(irq_stack_ptr, cpu) = per_cpu(irq_stack, cpu);
  62. }
  63. #endif
  64. #ifndef CONFIG_PREEMPT_RT
  65. static void ____do_softirq(struct pt_regs *regs)
  66. {
  67. __do_softirq();
  68. }
  69. void do_softirq_own_stack(void)
  70. {
  71. call_on_irq_stack(NULL, ____do_softirq);
  72. }
  73. #endif
  74. static void default_handle_irq(struct pt_regs *regs)
  75. {
  76. panic("IRQ taken without a root IRQ handler\n");
  77. }
  78. static void default_handle_fiq(struct pt_regs *regs)
  79. {
  80. panic("FIQ taken without a root FIQ handler\n");
  81. }
  82. void (*handle_arch_irq)(struct pt_regs *) __ro_after_init = default_handle_irq;
  83. void (*handle_arch_fiq)(struct pt_regs *) __ro_after_init = default_handle_fiq;
  84. int __init set_handle_irq(void (*handle_irq)(struct pt_regs *))
  85. {
  86. if (handle_arch_irq != default_handle_irq)
  87. return -EBUSY;
  88. handle_arch_irq = handle_irq;
  89. pr_info("Root IRQ handler: %ps\n", handle_irq);
  90. return 0;
  91. }
  92. int __init set_handle_fiq(void (*handle_fiq)(struct pt_regs *))
  93. {
  94. if (handle_arch_fiq != default_handle_fiq)
  95. return -EBUSY;
  96. handle_arch_fiq = handle_fiq;
  97. pr_info("Root FIQ handler: %ps\n", handle_fiq);
  98. return 0;
  99. }
  100. void __init init_IRQ(void)
  101. {
  102. init_irq_stacks();
  103. init_irq_scs();
  104. irqchip_init();
  105. if (system_uses_irq_prio_masking()) {
  106. /*
  107. * Now that we have a stack for our IRQ handler, set
  108. * the PMR/PSR pair to a consistent state.
  109. */
  110. WARN_ON(read_sysreg(daif) & PSR_A_BIT);
  111. local_daif_restore(DAIF_PROCCTX_NOIRQ);
  112. }
  113. }