From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1g9pnh-0001Rd-03 for mharc-grub-devel@gnu.org; Tue, 09 Oct 2018 07:03:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43042) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9pnY-0001Mx-AC for grub-devel@gnu.org; Tue, 09 Oct 2018 07:03:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9pnU-0005PM-4z for grub-devel@gnu.org; Tue, 09 Oct 2018 07:03:32 -0400 Received: from mx2.suse.de ([195.135.220.15]:55290 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9pnT-0005Lp-Qx for grub-devel@gnu.org; Tue, 09 Oct 2018 07:03:27 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 1FD26AFB5; Tue, 9 Oct 2018 11:03:22 +0000 (UTC) From: Juergen Gross To: grub-devel@gnu.org Cc: xen-devel@lists.xen.org, phcoder@gmail.com, daniel.kiper@oracle.com, hans@knorrie.org, Juergen Gross Subject: [PATCH v2 10/18] xen: setup hypercall page for PVH Date: Tue, 9 Oct 2018 13:03:09 +0200 Message-Id: <20181009110317.6022-11-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20181009110317.6022-1-jgross@suse.com> References: <20181009110317.6022-1-jgross@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Oct 2018 11:03:38 -0000 Add the needed code to setup the hypercall page for calling into the Xen hypervisor. Signed-off-by: Juergen Gross --- grub-core/kern/i386/xen/pvh.c | 70 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/grub-core/kern/i386/xen/pvh.c b/grub-core/kern/i386/xen/pvh.c index 182ef95f9..c1b1cf8db 100644 --- a/grub-core/kern/i386/xen/pvh.c +++ b/grub-core/kern/i386/xen/pvh.c @@ -20,14 +20,84 @@ #include #include #include +#include #include #include grub_uint64_t grub_rsdp_addr; +static struct { char _entry[32]; } hypercall_page[128] + __attribute__ ((aligned (GRUB_XEN_PAGE_SIZE))); + +static grub_uint32_t xen_cpuid_base; + +static void +grub_xen_early_halt (void) +{ + asm volatile ("hlt"); +} + +static void +grub_xen_cpuid_base (void) +{ + grub_uint32_t base, eax, signature[3]; + + for (base = 0x40000000; base < 0x40010000; base += 0x100) + { + grub_cpuid (base, eax, signature[0], signature[1], signature[2]); + if (!grub_memcmp ("XenVMMXenVMM", signature, 12) && (eax - base) >= 2) + { + xen_cpuid_base = base; + return; + } + } + + grub_xen_early_halt (); +} + +static void +grub_xen_setup_hypercall_page (void) +{ + grub_uint32_t msr, pfn, eax, ebx, ecx, edx; + + grub_cpuid (xen_cpuid_base + 2, eax, ebx, ecx, edx); + msr = ebx; + pfn = (grub_uint32_t) (&hypercall_page[0]); + + asm volatile ("wrmsr" : : "c" (msr), "a" (pfn), "d" (0) : "memory"); +} + +int +grub_xen_hypercall (grub_uint32_t callno, grub_uint32_t a0, + grub_uint32_t a1, grub_uint32_t a2, + grub_uint32_t a3, grub_uint32_t a4, + grub_uint32_t a5 __attribute__ ((unused))) +{ + register unsigned long __res asm("eax"); + register unsigned long __arg0 asm("ebx") = __arg0; + register unsigned long __arg1 asm("ecx") = __arg1; + register unsigned long __arg2 asm("edx") = __arg2; + register unsigned long __arg3 asm("esi") = __arg3; + register unsigned long __arg4 asm("edi") = __arg4; + + __arg0 = a0; + __arg1 = a1; + __arg2 = a2; + __arg3 = a3; + __arg4 = a4; + asm volatile ("call *%[callno]" + : "=r" (__res), "+r" (__arg0), "+r" (__arg1), "+r" (__arg2), + "+r" (__arg3), "+r" (__arg4) + : [callno] "a" (&hypercall_page[callno]) + : "memory"); + return __res; +} + void grub_xen_setup_pvh (void) { + grub_xen_cpuid_base (); + grub_xen_setup_hypercall_page (); } grub_err_t -- 2.16.4