]> Git Repo - qemu.git/blame - hw/misc/vmcoreinfo.c
Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging
[qemu.git] / hw / misc / vmcoreinfo.c
CommitLineData
6e43353f
MAL
1/*
2 * Virtual Machine coreinfo device
3 *
4 * Copyright (C) 2017 Red Hat, Inc.
5 *
6 * Authors: Marc-André Lureau <[email protected]>
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 */
0b8fa32f 12
6e43353f
MAL
13#include "qemu/osdep.h"
14#include "qapi/error.h"
0b8fa32f 15#include "qemu/module.h"
71e8a915 16#include "sysemu/reset.h"
6e43353f 17#include "hw/nvram/fw_cfg.h"
d6454270 18#include "migration/vmstate.h"
6e43353f
MAL
19#include "hw/misc/vmcoreinfo.h"
20
21static void fw_cfg_vmci_write(void *dev, off_t offset, size_t len)
22{
23 VMCoreInfoState *s = VMCOREINFO(dev);
24
25 s->has_vmcoreinfo = offset == 0 && len == sizeof(s->vmcoreinfo)
5be5df72 26 && s->vmcoreinfo.guest_format != FW_CFG_VMCOREINFO_FORMAT_NONE;
6e43353f
MAL
27}
28
29static void vmcoreinfo_reset(void *dev)
30{
31 VMCoreInfoState *s = VMCOREINFO(dev);
32
33 s->has_vmcoreinfo = false;
34 memset(&s->vmcoreinfo, 0, sizeof(s->vmcoreinfo));
5be5df72 35 s->vmcoreinfo.host_format = cpu_to_le16(FW_CFG_VMCOREINFO_FORMAT_ELF);
6e43353f
MAL
36}
37
38static void vmcoreinfo_realize(DeviceState *dev, Error **errp)
39{
40 VMCoreInfoState *s = VMCOREINFO(dev);
41 FWCfgState *fw_cfg = fw_cfg_find();
c3b1642b
MAL
42 /* for gdb script dump-guest-memory.py */
43 static VMCoreInfoState * volatile vmcoreinfo_state G_GNUC_UNUSED;
6e43353f
MAL
44
45 /* Given that this function is executing, there is at least one VMCOREINFO
46 * device. Check if there are several.
47 */
48 if (!vmcoreinfo_find()) {
49 error_setg(errp, "at most one %s device is permitted",
50 VMCOREINFO_DEVICE);
51 return;
52 }
53
54 if (!fw_cfg || !fw_cfg->dma_enabled) {
55 error_setg(errp, "%s device requires fw_cfg with DMA",
56 VMCOREINFO_DEVICE);
57 return;
58 }
59
5be5df72 60 fw_cfg_add_file_callback(fw_cfg, FW_CFG_VMCOREINFO_FILENAME,
6e43353f
MAL
61 NULL, fw_cfg_vmci_write, s,
62 &s->vmcoreinfo, sizeof(s->vmcoreinfo), false);
63
64 qemu_register_reset(vmcoreinfo_reset, dev);
c3b1642b 65 vmcoreinfo_state = s;
6e43353f
MAL
66}
67
68static const VMStateDescription vmstate_vmcoreinfo = {
69 .name = "vmcoreinfo",
70 .version_id = 1,
71 .minimum_version_id = 1,
72 .fields = (VMStateField[]) {
73 VMSTATE_BOOL(has_vmcoreinfo, VMCoreInfoState),
74 VMSTATE_UINT16(vmcoreinfo.host_format, VMCoreInfoState),
75 VMSTATE_UINT16(vmcoreinfo.guest_format, VMCoreInfoState),
76 VMSTATE_UINT32(vmcoreinfo.size, VMCoreInfoState),
77 VMSTATE_UINT64(vmcoreinfo.paddr, VMCoreInfoState),
78 VMSTATE_END_OF_LIST()
79 },
80};
81
82static void vmcoreinfo_device_class_init(ObjectClass *klass, void *data)
83{
84 DeviceClass *dc = DEVICE_CLASS(klass);
85
86 dc->vmsd = &vmstate_vmcoreinfo;
87 dc->realize = vmcoreinfo_realize;
88 dc->hotpluggable = false;
b948bb55 89 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
6e43353f
MAL
90}
91
92static const TypeInfo vmcoreinfo_device_info = {
93 .name = VMCOREINFO_DEVICE,
94 .parent = TYPE_DEVICE,
95 .instance_size = sizeof(VMCoreInfoState),
96 .class_init = vmcoreinfo_device_class_init,
97};
98
99static void vmcoreinfo_register_types(void)
100{
101 type_register_static(&vmcoreinfo_device_info);
102}
103
104type_init(vmcoreinfo_register_types)
This page took 0.131859 seconds and 4 git commands to generate.