blob: 7b591443833c97373ab532819ae9edbde0de225a [file] [log] [blame]
Thomas Gleixner457c8992019-05-19 13:08:55 +01001// SPDX-License-Identifier: GPL-2.0-only
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07002/******************************************************************************
3 * features.c
4 *
5 * Xen feature flags.
6 *
7 * Copyright (c) 2006, Ian Campbell, XenSource Inc.
8 */
9#include <linux/types.h>
10#include <linux/cache.h>
Paul Gortmaker59aa56b2016-02-21 19:06:04 -050011#include <linux/export.h>
Juergen Grossac4c4032021-07-30 09:18:02 +020012#include <linux/printk.h>
Jeremy Fitzhardingeecbf29c2008-12-16 12:37:07 -080013
14#include <asm/xen/hypercall.h>
15
Juergen Grossac4c4032021-07-30 09:18:02 +020016#include <xen/xen.h>
Jeremy Fitzhardingeecbf29c2008-12-16 12:37:07 -080017#include <xen/interface/xen.h>
18#include <xen/interface/version.h>
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070019#include <xen/features.h>
20
Juergen Grossac4c4032021-07-30 09:18:02 +020021/*
22 * Linux kernel expects at least Xen 4.0.
23 *
24 * Assume some features to be available for that reason (depending on guest
25 * mode, of course).
26 */
27#define chk_required_feature(f) { \
28 if (!xen_feature(f)) \
29 panic("Xen: feature %s not available!\n", #f); \
30 }
31
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070032u8 xen_features[XENFEAT_NR_SUBMAPS * 32] __read_mostly;
33EXPORT_SYMBOL_GPL(xen_features);
34
35void xen_setup_features(void)
36{
37 struct xen_feature_info fi;
38 int i, j;
39
40 for (i = 0; i < XENFEAT_NR_SUBMAPS; i++) {
41 fi.submap_idx = i;
42 if (HYPERVISOR_xen_version(XENVER_get_features, &fi) < 0)
43 break;
44 for (j = 0; j < 32; j++)
45 xen_features[i * 32 + j] = !!(fi.submap & 1<<j);
46 }
Juergen Grossac4c4032021-07-30 09:18:02 +020047
48 if (xen_pv_domain()) {
49 chk_required_feature(XENFEAT_mmu_pt_update_preserve_ad);
50 chk_required_feature(XENFEAT_gnttab_map_avail_bits);
51 }
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070052}