LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Liu Yu <yu.liu@freescale.com>
To: <agraf@suse.de>, <kvm-ppc@vger.kernel.org>, <kvm@vger.kernel.org>
Cc: scottwood@freescale.com, linuxppc-dev@ozlabs.org,
	Liu Yu <yu.liu@freescale.com>,
	timur@freescale.com
Subject: [PATCH v2 3/3] KVM: PPC: epapr: install ev_idle hcall for e500 guest
Date: Thu, 5 Jan 2012 17:06:52 +0800	[thread overview]
Message-ID: <1325754412-29963-2-git-send-email-yu.liu@freescale.com> (raw)
In-Reply-To: <1325754412-29963-1-git-send-email-yu.liu@freescale.com>

If the guest hypervisor node contains "has-idle" property.

Signed-off-by: Liu Yu <yu.liu@freescale.com>
---
v2:
1. move the idle code into assembly.
2. move the part that check "has-idle" into epapr code.

 arch/powerpc/include/asm/epapr_hcalls.h |    1 +
 arch/powerpc/include/asm/machdep.h      |    5 +++++
 arch/powerpc/kernel/epapr_para.c        |    4 ++++
 arch/powerpc/kernel/idle_e500.S         |   17 +++++++++++++++++
 arch/powerpc/kernel/kvm.c               |   24 ++++++++++++++++++++++++
 5 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h b/arch/powerpc/include/asm/epapr_hcalls.h
index c4b86e4..566805e 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -150,6 +150,7 @@
 
 extern u32 *epapr_hcall_insts;
 extern int epapr_hcall_insts_len;
+extern bool epapr_hcall_has_idle;
 
 static inline void epapr_get_hcall_insts(u32 **instp, int *lenp)
 {
diff --git a/arch/powerpc/include/asm/machdep.h b/arch/powerpc/include/asm/machdep.h
index 47cacdd..7e56abf 100644
--- a/arch/powerpc/include/asm/machdep.h
+++ b/arch/powerpc/include/asm/machdep.h
@@ -255,6 +255,11 @@ extern void power4_idle(void);
 extern void power7_idle(void);
 extern void ppc6xx_idle(void);
 extern void book3e_idle(void);
+#ifdef CONFIG_KVM_GUEST
+extern void e500_ev_idle(unsigned long *, unsigned long *, unsigned long,
+                         unsigned long (*)(unsigned long *, unsigned long *,
+                                          unsigned long));
+#endif
 
 /*
  * ppc_md contains a copy of the machine description structure for the
diff --git a/arch/powerpc/kernel/epapr_para.c b/arch/powerpc/kernel/epapr_para.c
index 714dcb3..1f37ddf 100644
--- a/arch/powerpc/kernel/epapr_para.c
+++ b/arch/powerpc/kernel/epapr_para.c
@@ -22,6 +22,7 @@
 
 u32 *epapr_hcall_insts;
 int epapr_hcall_insts_len;
+bool epapr_hcall_has_idle;
 
 static int __init epapr_para_init(void)
 {
@@ -39,6 +40,9 @@ static int __init epapr_para_init(void)
 		epapr_hcall_insts_len = len;
 	}
 
+	if (of_get_property(hyper_node, "has-idle", NULL))
+		epapr_hcall_has_idle = true;
+
 	return 0;
 }
 
diff --git a/arch/powerpc/kernel/idle_e500.S b/arch/powerpc/kernel/idle_e500.S
index 3e2b95c..6ea95f0 100644
--- a/arch/powerpc/kernel/idle_e500.S
+++ b/arch/powerpc/kernel/idle_e500.S
@@ -85,6 +85,23 @@ END_FTR_SECTION_IFSET(CPU_FTR_L2CSR|CPU_FTR_CAN_NAP)
 2:	b	2b
 #endif /* !E500MC */
 
+#ifdef CONFIG_KVM_GUEST
+/*
+ * r3 contains the pointer to in[8]
+ * r4 contains the pointer to out[8]
+ * r5 contains the hcall vendor and nr
+ * r6 contains the handler which send hcall
+ */
+_GLOBAL(e500_ev_idle)
+	rlwinm	r7,r1,0,0,31-THREAD_SHIFT	/* current thread_info */
+	lwz	r8,TI_LOCAL_FLAGS(r7)	/* set napping bit */
+	ori	r8,r8,_TLF_NAPPING	/* so when we take an exception */
+	stw	r8,TI_LOCAL_FLAGS(r7)	/* it will return to our caller */
+	wrteei	1
+	mtctr	r6
+	bctr
+#endif /* KVM_GUEST */
+
 /*
  * Return from NAP/DOZE mode, restore some CPU specific registers,
  * r2 containing physical address of current.
diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index 82a9137..8952e12 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -29,6 +29,7 @@
 #include <asm/cacheflush.h>
 #include <asm/disassemble.h>
 #include <asm/epapr_hcalls.h>
+#include <asm/machdep.h>
 
 #define KVM_MAGIC_PAGE		(-4096L)
 #define magic_var(x) KVM_MAGIC_PAGE + offsetof(struct kvm_vcpu_arch_shared, x)
@@ -578,6 +579,25 @@ static __init void kvm_free_tmp(void)
 	}
 }
 
+static void kvm_hcall_idle(void)
+{
+#ifdef CONFIG_KVM_E500
+	ulong in[8];
+	ulong out[8];
+
+	e500_ev_idle(in, out, HC_VENDOR_EPAPR | HC_EV_IDLE, kvm_hypercall);
+#endif
+}
+
+static bool kvm_para_has_idle(void)
+{
+#ifdef CONFIG_BOOKE
+	return epapr_hcall_has_idle;
+#else
+	return false;
+#endif
+}
+
 static int __init kvm_guest_init(void)
 {
 	if (!kvm_para_available())
@@ -594,6 +614,10 @@ static int __init kvm_guest_init(void)
 	powersave_nap = 1;
 #endif
 
+	/* Install hcall based power_save for guest kernel */
+	if (kvm_para_has_idle())
+		ppc_md.power_save = kvm_hcall_idle;
+
 free_tmp:
 	kvm_free_tmp();
 
-- 
1.6.4

  reply	other threads:[~2012-01-05  9:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-05  9:06 [PATCH 1/3] KVM: PPC: epapr: Factor out the epapr init Liu Yu
2012-01-05  9:06 ` Liu Yu [this message]
2012-01-09 14:05   ` [PATCH v2 3/3] KVM: PPC: epapr: install ev_idle hcall for e500 guest Alexander Graf
2012-01-09 21:15   ` Scott Wood
2012-01-09 13:50 ` [PATCH 1/3] KVM: PPC: epapr: Factor out the epapr init Alexander Graf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1325754412-29963-2-git-send-email-yu.liu@freescale.com \
    --to=yu.liu@freescale.com \
    --cc=agraf@suse.de \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=scottwood@freescale.com \
    --cc=timur@freescale.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox