/src/qemu/hw/misc/debugexit.c
Line | Count | Source |
1 | | /* |
2 | | * debug exit port emulation |
3 | | * |
4 | | * This program is free software; you can redistribute it and/or |
5 | | * modify it under the terms of the GNU General Public License as |
6 | | * published by the Free Software Foundation; either version 2 or |
7 | | * (at your option) any later version. |
8 | | */ |
9 | | |
10 | | #include "qemu/osdep.h" |
11 | | #include "hw/isa/isa.h" |
12 | | #include "hw/core/qdev-properties.h" |
13 | | #include "qemu/module.h" |
14 | | #include "qom/object.h" |
15 | | #include "system/runstate.h" |
16 | | |
17 | 0 | #define TYPE_ISA_DEBUG_EXIT_DEVICE "isa-debug-exit" |
18 | | OBJECT_DECLARE_SIMPLE_TYPE(ISADebugExitState, ISA_DEBUG_EXIT_DEVICE) |
19 | | |
20 | | struct ISADebugExitState { |
21 | | ISADevice parent_obj; |
22 | | |
23 | | uint32_t iobase; |
24 | | uint32_t iosize; |
25 | | MemoryRegion io; |
26 | | }; |
27 | | |
28 | | static uint64_t debug_exit_read(void *opaque, hwaddr addr, unsigned size) |
29 | 0 | { |
30 | 0 | return 0; |
31 | 0 | } |
32 | | |
33 | | static void debug_exit_write(void *opaque, hwaddr addr, uint64_t val, |
34 | | unsigned width) |
35 | 0 | { |
36 | 0 | qemu_system_shutdown_request_with_code(SHUTDOWN_CAUSE_GUEST_SHUTDOWN, |
37 | 0 | (val << 1) | 1); |
38 | 0 | } |
39 | | |
40 | | static const MemoryRegionOps debug_exit_ops = { |
41 | | .read = debug_exit_read, |
42 | | .write = debug_exit_write, |
43 | | .valid.min_access_size = 1, |
44 | | .valid.max_access_size = 4, |
45 | | .endianness = DEVICE_LITTLE_ENDIAN, |
46 | | }; |
47 | | |
48 | | static void debug_exit_realizefn(DeviceState *d, Error **errp) |
49 | 0 | { |
50 | 0 | ISADevice *dev = ISA_DEVICE(d); |
51 | 0 | ISADebugExitState *isa = ISA_DEBUG_EXIT_DEVICE(d); |
52 | |
|
53 | 0 | memory_region_init_io(&isa->io, OBJECT(dev), &debug_exit_ops, isa, |
54 | 0 | TYPE_ISA_DEBUG_EXIT_DEVICE, isa->iosize); |
55 | 0 | memory_region_add_subregion(isa_address_space_io(dev), |
56 | 0 | isa->iobase, &isa->io); |
57 | 0 | } |
58 | | |
59 | | static const Property debug_exit_properties[] = { |
60 | | DEFINE_PROP_UINT32("iobase", ISADebugExitState, iobase, 0x501), |
61 | | DEFINE_PROP_UINT32("iosize", ISADebugExitState, iosize, 0x02), |
62 | | }; |
63 | | |
64 | | static void debug_exit_class_initfn(ObjectClass *klass, const void *data) |
65 | 63 | { |
66 | 63 | DeviceClass *dc = DEVICE_CLASS(klass); |
67 | | |
68 | 63 | dc->realize = debug_exit_realizefn; |
69 | 63 | device_class_set_props(dc, debug_exit_properties); |
70 | 63 | set_bit(DEVICE_CATEGORY_MISC, dc->categories); |
71 | 63 | } |
72 | | |
73 | | static const TypeInfo debug_exit_info = { |
74 | | .name = TYPE_ISA_DEBUG_EXIT_DEVICE, |
75 | | .parent = TYPE_ISA_DEVICE, |
76 | | .instance_size = sizeof(ISADebugExitState), |
77 | | .class_init = debug_exit_class_initfn, |
78 | | }; |
79 | | |
80 | | static void debug_exit_register_types(void) |
81 | 63 | { |
82 | 63 | type_register_static(&debug_exit_info); |
83 | 63 | } |
84 | | |
85 | | type_init(debug_exit_register_types) |