target/arm: Convert Add/subtract (immediate) to decodetree
[qemu/ar7.git] / accel / xen / xen-all.c
blob5ff0cb8bd9e55c1468872b8a616a6226bbe9b19a
1 /*
2 * Copyright (C) 2014 Citrix Systems UK Ltd.
4 * This work is licensed under the terms of the GNU GPL, version 2. See
5 * the COPYING file in the top-level directory.
7 * Contributions after 2012-01-13 are licensed under the terms of the
8 * GNU GPL, version 2 or (at your option) any later version.
9 */
11 #include "qemu/osdep.h"
12 #include "qemu/error-report.h"
13 #include "qemu/module.h"
14 #include "qapi/error.h"
15 #include "hw/xen/xen_native.h"
16 #include "hw/xen/xen-legacy-backend.h"
17 #include "hw/xen/xen_pt.h"
18 #include "chardev/char.h"
19 #include "qemu/accel.h"
20 #include "sysemu/cpus.h"
21 #include "sysemu/xen.h"
22 #include "sysemu/runstate.h"
23 #include "migration/misc.h"
24 #include "migration/global_state.h"
25 #include "hw/boards.h"
27 bool xen_allowed;
29 xc_interface *xen_xc;
30 xenforeignmemory_handle *xen_fmem;
31 xendevicemodel_handle *xen_dmod;
33 static void xenstore_record_dm_state(const char *state)
35 char path[50];
37 snprintf(path, sizeof (path), "device-model/%u/state", xen_domid);
38 if (!qemu_xen_xs_write(xenstore, XBT_NULL, path, state, strlen(state))) {
39 error_report("error recording dm state");
40 exit(1);
45 static void xen_change_state_handler(void *opaque, bool running,
46 RunState state)
48 if (running) {
49 /* record state running */
50 xenstore_record_dm_state("running");
54 static bool xen_get_igd_gfx_passthru(Object *obj, Error **errp)
56 return xen_igd_gfx_pt_enabled();
59 static void xen_set_igd_gfx_passthru(Object *obj, bool value, Error **errp)
61 xen_igd_gfx_pt_set(value, errp);
64 static void xen_setup_post(MachineState *ms, AccelState *accel)
66 int rc;
68 if (xen_domid_restrict) {
69 rc = xen_restrict(xen_domid);
70 if (rc < 0) {
71 perror("xen: failed to restrict");
72 exit(1);
77 static int xen_init(MachineState *ms)
79 MachineClass *mc = MACHINE_GET_CLASS(ms);
81 xen_xc = xc_interface_open(0, 0, 0);
82 if (xen_xc == NULL) {
83 xen_pv_printf(NULL, 0, "can't open xen interface\n");
84 return -1;
86 xen_fmem = xenforeignmemory_open(0, 0);
87 if (xen_fmem == NULL) {
88 xen_pv_printf(NULL, 0, "can't open xen fmem interface\n");
89 xc_interface_close(xen_xc);
90 return -1;
92 xen_dmod = xendevicemodel_open(0, 0);
93 if (xen_dmod == NULL) {
94 xen_pv_printf(NULL, 0, "can't open xen devicemodel interface\n");
95 xenforeignmemory_close(xen_fmem);
96 xc_interface_close(xen_xc);
97 return -1;
101 * The XenStore write would fail when running restricted so don't attempt
102 * it in that case. Toolstacks should instead use QMP to listen for state
103 * changes.
105 if (!xen_domid_restrict) {
106 qemu_add_vm_change_state_handler(xen_change_state_handler, NULL);
109 * opt out of system RAM being allocated by generic code
111 mc->default_ram_id = NULL;
113 xen_mode = XEN_ATTACH;
114 return 0;
117 static void xen_accel_class_init(ObjectClass *oc, void *data)
119 AccelClass *ac = ACCEL_CLASS(oc);
120 static GlobalProperty compat[] = {
121 { "migration", "store-global-state", "off" },
122 { "migration", "send-configuration", "off" },
123 { "migration", "send-section-footer", "off" },
126 ac->name = "Xen";
127 ac->init_machine = xen_init;
128 ac->setup_post = xen_setup_post;
129 ac->allowed = &xen_allowed;
130 ac->compat_props = g_ptr_array_new();
132 compat_props_add(ac->compat_props, compat, G_N_ELEMENTS(compat));
134 object_class_property_add_bool(oc, "igd-passthru",
135 xen_get_igd_gfx_passthru, xen_set_igd_gfx_passthru);
136 object_class_property_set_description(oc, "igd-passthru",
137 "Set on/off to enable/disable igd passthrou");
140 #define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
142 static const TypeInfo xen_accel_type = {
143 .name = TYPE_XEN_ACCEL,
144 .parent = TYPE_ACCEL,
145 .class_init = xen_accel_class_init,
148 static void xen_accel_ops_class_init(ObjectClass *oc, void *data)
150 AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
152 ops->create_vcpu_thread = dummy_start_vcpu_thread;
155 static const TypeInfo xen_accel_ops_type = {
156 .name = ACCEL_OPS_NAME("xen"),
158 .parent = TYPE_ACCEL_OPS,
159 .class_init = xen_accel_ops_class_init,
160 .abstract = true,
163 static void xen_type_init(void)
165 type_register_static(&xen_accel_type);
166 type_register_static(&xen_accel_ops_type);
168 type_init(xen_type_init);