]> git.proxmox.com Git - mirror_qemu.git/blame - hw/char/serial-isa.c
Include migration/vmstate.h less
[mirror_qemu.git] / hw / char / serial-isa.c
CommitLineData
488cb996
GH
1/*
2 * QEMU 16550A UART emulation
3 *
4 * Copyright (c) 2003-2004 Fabrice Bellard
5 * Copyright (c) 2008 Citrix Systems, Inc.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 */
25
b6a0aa05 26#include "qemu/osdep.h"
da34e65c 27#include "qapi/error.h"
0b8fa32f 28#include "qemu/module.h"
0d09e41a
PB
29#include "hw/char/serial.h"
30#include "hw/isa/isa.h"
d6454270 31#include "migration/vmstate.h"
488cb996 32
eeceb084
AF
33#define ISA_SERIAL(obj) OBJECT_CHECK(ISASerialState, (obj), TYPE_ISA_SERIAL)
34
488cb996 35typedef struct ISASerialState {
eeceb084
AF
36 ISADevice parent_obj;
37
488cb996
GH
38 uint32_t index;
39 uint32_t iobase;
40 uint32_t isairq;
41 SerialState state;
42} ISASerialState;
43
def337ff 44static const int isa_serial_io[MAX_ISA_SERIAL_PORTS] = {
488cb996
GH
45 0x3f8, 0x2f8, 0x3e8, 0x2e8
46};
def337ff 47static const int isa_serial_irq[MAX_ISA_SERIAL_PORTS] = {
488cb996
GH
48 4, 3, 4, 3
49};
50
db895a1e 51static void serial_isa_realizefn(DeviceState *dev, Error **errp)
488cb996
GH
52{
53 static int index;
db895a1e 54 ISADevice *isadev = ISA_DEVICE(dev);
eeceb084 55 ISASerialState *isa = ISA_SERIAL(dev);
488cb996
GH
56 SerialState *s = &isa->state;
57
58 if (isa->index == -1) {
59 isa->index = index;
60 }
def337ff 61 if (isa->index >= MAX_ISA_SERIAL_PORTS) {
db895a1e 62 error_setg(errp, "Max. supported number of ISA serial ports is %d.",
def337ff 63 MAX_ISA_SERIAL_PORTS);
db895a1e 64 return;
488cb996
GH
65 }
66 if (isa->iobase == -1) {
67 isa->iobase = isa_serial_io[isa->index];
68 }
69 if (isa->isairq == -1) {
70 isa->isairq = isa_serial_irq[isa->index];
71 }
72 index++;
73
74 s->baudbase = 115200;
db895a1e
AF
75 isa_init_irq(isadev, &s->irq, isa->isairq);
76 serial_realize_core(s, errp);
77 qdev_set_legacy_instance_id(dev, isa->iobase, 3);
488cb996 78
300b1fc6 79 memory_region_init_io(&s->io, OBJECT(isa), &serial_io_ops, s, "serial", 8);
db895a1e 80 isa_register_ioport(isadev, &s->io, isa->iobase);
488cb996
GH
81}
82
83static const VMStateDescription vmstate_isa_serial = {
84 .name = "serial",
85 .version_id = 3,
86 .minimum_version_id = 2,
87 .fields = (VMStateField[]) {
88 VMSTATE_STRUCT(state, ISASerialState, 0, vmstate_serial, SerialState),
89 VMSTATE_END_OF_LIST()
90 }
91};
92
93static Property serial_isa_properties[] = {
94 DEFINE_PROP_UINT32("index", ISASerialState, index, -1),
c7bcc85d 95 DEFINE_PROP_UINT32("iobase", ISASerialState, iobase, -1),
488cb996
GH
96 DEFINE_PROP_UINT32("irq", ISASerialState, isairq, -1),
97 DEFINE_PROP_CHR("chardev", ISASerialState, state.chr),
98 DEFINE_PROP_UINT32("wakeup", ISASerialState, state.wakeup, 0),
99 DEFINE_PROP_END_OF_LIST(),
100};
101
102static void serial_isa_class_initfn(ObjectClass *klass, void *data)
103{
104 DeviceClass *dc = DEVICE_CLASS(klass);
db895a1e
AF
105
106 dc->realize = serial_isa_realizefn;
488cb996
GH
107 dc->vmsd = &vmstate_isa_serial;
108 dc->props = serial_isa_properties;
125ee0ed 109 set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
488cb996
GH
110}
111
8c43a6f0 112static const TypeInfo serial_isa_info = {
eeceb084 113 .name = TYPE_ISA_SERIAL,
488cb996
GH
114 .parent = TYPE_ISA_DEVICE,
115 .instance_size = sizeof(ISASerialState),
116 .class_init = serial_isa_class_initfn,
117};
118
119static void serial_register_types(void)
120{
121 type_register_static(&serial_isa_info);
122}
123
124type_init(serial_register_types)
125
0ec7b3e7 126static void serial_isa_init(ISABus *bus, int index, Chardev *chr)
488cb996 127{
4a17cc4f
AF
128 DeviceState *dev;
129 ISADevice *isadev;
488cb996 130
c6f10a58 131 isadev = isa_create(bus, TYPE_ISA_SERIAL);
4a17cc4f
AF
132 dev = DEVICE(isadev);
133 qdev_prop_set_uint32(dev, "index", index);
134 qdev_prop_set_chr(dev, "chardev", chr);
c6f10a58 135 qdev_init_nofail(dev);
488cb996 136}
b6607a1a 137
4496dc49 138void serial_hds_isa_init(ISABus *bus, int from, int to)
b6607a1a
MA
139{
140 int i;
141
4496dc49 142 assert(from >= 0);
def337ff 143 assert(to <= MAX_ISA_SERIAL_PORTS);
b6607a1a 144
4496dc49 145 for (i = from; i < to; ++i) {
9bca0edb
PM
146 if (serial_hd(i)) {
147 serial_isa_init(bus, i, serial_hd(i));
b6607a1a
MA
148 }
149 }
150}