2018-03-08 23:39:29 +01: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é
|
|
|
|
*
|
2020-03-12 22:37:12 +01:00
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
2018-03-08 23:39:29 +01:00
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2019-05-23 16:35:07 +02:00
|
|
|
|
2018-03-08 23:39:29 +01:00
|
|
|
#include "qemu/osdep.h"
|
2018-03-08 23:39:31 +01:00
|
|
|
#include "qemu/error-report.h"
|
2019-05-23 16:35:07 +02:00
|
|
|
#include "qemu/module.h"
|
2018-03-08 23:39:33 +01:00
|
|
|
#include "qapi/error.h"
|
|
|
|
#include "sysemu/blockdev.h"
|
2018-03-08 23:39:31 +01:00
|
|
|
#include "chardev/char.h"
|
fdc: Reject clash between -drive if=floppy and -global isa-fdc
The floppy controller devices desugar their drive properties into
floppy devices (since commit a92bd191a4 "fdc: Move qdev properties to
FloppyDrive", v2.8.0). This involves some bad magic in
fdctrl_connect_drives(), and exists for backward compatibility.
The functions for boards to create floppy controller devices
fdctrl_init_isa(), fdctrl_init_sysbus(), and sun4m_fdctrl_init()
desugar -drive if=floppy to these floppy controller drive properties.
If you use both -drive if=floppy (or its -fda / -fdb sugar) and
-global isa-fdc for the same floppy device, -global silently loses the
conflict, and both backends involved end up with the floppy device
frontend attached, as demonstrated by iotest 172 (see commit before
previous). This is wrong.
Desugar -drive if=floppy straight to floppy devices instead, with
helper fdctrl_init_drives(). The conflict now gets rejected cleanly:
first, fdctrl_connect_drives() creates the floppy for the controller's
property, then fdctrl_init_drives() attempts to create the floppy for
-drive if=floppy, but fails because the unit is already in use.
Output of iotest 172 changes in three ways:
1. The clash gets rejected.
2. In one test case, "info qtree" has the floppy devices swapped, and
"info block" has their QOM paths swapped. This is because the
floppy device for -fda now gets created after the one for -global
isa-fdc.driveB.
3. The error message for -global floppy.drive=floppy0 changes. Before
the patch, we set isa-fdc.driveA to -fda's block backend, then
create the floppy device for it, then move the backend from
isa-fdc.driveA to floppy.drive. Floppy creation fails when
applying -global floppy.drive=floppy0, because floppy0 is still
attached to isa-fdc. After the patch, we create the floppy for
-fda, then set its drive property to floppy0. Now floppy creation
succeeds, but setting the drive property fails, because -global
already set it. Yes, this is exasperatingly complicated.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200622094227.1271650-5-armbru@redhat.com>
2020-06-22 11:42:15 +02:00
|
|
|
#include "hw/block/fdc.h"
|
2018-03-08 23:39:29 +01:00
|
|
|
#include "hw/isa/superio.h"
|
2019-08-12 07:23:51 +02:00
|
|
|
#include "hw/qdev-properties.h"
|
2018-03-08 23:39:34 +01:00
|
|
|
#include "hw/input/i8042.h"
|
2018-03-08 23:39:32 +01:00
|
|
|
#include "hw/char/serial.h"
|
2018-03-08 23:39:29 +01:00
|
|
|
#include "trace.h"
|
|
|
|
|
2018-03-08 23:39:31 +01: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;
|
fdc: Reject clash between -drive if=floppy and -global isa-fdc
The floppy controller devices desugar their drive properties into
floppy devices (since commit a92bd191a4 "fdc: Move qdev properties to
FloppyDrive", v2.8.0). This involves some bad magic in
fdctrl_connect_drives(), and exists for backward compatibility.
The functions for boards to create floppy controller devices
fdctrl_init_isa(), fdctrl_init_sysbus(), and sun4m_fdctrl_init()
desugar -drive if=floppy to these floppy controller drive properties.
If you use both -drive if=floppy (or its -fda / -fdb sugar) and
-global isa-fdc for the same floppy device, -global silently loses the
conflict, and both backends involved end up with the floppy device
frontend attached, as demonstrated by iotest 172 (see commit before
previous). This is wrong.
Desugar -drive if=floppy straight to floppy devices instead, with
helper fdctrl_init_drives(). The conflict now gets rejected cleanly:
first, fdctrl_connect_drives() creates the floppy for the controller's
property, then fdctrl_init_drives() attempts to create the floppy for
-drive if=floppy, but fails because the unit is already in use.
Output of iotest 172 changes in three ways:
1. The clash gets rejected.
2. In one test case, "info qtree" has the floppy devices swapped, and
"info block" has their QOM paths swapped. This is because the
floppy device for -fda now gets created after the one for -global
isa-fdc.driveB.
3. The error message for -global floppy.drive=floppy0 changes. Before
the patch, we set isa-fdc.driveA to -fda's block backend, then
create the floppy device for it, then move the backend from
isa-fdc.driveA to floppy.drive. Floppy creation fails when
applying -global floppy.drive=floppy0, because floppy0 is still
attached to isa-fdc. After the patch, we create the floppy for
-fda, then set its drive property to floppy0. Now floppy creation
succeeds, but setting the drive property fails, because -global
already set it. Yes, this is exasperatingly complicated.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200622094227.1271650-5-armbru@redhat.com>
2020-06-22 11:42:15 +02:00
|
|
|
DriveInfo *fd[MAX_FD];
|
2018-03-08 23:39:31 +01: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 17:24:59 +02:00
|
|
|
if (chr == NULL) {
|
2018-03-08 23:39:31 +01:00
|
|
|
name = g_strdup_printf("discarding-parallel%d", i);
|
2019-02-13 14:18:13 +01:00
|
|
|
chr = qemu_chr_new(name, "null", NULL);
|
2018-03-08 23:39:31 +01:00
|
|
|
} else {
|
|
|
|
name = g_strdup_printf("parallel%d", i);
|
|
|
|
}
|
isa: Convert uses of isa_create() with Coccinelle
Replace
dev = isa_create(bus, type_name);
...
qdev_init_nofail(dev);
by
dev = isa_new(type_name);
...
isa_realize_and_unref(dev, bus, &error_fatal);
Recent commit "qdev: New qdev_new(), qdev_realize(), etc." explains
why.
Coccinelle script:
@@
expression dev, bus, expr;
expression list args;
expression d;
@@
- dev = isa_create(bus, args);
+ dev = isa_new(args);
(
d = &dev->qdev;
|
d = DEVICE(dev);
)
... when != dev = expr
- qdev_init_nofail(d);
+ isa_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = isa_create(bus, args);
+ dev = isa_new(args);
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ isa_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = DEVICE(isa_create(bus, args));
+ ISADevice *isa_dev; // TODO move
+ isa_dev = isa_new(args);
+ dev = DEVICE(isa_dev);
... when != dev = expr
- qdev_init_nofail(dev);
+ isa_realize_and_unref(isa_dev, bus, &error_fatal);
Missing #include "qapi/error.h" added manually, whitespace changes
minimized manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-20-armbru@redhat.com>
2020-06-10 07:32:08 +02:00
|
|
|
isa = isa_new("isa-parallel");
|
2018-03-08 23:39:31 +01:00
|
|
|
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);
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 17:29:22 +02:00
|
|
|
object_property_add_child(OBJECT(dev), name, OBJECT(isa));
|
isa: Convert uses of isa_create() with Coccinelle
Replace
dev = isa_create(bus, type_name);
...
qdev_init_nofail(dev);
by
dev = isa_new(type_name);
...
isa_realize_and_unref(dev, bus, &error_fatal);
Recent commit "qdev: New qdev_new(), qdev_realize(), etc." explains
why.
Coccinelle script:
@@
expression dev, bus, expr;
expression list args;
expression d;
@@
- dev = isa_create(bus, args);
+ dev = isa_new(args);
(
d = &dev->qdev;
|
d = DEVICE(dev);
)
... when != dev = expr
- qdev_init_nofail(d);
+ isa_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = isa_create(bus, args);
+ dev = isa_new(args);
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ isa_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = DEVICE(isa_create(bus, args));
+ ISADevice *isa_dev; // TODO move
+ isa_dev = isa_new(args);
+ dev = DEVICE(isa_dev);
... when != dev = expr
- qdev_init_nofail(dev);
+ isa_realize_and_unref(isa_dev, bus, &error_fatal);
Missing #include "qapi/error.h" added manually, whitespace changes
minimized manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-20-armbru@redhat.com>
2020-06-10 07:32:08 +02:00
|
|
|
isa_realize_and_unref(isa, bus, &error_fatal);
|
2018-03-08 23:39:31 +01:00
|
|
|
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);
|
|
|
|
g_free(name);
|
|
|
|
}
|
|
|
|
}
|
2018-03-08 23:39:32 +01: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 16:52:43 +02:00
|
|
|
/* FIXME use a qdev chardev prop instead of serial_hd() */
|
|
|
|
chr = serial_hd(i);
|
2018-05-15 17:24:59 +02:00
|
|
|
if (chr == NULL) {
|
2018-03-08 23:39:32 +01:00
|
|
|
name = g_strdup_printf("discarding-serial%d", i);
|
2019-02-13 14:18:13 +01:00
|
|
|
chr = qemu_chr_new(name, "null", NULL);
|
2018-03-08 23:39:32 +01:00
|
|
|
} else {
|
|
|
|
name = g_strdup_printf("serial%d", i);
|
|
|
|
}
|
isa: Convert uses of isa_create() with Coccinelle
Replace
dev = isa_create(bus, type_name);
...
qdev_init_nofail(dev);
by
dev = isa_new(type_name);
...
isa_realize_and_unref(dev, bus, &error_fatal);
Recent commit "qdev: New qdev_new(), qdev_realize(), etc." explains
why.
Coccinelle script:
@@
expression dev, bus, expr;
expression list args;
expression d;
@@
- dev = isa_create(bus, args);
+ dev = isa_new(args);
(
d = &dev->qdev;
|
d = DEVICE(dev);
)
... when != dev = expr
- qdev_init_nofail(d);
+ isa_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = isa_create(bus, args);
+ dev = isa_new(args);
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ isa_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = DEVICE(isa_create(bus, args));
+ ISADevice *isa_dev; // TODO move
+ isa_dev = isa_new(args);
+ dev = DEVICE(isa_dev);
... when != dev = expr
- qdev_init_nofail(dev);
+ isa_realize_and_unref(isa_dev, bus, &error_fatal);
Missing #include "qapi/error.h" added manually, whitespace changes
minimized manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-20-armbru@redhat.com>
2020-06-10 07:32:08 +02:00
|
|
|
isa = isa_new(TYPE_ISA_SERIAL);
|
2018-03-08 23:39:32 +01:00
|
|
|
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);
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 17:29:22 +02:00
|
|
|
object_property_add_child(OBJECT(dev), name, OBJECT(isa));
|
isa: Convert uses of isa_create() with Coccinelle
Replace
dev = isa_create(bus, type_name);
...
qdev_init_nofail(dev);
by
dev = isa_new(type_name);
...
isa_realize_and_unref(dev, bus, &error_fatal);
Recent commit "qdev: New qdev_new(), qdev_realize(), etc." explains
why.
Coccinelle script:
@@
expression dev, bus, expr;
expression list args;
expression d;
@@
- dev = isa_create(bus, args);
+ dev = isa_new(args);
(
d = &dev->qdev;
|
d = DEVICE(dev);
)
... when != dev = expr
- qdev_init_nofail(d);
+ isa_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = isa_create(bus, args);
+ dev = isa_new(args);
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ isa_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = DEVICE(isa_create(bus, args));
+ ISADevice *isa_dev; // TODO move
+ isa_dev = isa_new(args);
+ dev = DEVICE(isa_dev);
... when != dev = expr
- qdev_init_nofail(dev);
+ isa_realize_and_unref(isa_dev, bus, &error_fatal);
Missing #include "qapi/error.h" added manually, whitespace changes
minimized manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-20-armbru@redhat.com>
2020-06-10 07:32:08 +02:00
|
|
|
isa_realize_and_unref(isa, bus, &error_fatal);
|
2018-03-08 23:39:32 +01:00
|
|
|
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);
|
|
|
|
g_free(name);
|
|
|
|
}
|
|
|
|
}
|
2018-03-08 23:39:33 +01:00
|
|
|
|
|
|
|
/* Floppy disc */
|
|
|
|
if (!k->floppy.is_enabled || k->floppy.is_enabled(sio, 0)) {
|
fdc: Reject clash between -drive if=floppy and -global isa-fdc
The floppy controller devices desugar their drive properties into
floppy devices (since commit a92bd191a4 "fdc: Move qdev properties to
FloppyDrive", v2.8.0). This involves some bad magic in
fdctrl_connect_drives(), and exists for backward compatibility.
The functions for boards to create floppy controller devices
fdctrl_init_isa(), fdctrl_init_sysbus(), and sun4m_fdctrl_init()
desugar -drive if=floppy to these floppy controller drive properties.
If you use both -drive if=floppy (or its -fda / -fdb sugar) and
-global isa-fdc for the same floppy device, -global silently loses the
conflict, and both backends involved end up with the floppy device
frontend attached, as demonstrated by iotest 172 (see commit before
previous). This is wrong.
Desugar -drive if=floppy straight to floppy devices instead, with
helper fdctrl_init_drives(). The conflict now gets rejected cleanly:
first, fdctrl_connect_drives() creates the floppy for the controller's
property, then fdctrl_init_drives() attempts to create the floppy for
-drive if=floppy, but fails because the unit is already in use.
Output of iotest 172 changes in three ways:
1. The clash gets rejected.
2. In one test case, "info qtree" has the floppy devices swapped, and
"info block" has their QOM paths swapped. This is because the
floppy device for -fda now gets created after the one for -global
isa-fdc.driveB.
3. The error message for -global floppy.drive=floppy0 changes. Before
the patch, we set isa-fdc.driveA to -fda's block backend, then
create the floppy device for it, then move the backend from
isa-fdc.driveA to floppy.drive. Floppy creation fails when
applying -global floppy.drive=floppy0, because floppy0 is still
attached to isa-fdc. After the patch, we create the floppy for
-fda, then set its drive property to floppy0. Now floppy creation
succeeds, but setting the drive property fails, because -global
already set it. Yes, this is exasperatingly complicated.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200622094227.1271650-5-armbru@redhat.com>
2020-06-22 11:42:15 +02:00
|
|
|
isa = isa_new(TYPE_ISA_FDC);
|
2018-03-08 23:39:33 +01:00
|
|
|
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() */
|
fdc: Reject clash between -drive if=floppy and -global isa-fdc
The floppy controller devices desugar their drive properties into
floppy devices (since commit a92bd191a4 "fdc: Move qdev properties to
FloppyDrive", v2.8.0). This involves some bad magic in
fdctrl_connect_drives(), and exists for backward compatibility.
The functions for boards to create floppy controller devices
fdctrl_init_isa(), fdctrl_init_sysbus(), and sun4m_fdctrl_init()
desugar -drive if=floppy to these floppy controller drive properties.
If you use both -drive if=floppy (or its -fda / -fdb sugar) and
-global isa-fdc for the same floppy device, -global silently loses the
conflict, and both backends involved end up with the floppy device
frontend attached, as demonstrated by iotest 172 (see commit before
previous). This is wrong.
Desugar -drive if=floppy straight to floppy devices instead, with
helper fdctrl_init_drives(). The conflict now gets rejected cleanly:
first, fdctrl_connect_drives() creates the floppy for the controller's
property, then fdctrl_init_drives() attempts to create the floppy for
-drive if=floppy, but fails because the unit is already in use.
Output of iotest 172 changes in three ways:
1. The clash gets rejected.
2. In one test case, "info qtree" has the floppy devices swapped, and
"info block" has their QOM paths swapped. This is because the
floppy device for -fda now gets created after the one for -global
isa-fdc.driveB.
3. The error message for -global floppy.drive=floppy0 changes. Before
the patch, we set isa-fdc.driveA to -fda's block backend, then
create the floppy device for it, then move the backend from
isa-fdc.driveA to floppy.drive. Floppy creation fails when
applying -global floppy.drive=floppy0, because floppy0 is still
attached to isa-fdc. After the patch, we create the floppy for
-fda, then set its drive property to floppy0. Now floppy creation
succeeds, but setting the drive property fails, because -global
already set it. Yes, this is exasperatingly complicated.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200622094227.1271650-5-armbru@redhat.com>
2020-06-22 11:42:15 +02:00
|
|
|
for (i = 0; i < MAX_FD; i++) {
|
|
|
|
fd[i] = drive_get(IF_FLOPPY, 0, i);
|
2018-03-08 23:39:33 +01:00
|
|
|
}
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 17:29:22 +02:00
|
|
|
object_property_add_child(OBJECT(sio), "isa-fdc", OBJECT(isa));
|
isa: Convert uses of isa_create() with Coccinelle
Replace
dev = isa_create(bus, type_name);
...
qdev_init_nofail(dev);
by
dev = isa_new(type_name);
...
isa_realize_and_unref(dev, bus, &error_fatal);
Recent commit "qdev: New qdev_new(), qdev_realize(), etc." explains
why.
Coccinelle script:
@@
expression dev, bus, expr;
expression list args;
expression d;
@@
- dev = isa_create(bus, args);
+ dev = isa_new(args);
(
d = &dev->qdev;
|
d = DEVICE(dev);
)
... when != dev = expr
- qdev_init_nofail(d);
+ isa_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = isa_create(bus, args);
+ dev = isa_new(args);
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ isa_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = DEVICE(isa_create(bus, args));
+ ISADevice *isa_dev; // TODO move
+ isa_dev = isa_new(args);
+ dev = DEVICE(isa_dev);
... when != dev = expr
- qdev_init_nofail(dev);
+ isa_realize_and_unref(isa_dev, bus, &error_fatal);
Missing #include "qapi/error.h" added manually, whitespace changes
minimized manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-20-armbru@redhat.com>
2020-06-10 07:32:08 +02:00
|
|
|
isa_realize_and_unref(isa, bus, &error_fatal);
|
fdc: Reject clash between -drive if=floppy and -global isa-fdc
The floppy controller devices desugar their drive properties into
floppy devices (since commit a92bd191a4 "fdc: Move qdev properties to
FloppyDrive", v2.8.0). This involves some bad magic in
fdctrl_connect_drives(), and exists for backward compatibility.
The functions for boards to create floppy controller devices
fdctrl_init_isa(), fdctrl_init_sysbus(), and sun4m_fdctrl_init()
desugar -drive if=floppy to these floppy controller drive properties.
If you use both -drive if=floppy (or its -fda / -fdb sugar) and
-global isa-fdc for the same floppy device, -global silently loses the
conflict, and both backends involved end up with the floppy device
frontend attached, as demonstrated by iotest 172 (see commit before
previous). This is wrong.
Desugar -drive if=floppy straight to floppy devices instead, with
helper fdctrl_init_drives(). The conflict now gets rejected cleanly:
first, fdctrl_connect_drives() creates the floppy for the controller's
property, then fdctrl_init_drives() attempts to create the floppy for
-drive if=floppy, but fails because the unit is already in use.
Output of iotest 172 changes in three ways:
1. The clash gets rejected.
2. In one test case, "info qtree" has the floppy devices swapped, and
"info block" has their QOM paths swapped. This is because the
floppy device for -fda now gets created after the one for -global
isa-fdc.driveB.
3. The error message for -global floppy.drive=floppy0 changes. Before
the patch, we set isa-fdc.driveA to -fda's block backend, then
create the floppy device for it, then move the backend from
isa-fdc.driveA to floppy.drive. Floppy creation fails when
applying -global floppy.drive=floppy0, because floppy0 is still
attached to isa-fdc. After the patch, we create the floppy for
-fda, then set its drive property to floppy0. Now floppy creation
succeeds, but setting the drive property fails, because -global
already set it. Yes, this is exasperatingly complicated.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200622094227.1271650-5-armbru@redhat.com>
2020-06-22 11:42:15 +02:00
|
|
|
isa_fdc_init_drives(isa, fd);
|
2018-03-08 23:39:33 +01:00
|
|
|
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-08 23:39:34 +01:00
|
|
|
/* Keyboard, mouse */
|
isa: Convert uses of isa_create() with Coccinelle
Replace
dev = isa_create(bus, type_name);
...
qdev_init_nofail(dev);
by
dev = isa_new(type_name);
...
isa_realize_and_unref(dev, bus, &error_fatal);
Recent commit "qdev: New qdev_new(), qdev_realize(), etc." explains
why.
Coccinelle script:
@@
expression dev, bus, expr;
expression list args;
expression d;
@@
- dev = isa_create(bus, args);
+ dev = isa_new(args);
(
d = &dev->qdev;
|
d = DEVICE(dev);
)
... when != dev = expr
- qdev_init_nofail(d);
+ isa_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = isa_create(bus, args);
+ dev = isa_new(args);
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ isa_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = DEVICE(isa_create(bus, args));
+ ISADevice *isa_dev; // TODO move
+ isa_dev = isa_new(args);
+ dev = DEVICE(isa_dev);
... when != dev = expr
- qdev_init_nofail(dev);
+ isa_realize_and_unref(isa_dev, bus, &error_fatal);
Missing #include "qapi/error.h" added manually, whitespace changes
minimized manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-20-armbru@redhat.com>
2020-06-10 07:32:08 +02:00
|
|
|
isa = isa_new(TYPE_I8042);
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 17:29:22 +02:00
|
|
|
object_property_add_child(OBJECT(sio), TYPE_I8042, OBJECT(isa));
|
isa: Convert uses of isa_create() with Coccinelle
Replace
dev = isa_create(bus, type_name);
...
qdev_init_nofail(dev);
by
dev = isa_new(type_name);
...
isa_realize_and_unref(dev, bus, &error_fatal);
Recent commit "qdev: New qdev_new(), qdev_realize(), etc." explains
why.
Coccinelle script:
@@
expression dev, bus, expr;
expression list args;
expression d;
@@
- dev = isa_create(bus, args);
+ dev = isa_new(args);
(
d = &dev->qdev;
|
d = DEVICE(dev);
)
... when != dev = expr
- qdev_init_nofail(d);
+ isa_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = isa_create(bus, args);
+ dev = isa_new(args);
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ isa_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = DEVICE(isa_create(bus, args));
+ ISADevice *isa_dev; // TODO move
+ isa_dev = isa_new(args);
+ dev = DEVICE(isa_dev);
... when != dev = expr
- qdev_init_nofail(dev);
+ isa_realize_and_unref(isa_dev, bus, &error_fatal);
Missing #include "qapi/error.h" added manually, whitespace changes
minimized manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-20-armbru@redhat.com>
2020-06-10 07:32:08 +02:00
|
|
|
isa_realize_and_unref(isa, bus, &error_fatal);
|
hw/isa/superio: Make the components QOM children
isa_superio_realize() attempts to make isa-parallel and isa-serial QOM
children, but this does not work, because it calls
object_property_add_child() after realizing with qdev_init_nofail().
Realizing a device without a parent gives it one: it gets put into the
"/machine/unattached/" orphanage. The extra
object_property_add_child() fails, and isa_superio_realize() ignores
the error.
Move the object_property_add_child() before qdev_init_nofail(), and
pass &error_abort.
For the other components, isa_superio_realize() doesn't even try. Add
object_property_add_child() there.
This affects machines 40p, clipper and fulong2e.
For instance, fulong2e has its vt82c686b-superio (which is an
isa-superio) at /machine/unattached/device[9]. Before the patch, its
components are at /machine/unattached/device[10] .. [14]. Afterwards,
they are at
/machine/unattached/device[9]/{parallel0,serial0,serial1,isa-fdc,i8042}.
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-11-armbru@redhat.com>
2020-05-05 17:29:18 +02:00
|
|
|
sio->kbc = isa;
|
2018-03-08 23:39:35 +01:00
|
|
|
|
|
|
|
/* IDE */
|
|
|
|
if (k->ide.count && (!k->ide.is_enabled || k->ide.is_enabled(sio, 0))) {
|
isa: Convert uses of isa_create() with Coccinelle
Replace
dev = isa_create(bus, type_name);
...
qdev_init_nofail(dev);
by
dev = isa_new(type_name);
...
isa_realize_and_unref(dev, bus, &error_fatal);
Recent commit "qdev: New qdev_new(), qdev_realize(), etc." explains
why.
Coccinelle script:
@@
expression dev, bus, expr;
expression list args;
expression d;
@@
- dev = isa_create(bus, args);
+ dev = isa_new(args);
(
d = &dev->qdev;
|
d = DEVICE(dev);
)
... when != dev = expr
- qdev_init_nofail(d);
+ isa_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = isa_create(bus, args);
+ dev = isa_new(args);
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ isa_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = DEVICE(isa_create(bus, args));
+ ISADevice *isa_dev; // TODO move
+ isa_dev = isa_new(args);
+ dev = DEVICE(isa_dev);
... when != dev = expr
- qdev_init_nofail(dev);
+ isa_realize_and_unref(isa_dev, bus, &error_fatal);
Missing #include "qapi/error.h" added manually, whitespace changes
minimized manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-20-armbru@redhat.com>
2020-06-10 07:32:08 +02:00
|
|
|
isa = isa_new("isa-ide");
|
2018-03-08 23:39:35 +01:00
|
|
|
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));
|
|
|
|
}
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 17:29:22 +02:00
|
|
|
object_property_add_child(OBJECT(sio), "isa-ide", OBJECT(isa));
|
2020-07-21 14:45:16 +02:00
|
|
|
isa_realize_and_unref(isa, bus, &error_fatal);
|
2018-03-08 23:39:35 +01:00
|
|
|
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-08 23:39:31 +01: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-08 23:39:29 +01:00
|
|
|
static const TypeInfo isa_superio_type_info = {
|
|
|
|
.name = TYPE_ISA_SUPERIO,
|
|
|
|
.parent = TYPE_ISA_DEVICE,
|
|
|
|
.abstract = true,
|
|
|
|
.class_size = sizeof(ISASuperIOClass),
|
2018-03-08 23:39:31 +01:00
|
|
|
.class_init = isa_superio_class_init,
|
2018-03-08 23:39:29 +01:00
|
|
|
};
|
|
|
|
|
2018-03-08 23:39:37 +01: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-08 23:39:29 +01:00
|
|
|
static void isa_superio_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&isa_superio_type_info);
|
2018-03-08 23:39:37 +01:00
|
|
|
type_register_static(&fdc37m81x_type_info);
|
2018-03-08 23:39:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type_init(isa_superio_register_types)
|