idle_book3e.S 2.3 KB

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