2 * Generic ISA Super I/O
4 * Copyright (c) 2010-2012 Herve Poussineau
5 * Copyright (c) 2011-2012 Andreas Färber
6 * Copyright (c) 2018 Philippe Mathieu-Daudé
8 * This code is licensed under the GNU GPLv2 and later.
9 * See the COPYING file in the top-level directory.
10 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "qemu/osdep.h"
13 #include "qemu/error-report.h"
14 #include "qapi/error.h"
15 #include "sysemu/sysemu.h"
16 #include "sysemu/block-backend.h"
17 #include "sysemu/blockdev.h"
18 #include "chardev/char.h"
19 #include "hw/isa/superio.h"
20 #include "hw/input/i8042.h"
21 #include "hw/char/serial.h"
24 static void isa_superio_realize(DeviceState
*dev
, Error
**errp
)
26 ISASuperIODevice
*sio
= ISA_SUPERIO(dev
);
27 ISASuperIOClass
*k
= ISA_SUPERIO_GET_CLASS(sio
);
28 ISABus
*bus
= isa_bus_from_device(ISA_DEVICE(dev
));
37 for (i
= 0; i
< k
->parallel
.count
; i
++) {
38 if (i
>= ARRAY_SIZE(sio
->parallel
)) {
39 warn_report("superio: ignoring %td parallel controllers",
40 k
->parallel
.count
- ARRAY_SIZE(sio
->parallel
));
43 if (!k
->parallel
.is_enabled
|| k
->parallel
.is_enabled(sio
, i
)) {
44 /* FIXME use a qdev chardev prop instead of parallel_hds[] */
45 chr
= parallel_hds
[i
];
46 if (chr
== NULL
|| chr
->be
) {
47 name
= g_strdup_printf("discarding-parallel%d", i
);
48 chr
= qemu_chr_new(name
, "null");
50 name
= g_strdup_printf("parallel%d", i
);
52 isa
= isa_create(bus
, "isa-parallel");
54 qdev_prop_set_uint32(d
, "index", i
);
55 if (k
->parallel
.get_iobase
) {
56 qdev_prop_set_uint32(d
, "iobase",
57 k
->parallel
.get_iobase(sio
, i
));
59 if (k
->parallel
.get_irq
) {
60 qdev_prop_set_uint32(d
, "irq", k
->parallel
.get_irq(sio
, i
));
62 qdev_prop_set_chr(d
, "chardev", chr
);
64 sio
->parallel
[i
] = isa
;
65 trace_superio_create_parallel(i
,
66 k
->parallel
.get_iobase
?
67 k
->parallel
.get_iobase(sio
, i
) : -1,
69 k
->parallel
.get_irq(sio
, i
) : -1);
70 object_property_add_child(OBJECT(dev
), name
,
71 OBJECT(sio
->parallel
[i
]), NULL
);
77 for (i
= 0; i
< k
->serial
.count
; i
++) {
78 if (i
>= ARRAY_SIZE(sio
->serial
)) {
79 warn_report("superio: ignoring %td serial controllers",
80 k
->serial
.count
- ARRAY_SIZE(sio
->serial
));
83 if (!k
->serial
.is_enabled
|| k
->serial
.is_enabled(sio
, i
)) {
84 /* FIXME use a qdev chardev prop instead of serial_hd() */
86 if (chr
== NULL
|| chr
->be
) {
87 name
= g_strdup_printf("discarding-serial%d", i
);
88 chr
= qemu_chr_new(name
, "null");
90 name
= g_strdup_printf("serial%d", i
);
92 isa
= isa_create(bus
, TYPE_ISA_SERIAL
);
94 qdev_prop_set_uint32(d
, "index", i
);
95 if (k
->serial
.get_iobase
) {
96 qdev_prop_set_uint32(d
, "iobase",
97 k
->serial
.get_iobase(sio
, i
));
99 if (k
->serial
.get_irq
) {
100 qdev_prop_set_uint32(d
, "irq", k
->serial
.get_irq(sio
, i
));
102 qdev_prop_set_chr(d
, "chardev", chr
);
104 sio
->serial
[i
] = isa
;
105 trace_superio_create_serial(i
,
106 k
->serial
.get_iobase
?
107 k
->serial
.get_iobase(sio
, i
) : -1,
109 k
->serial
.get_irq(sio
, i
) : -1);
110 object_property_add_child(OBJECT(dev
), name
,
111 OBJECT(sio
->serial
[0]), NULL
);
117 if (!k
->floppy
.is_enabled
|| k
->floppy
.is_enabled(sio
, 0)) {
118 isa
= isa_create(bus
, "isa-fdc");
120 if (k
->floppy
.get_iobase
) {
121 qdev_prop_set_uint32(d
, "iobase", k
->floppy
.get_iobase(sio
, 0));
123 if (k
->floppy
.get_irq
) {
124 qdev_prop_set_uint32(d
, "irq", k
->floppy
.get_irq(sio
, 0));
126 /* FIXME use a qdev drive property instead of drive_get() */
127 drive
= drive_get(IF_FLOPPY
, 0, 0);
129 qdev_prop_set_drive(d
, "driveA", blk_by_legacy_dinfo(drive
),
132 /* FIXME use a qdev drive property instead of drive_get() */
133 drive
= drive_get(IF_FLOPPY
, 0, 1);
135 qdev_prop_set_drive(d
, "driveB", blk_by_legacy_dinfo(drive
),
140 trace_superio_create_floppy(0,
141 k
->floppy
.get_iobase
?
142 k
->floppy
.get_iobase(sio
, 0) : -1,
144 k
->floppy
.get_irq(sio
, 0) : -1);
147 /* Keyboard, mouse */
148 sio
->kbc
= isa_create_simple(bus
, TYPE_I8042
);
151 if (k
->ide
.count
&& (!k
->ide
.is_enabled
|| k
->ide
.is_enabled(sio
, 0))) {
152 isa
= isa_create(bus
, "isa-ide");
154 if (k
->ide
.get_iobase
) {
155 qdev_prop_set_uint32(d
, "iobase", k
->ide
.get_iobase(sio
, 0));
157 if (k
->ide
.get_iobase
) {
158 qdev_prop_set_uint32(d
, "iobase2", k
->ide
.get_iobase(sio
, 1));
160 if (k
->ide
.get_irq
) {
161 qdev_prop_set_uint32(d
, "irq", k
->ide
.get_irq(sio
, 0));
165 trace_superio_create_ide(0,
167 k
->ide
.get_iobase(sio
, 0) : -1,
169 k
->ide
.get_irq(sio
, 0) : -1);
173 static void isa_superio_class_init(ObjectClass
*oc
, void *data
)
175 DeviceClass
*dc
= DEVICE_CLASS(oc
);
177 dc
->realize
= isa_superio_realize
;
178 /* Reason: Uses parallel_hds[0] in realize(), so it can't be used twice */
179 dc
->user_creatable
= false;
182 static const TypeInfo isa_superio_type_info
= {
183 .name
= TYPE_ISA_SUPERIO
,
184 .parent
= TYPE_ISA_DEVICE
,
186 .class_size
= sizeof(ISASuperIOClass
),
187 .class_init
= isa_superio_class_init
,
190 /* SMS FDC37M817 Super I/O */
191 static void fdc37m81x_class_init(ObjectClass
*klass
, void *data
)
193 ISASuperIOClass
*sc
= ISA_SUPERIO_CLASS(klass
);
195 sc
->serial
.count
= 2; /* NS16C550A */
196 sc
->parallel
.count
= 1;
197 sc
->floppy
.count
= 1; /* SMSC 82077AA Compatible */
201 static const TypeInfo fdc37m81x_type_info
= {
202 .name
= TYPE_FDC37M81X_SUPERIO
,
203 .parent
= TYPE_ISA_SUPERIO
,
204 .instance_size
= sizeof(ISASuperIODevice
),
205 .class_init
= fdc37m81x_class_init
,
208 static void isa_superio_register_types(void)
210 type_register_static(&isa_superio_type_info
);
211 type_register_static(&fdc37m81x_type_info
);
214 type_init(isa_superio_register_types
)