xref: /openbmc/linux/drivers/xen/features.c (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1457c8996SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2af711cdaSIsaku Yamahata /******************************************************************************
3af711cdaSIsaku Yamahata  * features.c
4af711cdaSIsaku Yamahata  *
5af711cdaSIsaku Yamahata  * Xen feature flags.
6af711cdaSIsaku Yamahata  *
7af711cdaSIsaku Yamahata  * Copyright (c) 2006, Ian Campbell, XenSource Inc.
8af711cdaSIsaku Yamahata  */
9af711cdaSIsaku Yamahata #include <linux/types.h>
10af711cdaSIsaku Yamahata #include <linux/cache.h>
1159aa56bfSPaul Gortmaker #include <linux/export.h>
12ac4c403cSJuergen Gross #include <linux/printk.h>
13ecbf29cdSJeremy Fitzhardinge 
14ecbf29cdSJeremy Fitzhardinge #include <asm/xen/hypercall.h>
15ecbf29cdSJeremy Fitzhardinge 
16ac4c403cSJuergen Gross #include <xen/xen.h>
17ecbf29cdSJeremy Fitzhardinge #include <xen/interface/xen.h>
18ecbf29cdSJeremy Fitzhardinge #include <xen/interface/version.h>
19af711cdaSIsaku Yamahata #include <xen/features.h>
20af711cdaSIsaku Yamahata 
21ac4c403cSJuergen Gross /*
22ac4c403cSJuergen Gross  * Linux kernel expects at least Xen 4.0.
23ac4c403cSJuergen Gross  *
24ac4c403cSJuergen Gross  * Assume some features to be available for that reason (depending on guest
25ac4c403cSJuergen Gross  * mode, of course).
26ac4c403cSJuergen Gross  */
27ac4c403cSJuergen Gross #define chk_required_feature(f) {					\
28ac4c403cSJuergen Gross 		if (!xen_feature(f))					\
29ac4c403cSJuergen Gross 			panic("Xen: feature %s not available!\n", #f);	\
30ac4c403cSJuergen Gross 	}
31ac4c403cSJuergen Gross 
32af711cdaSIsaku Yamahata u8 xen_features[XENFEAT_NR_SUBMAPS * 32] __read_mostly;
33af711cdaSIsaku Yamahata EXPORT_SYMBOL_GPL(xen_features);
34af711cdaSIsaku Yamahata 
xen_setup_features(void)35af711cdaSIsaku Yamahata void xen_setup_features(void)
36af711cdaSIsaku Yamahata {
37af711cdaSIsaku Yamahata 	struct xen_feature_info fi;
38af711cdaSIsaku Yamahata 	int i, j;
39af711cdaSIsaku Yamahata 
40af711cdaSIsaku Yamahata 	for (i = 0; i < XENFEAT_NR_SUBMAPS; i++) {
41af711cdaSIsaku Yamahata 		fi.submap_idx = i;
42af711cdaSIsaku Yamahata 		if (HYPERVISOR_xen_version(XENVER_get_features, &fi) < 0)
43af711cdaSIsaku Yamahata 			break;
44af711cdaSIsaku Yamahata 		for (j = 0; j < 32; j++)
45*ecb6237fSJulien Grall 			xen_features[i * 32 + j] = !!(fi.submap & 1U << j);
46af711cdaSIsaku Yamahata 	}
47ac4c403cSJuergen Gross 
48ac4c403cSJuergen Gross 	if (xen_pv_domain()) {
49ac4c403cSJuergen Gross 		chk_required_feature(XENFEAT_mmu_pt_update_preserve_ad);
50ac4c403cSJuergen Gross 		chk_required_feature(XENFEAT_gnttab_map_avail_bits);
51ac4c403cSJuergen Gross 	}
52af711cdaSIsaku Yamahata }
53