Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * Copyright 2010 IBM Corp, Benjamin Herrenschmidt <benh@kernel.crashing.org>
0004  *
0005  * Generic idle routine for Book3E processors
0006  */
0007 
0008 #include <linux/threads.h>
0009 #include <asm/reg.h>
0010 #include <asm/ppc_asm.h>
0011 #include <asm/asm-offsets.h>
0012 #include <asm/ppc-opcode.h>
0013 #include <asm/processor.h>
0014 #include <asm/thread_info.h>
0015 #include <asm/epapr_hcalls.h>
0016 #include <asm/hw_irq.h>
0017 
0018 /* 64-bit version only for now */
0019 #ifdef CONFIG_PPC64
0020 
0021 .macro BOOK3E_IDLE name loop
0022 _GLOBAL(\name)
0023     /* Save LR for later */
0024     mflr    r0
0025     std r0,16(r1)
0026 
0027     /* Hard disable interrupts */
0028     wrteei  0
0029 
0030     /* Now check if an interrupt came in while we were soft disabled
0031      * since we may otherwise lose it (doorbells etc...).
0032      */
0033     lbz r3,PACAIRQHAPPENED(r13)
0034     cmpwi   cr0,r3,0
0035     bne 2f
0036 
0037     /* Now we are going to mark ourselves as soft and hard enabled in
0038      * order to be able to take interrupts while asleep. We inform lockdep
0039      * of that. We don't actually turn interrupts on just yet tho.
0040      */
0041 #ifdef CONFIG_TRACE_IRQFLAGS
0042     stdu    r1,-128(r1)
0043     bl  trace_hardirqs_on
0044     addi    r1,r1,128
0045 #endif
0046     li  r0,IRQS_ENABLED
0047     stb r0,PACAIRQSOFTMASK(r13)
0048     
0049     /* Interrupts will make use return to LR, so get something we want
0050      * in there
0051      */
0052     bl  1f
0053 
0054     /* And return (interrupts are on) */
0055     ld  r0,16(r1)
0056     mtlr    r0
0057     blr
0058 
0059 1:  /* Let's set the _TLF_NAPPING flag so interrupts make us return
0060      * to the right spot
0061     */
0062     ld  r11, PACACURRENT(r13)
0063     ld  r10,TI_LOCAL_FLAGS(r11)
0064     ori r10,r10,_TLF_NAPPING
0065     std r10,TI_LOCAL_FLAGS(r11)
0066 
0067     /* We can now re-enable hard interrupts and go to sleep */
0068     wrteei  1
0069     \loop
0070 
0071 2:
0072     lbz r10,PACAIRQHAPPENED(r13)
0073     ori r10,r10,PACA_IRQ_HARD_DIS
0074     stb r10,PACAIRQHAPPENED(r13)
0075     blr
0076 .endm
0077 
0078 .macro BOOK3E_IDLE_LOOP
0079 1:
0080     PPC_WAIT(0)
0081     b   1b
0082 .endm
0083 
0084 /* epapr_ev_idle_start below is patched with the proper hcall
0085    opcodes during kernel initialization */
0086 .macro EPAPR_EV_IDLE_LOOP
0087 idle_loop:
0088     LOAD_REG_IMMEDIATE(r11, EV_HCALL_TOKEN(EV_IDLE))
0089 
0090 .global epapr_ev_idle_start
0091 epapr_ev_idle_start:
0092     li      r3, -1
0093     nop
0094     nop
0095     nop
0096     b       idle_loop
0097 .endm
0098 
0099 BOOK3E_IDLE epapr_ev_idle EPAPR_EV_IDLE_LOOP
0100 
0101 BOOK3E_IDLE book3e_idle BOOK3E_IDLE_LOOP
0102 
0103 #endif /* CONFIG_PPC64 */