2007-10-29 02:42:18 +03:00
|
|
|
/*
|
|
|
|
* PowerMac MacIO device emulation
|
|
|
|
*
|
|
|
|
* Copyright (c) 2005-2007 Fabrice Bellard
|
|
|
|
* Copyright (c) 2007 Jocelyn Mayer
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2019-05-23 17:35:07 +03:00
|
|
|
|
2016-01-26 21:16:58 +03:00
|
|
|
#include "qemu/osdep.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 11:01:28 +03:00
|
|
|
#include "qapi/error.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/ppc/mac.h"
|
2018-02-09 21:51:41 +03:00
|
|
|
#include "hw/misc/macio/cuda.h"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/pci/pci.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/ppc/mac_dbdma.h"
|
2019-08-12 08:23:51 +03:00
|
|
|
#include "hw/qdev-properties.h"
|
2019-08-12 08:23:45 +03:00
|
|
|
#include "migration/vmstate.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/char/escc.h"
|
2018-02-28 23:32:37 +03:00
|
|
|
#include "hw/misc/macio/macio.h"
|
2018-02-28 23:32:38 +03:00
|
|
|
#include "hw/intc/heathrow_pic.h"
|
2019-08-12 08:23:58 +03:00
|
|
|
#include "sysemu/sysemu.h"
|
2018-05-06 17:20:03 +03:00
|
|
|
#include "trace.h"
|
2013-01-24 03:04:01 +04:00
|
|
|
|
2018-02-28 23:32:43 +03:00
|
|
|
/* Note: this code is strongly inspirated from the corresponding code
|
|
|
|
* in PearPC */
|
|
|
|
|
2013-06-26 15:58:31 +04:00
|
|
|
/*
|
|
|
|
* The mac-io has two interfaces to the ESCC. One is called "escc-legacy",
|
|
|
|
* while the other one is the normal, current ESCC interface.
|
|
|
|
*
|
|
|
|
* The magic below creates memory aliases to spawn the escc-legacy device
|
|
|
|
* purely by rerouting the respective registers to our escc region. This
|
|
|
|
* works because the only difference between the two memory regions is the
|
|
|
|
* register layout, not their semantics.
|
|
|
|
*
|
|
|
|
* Reference: ftp://ftp.software.ibm.com/rs6000/technology/spec/chrp/inwork/CHRP_IORef_1.0.pdf
|
|
|
|
*/
|
2018-02-28 23:32:33 +03:00
|
|
|
static void macio_escc_legacy_setup(MacIOState *s)
|
2013-06-26 15:58:31 +04:00
|
|
|
{
|
2018-02-28 23:32:33 +03:00
|
|
|
ESCCState *escc = ESCC(&s->escc);
|
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(escc);
|
2013-06-26 15:58:31 +04:00
|
|
|
MemoryRegion *escc_legacy = g_new(MemoryRegion, 1);
|
2018-02-28 23:32:33 +03:00
|
|
|
MemoryRegion *bar = &s->bar;
|
2013-06-26 15:58:31 +04:00
|
|
|
int i;
|
|
|
|
static const int maps[] = {
|
2016-08-02 12:22:43 +03:00
|
|
|
0x00, 0x00, /* Command B */
|
|
|
|
0x02, 0x20, /* Command A */
|
|
|
|
0x04, 0x10, /* Data B */
|
|
|
|
0x06, 0x30, /* Data A */
|
|
|
|
0x08, 0x40, /* Enhancement B */
|
|
|
|
0x0A, 0x50, /* Enhancement A */
|
|
|
|
0x80, 0x80, /* Recovery count */
|
|
|
|
0x90, 0x90, /* Start A */
|
|
|
|
0xa0, 0xa0, /* Start B */
|
|
|
|
0xb0, 0xb0, /* Detect AB */
|
2013-06-26 15:58:31 +04:00
|
|
|
};
|
|
|
|
|
2018-02-28 23:32:33 +03:00
|
|
|
memory_region_init(escc_legacy, OBJECT(s), "escc-legacy", 256);
|
2013-06-26 15:58:31 +04:00
|
|
|
for (i = 0; i < ARRAY_SIZE(maps); i += 2) {
|
|
|
|
MemoryRegion *port = g_new(MemoryRegion, 1);
|
2018-02-28 23:32:33 +03:00
|
|
|
memory_region_init_alias(port, OBJECT(s), "escc-legacy-port",
|
|
|
|
sysbus_mmio_get_region(sbd, 0),
|
|
|
|
maps[i + 1], 0x2);
|
2013-06-26 15:58:31 +04:00
|
|
|
memory_region_add_subregion(escc_legacy, maps[i], port);
|
|
|
|
}
|
|
|
|
|
|
|
|
memory_region_add_subregion(bar, 0x12000, escc_legacy);
|
|
|
|
}
|
|
|
|
|
2018-02-28 23:32:33 +03:00
|
|
|
static void macio_bar_setup(MacIOState *s)
|
2007-10-29 02:42:18 +03:00
|
|
|
{
|
2018-02-28 23:32:33 +03:00
|
|
|
ESCCState *escc = ESCC(&s->escc);
|
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(escc);
|
|
|
|
MemoryRegion *bar = &s->bar;
|
2007-10-29 02:42:18 +03:00
|
|
|
|
2018-02-28 23:32:33 +03:00
|
|
|
memory_region_add_subregion(bar, 0x13000, sysbus_mmio_get_region(sbd, 0));
|
|
|
|
macio_escc_legacy_setup(s);
|
2007-10-29 02:42:18 +03:00
|
|
|
}
|
|
|
|
|
2015-03-17 10:46:15 +03:00
|
|
|
static void macio_common_realize(PCIDevice *d, Error **errp)
|
2011-12-22 02:14:09 +04:00
|
|
|
{
|
2013-01-24 03:03:56 +04:00
|
|
|
MacIOState *s = MACIO(d);
|
2013-01-24 03:04:02 +04:00
|
|
|
SysBusDevice *sysbus_dev;
|
2015-10-01 11:59:52 +03:00
|
|
|
|
error: Eliminate error_propagate() with Coccinelle, part 1
When all we do with an Error we receive into a local variable is
propagating to somewhere else, we can just as well receive it there
right away. Convert
if (!foo(..., &err)) {
...
error_propagate(errp, err);
...
return ...
}
to
if (!foo(..., errp)) {
...
...
return ...
}
where nothing else needs @err. Coccinelle script:
@rule1 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
binary operator op;
constant c1, c2;
symbol false;
@@
if (
(
- fun(args, &err, args2)
+ fun(args, errp, args2)
|
- !fun(args, &err, args2)
+ !fun(args, errp, args2)
|
- fun(args, &err, args2) op c1
+ fun(args, errp, args2) op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
)
}
@rule2 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
expression var;
binary operator op;
constant c1, c2;
symbol false;
@@
- var = fun(args, &err, args2);
+ var = fun(args, errp, args2);
... when != err
if (
(
var
|
!var
|
var op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
|
return var;
)
}
@depends on rule1 || rule2@
identifier err;
@@
- Error *err = NULL;
... when != err
Not exactly elegant, I'm afraid.
The "when != lbl:" is necessary to avoid transforming
if (fun(args, &err)) {
goto out
}
...
out:
error_propagate(errp, err);
even though other paths to label out still need the error_propagate().
For an actual example, see sclp_realize().
Without the "when strict", Coccinelle transforms vfio_msix_setup(),
incorrectly. I don't know what exactly "when strict" does, only that
it helps here.
The match of return is narrower than what I want, but I can't figure
out how to express "return where the operand doesn't use @err". For
an example where it's too narrow, see vfio_intx_enable().
Silently fails to convert hw/arm/armsse.c, because Coccinelle gets
confused by ARMSSE being used both as typedef and function-like macro
there. Converted manually.
Line breaks tidied up manually. One nested declaration of @local_err
deleted manually. Preexisting unwanted blank line dropped in
hw/riscv/sifive_e.c.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-35-armbru@redhat.com>
2020-07-07 19:06:02 +03:00
|
|
|
if (!qdev_realize(DEVICE(&s->dbdma), BUS(&s->macio_bus), errp)) {
|
2017-09-24 17:47:42 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-02-28 23:32:32 +03:00
|
|
|
sysbus_dev = SYS_BUS_DEVICE(&s->dbdma);
|
2017-09-24 17:47:42 +03:00
|
|
|
memory_region_add_subregion(&s->bar, 0x08000,
|
|
|
|
sysbus_mmio_get_region(sysbus_dev, 0));
|
2013-01-24 03:03:56 +04:00
|
|
|
|
2018-03-19 17:00:46 +03:00
|
|
|
qdev_prop_set_uint32(DEVICE(&s->escc), "disabled", 0);
|
|
|
|
qdev_prop_set_uint32(DEVICE(&s->escc), "frequency", ESCC_CLOCK);
|
|
|
|
qdev_prop_set_uint32(DEVICE(&s->escc), "it_shift", 4);
|
2018-04-20 17:52:43 +03:00
|
|
|
qdev_prop_set_chr(DEVICE(&s->escc), "chrA", serial_hd(0));
|
|
|
|
qdev_prop_set_chr(DEVICE(&s->escc), "chrB", serial_hd(1));
|
2018-03-19 17:00:46 +03:00
|
|
|
qdev_prop_set_uint32(DEVICE(&s->escc), "chnBtype", escc_serial);
|
|
|
|
qdev_prop_set_uint32(DEVICE(&s->escc), "chnAtype", escc_serial);
|
error: Eliminate error_propagate() with Coccinelle, part 1
When all we do with an Error we receive into a local variable is
propagating to somewhere else, we can just as well receive it there
right away. Convert
if (!foo(..., &err)) {
...
error_propagate(errp, err);
...
return ...
}
to
if (!foo(..., errp)) {
...
...
return ...
}
where nothing else needs @err. Coccinelle script:
@rule1 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
binary operator op;
constant c1, c2;
symbol false;
@@
if (
(
- fun(args, &err, args2)
+ fun(args, errp, args2)
|
- !fun(args, &err, args2)
+ !fun(args, errp, args2)
|
- fun(args, &err, args2) op c1
+ fun(args, errp, args2) op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
)
}
@rule2 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
expression var;
binary operator op;
constant c1, c2;
symbol false;
@@
- var = fun(args, &err, args2);
+ var = fun(args, errp, args2);
... when != err
if (
(
var
|
!var
|
var op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
|
return var;
)
}
@depends on rule1 || rule2@
identifier err;
@@
- Error *err = NULL;
... when != err
Not exactly elegant, I'm afraid.
The "when != lbl:" is necessary to avoid transforming
if (fun(args, &err)) {
goto out
}
...
out:
error_propagate(errp, err);
even though other paths to label out still need the error_propagate().
For an actual example, see sclp_realize().
Without the "when strict", Coccinelle transforms vfio_msix_setup(),
incorrectly. I don't know what exactly "when strict" does, only that
it helps here.
The match of return is narrower than what I want, but I can't figure
out how to express "return where the operand doesn't use @err". For
an example where it's too narrow, see vfio_intx_enable().
Silently fails to convert hw/arm/armsse.c, because Coccinelle gets
confused by ARMSSE being used both as typedef and function-like macro
there. Converted manually.
Line breaks tidied up manually. One nested declaration of @local_err
deleted manually. Preexisting unwanted blank line dropped in
hw/riscv/sifive_e.c.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-35-armbru@redhat.com>
2020-07-07 19:06:02 +03:00
|
|
|
if (!qdev_realize(DEVICE(&s->escc), BUS(&s->macio_bus), errp)) {
|
2018-02-28 23:32:33 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-24 03:03:56 +04:00
|
|
|
macio_bar_setup(s);
|
|
|
|
pci_register_bar(d, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->bar);
|
2011-12-22 02:14:09 +04:00
|
|
|
}
|
|
|
|
|
2015-03-17 10:46:15 +03:00
|
|
|
static void macio_realize_ide(MacIOState *s, MACIOIDEState *ide,
|
|
|
|
qemu_irq irq0, qemu_irq irq1, int dmaid,
|
|
|
|
Error **errp)
|
2013-06-24 23:40:50 +04:00
|
|
|
{
|
|
|
|
SysBusDevice *sysbus_dev;
|
|
|
|
|
|
|
|
sysbus_dev = SYS_BUS_DEVICE(ide);
|
|
|
|
sysbus_connect_irq(sysbus_dev, 0, irq0);
|
|
|
|
sysbus_connect_irq(sysbus_dev, 1, irq1);
|
2017-09-24 17:47:43 +03:00
|
|
|
qdev_prop_set_uint32(DEVICE(ide), "channel", dmaid);
|
qom: Put name parameter before value / visitor parameter
The object_property_set_FOO() setters take property name and value in
an unusual order:
void object_property_set_FOO(Object *obj, FOO_TYPE value,
const char *name, Error **errp)
Having to pass value before name feels grating. Swap them.
Same for object_property_set(), object_property_get(), and
object_property_parse().
Convert callers with this Coccinelle script:
@@
identifier fun = {
object_property_get, object_property_parse, object_property_set_str,
object_property_set_link, object_property_set_bool,
object_property_set_int, object_property_set_uint, object_property_set,
object_property_set_qobject
};
expression obj, v, name, errp;
@@
- fun(obj, v, name, errp)
+ fun(obj, name, v, errp)
Chokes on hw/arm/musicpal.c's lcd_refresh() with the unhelpful error
message "no position information". Convert that one manually.
Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
ARMSSE being used both as typedef and function-like macro there.
Convert manually.
Fails to convert hw/rx/rx-gdbsim.c, because Coccinelle gets confused
by RXCPU being used both as typedef and function-like macro there.
Convert manually. The other files using RXCPU that way don't need
conversion.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20200707160613.848843-27-armbru@redhat.com>
[Straightforwad conflict with commit 2336172d9b "audio: set default
value for pcspk.iobase property" resolved]
2020-07-07 19:05:54 +03:00
|
|
|
object_property_set_link(OBJECT(ide), "dbdma", OBJECT(&s->dbdma),
|
hw: Fix error API violation around object_property_set_link()
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.
virtio_gpu_pci_base_realize(), virtio_vga_base_realize(),
sparc32_ledma_device_realize(), sparc32_dma_realize(),
sparc32_dma_realize() xilinx_axidma_realize(), mips_cps_realize(),
macio_realize_ide(), xilinx_enet_realize(), and
virtio_iommu_pci_realize() are wrong that way: they reuse the argument
they pass to object_property_set_link() for another call.
Harmless, because object_property_set_link() can't actually fail for
them: it fails when the property doesn't exist, is not settable, or
its .check() method fails. Fix by passing &error_abort instead.
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Cc: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>
Cc: Alistair Francis <alistair@alistair23.me>
Cc: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-arm@nongnu.org
Cc: Aleksandar Markovic <aleksandar.qemu.devel@gmail.com>
Cc: Aurelien Jarno <aurelien@aurel32.net>
Cc: Aleksandar Rikalo <aleksandar.rikalo@syrmia.com>
Cc: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-Id: <20200630090351.1247703-16-armbru@redhat.com>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
2020-06-30 12:03:40 +03:00
|
|
|
&error_abort);
|
2017-09-24 17:47:44 +03:00
|
|
|
macio_ide_register_dma(ide);
|
2017-09-24 17:47:43 +03:00
|
|
|
|
2020-06-10 08:32:26 +03:00
|
|
|
qdev_realize(DEVICE(ide), BUS(&s->macio_bus), errp);
|
2013-06-24 23:40:50 +04:00
|
|
|
}
|
|
|
|
|
2015-03-17 10:46:15 +03:00
|
|
|
static void macio_oldworld_realize(PCIDevice *d, Error **errp)
|
2013-01-24 03:03:57 +04:00
|
|
|
{
|
|
|
|
MacIOState *s = MACIO(d);
|
2013-01-24 03:04:00 +04:00
|
|
|
OldWorldMacIOState *os = OLDWORLD_MACIO(d);
|
2018-03-07 01:01:59 +03:00
|
|
|
DeviceState *pic_dev = DEVICE(os->pic);
|
2015-03-17 10:46:15 +03:00
|
|
|
Error *err = NULL;
|
2013-01-24 03:04:00 +04:00
|
|
|
SysBusDevice *sysbus_dev;
|
2015-03-17 10:46:15 +03:00
|
|
|
|
|
|
|
macio_common_realize(d, &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
2013-01-24 03:03:57 +04:00
|
|
|
}
|
|
|
|
|
2018-06-12 19:44:02 +03:00
|
|
|
qdev_prop_set_uint64(DEVICE(&s->cuda), "timebase-frequency",
|
|
|
|
s->frequency);
|
error: Eliminate error_propagate() with Coccinelle, part 1
When all we do with an Error we receive into a local variable is
propagating to somewhere else, we can just as well receive it there
right away. Convert
if (!foo(..., &err)) {
...
error_propagate(errp, err);
...
return ...
}
to
if (!foo(..., errp)) {
...
...
return ...
}
where nothing else needs @err. Coccinelle script:
@rule1 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
binary operator op;
constant c1, c2;
symbol false;
@@
if (
(
- fun(args, &err, args2)
+ fun(args, errp, args2)
|
- !fun(args, &err, args2)
+ !fun(args, errp, args2)
|
- fun(args, &err, args2) op c1
+ fun(args, errp, args2) op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
)
}
@rule2 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
expression var;
binary operator op;
constant c1, c2;
symbol false;
@@
- var = fun(args, &err, args2);
+ var = fun(args, errp, args2);
... when != err
if (
(
var
|
!var
|
var op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
|
return var;
)
}
@depends on rule1 || rule2@
identifier err;
@@
- Error *err = NULL;
... when != err
Not exactly elegant, I'm afraid.
The "when != lbl:" is necessary to avoid transforming
if (fun(args, &err)) {
goto out
}
...
out:
error_propagate(errp, err);
even though other paths to label out still need the error_propagate().
For an actual example, see sclp_realize().
Without the "when strict", Coccinelle transforms vfio_msix_setup(),
incorrectly. I don't know what exactly "when strict" does, only that
it helps here.
The match of return is narrower than what I want, but I can't figure
out how to express "return where the operand doesn't use @err". For
an example where it's too narrow, see vfio_intx_enable().
Silently fails to convert hw/arm/armsse.c, because Coccinelle gets
confused by ARMSSE being used both as typedef and function-like macro
there. Converted manually.
Line breaks tidied up manually. One nested declaration of @local_err
deleted manually. Preexisting unwanted blank line dropped in
hw/riscv/sifive_e.c.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-35-armbru@redhat.com>
2020-07-07 19:06:02 +03:00
|
|
|
if (!qdev_realize(DEVICE(&s->cuda), BUS(&s->macio_bus), errp)) {
|
2018-06-12 19:44:02 +03:00
|
|
|
return;
|
|
|
|
}
|
2013-01-24 03:04:02 +04:00
|
|
|
sysbus_dev = SYS_BUS_DEVICE(&s->cuda);
|
2018-06-12 19:44:02 +03:00
|
|
|
memory_region_add_subregion(&s->bar, 0x16000,
|
|
|
|
sysbus_mmio_get_region(sysbus_dev, 0));
|
2018-03-07 01:01:59 +03:00
|
|
|
sysbus_connect_irq(sysbus_dev, 0, qdev_get_gpio_in(pic_dev,
|
|
|
|
OLDWORLD_CUDA_IRQ));
|
2013-01-24 03:04:02 +04:00
|
|
|
|
2018-02-28 23:32:33 +03:00
|
|
|
sysbus_dev = SYS_BUS_DEVICE(&s->escc);
|
2018-03-07 01:01:59 +03:00
|
|
|
sysbus_connect_irq(sysbus_dev, 0, qdev_get_gpio_in(pic_dev,
|
|
|
|
OLDWORLD_ESCCB_IRQ));
|
|
|
|
sysbus_connect_irq(sysbus_dev, 1, qdev_get_gpio_in(pic_dev,
|
|
|
|
OLDWORLD_ESCCA_IRQ));
|
2018-02-28 23:32:33 +03:00
|
|
|
|
error: Eliminate error_propagate() with Coccinelle, part 1
When all we do with an Error we receive into a local variable is
propagating to somewhere else, we can just as well receive it there
right away. Convert
if (!foo(..., &err)) {
...
error_propagate(errp, err);
...
return ...
}
to
if (!foo(..., errp)) {
...
...
return ...
}
where nothing else needs @err. Coccinelle script:
@rule1 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
binary operator op;
constant c1, c2;
symbol false;
@@
if (
(
- fun(args, &err, args2)
+ fun(args, errp, args2)
|
- !fun(args, &err, args2)
+ !fun(args, errp, args2)
|
- fun(args, &err, args2) op c1
+ fun(args, errp, args2) op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
)
}
@rule2 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
expression var;
binary operator op;
constant c1, c2;
symbol false;
@@
- var = fun(args, &err, args2);
+ var = fun(args, errp, args2);
... when != err
if (
(
var
|
!var
|
var op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
|
return var;
)
}
@depends on rule1 || rule2@
identifier err;
@@
- Error *err = NULL;
... when != err
Not exactly elegant, I'm afraid.
The "when != lbl:" is necessary to avoid transforming
if (fun(args, &err)) {
goto out
}
...
out:
error_propagate(errp, err);
even though other paths to label out still need the error_propagate().
For an actual example, see sclp_realize().
Without the "when strict", Coccinelle transforms vfio_msix_setup(),
incorrectly. I don't know what exactly "when strict" does, only that
it helps here.
The match of return is narrower than what I want, but I can't figure
out how to express "return where the operand doesn't use @err". For
an example where it's too narrow, see vfio_intx_enable().
Silently fails to convert hw/arm/armsse.c, because Coccinelle gets
confused by ARMSSE being used both as typedef and function-like macro
there. Converted manually.
Line breaks tidied up manually. One nested declaration of @local_err
deleted manually. Preexisting unwanted blank line dropped in
hw/riscv/sifive_e.c.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-35-armbru@redhat.com>
2020-07-07 19:06:02 +03:00
|
|
|
if (!qdev_realize(DEVICE(&os->nvram), BUS(&s->macio_bus), errp)) {
|
2015-03-17 10:46:15 +03:00
|
|
|
return;
|
2013-01-24 03:04:00 +04:00
|
|
|
}
|
|
|
|
sysbus_dev = SYS_BUS_DEVICE(&os->nvram);
|
|
|
|
memory_region_add_subregion(&s->bar, 0x60000,
|
|
|
|
sysbus_mmio_get_region(sysbus_dev, 0));
|
|
|
|
pmac_format_nvram_partition(&os->nvram, os->nvram.size);
|
|
|
|
|
2018-02-28 23:32:38 +03:00
|
|
|
/* Heathrow PIC */
|
|
|
|
sysbus_dev = SYS_BUS_DEVICE(os->pic);
|
|
|
|
memory_region_add_subregion(&s->bar, 0x0,
|
|
|
|
sysbus_mmio_get_region(sysbus_dev, 0));
|
2013-01-24 03:03:57 +04:00
|
|
|
|
2013-06-24 23:40:50 +04:00
|
|
|
/* IDE buses */
|
2018-03-07 01:01:59 +03:00
|
|
|
macio_realize_ide(s, &os->ide[0],
|
|
|
|
qdev_get_gpio_in(pic_dev, OLDWORLD_IDE0_IRQ),
|
|
|
|
qdev_get_gpio_in(pic_dev, OLDWORLD_IDE0_DMA_IRQ),
|
|
|
|
0x16, &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
macio_realize_ide(s, &os->ide[1],
|
|
|
|
qdev_get_gpio_in(pic_dev, OLDWORLD_IDE1_IRQ),
|
|
|
|
qdev_get_gpio_in(pic_dev, OLDWORLD_IDE1_DMA_IRQ),
|
|
|
|
0x1a, &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
2013-01-24 03:04:01 +04:00
|
|
|
}
|
2013-01-24 03:03:57 +04:00
|
|
|
}
|
|
|
|
|
2020-06-10 08:32:27 +03:00
|
|
|
static void macio_init_ide(MacIOState *s, MACIOIDEState *ide, int index)
|
2013-06-24 23:40:50 +04:00
|
|
|
{
|
2018-07-17 17:51:54 +03:00
|
|
|
gchar *name = g_strdup_printf("ide[%i]", index);
|
2018-08-29 19:59:07 +03:00
|
|
|
uint32_t addr = 0x1f000 + ((index + 1) * 0x1000);
|
2013-06-24 23:40:50 +04:00
|
|
|
|
2020-06-10 08:32:27 +03:00
|
|
|
object_initialize_child(OBJECT(s), name, ide, TYPE_MACIO_IDE);
|
2018-08-29 19:59:07 +03:00
|
|
|
qdev_prop_set_uint32(DEVICE(ide), "addr", addr);
|
|
|
|
memory_region_add_subregion(&s->bar, addr, &ide->mem);
|
2013-06-24 23:40:50 +04:00
|
|
|
g_free(name);
|
|
|
|
}
|
|
|
|
|
2013-01-24 03:04:00 +04:00
|
|
|
static void macio_oldworld_init(Object *obj)
|
|
|
|
{
|
2013-01-24 03:04:01 +04:00
|
|
|
MacIOState *s = MACIO(obj);
|
2013-01-24 03:04:00 +04:00
|
|
|
OldWorldMacIOState *os = OLDWORLD_MACIO(obj);
|
|
|
|
DeviceState *dev;
|
2013-06-24 23:40:50 +04:00
|
|
|
int i;
|
2013-01-24 03:04:00 +04:00
|
|
|
|
2018-02-28 23:32:38 +03:00
|
|
|
object_property_add_link(obj, "pic", TYPE_HEATHROW,
|
|
|
|
(Object **) &os->pic,
|
|
|
|
qdev_prop_allow_set_link_before_realize,
|
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 18:29:22 +03:00
|
|
|
0);
|
2018-02-28 23:32:38 +03:00
|
|
|
|
2020-06-10 08:32:27 +03:00
|
|
|
object_initialize_child(OBJECT(s), "cuda", &s->cuda, TYPE_CUDA);
|
2018-06-12 19:44:02 +03:00
|
|
|
|
2020-06-10 08:32:27 +03:00
|
|
|
object_initialize_child(OBJECT(s), "nvram", &os->nvram, TYPE_MACIO_NVRAM);
|
2013-01-24 03:04:00 +04:00
|
|
|
dev = DEVICE(&os->nvram);
|
|
|
|
qdev_prop_set_uint32(dev, "size", 0x2000);
|
|
|
|
qdev_prop_set_uint32(dev, "it_shift", 4);
|
2013-01-24 03:04:01 +04:00
|
|
|
|
2013-06-24 23:40:50 +04:00
|
|
|
for (i = 0; i < 2; i++) {
|
2020-06-10 08:32:27 +03:00
|
|
|
macio_init_ide(s, &os->ide[i], i);
|
2013-06-24 23:40:50 +04:00
|
|
|
}
|
2013-01-24 03:04:00 +04:00
|
|
|
}
|
|
|
|
|
2013-06-30 07:15:14 +04:00
|
|
|
static void timer_write(void *opaque, hwaddr addr, uint64_t value,
|
|
|
|
unsigned size)
|
|
|
|
{
|
2018-05-06 17:20:03 +03:00
|
|
|
trace_macio_timer_write(addr, size, value);
|
2013-06-30 07:15:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t timer_read(void *opaque, hwaddr addr, unsigned size)
|
|
|
|
{
|
|
|
|
uint32_t value = 0;
|
2014-07-13 18:45:46 +04:00
|
|
|
uint64_t systime = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
|
|
|
|
uint64_t kltime;
|
|
|
|
|
2016-03-21 19:02:30 +03:00
|
|
|
kltime = muldiv64(systime, 4194300, NANOSECONDS_PER_SECOND * 4);
|
2014-07-13 18:45:46 +04:00
|
|
|
kltime = muldiv64(kltime, 18432000, 1048575);
|
2013-06-30 07:15:14 +04:00
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
case 0x38:
|
2014-07-13 18:45:46 +04:00
|
|
|
value = kltime;
|
2013-06-30 07:15:14 +04:00
|
|
|
break;
|
|
|
|
case 0x3c:
|
2014-07-13 18:45:46 +04:00
|
|
|
value = kltime >> 32;
|
2013-06-30 07:15:14 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-05-06 17:20:03 +03:00
|
|
|
trace_macio_timer_read(addr, size, value);
|
2013-06-30 07:15:14 +04:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MemoryRegionOps timer_ops = {
|
|
|
|
.read = timer_read,
|
|
|
|
.write = timer_write,
|
2014-05-27 03:59:06 +04:00
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
2013-06-30 07:15:14 +04:00
|
|
|
};
|
|
|
|
|
2015-03-17 10:46:15 +03:00
|
|
|
static void macio_newworld_realize(PCIDevice *d, Error **errp)
|
2013-01-24 03:03:57 +04:00
|
|
|
{
|
|
|
|
MacIOState *s = MACIO(d);
|
2013-01-24 03:04:01 +04:00
|
|
|
NewWorldMacIOState *ns = NEWWORLD_MACIO(d);
|
2018-05-03 23:24:41 +03:00
|
|
|
DeviceState *pic_dev = DEVICE(ns->pic);
|
2015-03-17 10:46:15 +03:00
|
|
|
Error *err = NULL;
|
2013-01-24 03:04:01 +04:00
|
|
|
SysBusDevice *sysbus_dev;
|
2015-02-27 10:50:14 +03:00
|
|
|
MemoryRegion *timer_memory = NULL;
|
2015-03-17 10:46:15 +03:00
|
|
|
|
|
|
|
macio_common_realize(d, &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
2013-01-24 03:03:57 +04:00
|
|
|
}
|
|
|
|
|
2018-02-28 23:32:33 +03:00
|
|
|
sysbus_dev = SYS_BUS_DEVICE(&s->escc);
|
2018-05-03 23:24:41 +03:00
|
|
|
sysbus_connect_irq(sysbus_dev, 0, qdev_get_gpio_in(pic_dev,
|
|
|
|
NEWWORLD_ESCCB_IRQ));
|
|
|
|
sysbus_connect_irq(sysbus_dev, 1, qdev_get_gpio_in(pic_dev,
|
|
|
|
NEWWORLD_ESCCA_IRQ));
|
2018-02-28 23:32:33 +03:00
|
|
|
|
2018-02-28 23:32:41 +03:00
|
|
|
/* OpenPIC */
|
|
|
|
sysbus_dev = SYS_BUS_DEVICE(ns->pic);
|
|
|
|
memory_region_add_subregion(&s->bar, 0x40000,
|
|
|
|
sysbus_mmio_get_region(sysbus_dev, 0));
|
2013-01-24 03:03:57 +04:00
|
|
|
|
2013-06-24 23:40:50 +04:00
|
|
|
/* IDE buses */
|
2018-05-03 23:24:41 +03:00
|
|
|
macio_realize_ide(s, &ns->ide[0],
|
|
|
|
qdev_get_gpio_in(pic_dev, NEWWORLD_IDE0_IRQ),
|
|
|
|
qdev_get_gpio_in(pic_dev, NEWWORLD_IDE0_DMA_IRQ),
|
|
|
|
0x16, &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
macio_realize_ide(s, &ns->ide[1],
|
|
|
|
qdev_get_gpio_in(pic_dev, NEWWORLD_IDE1_IRQ),
|
|
|
|
qdev_get_gpio_in(pic_dev, NEWWORLD_IDE1_DMA_IRQ),
|
|
|
|
0x1a, &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
2013-01-24 03:04:01 +04:00
|
|
|
}
|
|
|
|
|
2013-06-30 07:15:14 +04:00
|
|
|
/* Timer */
|
2015-02-27 10:50:14 +03:00
|
|
|
timer_memory = g_new(MemoryRegion, 1);
|
2013-06-30 07:15:14 +04:00
|
|
|
memory_region_init_io(timer_memory, OBJECT(s), &timer_ops, NULL, "timer",
|
|
|
|
0x1000);
|
|
|
|
memory_region_add_subregion(&s->bar, 0x15000, timer_memory);
|
2018-06-12 19:43:58 +03:00
|
|
|
|
|
|
|
if (ns->has_pmu) {
|
|
|
|
/* GPIOs */
|
|
|
|
sysbus_dev = SYS_BUS_DEVICE(&ns->gpio);
|
qom: Put name parameter before value / visitor parameter
The object_property_set_FOO() setters take property name and value in
an unusual order:
void object_property_set_FOO(Object *obj, FOO_TYPE value,
const char *name, Error **errp)
Having to pass value before name feels grating. Swap them.
Same for object_property_set(), object_property_get(), and
object_property_parse().
Convert callers with this Coccinelle script:
@@
identifier fun = {
object_property_get, object_property_parse, object_property_set_str,
object_property_set_link, object_property_set_bool,
object_property_set_int, object_property_set_uint, object_property_set,
object_property_set_qobject
};
expression obj, v, name, errp;
@@
- fun(obj, v, name, errp)
+ fun(obj, name, v, errp)
Chokes on hw/arm/musicpal.c's lcd_refresh() with the unhelpful error
message "no position information". Convert that one manually.
Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
ARMSSE being used both as typedef and function-like macro there.
Convert manually.
Fails to convert hw/rx/rx-gdbsim.c, because Coccinelle gets confused
by RXCPU being used both as typedef and function-like macro there.
Convert manually. The other files using RXCPU that way don't need
conversion.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20200707160613.848843-27-armbru@redhat.com>
[Straightforwad conflict with commit 2336172d9b "audio: set default
value for pcspk.iobase property" resolved]
2020-07-07 19:05:54 +03:00
|
|
|
object_property_set_link(OBJECT(&ns->gpio), "pic", OBJECT(pic_dev),
|
2018-06-12 19:43:58 +03:00
|
|
|
&error_abort);
|
|
|
|
memory_region_add_subregion(&s->bar, 0x50,
|
|
|
|
sysbus_mmio_get_region(sysbus_dev, 0));
|
2020-07-07 19:05:33 +03:00
|
|
|
if (!qdev_realize(DEVICE(&ns->gpio), BUS(&s->macio_bus), errp)) {
|
|
|
|
return;
|
|
|
|
}
|
2018-06-12 19:44:02 +03:00
|
|
|
|
|
|
|
/* PMU */
|
qom: Less verbose object_initialize_child()
All users of object_initialize_child() pass the obvious child size
argument. Almost all pass &error_abort and no properties. Tiresome.
Rename object_initialize_child() to
object_initialize_child_with_props() to free the name. New
convenience wrapper object_initialize_child() automates the size
argument, and passes &error_abort and no properties.
Rename object_initialize_childv() to
object_initialize_child_with_propsv() for consistency.
Convert callers with this Coccinelle script:
@@
expression parent, propname, type;
expression child, size;
symbol error_abort;
@@
- object_initialize_child(parent, propname, OBJECT(child), size, type, &error_abort, NULL)
+ object_initialize_child(parent, propname, child, size, type, &error_abort, NULL)
@@
expression parent, propname, type;
expression child;
symbol error_abort;
@@
- object_initialize_child(parent, propname, child, sizeof(*child), type, &error_abort, NULL)
+ object_initialize_child(parent, propname, child, type)
@@
expression parent, propname, type;
expression child;
symbol error_abort;
@@
- object_initialize_child(parent, propname, &child, sizeof(child), type, &error_abort, NULL)
+ object_initialize_child(parent, propname, &child, type)
@@
expression parent, propname, type;
expression child, size, err;
expression list props;
@@
- object_initialize_child(parent, propname, child, size, type, err, props)
+ object_initialize_child_with_props(parent, propname, child, size, type, err, props)
Note that Coccinelle chokes on ARMSSE typedef vs. macro in
hw/arm/armsse.c. Worked around by temporarily renaming the macro for
the spatch run.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
[Rebased: machine opentitan is new (commit fe0fe4735e7)]
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-37-armbru@redhat.com>
2020-06-10 08:32:25 +03:00
|
|
|
object_initialize_child(OBJECT(s), "pmu", &s->pmu, TYPE_VIA_PMU);
|
qom: Put name parameter before value / visitor parameter
The object_property_set_FOO() setters take property name and value in
an unusual order:
void object_property_set_FOO(Object *obj, FOO_TYPE value,
const char *name, Error **errp)
Having to pass value before name feels grating. Swap them.
Same for object_property_set(), object_property_get(), and
object_property_parse().
Convert callers with this Coccinelle script:
@@
identifier fun = {
object_property_get, object_property_parse, object_property_set_str,
object_property_set_link, object_property_set_bool,
object_property_set_int, object_property_set_uint, object_property_set,
object_property_set_qobject
};
expression obj, v, name, errp;
@@
- fun(obj, v, name, errp)
+ fun(obj, name, v, errp)
Chokes on hw/arm/musicpal.c's lcd_refresh() with the unhelpful error
message "no position information". Convert that one manually.
Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
ARMSSE being used both as typedef and function-like macro there.
Convert manually.
Fails to convert hw/rx/rx-gdbsim.c, because Coccinelle gets confused
by RXCPU being used both as typedef and function-like macro there.
Convert manually. The other files using RXCPU that way don't need
conversion.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20200707160613.848843-27-armbru@redhat.com>
[Straightforwad conflict with commit 2336172d9b "audio: set default
value for pcspk.iobase property" resolved]
2020-07-07 19:05:54 +03:00
|
|
|
object_property_set_link(OBJECT(&s->pmu), "gpio", OBJECT(sysbus_dev),
|
2018-06-12 19:44:02 +03:00
|
|
|
&error_abort);
|
|
|
|
qdev_prop_set_bit(DEVICE(&s->pmu), "has-adb", ns->has_adb);
|
error: Eliminate error_propagate() with Coccinelle, part 1
When all we do with an Error we receive into a local variable is
propagating to somewhere else, we can just as well receive it there
right away. Convert
if (!foo(..., &err)) {
...
error_propagate(errp, err);
...
return ...
}
to
if (!foo(..., errp)) {
...
...
return ...
}
where nothing else needs @err. Coccinelle script:
@rule1 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
binary operator op;
constant c1, c2;
symbol false;
@@
if (
(
- fun(args, &err, args2)
+ fun(args, errp, args2)
|
- !fun(args, &err, args2)
+ !fun(args, errp, args2)
|
- fun(args, &err, args2) op c1
+ fun(args, errp, args2) op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
)
}
@rule2 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
expression var;
binary operator op;
constant c1, c2;
symbol false;
@@
- var = fun(args, &err, args2);
+ var = fun(args, errp, args2);
... when != err
if (
(
var
|
!var
|
var op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
|
return var;
)
}
@depends on rule1 || rule2@
identifier err;
@@
- Error *err = NULL;
... when != err
Not exactly elegant, I'm afraid.
The "when != lbl:" is necessary to avoid transforming
if (fun(args, &err)) {
goto out
}
...
out:
error_propagate(errp, err);
even though other paths to label out still need the error_propagate().
For an actual example, see sclp_realize().
Without the "when strict", Coccinelle transforms vfio_msix_setup(),
incorrectly. I don't know what exactly "when strict" does, only that
it helps here.
The match of return is narrower than what I want, but I can't figure
out how to express "return where the operand doesn't use @err". For
an example where it's too narrow, see vfio_intx_enable().
Silently fails to convert hw/arm/armsse.c, because Coccinelle gets
confused by ARMSSE being used both as typedef and function-like macro
there. Converted manually.
Line breaks tidied up manually. One nested declaration of @local_err
deleted manually. Preexisting unwanted blank line dropped in
hw/riscv/sifive_e.c.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-35-armbru@redhat.com>
2020-07-07 19:06:02 +03:00
|
|
|
if (!qdev_realize(DEVICE(&s->pmu), BUS(&s->macio_bus), errp)) {
|
2018-06-12 19:44:02 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
sysbus_dev = SYS_BUS_DEVICE(&s->pmu);
|
|
|
|
sysbus_connect_irq(sysbus_dev, 0, qdev_get_gpio_in(pic_dev,
|
|
|
|
NEWWORLD_PMU_IRQ));
|
|
|
|
memory_region_add_subregion(&s->bar, 0x16000,
|
|
|
|
sysbus_mmio_get_region(sysbus_dev, 0));
|
|
|
|
} else {
|
2020-06-09 15:23:25 +03:00
|
|
|
object_unparent(OBJECT(&ns->gpio));
|
|
|
|
|
2018-06-12 19:44:02 +03:00
|
|
|
/* CUDA */
|
qom: Less verbose object_initialize_child()
All users of object_initialize_child() pass the obvious child size
argument. Almost all pass &error_abort and no properties. Tiresome.
Rename object_initialize_child() to
object_initialize_child_with_props() to free the name. New
convenience wrapper object_initialize_child() automates the size
argument, and passes &error_abort and no properties.
Rename object_initialize_childv() to
object_initialize_child_with_propsv() for consistency.
Convert callers with this Coccinelle script:
@@
expression parent, propname, type;
expression child, size;
symbol error_abort;
@@
- object_initialize_child(parent, propname, OBJECT(child), size, type, &error_abort, NULL)
+ object_initialize_child(parent, propname, child, size, type, &error_abort, NULL)
@@
expression parent, propname, type;
expression child;
symbol error_abort;
@@
- object_initialize_child(parent, propname, child, sizeof(*child), type, &error_abort, NULL)
+ object_initialize_child(parent, propname, child, type)
@@
expression parent, propname, type;
expression child;
symbol error_abort;
@@
- object_initialize_child(parent, propname, &child, sizeof(child), type, &error_abort, NULL)
+ object_initialize_child(parent, propname, &child, type)
@@
expression parent, propname, type;
expression child, size, err;
expression list props;
@@
- object_initialize_child(parent, propname, child, size, type, err, props)
+ object_initialize_child_with_props(parent, propname, child, size, type, err, props)
Note that Coccinelle chokes on ARMSSE typedef vs. macro in
hw/arm/armsse.c. Worked around by temporarily renaming the macro for
the spatch run.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
[Rebased: machine opentitan is new (commit fe0fe4735e7)]
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-37-armbru@redhat.com>
2020-06-10 08:32:25 +03:00
|
|
|
object_initialize_child(OBJECT(s), "cuda", &s->cuda, TYPE_CUDA);
|
2018-06-12 19:44:02 +03:00
|
|
|
qdev_prop_set_uint64(DEVICE(&s->cuda), "timebase-frequency",
|
|
|
|
s->frequency);
|
|
|
|
|
error: Eliminate error_propagate() with Coccinelle, part 1
When all we do with an Error we receive into a local variable is
propagating to somewhere else, we can just as well receive it there
right away. Convert
if (!foo(..., &err)) {
...
error_propagate(errp, err);
...
return ...
}
to
if (!foo(..., errp)) {
...
...
return ...
}
where nothing else needs @err. Coccinelle script:
@rule1 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
binary operator op;
constant c1, c2;
symbol false;
@@
if (
(
- fun(args, &err, args2)
+ fun(args, errp, args2)
|
- !fun(args, &err, args2)
+ !fun(args, errp, args2)
|
- fun(args, &err, args2) op c1
+ fun(args, errp, args2) op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
)
}
@rule2 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
expression var;
binary operator op;
constant c1, c2;
symbol false;
@@
- var = fun(args, &err, args2);
+ var = fun(args, errp, args2);
... when != err
if (
(
var
|
!var
|
var op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
|
return var;
)
}
@depends on rule1 || rule2@
identifier err;
@@
- Error *err = NULL;
... when != err
Not exactly elegant, I'm afraid.
The "when != lbl:" is necessary to avoid transforming
if (fun(args, &err)) {
goto out
}
...
out:
error_propagate(errp, err);
even though other paths to label out still need the error_propagate().
For an actual example, see sclp_realize().
Without the "when strict", Coccinelle transforms vfio_msix_setup(),
incorrectly. I don't know what exactly "when strict" does, only that
it helps here.
The match of return is narrower than what I want, but I can't figure
out how to express "return where the operand doesn't use @err". For
an example where it's too narrow, see vfio_intx_enable().
Silently fails to convert hw/arm/armsse.c, because Coccinelle gets
confused by ARMSSE being used both as typedef and function-like macro
there. Converted manually.
Line breaks tidied up manually. One nested declaration of @local_err
deleted manually. Preexisting unwanted blank line dropped in
hw/riscv/sifive_e.c.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-35-armbru@redhat.com>
2020-07-07 19:06:02 +03:00
|
|
|
if (!qdev_realize(DEVICE(&s->cuda), BUS(&s->macio_bus), errp)) {
|
2018-06-12 19:44:02 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
sysbus_dev = SYS_BUS_DEVICE(&s->cuda);
|
|
|
|
sysbus_connect_irq(sysbus_dev, 0, qdev_get_gpio_in(pic_dev,
|
|
|
|
NEWWORLD_CUDA_IRQ));
|
|
|
|
memory_region_add_subregion(&s->bar, 0x16000,
|
|
|
|
sysbus_mmio_get_region(sysbus_dev, 0));
|
2018-06-12 19:43:58 +03:00
|
|
|
}
|
2013-01-24 03:03:57 +04:00
|
|
|
}
|
|
|
|
|
2013-01-24 03:04:01 +04:00
|
|
|
static void macio_newworld_init(Object *obj)
|
|
|
|
{
|
|
|
|
MacIOState *s = MACIO(obj);
|
|
|
|
NewWorldMacIOState *ns = NEWWORLD_MACIO(obj);
|
|
|
|
int i;
|
|
|
|
|
2018-02-28 23:32:41 +03:00
|
|
|
object_property_add_link(obj, "pic", TYPE_OPENPIC,
|
|
|
|
(Object **) &ns->pic,
|
|
|
|
qdev_prop_allow_set_link_before_realize,
|
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 18:29:22 +03:00
|
|
|
0);
|
2018-02-28 23:32:41 +03:00
|
|
|
|
2020-06-10 08:32:27 +03:00
|
|
|
object_initialize_child(OBJECT(s), "gpio", &ns->gpio, TYPE_MACIO_GPIO);
|
2018-06-12 19:43:58 +03:00
|
|
|
|
2013-01-24 03:04:01 +04:00
|
|
|
for (i = 0; i < 2; i++) {
|
2020-06-10 08:32:27 +03:00
|
|
|
macio_init_ide(s, &ns->ide[i], i);
|
2013-01-24 03:04:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-24 03:03:55 +04:00
|
|
|
static void macio_instance_init(Object *obj)
|
|
|
|
{
|
|
|
|
MacIOState *s = MACIO(obj);
|
|
|
|
|
2015-10-01 11:59:51 +03:00
|
|
|
memory_region_init(&s->bar, obj, "macio", 0x80000);
|
2013-01-24 03:04:01 +04:00
|
|
|
|
2018-08-29 19:59:06 +03:00
|
|
|
qbus_create_inplace(&s->macio_bus, sizeof(s->macio_bus), TYPE_MACIO_BUS,
|
|
|
|
DEVICE(obj), "macio.0");
|
2018-02-28 23:32:33 +03:00
|
|
|
|
2020-06-10 08:32:27 +03:00
|
|
|
object_initialize_child(OBJECT(s), "dbdma", &s->dbdma, TYPE_MAC_DBDMA);
|
2018-08-29 19:59:06 +03:00
|
|
|
|
2020-06-10 08:32:27 +03:00
|
|
|
object_initialize_child(OBJECT(s), "escc", &s->escc, TYPE_ESCC);
|
2013-01-24 03:03:55 +04:00
|
|
|
}
|
|
|
|
|
2015-02-10 01:40:44 +03:00
|
|
|
static const VMStateDescription vmstate_macio_oldworld = {
|
|
|
|
.name = "macio-oldworld",
|
|
|
|
.version_id = 0,
|
|
|
|
.minimum_version_id = 0,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_PCI_DEVICE(parent_obj.parent, OldWorldMacIOState),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-24 03:03:57 +04:00
|
|
|
static void macio_oldworld_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
PCIDeviceClass *pdc = PCI_DEVICE_CLASS(oc);
|
2015-02-10 01:40:44 +03:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
2013-01-24 03:03:57 +04:00
|
|
|
|
2015-03-17 10:46:15 +03:00
|
|
|
pdc->realize = macio_oldworld_realize;
|
2013-01-24 03:03:57 +04:00
|
|
|
pdc->device_id = PCI_DEVICE_ID_APPLE_343S1201;
|
2015-02-10 01:40:44 +03:00
|
|
|
dc->vmsd = &vmstate_macio_oldworld;
|
2013-01-24 03:03:57 +04:00
|
|
|
}
|
|
|
|
|
2015-02-10 01:40:44 +03:00
|
|
|
static const VMStateDescription vmstate_macio_newworld = {
|
|
|
|
.name = "macio-newworld",
|
|
|
|
.version_id = 0,
|
|
|
|
.minimum_version_id = 0,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_PCI_DEVICE(parent_obj.parent, NewWorldMacIOState),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-06-12 19:43:57 +03:00
|
|
|
static Property macio_newworld_properties[] = {
|
|
|
|
DEFINE_PROP_BOOL("has-pmu", NewWorldMacIOState, has_pmu, false),
|
|
|
|
DEFINE_PROP_BOOL("has-adb", NewWorldMacIOState, has_adb, false),
|
|
|
|
DEFINE_PROP_END_OF_LIST()
|
|
|
|
};
|
|
|
|
|
2013-01-24 03:03:57 +04:00
|
|
|
static void macio_newworld_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
PCIDeviceClass *pdc = PCI_DEVICE_CLASS(oc);
|
2015-02-10 01:40:44 +03:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
2013-01-24 03:03:57 +04:00
|
|
|
|
2015-03-17 10:46:15 +03:00
|
|
|
pdc->realize = macio_newworld_realize;
|
2013-01-24 03:03:57 +04:00
|
|
|
pdc->device_id = PCI_DEVICE_ID_APPLE_UNI_N_KEYL;
|
2015-02-10 01:40:44 +03:00
|
|
|
dc->vmsd = &vmstate_macio_newworld;
|
2020-01-10 18:30:32 +03:00
|
|
|
device_class_set_props(dc, macio_newworld_properties);
|
2013-01-24 03:03:57 +04:00
|
|
|
}
|
|
|
|
|
2014-07-14 00:31:53 +04:00
|
|
|
static Property macio_properties[] = {
|
|
|
|
DEFINE_PROP_UINT64("frequency", MacIOState, frequency, 0),
|
|
|
|
DEFINE_PROP_END_OF_LIST()
|
|
|
|
};
|
|
|
|
|
2011-12-04 22:22:06 +04:00
|
|
|
static void macio_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
|
2014-07-14 00:31:53 +04:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2011-12-04 22:22:06 +04:00
|
|
|
|
|
|
|
k->vendor_id = PCI_VENDOR_ID_APPLE;
|
|
|
|
k->class_id = PCI_CLASS_OTHERS << 8;
|
2020-01-10 18:30:32 +03:00
|
|
|
device_class_set_props(dc, macio_properties);
|
2015-09-26 19:22:10 +03:00
|
|
|
set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
|
2018-03-07 17:22:54 +03:00
|
|
|
/* Reason: Uses serial_hds in macio_instance_init */
|
|
|
|
dc->user_creatable = false;
|
2011-12-04 22:22:06 +04:00
|
|
|
}
|
|
|
|
|
2018-08-29 19:59:06 +03:00
|
|
|
static const TypeInfo macio_bus_info = {
|
|
|
|
.name = TYPE_MACIO_BUS,
|
2020-06-09 15:23:30 +03:00
|
|
|
.parent = TYPE_SYSTEM_BUS,
|
2018-08-29 19:59:06 +03:00
|
|
|
.instance_size = sizeof(MacIOBusState),
|
|
|
|
};
|
|
|
|
|
2013-01-24 03:03:57 +04:00
|
|
|
static const TypeInfo macio_oldworld_type_info = {
|
|
|
|
.name = TYPE_OLDWORLD_MACIO,
|
|
|
|
.parent = TYPE_MACIO,
|
2013-01-24 03:04:00 +04:00
|
|
|
.instance_size = sizeof(OldWorldMacIOState),
|
|
|
|
.instance_init = macio_oldworld_init,
|
2013-01-24 03:03:57 +04:00
|
|
|
.class_init = macio_oldworld_class_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const TypeInfo macio_newworld_type_info = {
|
|
|
|
.name = TYPE_NEWWORLD_MACIO,
|
|
|
|
.parent = TYPE_MACIO,
|
2013-01-24 03:04:01 +04:00
|
|
|
.instance_size = sizeof(NewWorldMacIOState),
|
|
|
|
.instance_init = macio_newworld_init,
|
2013-01-24 03:03:57 +04:00
|
|
|
.class_init = macio_newworld_class_init,
|
|
|
|
};
|
|
|
|
|
2013-01-24 03:03:55 +04:00
|
|
|
static const TypeInfo macio_type_info = {
|
|
|
|
.name = TYPE_MACIO,
|
2011-12-08 07:34:16 +04:00
|
|
|
.parent = TYPE_PCI_DEVICE,
|
|
|
|
.instance_size = sizeof(MacIOState),
|
2013-01-24 03:03:55 +04:00
|
|
|
.instance_init = macio_instance_init,
|
2013-01-24 03:03:57 +04:00
|
|
|
.abstract = true,
|
2011-12-08 07:34:16 +04:00
|
|
|
.class_init = macio_class_init,
|
2017-09-27 22:56:34 +03:00
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ INTERFACE_CONVENTIONAL_PCI_DEVICE },
|
|
|
|
{ },
|
|
|
|
},
|
2011-12-22 02:14:09 +04:00
|
|
|
};
|
|
|
|
|
2012-02-09 18:20:55 +04:00
|
|
|
static void macio_register_types(void)
|
2011-12-22 02:14:09 +04:00
|
|
|
{
|
2018-08-29 19:59:06 +03:00
|
|
|
type_register_static(&macio_bus_info);
|
2013-01-24 03:03:55 +04:00
|
|
|
type_register_static(&macio_type_info);
|
2013-01-24 03:03:57 +04:00
|
|
|
type_register_static(&macio_oldworld_type_info);
|
|
|
|
type_register_static(&macio_newworld_type_info);
|
2011-12-22 02:14:09 +04:00
|
|
|
}
|
|
|
|
|
2012-02-09 18:20:55 +04:00
|
|
|
type_init(macio_register_types)
|