Benjamin Herrenschmidt | 34d97e07 | 2010-07-14 14:12:16 +1000 | [diff] [blame] | 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 | |
| 12 | #include <linux/threads.h> |
| 13 | #include <asm/reg.h> |
| 14 | #include <asm/ppc_asm.h> |
| 15 | #include <asm/asm-offsets.h> |
| 16 | #include <asm/ppc-opcode.h> |
| 17 | #include <asm/processor.h> |
| 18 | #include <asm/thread_info.h> |
Stuart Yoder | f070986 | 2013-02-08 13:22:56 -0600 | [diff] [blame] | 19 | #include <asm/epapr_hcalls.h> |
Madhavan Srinivasan | c2e480b | 2017-12-20 09:25:42 +0530 | [diff] [blame] | 20 | #include <asm/hw_irq.h> |
Benjamin Herrenschmidt | 34d97e07 | 2010-07-14 14:12:16 +1000 | [diff] [blame] | 21 | |
| 22 | /* 64-bit version only for now */ |
| 23 | #ifdef CONFIG_PPC64 |
| 24 | |
Stuart Yoder | f070986 | 2013-02-08 13:22:56 -0600 | [diff] [blame] | 25 | .macro BOOK3E_IDLE name loop |
| 26 | _GLOBAL(\name) |
Benjamin Herrenschmidt | 34d97e07 | 2010-07-14 14:12:16 +1000 | [diff] [blame] | 27 | /* Save LR for later */ |
| 28 | mflr r0 |
| 29 | std r0,16(r1) |
| 30 | |
| 31 | /* Hard disable interrupts */ |
| 32 | wrteei 0 |
| 33 | |
| 34 | /* Now check if an interrupt came in while we were soft disabled |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 35 | * since we may otherwise lose it (doorbells etc...). |
Benjamin Herrenschmidt | 34d97e07 | 2010-07-14 14:12:16 +1000 | [diff] [blame] | 36 | */ |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 37 | lbz r3,PACAIRQHAPPENED(r13) |
Benjamin Herrenschmidt | 34d97e07 | 2010-07-14 14:12:16 +1000 | [diff] [blame] | 38 | cmpwi cr0,r3,0 |
Nicholas Piggin | 9b81c02 | 2018-06-03 22:24:32 +1000 | [diff] [blame] | 39 | bne 2f |
Benjamin Herrenschmidt | 34d97e07 | 2010-07-14 14:12:16 +1000 | [diff] [blame] | 40 | |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 41 | /* Now we are going to mark ourselves as soft and hard enabled in |
Benjamin Herrenschmidt | 34d97e07 | 2010-07-14 14:12:16 +1000 | [diff] [blame] | 42 | * order to be able to take interrupts while asleep. We inform lockdep |
| 43 | * of that. We don't actually turn interrupts on just yet tho. |
| 44 | */ |
| 45 | #ifdef CONFIG_TRACE_IRQFLAGS |
| 46 | stdu r1,-128(r1) |
Anton Blanchard | b1576fe | 2014-02-04 16:04:35 +1100 | [diff] [blame] | 47 | bl trace_hardirqs_on |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 48 | addi r1,r1,128 |
Benjamin Herrenschmidt | 34d97e07 | 2010-07-14 14:12:16 +1000 | [diff] [blame] | 49 | #endif |
Madhavan Srinivasan | c2e480b | 2017-12-20 09:25:42 +0530 | [diff] [blame] | 50 | li r0,IRQS_ENABLED |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 51 | stb r0,PACAIRQSOFTMASK(r13) |
Benjamin Herrenschmidt | 34d97e07 | 2010-07-14 14:12:16 +1000 | [diff] [blame] | 52 | |
| 53 | /* Interrupts will make use return to LR, so get something we want |
| 54 | * in there |
| 55 | */ |
| 56 | bl 1f |
| 57 | |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 58 | /* And return (interrupts are on) */ |
Benjamin Herrenschmidt | 34d97e07 | 2010-07-14 14:12:16 +1000 | [diff] [blame] | 59 | ld r0,16(r1) |
| 60 | mtlr r0 |
| 61 | blr |
| 62 | |
| 63 | 1: /* Let's set the _TLF_NAPPING flag so interrupts make us return |
| 64 | * to the right spot |
| 65 | */ |
Stuart Yoder | 9778b69 | 2012-07-05 04:41:35 +0000 | [diff] [blame] | 66 | CURRENT_THREAD_INFO(r11, r1) |
Benjamin Herrenschmidt | 34d97e07 | 2010-07-14 14:12:16 +1000 | [diff] [blame] | 67 | ld r10,TI_LOCAL_FLAGS(r11) |
| 68 | ori r10,r10,_TLF_NAPPING |
| 69 | std r10,TI_LOCAL_FLAGS(r11) |
| 70 | |
| 71 | /* We can now re-enable hard interrupts and go to sleep */ |
| 72 | wrteei 1 |
Stuart Yoder | f070986 | 2013-02-08 13:22:56 -0600 | [diff] [blame] | 73 | \loop |
| 74 | |
Nicholas Piggin | 9b81c02 | 2018-06-03 22:24:32 +1000 | [diff] [blame] | 75 | 2: |
| 76 | lbz r10,PACAIRQHAPPENED(r13) |
| 77 | ori r10,r10,PACA_IRQ_HARD_DIS |
| 78 | stb r10,PACAIRQHAPPENED(r13) |
| 79 | blr |
Stuart Yoder | f070986 | 2013-02-08 13:22:56 -0600 | [diff] [blame] | 80 | .endm |
| 81 | |
| 82 | .macro BOOK3E_IDLE_LOOP |
| 83 | 1: |
| 84 | PPC_WAIT(0) |
Benjamin Herrenschmidt | 34d97e07 | 2010-07-14 14:12:16 +1000 | [diff] [blame] | 85 | b 1b |
Stuart Yoder | f070986 | 2013-02-08 13:22:56 -0600 | [diff] [blame] | 86 | .endm |
| 87 | |
| 88 | /* epapr_ev_idle_start below is patched with the proper hcall |
| 89 | opcodes during kernel initialization */ |
| 90 | .macro EPAPR_EV_IDLE_LOOP |
| 91 | idle_loop: |
| 92 | LOAD_REG_IMMEDIATE(r11, EV_HCALL_TOKEN(EV_IDLE)) |
| 93 | |
| 94 | .global epapr_ev_idle_start |
| 95 | epapr_ev_idle_start: |
| 96 | li r3, -1 |
| 97 | nop |
| 98 | nop |
| 99 | nop |
| 100 | b idle_loop |
| 101 | .endm |
| 102 | |
| 103 | BOOK3E_IDLE epapr_ev_idle EPAPR_EV_IDLE_LOOP |
| 104 | |
| 105 | BOOK3E_IDLE book3e_idle BOOK3E_IDLE_LOOP |
Benjamin Herrenschmidt | 34d97e07 | 2010-07-14 14:12:16 +1000 | [diff] [blame] | 106 | |
| 107 | #endif /* CONFIG_PPC64 */ |