2018-03-09 06:39:29 +08:00
|
|
|
/*
|
|
|
|
* Generic ISA Super I/O
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010-2012 Herve Poussineau
|
|
|
|
* Copyright (c) 2011-2012 Andreas Färber
|
|
|
|
* Copyright (c) 2018 Philippe Mathieu-Daudé
|
|
|
|
*
|
|
|
|
* This code is licensed under the GNU GPLv2 and later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2019-05-23 22:35:07 +08:00
|
|
|
|
2018-03-09 06:39:29 +08:00
|
|
|
#include "qemu/osdep.h"
|
2018-03-09 06:39:31 +08:00
|
|
|
#include "qemu/error-report.h"
|
2019-05-23 22:35:07 +08:00
|
|
|
#include "qemu/module.h"
|
2018-03-09 06:39:33 +08:00
|
|
|
#include "qapi/error.h"
|
2018-03-09 06:39:31 +08:00
|
|
|
#include "sysemu/sysemu.h"
|
2018-03-09 06:39:33 +08:00
|
|
|
#include "sysemu/blockdev.h"
|
2018-03-09 06:39:31 +08:00
|
|
|
#include "chardev/char.h"
|
2018-03-09 06:39:29 +08:00
|
|
|
#include "hw/isa/superio.h"
|
2018-03-09 06:39:34 +08:00
|
|
|
#include "hw/input/i8042.h"
|
2018-03-09 06:39:32 +08:00
|
|
|
#include "hw/char/serial.h"
|
2018-03-09 06:39:29 +08:00
|
|
|
#include "trace.h"
|
|
|
|
|
2018-03-09 06:39:31 +08:00
|
|
|
static void isa_superio_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
ISASuperIODevice *sio = ISA_SUPERIO(dev);
|
|
|
|
ISASuperIOClass *k = ISA_SUPERIO_GET_CLASS(sio);
|
|
|
|
ISABus *bus = isa_bus_from_device(ISA_DEVICE(dev));
|
|
|
|
ISADevice *isa;
|
|
|
|
DeviceState *d;
|
|
|
|
Chardev *chr;
|
2018-03-09 06:39:33 +08:00
|
|
|
DriveInfo *drive;
|
2018-03-09 06:39:31 +08:00
|
|
|
char *name;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Parallel port */
|
|
|
|
for (i = 0; i < k->parallel.count; i++) {
|
|
|
|
if (i >= ARRAY_SIZE(sio->parallel)) {
|
|
|
|
warn_report("superio: ignoring %td parallel controllers",
|
|
|
|
k->parallel.count - ARRAY_SIZE(sio->parallel));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!k->parallel.is_enabled || k->parallel.is_enabled(sio, i)) {
|
|
|
|
/* FIXME use a qdev chardev prop instead of parallel_hds[] */
|
|
|
|
chr = parallel_hds[i];
|
2018-05-15 23:24:59 +08:00
|
|
|
if (chr == NULL) {
|
2018-03-09 06:39:31 +08:00
|
|
|
name = g_strdup_printf("discarding-parallel%d", i);
|
2019-02-13 21:18:13 +08:00
|
|
|
chr = qemu_chr_new(name, "null", NULL);
|
2018-03-09 06:39:31 +08:00
|
|
|
} else {
|
|
|
|
name = g_strdup_printf("parallel%d", i);
|
|
|
|
}
|
|
|
|
isa = isa_create(bus, "isa-parallel");
|
|
|
|
d = DEVICE(isa);
|
|
|
|
qdev_prop_set_uint32(d, "index", i);
|
|
|
|
if (k->parallel.get_iobase) {
|
|
|
|
qdev_prop_set_uint32(d, "iobase",
|
|
|
|
k->parallel.get_iobase(sio, i));
|
|
|
|
}
|
|
|
|
if (k->parallel.get_irq) {
|
|
|
|
qdev_prop_set_uint32(d, "irq", k->parallel.get_irq(sio, i));
|
|
|
|
}
|
|
|
|
qdev_prop_set_chr(d, "chardev", chr);
|
|
|
|
qdev_init_nofail(d);
|
|
|
|
sio->parallel[i] = isa;
|
|
|
|
trace_superio_create_parallel(i,
|
|
|
|
k->parallel.get_iobase ?
|
|
|
|
k->parallel.get_iobase(sio, i) : -1,
|
|
|
|
k->parallel.get_irq ?
|
|
|
|
k->parallel.get_irq(sio, i) : -1);
|
|
|
|
object_property_add_child(OBJECT(dev), name,
|
|
|
|
OBJECT(sio->parallel[i]), NULL);
|
|
|
|
g_free(name);
|
|
|
|
}
|
|
|
|
}
|
2018-03-09 06:39:32 +08:00
|
|
|
|
|
|
|
/* Serial */
|
|
|
|
for (i = 0; i < k->serial.count; i++) {
|
|
|
|
if (i >= ARRAY_SIZE(sio->serial)) {
|
|
|
|
warn_report("superio: ignoring %td serial controllers",
|
|
|
|
k->serial.count - ARRAY_SIZE(sio->serial));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!k->serial.is_enabled || k->serial.is_enabled(sio, i)) {
|
2018-04-20 22:52:43 +08:00
|
|
|
/* FIXME use a qdev chardev prop instead of serial_hd() */
|
|
|
|
chr = serial_hd(i);
|
2018-05-15 23:24:59 +08:00
|
|
|
if (chr == NULL) {
|
2018-03-09 06:39:32 +08:00
|
|
|
name = g_strdup_printf("discarding-serial%d", i);
|
2019-02-13 21:18:13 +08:00
|
|
|
chr = qemu_chr_new(name, "null", NULL);
|
2018-03-09 06:39:32 +08:00
|
|
|
} else {
|
|
|
|
name = g_strdup_printf("serial%d", i);
|
|
|
|
}
|
|
|
|
isa = isa_create(bus, TYPE_ISA_SERIAL);
|
|
|
|
d = DEVICE(isa);
|
|
|
|
qdev_prop_set_uint32(d, "index", i);
|
|
|
|
if (k->serial.get_iobase) {
|
|
|
|
qdev_prop_set_uint32(d, "iobase",
|
|
|
|
k->serial.get_iobase(sio, i));
|
|
|
|
}
|
|
|
|
if (k->serial.get_irq) {
|
|
|
|
qdev_prop_set_uint32(d, "irq", k->serial.get_irq(sio, i));
|
|
|
|
}
|
|
|
|
qdev_prop_set_chr(d, "chardev", chr);
|
|
|
|
qdev_init_nofail(d);
|
|
|
|
sio->serial[i] = isa;
|
|
|
|
trace_superio_create_serial(i,
|
|
|
|
k->serial.get_iobase ?
|
|
|
|
k->serial.get_iobase(sio, i) : -1,
|
|
|
|
k->serial.get_irq ?
|
|
|
|
k->serial.get_irq(sio, i) : -1);
|
|
|
|
object_property_add_child(OBJECT(dev), name,
|
|
|
|
OBJECT(sio->serial[0]), NULL);
|
|
|
|
g_free(name);
|
|
|
|
}
|
|
|
|
}
|
2018-03-09 06:39:33 +08:00
|
|
|
|
|
|
|
/* Floppy disc */
|
|
|
|
if (!k->floppy.is_enabled || k->floppy.is_enabled(sio, 0)) {
|
|
|
|
isa = isa_create(bus, "isa-fdc");
|
|
|
|
d = DEVICE(isa);
|
|
|
|
if (k->floppy.get_iobase) {
|
|
|
|
qdev_prop_set_uint32(d, "iobase", k->floppy.get_iobase(sio, 0));
|
|
|
|
}
|
|
|
|
if (k->floppy.get_irq) {
|
|
|
|
qdev_prop_set_uint32(d, "irq", k->floppy.get_irq(sio, 0));
|
|
|
|
}
|
|
|
|
/* FIXME use a qdev drive property instead of drive_get() */
|
|
|
|
drive = drive_get(IF_FLOPPY, 0, 0);
|
|
|
|
if (drive != NULL) {
|
|
|
|
qdev_prop_set_drive(d, "driveA", blk_by_legacy_dinfo(drive),
|
|
|
|
&error_fatal);
|
|
|
|
}
|
|
|
|
/* FIXME use a qdev drive property instead of drive_get() */
|
|
|
|
drive = drive_get(IF_FLOPPY, 0, 1);
|
|
|
|
if (drive != NULL) {
|
|
|
|
qdev_prop_set_drive(d, "driveB", blk_by_legacy_dinfo(drive),
|
|
|
|
&error_fatal);
|
|
|
|
}
|
|
|
|
qdev_init_nofail(d);
|
|
|
|
sio->floppy = isa;
|
|
|
|
trace_superio_create_floppy(0,
|
|
|
|
k->floppy.get_iobase ?
|
|
|
|
k->floppy.get_iobase(sio, 0) : -1,
|
|
|
|
k->floppy.get_irq ?
|
|
|
|
k->floppy.get_irq(sio, 0) : -1);
|
|
|
|
}
|
|
|
|
|
2018-03-09 06:39:34 +08:00
|
|
|
/* Keyboard, mouse */
|
|
|
|
sio->kbc = isa_create_simple(bus, TYPE_I8042);
|
2018-03-09 06:39:35 +08:00
|
|
|
|
|
|
|
/* IDE */
|
|
|
|
if (k->ide.count && (!k->ide.is_enabled || k->ide.is_enabled(sio, 0))) {
|
|
|
|
isa = isa_create(bus, "isa-ide");
|
|
|
|
d = DEVICE(isa);
|
|
|
|
if (k->ide.get_iobase) {
|
|
|
|
qdev_prop_set_uint32(d, "iobase", k->ide.get_iobase(sio, 0));
|
|
|
|
}
|
|
|
|
if (k->ide.get_iobase) {
|
|
|
|
qdev_prop_set_uint32(d, "iobase2", k->ide.get_iobase(sio, 1));
|
|
|
|
}
|
|
|
|
if (k->ide.get_irq) {
|
|
|
|
qdev_prop_set_uint32(d, "irq", k->ide.get_irq(sio, 0));
|
|
|
|
}
|
|
|
|
qdev_init_nofail(d);
|
|
|
|
sio->ide = isa;
|
|
|
|
trace_superio_create_ide(0,
|
|
|
|
k->ide.get_iobase ?
|
|
|
|
k->ide.get_iobase(sio, 0) : -1,
|
|
|
|
k->ide.get_irq ?
|
|
|
|
k->ide.get_irq(sio, 0) : -1);
|
|
|
|
}
|
2018-03-09 06:39:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void isa_superio_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
|
|
|
|
|
|
|
dc->realize = isa_superio_realize;
|
|
|
|
/* Reason: Uses parallel_hds[0] in realize(), so it can't be used twice */
|
|
|
|
dc->user_creatable = false;
|
|
|
|
}
|
|
|
|
|
2018-03-09 06:39:29 +08:00
|
|
|
static const TypeInfo isa_superio_type_info = {
|
|
|
|
.name = TYPE_ISA_SUPERIO,
|
|
|
|
.parent = TYPE_ISA_DEVICE,
|
|
|
|
.abstract = true,
|
|
|
|
.class_size = sizeof(ISASuperIOClass),
|
2018-03-09 06:39:31 +08:00
|
|
|
.class_init = isa_superio_class_init,
|
2018-03-09 06:39:29 +08:00
|
|
|
};
|
|
|
|
|
2018-03-09 06:39:37 +08:00
|
|
|
/* SMS FDC37M817 Super I/O */
|
|
|
|
static void fdc37m81x_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
ISASuperIOClass *sc = ISA_SUPERIO_CLASS(klass);
|
|
|
|
|
|
|
|
sc->serial.count = 2; /* NS16C550A */
|
|
|
|
sc->parallel.count = 1;
|
|
|
|
sc->floppy.count = 1; /* SMSC 82077AA Compatible */
|
|
|
|
sc->ide.count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo fdc37m81x_type_info = {
|
|
|
|
.name = TYPE_FDC37M81X_SUPERIO,
|
|
|
|
.parent = TYPE_ISA_SUPERIO,
|
|
|
|
.instance_size = sizeof(ISASuperIODevice),
|
|
|
|
.class_init = fdc37m81x_class_init,
|
|
|
|
};
|
|
|
|
|
2018-03-09 06:39:29 +08:00
|
|
|
static void isa_superio_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&isa_superio_type_info);
|
2018-03-09 06:39:37 +08:00
|
|
|
type_register_static(&fdc37m81x_type_info);
|
2018-03-09 06:39:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type_init(isa_superio_register_types)
|