blob: ff007b59448db24523fc1590caa83057a6446dce [file] [log] [blame]
Benjamin Herrenschmidt34d97e02010-07-14 14:12:16 +10001/*
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>
19
20/* 64-bit version only for now */
21#ifdef CONFIG_PPC64
22
23_GLOBAL(book3e_idle)
24 /* Save LR for later */
25 mflr r0
26 std r0,16(r1)
27
28 /* Hard disable interrupts */
29 wrteei 0
30
31 /* Now check if an interrupt came in while we were soft disabled
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +110032 * since we may otherwise lose it (doorbells etc...).
Benjamin Herrenschmidt34d97e02010-07-14 14:12:16 +100033 */
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +110034 lbz r3,PACAIRQHAPPENED(r13)
Benjamin Herrenschmidt34d97e02010-07-14 14:12:16 +100035 cmpwi cr0,r3,0
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +110036 bnelr
Benjamin Herrenschmidt34d97e02010-07-14 14:12:16 +100037
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +110038 /* Now we are going to mark ourselves as soft and hard enabled in
Benjamin Herrenschmidt34d97e02010-07-14 14:12:16 +100039 * order to be able to take interrupts while asleep. We inform lockdep
40 * of that. We don't actually turn interrupts on just yet tho.
41 */
42#ifdef CONFIG_TRACE_IRQFLAGS
43 stdu r1,-128(r1)
44 bl .trace_hardirqs_on
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +110045 addi r1,r1,128
Benjamin Herrenschmidt34d97e02010-07-14 14:12:16 +100046#endif
47 li r0,1
48 stb r0,PACASOFTIRQEN(r13)
Benjamin Herrenschmidt34d97e02010-07-14 14:12:16 +100049
50 /* Interrupts will make use return to LR, so get something we want
51 * in there
52 */
53 bl 1f
54
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +110055 /* And return (interrupts are on) */
Benjamin Herrenschmidt34d97e02010-07-14 14:12:16 +100056 ld r0,16(r1)
57 mtlr r0
58 blr
59
601: /* Let's set the _TLF_NAPPING flag so interrupts make us return
61 * to the right spot
62 */
63 clrrdi r11,r1,THREAD_SHIFT
64 ld r10,TI_LOCAL_FLAGS(r11)
65 ori r10,r10,_TLF_NAPPING
66 std r10,TI_LOCAL_FLAGS(r11)
67
68 /* We can now re-enable hard interrupts and go to sleep */
69 wrteei 1
701: PPC_WAIT(0)
71 b 1b
72
73#endif /* CONFIG_PPC64 */