irq.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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/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/vmap_stack.h>
  24. /* Only access this in an NMI enter/exit */
  25. DEFINE_PER_CPU(struct nmi_ctx, nmi_contexts);
  26. DEFINE_PER_CPU(unsigned long *, irq_stack_ptr);
  27. DECLARE_PER_CPU(unsigned long *, irq_shadow_call_stack_ptr);
  28. #ifdef CONFIG_SHADOW_CALL_STACK
  29. DEFINE_PER_CPU(unsigned long *, irq_shadow_call_stack_ptr);
  30. #endif
  31. static void init_irq_scs(void)
  32. {
  33. int cpu;
  34. if (!IS_ENABLED(CONFIG_SHADOW_CALL_STACK))
  35. return;
  36. for_each_possible_cpu(cpu)
  37. per_cpu(irq_shadow_call_stack_ptr, cpu) =
  38. scs_alloc(cpu_to_node(cpu));
  39. }
  40. #ifdef CONFIG_VMAP_STACK
  41. static void init_irq_stacks(void)
  42. {
  43. int cpu;
  44. unsigned long *p;
  45. for_each_possible_cpu(cpu) {
  46. p = arch_alloc_vmap_stack(IRQ_STACK_SIZE, cpu_to_node(cpu));
  47. per_cpu(irq_stack_ptr, cpu) = p;
  48. }
  49. }
  50. #else
  51. /* irq stack only needs to be 16 byte aligned - not IRQ_STACK_SIZE aligned. */
  52. DEFINE_PER_CPU_ALIGNED(unsigned long [IRQ_STACK_SIZE/sizeof(long)], irq_stack);
  53. static void init_irq_stacks(void)
  54. {
  55. int cpu;
  56. for_each_possible_cpu(cpu)
  57. per_cpu(irq_stack_ptr, cpu) = per_cpu(irq_stack, cpu);
  58. }
  59. #endif
  60. void __init init_IRQ(void)
  61. {
  62. init_irq_stacks();
  63. init_irq_scs();
  64. irqchip_init();
  65. if (!handle_arch_irq)
  66. panic("No interrupt controller found.");
  67. if (system_uses_irq_prio_masking()) {
  68. /*
  69. * Now that we have a stack for our IRQ handler, set
  70. * the PMR/PSR pair to a consistent state.
  71. */
  72. WARN_ON(read_sysreg(daif) & PSR_A_BIT);
  73. local_daif_restore(DAIF_PROCCTX_NOIRQ);
  74. }
  75. }