2009-05-15 01:35:06 +04:00
|
|
|
/*
|
|
|
|
* System (CPU) Bus device support code
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009 CodeSourcery
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2020-10-23 15:44:24 +03:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2009-05-15 01:35:06 +04:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2009-07-17 00:47:01 +04:00
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2009-05-15 01:35:06 +04:00
|
|
|
*/
|
|
|
|
|
2016-01-26 21:17:29 +03:00
|
|
|
#include "qemu/osdep.h"
|
2018-05-28 17:45:08 +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/sysbus.h"
|
2012-12-17 21:19:49 +04:00
|
|
|
#include "monitor/monitor.h"
|
2012-12-17 21:19:49 +04:00
|
|
|
#include "exec/address-spaces.h"
|
2009-05-15 01:35:06 +04:00
|
|
|
|
2009-06-30 16:12:08 +04:00
|
|
|
static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent);
|
2010-12-08 14:35:00 +03:00
|
|
|
static char *sysbus_get_fw_dev_path(DeviceState *dev);
|
2009-06-30 16:12:08 +04:00
|
|
|
|
2014-09-24 15:06:57 +04:00
|
|
|
typedef struct SysBusFind {
|
|
|
|
void *opaque;
|
|
|
|
FindSysbusDeviceFunc *func;
|
|
|
|
} SysBusFind;
|
|
|
|
|
|
|
|
/* Run func() for every sysbus device, traverse the tree for everything else */
|
|
|
|
static int find_sysbus_device(Object *obj, void *opaque)
|
|
|
|
{
|
|
|
|
SysBusFind *find = opaque;
|
|
|
|
Object *dev;
|
|
|
|
SysBusDevice *sbdev;
|
|
|
|
|
|
|
|
dev = object_dynamic_cast(obj, TYPE_SYS_BUS_DEVICE);
|
|
|
|
sbdev = (SysBusDevice *)dev;
|
|
|
|
|
|
|
|
if (!sbdev) {
|
|
|
|
/* Container, traverse it for children */
|
|
|
|
return object_child_foreach(obj, find_sysbus_device, opaque);
|
|
|
|
}
|
|
|
|
|
|
|
|
find->func(sbdev, find->opaque);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Loop through all dynamically created sysbus devices and call
|
|
|
|
* func() for each instance.
|
|
|
|
*/
|
|
|
|
void foreach_dynamic_sysbus_device(FindSysbusDeviceFunc *func, void *opaque)
|
|
|
|
{
|
|
|
|
Object *container;
|
|
|
|
SysBusFind find = {
|
|
|
|
.func = func,
|
|
|
|
.opaque = opaque,
|
|
|
|
};
|
|
|
|
|
2020-08-06 16:09:44 +03:00
|
|
|
/* Loop through all sysbus devices that were spawned outside the machine */
|
2014-09-24 15:06:57 +04:00
|
|
|
container = container_get(qdev_get_machine(), "/peripheral");
|
|
|
|
find_sysbus_device(container, &find);
|
|
|
|
container = container_get(qdev_get_machine(), "/peripheral-anon");
|
|
|
|
find_sysbus_device(container, &find);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-02 11:00:20 +04:00
|
|
|
static void system_bus_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
BusClass *k = BUS_CLASS(klass);
|
|
|
|
|
|
|
|
k->print_dev = sysbus_dev_print;
|
|
|
|
k->get_fw_dev_path = sysbus_get_fw_dev_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo system_bus_info = {
|
|
|
|
.name = TYPE_SYSTEM_BUS,
|
|
|
|
.parent = TYPE_BUS,
|
|
|
|
.instance_size = sizeof(BusState),
|
|
|
|
.class_init = system_bus_class_init,
|
2009-06-30 16:12:08 +04:00
|
|
|
};
|
|
|
|
|
2014-09-24 14:32:17 +04:00
|
|
|
/* Check whether an IRQ source exists */
|
|
|
|
bool sysbus_has_irq(SysBusDevice *dev, int n)
|
|
|
|
{
|
|
|
|
char *prop = g_strdup_printf("%s[%d]", SYSBUS_DEVICE_GPIO_IRQ, n);
|
|
|
|
ObjectProperty *r;
|
|
|
|
|
2020-09-14 16:56:17 +03:00
|
|
|
r = object_property_find(OBJECT(dev), prop);
|
2015-02-27 10:50:18 +03:00
|
|
|
g_free(prop);
|
|
|
|
|
2014-09-24 14:32:17 +04:00
|
|
|
return (r != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool sysbus_is_irq_connected(SysBusDevice *dev, int n)
|
|
|
|
{
|
|
|
|
return !!sysbus_get_connected_irq(dev, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
qemu_irq sysbus_get_connected_irq(SysBusDevice *dev, int n)
|
|
|
|
{
|
|
|
|
DeviceState *d = DEVICE(dev);
|
|
|
|
return qdev_get_gpio_out_connector(d, SYSBUS_DEVICE_GPIO_IRQ, n);
|
|
|
|
}
|
|
|
|
|
2009-05-15 01:35:06 +04:00
|
|
|
void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq)
|
|
|
|
{
|
2015-07-06 21:15:14 +03:00
|
|
|
SysBusDeviceClass *sbd = SYS_BUS_DEVICE_GET_CLASS(dev);
|
|
|
|
|
2014-09-26 09:24:15 +04:00
|
|
|
qdev_connect_gpio_out_named(DEVICE(dev), SYSBUS_DEVICE_GPIO_IRQ, n, irq);
|
2015-07-06 21:15:14 +03:00
|
|
|
|
|
|
|
if (sbd->connect_irq_notifier) {
|
|
|
|
sbd->connect_irq_notifier(dev, irq);
|
|
|
|
}
|
2009-05-15 01:35:06 +04:00
|
|
|
}
|
|
|
|
|
2014-09-24 14:36:30 +04:00
|
|
|
/* Check whether an MMIO region exists */
|
|
|
|
bool sysbus_has_mmio(SysBusDevice *dev, unsigned int n)
|
|
|
|
{
|
|
|
|
return (n < dev->num_mmio);
|
|
|
|
}
|
|
|
|
|
2013-02-22 07:58:44 +04:00
|
|
|
static void sysbus_mmio_map_common(SysBusDevice *dev, int n, hwaddr addr,
|
2013-09-16 12:21:14 +04:00
|
|
|
bool may_overlap, int priority)
|
2009-05-15 01:35:06 +04:00
|
|
|
{
|
|
|
|
assert(n >= 0 && n < dev->num_mmio);
|
|
|
|
|
|
|
|
if (dev->mmio[n].addr == addr) {
|
|
|
|
/* ??? region already mapped here. */
|
|
|
|
return;
|
|
|
|
}
|
2012-10-23 14:30:10 +04:00
|
|
|
if (dev->mmio[n].addr != (hwaddr)-1) {
|
2009-05-15 01:35:06 +04:00
|
|
|
/* Unregister previous mapping. */
|
2011-12-20 00:33:59 +04:00
|
|
|
memory_region_del_subregion(get_system_memory(), dev->mmio[n].memory);
|
2009-05-15 01:35:06 +04:00
|
|
|
}
|
|
|
|
dev->mmio[n].addr = addr;
|
2013-02-22 07:58:44 +04:00
|
|
|
if (may_overlap) {
|
|
|
|
memory_region_add_subregion_overlap(get_system_memory(),
|
|
|
|
addr,
|
|
|
|
dev->mmio[n].memory,
|
|
|
|
priority);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
memory_region_add_subregion(get_system_memory(),
|
|
|
|
addr,
|
|
|
|
dev->mmio[n].memory);
|
|
|
|
}
|
2009-05-15 01:35:06 +04:00
|
|
|
}
|
|
|
|
|
2019-05-13 11:42:39 +03:00
|
|
|
void sysbus_mmio_unmap(SysBusDevice *dev, int n)
|
|
|
|
{
|
|
|
|
assert(n >= 0 && n < dev->num_mmio);
|
|
|
|
|
|
|
|
if (dev->mmio[n].addr != (hwaddr)-1) {
|
|
|
|
memory_region_del_subregion(get_system_memory(), dev->mmio[n].memory);
|
|
|
|
dev->mmio[n].addr = (hwaddr)-1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-22 07:58:44 +04:00
|
|
|
void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr)
|
|
|
|
{
|
|
|
|
sysbus_mmio_map_common(dev, n, addr, false, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr,
|
2013-09-16 12:21:14 +04:00
|
|
|
int priority)
|
2013-02-22 07:58:44 +04:00
|
|
|
{
|
|
|
|
sysbus_mmio_map_common(dev, n, addr, true, priority);
|
|
|
|
}
|
2009-05-15 01:35:06 +04:00
|
|
|
|
|
|
|
/* Request an IRQ source. The actual IRQ object may be populated later. */
|
|
|
|
void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p)
|
|
|
|
{
|
2014-09-26 09:24:15 +04:00
|
|
|
qdev_init_gpio_out_named(DEVICE(dev), p, SYSBUS_DEVICE_GPIO_IRQ, 1);
|
2009-05-15 01:35:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Pass IRQs from a target device. */
|
|
|
|
void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target)
|
|
|
|
{
|
2014-09-26 09:24:15 +04:00
|
|
|
qdev_pass_gpios(DEVICE(target), DEVICE(dev), SYSBUS_DEVICE_GPIO_IRQ);
|
2009-05-15 01:35:06 +04:00
|
|
|
}
|
|
|
|
|
2011-11-27 13:38:10 +04:00
|
|
|
void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory)
|
2011-07-26 15:26:21 +04:00
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
|
|
|
assert(dev->num_mmio < QDEV_MAX_MMIO);
|
|
|
|
n = dev->num_mmio++;
|
|
|
|
dev->mmio[n].addr = -1;
|
|
|
|
dev->mmio[n].memory = memory;
|
|
|
|
}
|
|
|
|
|
2011-08-28 20:22:17 +04:00
|
|
|
MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n)
|
|
|
|
{
|
2020-08-06 16:09:45 +03:00
|
|
|
assert(n >= 0 && n < QDEV_MAX_MMIO);
|
2011-08-28 20:22:17 +04:00
|
|
|
return dev->mmio[n].memory;
|
|
|
|
}
|
|
|
|
|
2016-03-16 12:20:34 +03:00
|
|
|
void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size)
|
2010-12-08 14:35:00 +03:00
|
|
|
{
|
2016-03-16 12:20:34 +03:00
|
|
|
uint32_t i;
|
2010-12-08 14:35:00 +03:00
|
|
|
|
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
assert(dev->num_pio < QDEV_MAX_PIO);
|
|
|
|
dev->pio[dev->num_pio++] = ioport++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-13 16:48:03 +03:00
|
|
|
/* The purpose of preserving this empty realize function
|
|
|
|
* is to prevent the parent_realize field of some subclasses
|
|
|
|
* from being set to NULL to break the normal init/realize
|
|
|
|
* of some devices.
|
|
|
|
*/
|
2020-06-10 08:32:33 +03:00
|
|
|
static void sysbus_device_realize(DeviceState *dev, Error **errp)
|
2009-05-15 01:35:06 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceState *sysbus_create_varargs(const char *name,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr addr, ...)
|
2009-05-15 01:35:06 +04:00
|
|
|
{
|
|
|
|
DeviceState *dev;
|
|
|
|
SysBusDevice *s;
|
|
|
|
va_list va;
|
|
|
|
qemu_irq irq;
|
|
|
|
int n;
|
|
|
|
|
qdev: Convert uses of qdev_create() with Coccinelle
This is the transformation explained in the commit before previous.
Takes care of just one pattern that needs conversion. More to come in
this series.
Coccinelle script:
@ depends on !(file in "hw/arm/highbank.c")@
expression bus, type_name, dev, expr;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr;
identifier DOWN;
@@
- dev = DOWN(qdev_create(bus, type_name));
+ dev = DOWN(qdev_new(type_name));
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ qdev_realize_and_unref(DEVICE(dev), bus, &error_fatal);
@@
expression bus, type_name, expr;
identifier dev;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr, errp;
symbol true;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
@@
expression bus, type_name, expr, errp;
identifier dev;
symbol true;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
The first rule exempts hw/arm/highbank.c, because it matches along two
control flow paths there, with different @type_name. Covered by the
next commit's manual conversions.
Missing #include "qapi/error.h" added manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-10-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 08:31:58 +03:00
|
|
|
dev = qdev_new(name);
|
2013-01-20 05:47:33 +04:00
|
|
|
s = SYS_BUS_DEVICE(dev);
|
sysbus: Convert to sysbus_realize() etc. with Coccinelle
Convert from qdev_realize(), qdev_realize_and_unref() with null @bus
argument to sysbus_realize(), sysbus_realize_and_unref().
Coccinelle script:
@@
expression dev, errp;
@@
- qdev_realize(DEVICE(dev), NULL, errp);
+ sysbus_realize(SYS_BUS_DEVICE(dev), errp);
@@
expression sysbus_dev, dev, errp;
@@
+ sysbus_dev = SYS_BUS_DEVICE(dev);
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
- sysbus_dev = SYS_BUS_DEVICE(dev);
@@
expression sysbus_dev, dev, errp;
expression expr;
@@
sysbus_dev = SYS_BUS_DEVICE(dev);
... when != dev = expr;
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(DEVICE(dev), NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
Whitespace changes minimized manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-46-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 08:32:34 +03:00
|
|
|
sysbus_realize_and_unref(s, &error_fatal);
|
2012-10-23 14:30:10 +04:00
|
|
|
if (addr != (hwaddr)-1) {
|
2009-05-15 01:35:06 +04:00
|
|
|
sysbus_mmio_map(s, 0, addr);
|
|
|
|
}
|
|
|
|
va_start(va, addr);
|
|
|
|
n = 0;
|
|
|
|
while (1) {
|
2011-02-05 17:34:56 +03:00
|
|
|
irq = va_arg(va, qemu_irq);
|
|
|
|
if (!irq) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sysbus_connect_irq(s, n, irq);
|
|
|
|
n++;
|
|
|
|
}
|
2011-10-28 12:52:25 +04:00
|
|
|
va_end(va);
|
2011-02-05 17:34:56 +03:00
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
2020-06-10 08:32:33 +03:00
|
|
|
bool sysbus_realize(SysBusDevice *dev, Error **errp)
|
|
|
|
{
|
|
|
|
return qdev_realize(DEVICE(dev), sysbus_get_default(), errp);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool sysbus_realize_and_unref(SysBusDevice *dev, Error **errp)
|
|
|
|
{
|
|
|
|
return qdev_realize_and_unref(DEVICE(dev), sysbus_get_default(), errp);
|
|
|
|
}
|
|
|
|
|
2009-06-30 16:12:08 +04:00
|
|
|
static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent)
|
2009-06-05 18:53:17 +04:00
|
|
|
{
|
2013-01-20 05:47:33 +04:00
|
|
|
SysBusDevice *s = SYS_BUS_DEVICE(dev);
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr size;
|
2009-06-05 18:53:17 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < s->num_mmio; i++) {
|
2011-12-20 00:33:59 +04:00
|
|
|
size = memory_region_size(s->mmio[i].memory);
|
2009-06-05 18:53:17 +04:00
|
|
|
monitor_printf(mon, "%*smmio " TARGET_FMT_plx "/" TARGET_FMT_plx "\n",
|
2011-11-27 13:32:34 +04:00
|
|
|
indent, "", s->mmio[i].addr, size);
|
2009-06-05 18:53:17 +04:00
|
|
|
}
|
|
|
|
}
|
2010-12-08 14:35:00 +03:00
|
|
|
|
|
|
|
static char *sysbus_get_fw_dev_path(DeviceState *dev)
|
|
|
|
{
|
2013-01-20 05:47:33 +04:00
|
|
|
SysBusDevice *s = SYS_BUS_DEVICE(dev);
|
2015-06-19 05:40:16 +03:00
|
|
|
SysBusDeviceClass *sbc = SYS_BUS_DEVICE_GET_CLASS(s);
|
|
|
|
char *addr, *fw_dev_path;
|
2010-12-08 14:35:00 +03:00
|
|
|
|
2015-06-19 05:40:16 +03:00
|
|
|
if (sbc->explicit_ofw_unit_address) {
|
|
|
|
addr = sbc->explicit_ofw_unit_address(s);
|
|
|
|
if (addr) {
|
|
|
|
fw_dev_path = g_strdup_printf("%s@%s", qdev_fw_name(dev), addr);
|
|
|
|
g_free(addr);
|
|
|
|
return fw_dev_path;
|
|
|
|
}
|
|
|
|
}
|
2018-08-05 14:28:49 +03:00
|
|
|
if (s->num_mmio) {
|
|
|
|
return g_strdup_printf("%s@" TARGET_FMT_plx, qdev_fw_name(dev),
|
|
|
|
s->mmio[0].addr);
|
|
|
|
}
|
|
|
|
if (s->num_pio) {
|
|
|
|
return g_strdup_printf("%s@i%04x", qdev_fw_name(dev), s->pio[0]);
|
|
|
|
}
|
2015-06-17 15:45:03 +03:00
|
|
|
return g_strdup(qdev_fw_name(dev));
|
2010-12-08 14:35:00 +03:00
|
|
|
}
|
2011-07-24 18:12:11 +04:00
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
void sysbus_add_io(SysBusDevice *dev, hwaddr addr,
|
2011-07-24 18:12:11 +04:00
|
|
|
MemoryRegion *mem)
|
|
|
|
{
|
|
|
|
memory_region_add_subregion(get_system_io(), addr, mem);
|
|
|
|
}
|
|
|
|
|
2011-12-08 17:57:34 +04:00
|
|
|
MemoryRegion *sysbus_address_space(SysBusDevice *dev)
|
|
|
|
{
|
|
|
|
return get_system_memory();
|
|
|
|
}
|
2012-01-24 23:12:29 +04:00
|
|
|
|
2011-12-08 07:34:16 +04:00
|
|
|
static void sysbus_device_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *k = DEVICE_CLASS(klass);
|
2020-06-10 08:32:33 +03:00
|
|
|
k->realize = sysbus_device_realize;
|
2012-05-02 11:00:20 +04:00
|
|
|
k->bus_type = TYPE_SYSTEM_BUS;
|
sysbus: Set user_creatable=false by default on TYPE_SYS_BUS_DEVICE
commit 33cd52b5d7b9adfd009e95f07e6c64dd88ae2a31 unset
cannot_instantiate_with_device_add_yet in TYPE_SYSBUS, making all
sysbus devices appear on "-device help" and lack the "no-user"
flag in "info qdm".
To fix this, we can set user_creatable=false by default on
TYPE_SYS_BUS_DEVICE, but this requires setting
user_creatable=true explicitly on the sysbus devices that
actually work with -device.
Fortunately today we have just a few has_dynamic_sysbus=1
machines: virt, pc-q35-*, ppce500, and spapr.
virt, ppce500, and spapr have extra checks to ensure just a few
device types can be instantiated:
* virt supports only TYPE_VFIO_CALXEDA_XGMAC, TYPE_VFIO_AMD_XGBE.
* ppce500 supports only TYPE_ETSEC_COMMON.
* spapr supports only TYPE_SPAPR_PCI_HOST_BRIDGE.
This patch sets user_creatable=true explicitly on those 4 device
classes.
Now, the more complex cases:
pc-q35-*: q35 has no sysbus device whitelist yet (which is a
separate bug). We are in the process of fixing it and building a
sysbus whitelist on q35, but in the meantime we can fix the
"-device help" and "info qdm" bugs mentioned above. Also, despite
not being strictly necessary for fixing the q35 bug, reducing the
list of user_creatable=true devices will help us be more
confident when building the q35 whitelist.
xen: We also have a hack at xen_set_dynamic_sysbus(), that sets
has_dynamic_sysbus=true at runtime when using the Xen
accelerator. This hack is only used to allow xen-backend devices
to be dynamically plugged/unplugged.
This means today we can use -device with the following 22 device
types, that are the ones compiled into the qemu-system-x86_64 and
qemu-system-i386 binaries:
* allwinner-ahci
* amd-iommu
* cfi.pflash01
* esp
* fw_cfg_io
* fw_cfg_mem
* generic-sdhci
* hpet
* intel-iommu
* ioapic
* isabus-bridge
* kvmclock
* kvm-ioapic
* kvmvapic
* SUNW,fdtwo
* sysbus-ahci
* sysbus-fdc
* sysbus-ohci
* unimplemented-device
* virtio-mmio
* xen-backend
* xen-sysdev
This patch adds user_creatable=true explicitly to those devices,
temporarily, just to keep 100% compatibility with existing
behavior of q35. Subsequent patches will remove
user_creatable=true from the devices that are really not meant to
user-creatable on any machine, and remove the FIXME comment from
the ones that are really supposed to be user-creatable. This is
being done in separate patches because we still don't have an
obvious list of devices that will be whitelisted by q35, and I
would like to get each device reviewed individually.
Cc: Alexander Graf <agraf@suse.de>
Cc: Alex Williamson <alex.williamson@redhat.com>
Cc: Alistair Francis <alistair.francis@xilinx.com>
Cc: Beniamino Galvani <b.galvani@gmail.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Cornelia Huck <cornelia.huck@de.ibm.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Cc: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: Frank Blaschka <frank.blaschka@de.ibm.com>
Cc: Gabriel L. Somlo <somlo@cmu.edu>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: John Snow <jsnow@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Marcel Apfelbaum <marcel@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
Cc: Max Reitz <mreitz@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>
Cc: Pierre Morel <pmorel@linux.vnet.ibm.com>
Cc: Prasad J Pandit <pjp@fedoraproject.org>
Cc: qemu-arm@nongnu.org
Cc: qemu-block@nongnu.org
Cc: qemu-ppc@nongnu.org
Cc: Richard Henderson <rth@twiddle.net>
Cc: Rob Herring <robh@kernel.org>
Cc: Shannon Zhao <zhaoshenglong@huawei.com>
Cc: sstabellini@kernel.org
Cc: Thomas Huth <thuth@redhat.com>
Cc: Yi Min Zhao <zyimin@linux.vnet.ibm.com>
Acked-by: John Snow <jsnow@redhat.com>
Acked-by: Juergen Gross <jgross@suse.com>
Acked-by: Marcel Apfelbaum <marcel@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Message-Id: <20170503203604.31462-3-ehabkost@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[ehabkost: Small changes at sysbus_device_class_init() comments]
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2017-05-03 23:35:45 +03:00
|
|
|
/*
|
|
|
|
* device_add plugs devices into a suitable bus. For "real" buses,
|
|
|
|
* that actually connects the device. For sysbus, the connections
|
|
|
|
* need to be made separately, and device_add can't do that. The
|
|
|
|
* device would be left unconnected, and will probably not work
|
|
|
|
*
|
|
|
|
* However, a few machines can handle device_add/-device with
|
|
|
|
* a few specific sysbus devices. In those cases, the device
|
|
|
|
* subclass needs to override it and set user_creatable=true.
|
|
|
|
*/
|
|
|
|
k->user_creatable = false;
|
2011-12-08 07:34:16 +04:00
|
|
|
}
|
|
|
|
|
2013-01-10 19:19:07 +04:00
|
|
|
static const TypeInfo sysbus_device_type_info = {
|
2012-01-24 23:12:29 +04:00
|
|
|
.name = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.parent = TYPE_DEVICE,
|
|
|
|
.instance_size = sizeof(SysBusDevice),
|
|
|
|
.abstract = true,
|
|
|
|
.class_size = sizeof(SysBusDeviceClass),
|
2011-12-08 07:34:16 +04:00
|
|
|
.class_init = sysbus_device_class_init,
|
2012-01-24 23:12:29 +04:00
|
|
|
};
|
|
|
|
|
2012-05-02 14:06:55 +04:00
|
|
|
static BusState *main_system_bus;
|
|
|
|
|
|
|
|
static void main_system_bus_create(void)
|
|
|
|
{
|
|
|
|
/* assign main_system_bus before qbus_create_inplace()
|
|
|
|
* in order to make "if (bus != sysbus_get_default())" work */
|
2012-05-02 11:00:20 +04:00
|
|
|
main_system_bus = g_malloc0(system_bus_info.instance_size);
|
2013-08-24 02:02:27 +04:00
|
|
|
qbus_create_inplace(main_system_bus, system_bus_info.instance_size,
|
|
|
|
TYPE_SYSTEM_BUS, NULL, "main-system-bus");
|
2012-11-23 12:47:15 +04:00
|
|
|
OBJECT(main_system_bus)->free = g_free;
|
2012-05-02 14:06:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BusState *sysbus_get_default(void)
|
|
|
|
{
|
|
|
|
if (!main_system_bus) {
|
|
|
|
main_system_bus_create();
|
|
|
|
}
|
|
|
|
return main_system_bus;
|
|
|
|
}
|
|
|
|
|
2012-02-09 18:20:55 +04:00
|
|
|
static void sysbus_register_types(void)
|
2012-01-24 23:12:29 +04:00
|
|
|
{
|
2012-05-02 11:00:20 +04:00
|
|
|
type_register_static(&system_bus_info);
|
2012-01-24 23:12:29 +04:00
|
|
|
type_register_static(&sysbus_device_type_info);
|
|
|
|
}
|
|
|
|
|
2012-02-09 18:20:55 +04:00
|
|
|
type_init(sysbus_register_types)
|