irq.c 3.1 KB

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