349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * CDDL HEADER START
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * The contents of this file are subject to the terms of the
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * Common Development and Distribution License (the "License").
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * You may not use this file except in compliance with the License.
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * See the License for the specific language governing permissions
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * and limitations under the License.
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * When distributing Covered Code, include this CDDL HEADER in each
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * If applicable, add the following below this CDDL HEADER, with the
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * fields enclosed by brackets "[]" replaced with your own identifying
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * information: Portions Copyright [yyyy] [name of copyright owner]
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * CDDL HEADER END
6e5580c92a7a7c64dd50b768bda246808fb1ee17Frank Van Der Linden * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * This structure is ordinarily constructed by Xen. In the HVM world, we
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * manually fill in the few fields the PV drivers need.
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * Feature bits; more bits will be added, like direct I/O, etc.
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee/* Metadata page shared between domain and Xen */
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee/* Page containing code to issue hypercalls. */
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee if ((HYPERVISOR_hvm_op(HVMOP_get_param, &xhp) < 0))
6e5580c92a7a7c64dd50b768bda246808fb1ee17Frank Van Der Linden * Xen's pseudo-cpuid function returns a string representing
6e5580c92a7a7c64dd50b768bda246808fb1ee17Frank Van Der Linden * the Xen signature in %ebx, %ecx, and %edx.
6e5580c92a7a7c64dd50b768bda246808fb1ee17Frank Van Der Linden * Loop over the base values, since it may be different if
6e5580c92a7a7c64dd50b768bda246808fb1ee17Frank Van Der Linden * the hypervisor has hyper-v emulation switched on.
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * %eax contains the maximum supported cpuid function.
6e5580c92a7a7c64dd50b768bda246808fb1ee17Frank Van Der Linden for (base = 0x40000000; base < 0x40010000; base += 0x100) {
6e5580c92a7a7c64dd50b768bda246808fb1ee17Frank Van Der Linden if (strcmp("XenVMMXenVMM", xen_str) == 0 &&
6e5580c92a7a7c64dd50b768bda246808fb1ee17Frank Van Der Linden * cpuid function at base + 1 returns the Xen version in %eax. The
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * top 16 bits are the major version, the bottom 16 are the minor
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * Below version 3.1 we can't do anything special as a HVM domain;
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * the PV drivers don't work, many hypercalls are not available,
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee if (xen_major < 3 || (xen_major == 3 && xen_minor < 1))
6e5580c92a7a7c64dd50b768bda246808fb1ee17Frank Van Der Linden * cpuid function at base + 2 returns information about the
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * hypercall page. %eax nominally contains the number of pages
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * with hypercall code, but according to the Xen guys, "I'll
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * guarantee that remains one forever more, so you can just
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * allocate a single page and get quite upset if you ever see CPUID
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * return more than one page." %ebx contains an MSR we use to ask
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * Xen to remap each page at a specific pfn.
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * Let Xen know where we want the hypercall page mapped. We
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * already have a page allocated in the .text section to simplify
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * the wrapper code.
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee /* Fill in the xen_info data */
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee (void) sprintf(xen_info->magic, "xen-%d.%d", xen_major, xen_minor);
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee if (hvm_get_param(HVM_PARAM_STORE_PFN, &val) < 0)
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * The first hypercall worked, so mark hypercalls as working.
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee if (hvm_get_param(HVM_PARAM_STORE_EVTCHN, &val) < 0)
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee /* Figure out whether the hypervisor is 32-bit or 64-bit. */
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee if ((HYPERVISOR_xen_version(XENVER_capabilities, &caps) == 0)) {
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * Allocate space for the shared_info page and tell Xen where it
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee xen_shared_info_frame = va_to_pfn(&hypercall_shared_info_page);
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp) != 0)
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee HYPERVISOR_shared_info = (void *)&hypercall_shared_info_page;
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * A working HVM tlb flush hypercall was introduced in Xen 3.3.
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee if (xen_major > 3 || (xen_major == 3 && xen_minor >= 3))
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * -1 if a feature is not available
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * 1 if a boolean feature is available
349b53dd4e695e3d833b5380540385145b2d3ae8Stuart Maybee * > 0 if numeric feature is available