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