OSDN Git Service

hw/xen: Add xen_gnttab device for grant table emulation
[qmiga/qemu.git] / hw / i386 / kvm / xen_gnttab.c
1 /*
2  * QEMU Xen emulation: Grant table support
3  *
4  * Copyright © 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5  *
6  * Authors: David Woodhouse <dwmw2@infradead.org>
7  *
8  * This work is licensed under the terms of the GNU GPL, version 2 or later.
9  * See the COPYING file in the top-level directory.
10  */
11
12 #include "qemu/osdep.h"
13 #include "qemu/host-utils.h"
14 #include "qemu/module.h"
15 #include "qemu/lockable.h"
16 #include "qemu/main-loop.h"
17 #include "qapi/error.h"
18 #include "qom/object.h"
19 #include "exec/target_page.h"
20 #include "exec/address-spaces.h"
21 #include "migration/vmstate.h"
22
23 #include "hw/sysbus.h"
24 #include "hw/xen/xen.h"
25 #include "xen_overlay.h"
26 #include "xen_gnttab.h"
27
28 #include "sysemu/kvm.h"
29 #include "sysemu/kvm_xen.h"
30
31 #include "hw/xen/interface/memory.h"
32 #include "hw/xen/interface/grant_table.h"
33
34 #define TYPE_XEN_GNTTAB "xen-gnttab"
35 OBJECT_DECLARE_SIMPLE_TYPE(XenGnttabState, XEN_GNTTAB)
36
37 #define XEN_PAGE_SHIFT 12
38 #define XEN_PAGE_SIZE (1ULL << XEN_PAGE_SHIFT)
39
40 struct XenGnttabState {
41     /*< private >*/
42     SysBusDevice busdev;
43     /*< public >*/
44
45     uint32_t nr_frames;
46     uint32_t max_frames;
47 };
48
49 struct XenGnttabState *xen_gnttab_singleton;
50
51 static void xen_gnttab_realize(DeviceState *dev, Error **errp)
52 {
53     XenGnttabState *s = XEN_GNTTAB(dev);
54
55     if (xen_mode != XEN_EMULATE) {
56         error_setg(errp, "Xen grant table support is for Xen emulation");
57         return;
58     }
59     s->nr_frames = 0;
60     s->max_frames = kvm_xen_get_gnttab_max_frames();
61 }
62
63 static bool xen_gnttab_is_needed(void *opaque)
64 {
65     return xen_mode == XEN_EMULATE;
66 }
67
68 static const VMStateDescription xen_gnttab_vmstate = {
69     .name = "xen_gnttab",
70     .version_id = 1,
71     .minimum_version_id = 1,
72     .needed = xen_gnttab_is_needed,
73     .fields = (VMStateField[]) {
74         VMSTATE_UINT32(nr_frames, XenGnttabState),
75         VMSTATE_END_OF_LIST()
76     }
77 };
78
79 static void xen_gnttab_class_init(ObjectClass *klass, void *data)
80 {
81     DeviceClass *dc = DEVICE_CLASS(klass);
82
83     dc->realize = xen_gnttab_realize;
84     dc->vmsd = &xen_gnttab_vmstate;
85 }
86
87 static const TypeInfo xen_gnttab_info = {
88     .name          = TYPE_XEN_GNTTAB,
89     .parent        = TYPE_SYS_BUS_DEVICE,
90     .instance_size = sizeof(XenGnttabState),
91     .class_init    = xen_gnttab_class_init,
92 };
93
94 void xen_gnttab_create(void)
95 {
96     xen_gnttab_singleton = XEN_GNTTAB(sysbus_create_simple(TYPE_XEN_GNTTAB,
97                                                            -1, NULL));
98 }
99
100 static void xen_gnttab_register_types(void)
101 {
102     type_register_static(&xen_gnttab_info);
103 }
104
105 type_init(xen_gnttab_register_types)
106
107 int xen_gnttab_map_page(uint64_t idx, uint64_t gfn)
108 {
109     return -ENOSYS;
110 }
111