2008-10-28 01:41:46 +08:00
|
|
|
/*
|
|
|
|
* Common hypervisor code
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008, VMware, Inc.
|
|
|
|
* Author : Alok N Kataria <akataria@vmware.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
|
|
|
|
* NON INFRINGEMENT. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-07-14 08:18:56 +08:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/export.h>
|
2008-10-28 01:41:46 +08:00
|
|
|
#include <asm/processor.h>
|
2008-11-22 05:56:17 +08:00
|
|
|
#include <asm/hypervisor.h>
|
2008-10-28 01:41:46 +08:00
|
|
|
|
2017-11-09 21:27:36 +08:00
|
|
|
extern const struct hypervisor_x86 x86_hyper_vmware;
|
|
|
|
extern const struct hypervisor_x86 x86_hyper_ms_hyperv;
|
|
|
|
extern const struct hypervisor_x86 x86_hyper_xen_pv;
|
|
|
|
extern const struct hypervisor_x86 x86_hyper_xen_hvm;
|
|
|
|
extern const struct hypervisor_x86 x86_hyper_kvm;
|
2017-11-27 16:11:46 +08:00
|
|
|
extern const struct hypervisor_x86 x86_hyper_jailhouse;
|
2017-11-09 21:27:36 +08:00
|
|
|
|
2010-05-08 07:57:28 +08:00
|
|
|
static const __initconst struct hypervisor_x86 * const hypervisors[] =
|
2008-10-28 01:41:46 +08:00
|
|
|
{
|
2017-03-15 01:35:38 +08:00
|
|
|
#ifdef CONFIG_XEN_PV
|
2017-03-15 01:35:36 +08:00
|
|
|
&x86_hyper_xen_pv,
|
2017-03-15 01:35:38 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_XEN_PVHVM
|
2017-03-15 01:35:36 +08:00
|
|
|
&x86_hyper_xen_hvm,
|
2010-07-27 01:38:45 +08:00
|
|
|
#endif
|
2011-07-09 02:42:50 +08:00
|
|
|
&x86_hyper_vmware,
|
|
|
|
&x86_hyper_ms_hyperv,
|
2012-07-18 16:48:50 +08:00
|
|
|
#ifdef CONFIG_KVM_GUEST
|
2012-07-07 01:47:39 +08:00
|
|
|
&x86_hyper_kvm,
|
2012-07-18 16:48:50 +08:00
|
|
|
#endif
|
2017-11-27 16:11:46 +08:00
|
|
|
#ifdef CONFIG_JAILHOUSE_GUEST
|
|
|
|
&x86_hyper_jailhouse,
|
|
|
|
#endif
|
2010-05-08 07:57:28 +08:00
|
|
|
};
|
2008-10-28 01:41:46 +08:00
|
|
|
|
2017-11-09 21:27:36 +08:00
|
|
|
enum x86_hypervisor_type x86_hyper_type;
|
|
|
|
EXPORT_SYMBOL(x86_hyper_type);
|
2010-05-08 07:57:28 +08:00
|
|
|
|
2017-11-09 21:27:35 +08:00
|
|
|
static inline const struct hypervisor_x86 * __init
|
2010-05-08 07:57:28 +08:00
|
|
|
detect_hypervisor_vendor(void)
|
2008-11-01 03:01:58 +08:00
|
|
|
{
|
2017-11-09 21:27:35 +08:00
|
|
|
const struct hypervisor_x86 *h = NULL, * const *p;
|
2013-07-25 16:54:35 +08:00
|
|
|
uint32_t pri, max_pri = 0;
|
2010-05-08 07:57:28 +08:00
|
|
|
|
|
|
|
for (p = hypervisors; p < hypervisors + ARRAY_SIZE(hypervisors); p++) {
|
2017-11-09 21:27:35 +08:00
|
|
|
pri = (*p)->detect();
|
|
|
|
if (pri > max_pri) {
|
2013-07-25 16:54:35 +08:00
|
|
|
max_pri = pri;
|
2017-11-09 21:27:35 +08:00
|
|
|
h = *p;
|
2010-05-08 07:57:28 +08:00
|
|
|
}
|
|
|
|
}
|
2013-07-25 16:54:35 +08:00
|
|
|
|
2017-11-09 21:27:35 +08:00
|
|
|
if (h)
|
|
|
|
pr_info("Hypervisor detected: %s\n", h->name);
|
|
|
|
|
|
|
|
return h;
|
2008-11-01 03:01:58 +08:00
|
|
|
}
|
|
|
|
|
2017-11-09 21:27:35 +08:00
|
|
|
static void __init copy_array(const void *src, void *target, unsigned int size)
|
2009-08-20 23:06:25 +08:00
|
|
|
{
|
2017-11-09 21:27:35 +08:00
|
|
|
unsigned int i, n = size / sizeof(void *);
|
|
|
|
const void * const *from = (const void * const *)src;
|
|
|
|
const void **to = (const void **)target;
|
2010-05-08 07:57:28 +08:00
|
|
|
|
2017-11-09 21:27:35 +08:00
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
if (from[i])
|
|
|
|
to[i] = from[i];
|
2009-08-20 23:06:25 +08:00
|
|
|
}
|
2013-01-18 07:44:42 +08:00
|
|
|
|
2017-11-09 21:27:35 +08:00
|
|
|
void __init init_hypervisor_platform(void)
|
2013-01-18 07:44:42 +08:00
|
|
|
{
|
2017-11-09 21:27:35 +08:00
|
|
|
const struct hypervisor_x86 *h;
|
2016-08-29 14:48:43 +08:00
|
|
|
|
2017-11-09 21:27:35 +08:00
|
|
|
h = detect_hypervisor_vendor();
|
|
|
|
|
|
|
|
if (!h)
|
2016-08-29 14:48:43 +08:00
|
|
|
return;
|
|
|
|
|
2017-11-09 21:27:35 +08:00
|
|
|
copy_array(&h->init, &x86_init.hyper, sizeof(h->init));
|
|
|
|
copy_array(&h->runtime, &x86_platform.hyper, sizeof(h->runtime));
|
|
|
|
|
2017-11-09 21:27:36 +08:00
|
|
|
x86_hyper_type = h->type;
|
2017-11-09 21:27:35 +08:00
|
|
|
x86_init.hyper.init_platform();
|
2016-08-29 14:48:43 +08:00
|
|
|
}
|