blob: cc008de58b050925f81a2c05407f87e1bd2f3185 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Benjamin Herrenschmidt34d97e072010-07-14 14:12:16 +10002/*
3 * Copyright 2010 IBM Corp, Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 *
5 * Generic idle routine for Book3E processors
Benjamin Herrenschmidt34d97e072010-07-14 14:12:16 +10006 */
7
8#include <linux/threads.h>
9#include <asm/reg.h>
10#include <asm/ppc_asm.h>
11#include <asm/asm-offsets.h>
12#include <asm/ppc-opcode.h>
13#include <asm/processor.h>
14#include <asm/thread_info.h>
Stuart Yoderf0709862013-02-08 13:22:56 -060015#include <asm/epapr_hcalls.h>
Madhavan Srinivasanc2e480b2017-12-20 09:25:42 +053016#include <asm/hw_irq.h>
Benjamin Herrenschmidt34d97e072010-07-14 14:12:16 +100017
18/* 64-bit version only for now */
19#ifdef CONFIG_PPC64
20
Stuart Yoderf0709862013-02-08 13:22:56 -060021.macro BOOK3E_IDLE name loop
22_GLOBAL(\name)
Benjamin Herrenschmidt34d97e072010-07-14 14:12:16 +100023 /* Save LR for later */
24 mflr r0
25 std r0,16(r1)
26
27 /* Hard disable interrupts */
28 wrteei 0
29
30 /* Now check if an interrupt came in while we were soft disabled
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +110031 * since we may otherwise lose it (doorbells etc...).
Benjamin Herrenschmidt34d97e072010-07-14 14:12:16 +100032 */
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +110033 lbz r3,PACAIRQHAPPENED(r13)
Benjamin Herrenschmidt34d97e072010-07-14 14:12:16 +100034 cmpwi cr0,r3,0
Nicholas Piggin9b81c022018-06-03 22:24:32 +100035 bne 2f
Benjamin Herrenschmidt34d97e072010-07-14 14:12:16 +100036
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +110037 /* Now we are going to mark ourselves as soft and hard enabled in
Benjamin Herrenschmidt34d97e072010-07-14 14:12:16 +100038 * order to be able to take interrupts while asleep. We inform lockdep
39 * of that. We don't actually turn interrupts on just yet tho.
40 */
41#ifdef CONFIG_TRACE_IRQFLAGS
42 stdu r1,-128(r1)
Anton Blanchardb1576fe2014-02-04 16:04:35 +110043 bl trace_hardirqs_on
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +110044 addi r1,r1,128
Benjamin Herrenschmidt34d97e072010-07-14 14:12:16 +100045#endif
Madhavan Srinivasanc2e480b2017-12-20 09:25:42 +053046 li r0,IRQS_ENABLED
Madhavan Srinivasan4e26bc42017-12-20 09:25:50 +053047 stb r0,PACAIRQSOFTMASK(r13)
Benjamin Herrenschmidt34d97e072010-07-14 14:12:16 +100048
49 /* Interrupts will make use return to LR, so get something we want
50 * in there
51 */
52 bl 1f
53
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +110054 /* And return (interrupts are on) */
Benjamin Herrenschmidt34d97e072010-07-14 14:12:16 +100055 ld r0,16(r1)
56 mtlr r0
57 blr
58
591: /* Let's set the _TLF_NAPPING flag so interrupts make us return
60 * to the right spot
61 */
Christophe Leroyc911d2e2019-01-12 09:55:50 +000062 ld r11, PACACURRENT(r13)
Benjamin Herrenschmidt34d97e072010-07-14 14:12:16 +100063 ld r10,TI_LOCAL_FLAGS(r11)
64 ori r10,r10,_TLF_NAPPING
65 std r10,TI_LOCAL_FLAGS(r11)
66
67 /* We can now re-enable hard interrupts and go to sleep */
68 wrteei 1
Stuart Yoderf0709862013-02-08 13:22:56 -060069 \loop
70
Nicholas Piggin9b81c022018-06-03 22:24:32 +1000712:
72 lbz r10,PACAIRQHAPPENED(r13)
73 ori r10,r10,PACA_IRQ_HARD_DIS
74 stb r10,PACAIRQHAPPENED(r13)
75 blr
Stuart Yoderf0709862013-02-08 13:22:56 -060076.endm
77
78.macro BOOK3E_IDLE_LOOP
791:
80 PPC_WAIT(0)
Benjamin Herrenschmidt34d97e072010-07-14 14:12:16 +100081 b 1b
Stuart Yoderf0709862013-02-08 13:22:56 -060082.endm
83
84/* epapr_ev_idle_start below is patched with the proper hcall
85 opcodes during kernel initialization */
86.macro EPAPR_EV_IDLE_LOOP
87idle_loop:
88 LOAD_REG_IMMEDIATE(r11, EV_HCALL_TOKEN(EV_IDLE))
89
90.global epapr_ev_idle_start
91epapr_ev_idle_start:
92 li r3, -1
93 nop
94 nop
95 nop
96 b idle_loop
97.endm
98
99BOOK3E_IDLE epapr_ev_idle EPAPR_EV_IDLE_LOOP
100
101BOOK3E_IDLE book3e_idle BOOK3E_IDLE_LOOP
Benjamin Herrenschmidt34d97e072010-07-14 14:12:16 +1000102
103#endif /* CONFIG_PPC64 */