idle_book3e.S 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright 2010 IBM Corp, Benjamin Herrenschmidt <benh@kernel.crashing.org>
  4. *
  5. * Generic idle routine for Book3E processors
  6. */
  7. #include <linux/threads.h>
  8. #include <asm/reg.h>
  9. #include <asm/ppc_asm.h>
  10. #include <asm/asm-offsets.h>
  11. #include <asm/ppc-opcode.h>
  12. #include <asm/processor.h>
  13. #include <asm/thread_info.h>
  14. #include <asm/epapr_hcalls.h>
  15. #include <asm/hw_irq.h>
  16. /* 64-bit version only for now */
  17. #ifdef CONFIG_PPC64
  18. .macro BOOK3E_IDLE name loop
  19. _GLOBAL(\name)
  20. /* Save LR for later */
  21. mflr r0
  22. std r0,16(r1)
  23. /* Hard disable interrupts */
  24. wrteei 0
  25. /* Now check if an interrupt came in while we were soft disabled
  26. * since we may otherwise lose it (doorbells etc...).
  27. */
  28. lbz r3,PACAIRQHAPPENED(r13)
  29. cmpwi cr0,r3,0
  30. bne 2f
  31. /* Now we are going to mark ourselves as soft and hard enabled in
  32. * order to be able to take interrupts while asleep. We inform lockdep
  33. * of that. We don't actually turn interrupts on just yet tho.
  34. */
  35. #ifdef CONFIG_TRACE_IRQFLAGS
  36. stdu r1,-128(r1)
  37. bl trace_hardirqs_on
  38. addi r1,r1,128
  39. #endif
  40. li r0,IRQS_ENABLED
  41. stb r0,PACAIRQSOFTMASK(r13)
  42. /* Interrupts will make use return to LR, so get something we want
  43. * in there
  44. */
  45. bl 1f
  46. /* And return (interrupts are on) */
  47. ld r0,16(r1)
  48. mtlr r0
  49. blr
  50. 1: /* Let's set the _TLF_NAPPING flag so interrupts make us return
  51. * to the right spot
  52. */
  53. ld r11, PACACURRENT(r13)
  54. ld r10,TI_LOCAL_FLAGS(r11)
  55. ori r10,r10,_TLF_NAPPING
  56. std r10,TI_LOCAL_FLAGS(r11)
  57. /* We can now re-enable hard interrupts and go to sleep */
  58. wrteei 1
  59. \loop
  60. 2:
  61. lbz r10,PACAIRQHAPPENED(r13)
  62. ori r10,r10,PACA_IRQ_HARD_DIS
  63. stb r10,PACAIRQHAPPENED(r13)
  64. blr
  65. .endm
  66. .macro BOOK3E_IDLE_LOOP
  67. 1:
  68. PPC_WAIT(0)
  69. b 1b
  70. .endm
  71. /* epapr_ev_idle_start below is patched with the proper hcall
  72. opcodes during kernel initialization */
  73. .macro EPAPR_EV_IDLE_LOOP
  74. idle_loop:
  75. LOAD_REG_IMMEDIATE(r11, EV_HCALL_TOKEN(EV_IDLE))
  76. .global epapr_ev_idle_start
  77. epapr_ev_idle_start:
  78. li r3, -1
  79. nop
  80. nop
  81. nop
  82. b idle_loop
  83. .endm
  84. BOOK3E_IDLE epapr_ev_idle EPAPR_EV_IDLE_LOOP
  85. BOOK3E_IDLE book3e_idle BOOK3E_IDLE_LOOP
  86. #endif /* CONFIG_PPC64 */