2006-09-03 18:09:07 +02:00
|
|
|
/*
|
|
|
|
* QEMU Sparc32 DMA controller emulation
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006 Fabrice Bellard
|
|
|
|
*
|
2010-02-15 18:39:50 +01:00
|
|
|
* Modifications:
|
|
|
|
* 2010-Feb-14 Artyom Tarasenko : reworked irq generation
|
|
|
|
*
|
2006-09-03 18:09:07 +02:00
|
|
|
* 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.
|
|
|
|
*/
|
2009-07-15 22:45:19 +02:00
|
|
|
|
2016-01-26 19:17:30 +01:00
|
|
|
#include "qemu/osdep.h"
|
2019-08-12 07:23:42 +02:00
|
|
|
#include "hw/irq.h"
|
2019-08-12 07:23:51 +02:00
|
|
|
#include "hw/qdev-properties.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/sparc/sparc32_dma.h"
|
2018-01-08 19:16:34 +01:00
|
|
|
#include "hw/sparc/sun4m_iommu.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/sysbus.h"
|
2019-08-12 07:23:45 +02:00
|
|
|
#include "migration/vmstate.h"
|
2017-10-27 14:09:03 +02:00
|
|
|
#include "sysemu/dma.h"
|
2017-10-14 14:22:22 +02:00
|
|
|
#include "qapi/error.h"
|
2019-05-23 16:35:07 +02:00
|
|
|
#include "qemu/module.h"
|
2010-10-31 10:24:14 +01:00
|
|
|
#include "trace.h"
|
2006-09-03 18:09:07 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the DMA controller part of chip STP2000 (Master I/O), also
|
|
|
|
* produced as NCR89C100. See
|
|
|
|
* http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C100.txt
|
|
|
|
* and
|
|
|
|
* http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/DMA2.txt
|
|
|
|
*/
|
|
|
|
|
2007-05-26 19:39:43 +02:00
|
|
|
#define DMA_SIZE (4 * sizeof(uint32_t))
|
2008-12-15 21:24:25 +01:00
|
|
|
/* We need the mask, because one instance of the device is not page
|
|
|
|
aligned (ledma, start address 0x0010) */
|
|
|
|
#define DMA_MASK (DMA_SIZE - 1)
|
2010-12-20 18:55:33 +01:00
|
|
|
/* OBP says 0x20 bytes for ledma, the extras are aliased to espdma */
|
2010-12-18 18:09:04 +01:00
|
|
|
#define DMA_ETH_SIZE (8 * sizeof(uint32_t))
|
|
|
|
#define DMA_MAX_REG_OFFSET (2 * DMA_SIZE - 1)
|
2006-09-03 18:09:07 +02:00
|
|
|
|
|
|
|
#define DMA_VER 0xa0000000
|
|
|
|
#define DMA_INTR 1
|
|
|
|
#define DMA_INTREN 0x10
|
|
|
|
#define DMA_WRITE_MEM 0x100
|
2010-09-11 18:38:33 +02:00
|
|
|
#define DMA_EN 0x200
|
2006-09-03 18:09:07 +02:00
|
|
|
#define DMA_LOADED 0x04000000
|
2007-05-26 19:39:43 +02:00
|
|
|
#define DMA_DRAIN_FIFO 0x40
|
2006-09-03 18:09:07 +02:00
|
|
|
#define DMA_RESET 0x80
|
|
|
|
|
2010-05-22 10:38:56 +02:00
|
|
|
/* XXX SCSI and ethernet should have different read-only bit masks */
|
|
|
|
#define DMA_CSR_RO_MASK 0xfe000007
|
|
|
|
|
2010-09-11 18:38:33 +02:00
|
|
|
enum {
|
|
|
|
GPIO_RESET = 0,
|
|
|
|
GPIO_DMA,
|
2006-09-03 18:09:07 +02:00
|
|
|
};
|
|
|
|
|
2006-09-03 21:48:17 +02:00
|
|
|
/* Note: on sparc, the lance 16 bit bus is swapped */
|
2012-10-23 12:30:10 +02:00
|
|
|
void ledma_memory_read(void *opaque, hwaddr addr,
|
2006-09-03 21:48:17 +02:00
|
|
|
uint8_t *buf, int len, int do_bswap)
|
2006-09-03 18:09:07 +02:00
|
|
|
{
|
2017-10-14 14:22:21 +02:00
|
|
|
DMADeviceState *s = opaque;
|
2017-10-27 14:09:03 +02:00
|
|
|
IOMMUState *is = (IOMMUState *)s->iommu;
|
2006-09-03 21:48:17 +02:00
|
|
|
int i;
|
2006-09-03 18:09:07 +02:00
|
|
|
|
2007-05-26 19:39:43 +02:00
|
|
|
addr |= s->dmaregs[3];
|
2017-10-14 14:22:22 +02:00
|
|
|
trace_ledma_memory_read(addr, len);
|
2006-09-03 21:48:17 +02:00
|
|
|
if (do_bswap) {
|
2017-10-27 14:09:03 +02:00
|
|
|
dma_memory_read(&is->iommu_as, addr, buf, len);
|
2006-09-03 21:48:17 +02:00
|
|
|
} else {
|
|
|
|
addr &= ~1;
|
|
|
|
len &= ~1;
|
2017-10-27 14:09:03 +02:00
|
|
|
dma_memory_read(&is->iommu_as, addr, buf, len);
|
2006-09-03 21:48:17 +02:00
|
|
|
for(i = 0; i < len; i += 2) {
|
|
|
|
bswap16s((uint16_t *)(buf + i));
|
|
|
|
}
|
|
|
|
}
|
2006-09-03 18:09:07 +02:00
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
void ledma_memory_write(void *opaque, hwaddr addr,
|
2006-09-03 21:48:17 +02:00
|
|
|
uint8_t *buf, int len, int do_bswap)
|
2006-09-03 18:09:07 +02:00
|
|
|
{
|
2017-10-14 14:22:21 +02:00
|
|
|
DMADeviceState *s = opaque;
|
2017-10-27 14:09:03 +02:00
|
|
|
IOMMUState *is = (IOMMUState *)s->iommu;
|
2006-09-03 21:48:17 +02:00
|
|
|
int l, i;
|
|
|
|
uint16_t tmp_buf[32];
|
2006-09-03 18:09:07 +02:00
|
|
|
|
2007-05-26 19:39:43 +02:00
|
|
|
addr |= s->dmaregs[3];
|
2017-10-14 14:22:22 +02:00
|
|
|
trace_ledma_memory_write(addr, len);
|
2006-09-03 21:48:17 +02:00
|
|
|
if (do_bswap) {
|
2017-10-27 14:09:03 +02:00
|
|
|
dma_memory_write(&is->iommu_as, addr, buf, len);
|
2006-09-03 21:48:17 +02:00
|
|
|
} else {
|
|
|
|
addr &= ~1;
|
|
|
|
len &= ~1;
|
|
|
|
while (len > 0) {
|
|
|
|
l = len;
|
|
|
|
if (l > sizeof(tmp_buf))
|
|
|
|
l = sizeof(tmp_buf);
|
|
|
|
for(i = 0; i < l; i += 2) {
|
|
|
|
tmp_buf[i >> 1] = bswap16(*(uint16_t *)(buf + i));
|
|
|
|
}
|
2017-10-27 14:09:03 +02:00
|
|
|
dma_memory_write(&is->iommu_as, addr, tmp_buf, l);
|
2006-09-03 21:48:17 +02:00
|
|
|
len -= l;
|
|
|
|
buf += l;
|
|
|
|
addr += l;
|
|
|
|
}
|
|
|
|
}
|
2006-09-03 18:09:07 +02:00
|
|
|
}
|
|
|
|
|
2007-05-27 18:36:10 +02:00
|
|
|
static void dma_set_irq(void *opaque, int irq, int level)
|
2006-09-03 18:09:07 +02:00
|
|
|
{
|
2017-10-14 14:22:21 +02:00
|
|
|
DMADeviceState *s = opaque;
|
2007-05-27 18:36:10 +02:00
|
|
|
if (level) {
|
|
|
|
s->dmaregs[0] |= DMA_INTR;
|
2010-02-15 18:39:50 +01:00
|
|
|
if (s->dmaregs[0] & DMA_INTREN) {
|
2010-10-31 10:24:14 +01:00
|
|
|
trace_sparc32_dma_set_irq_raise();
|
2010-02-15 18:39:50 +01:00
|
|
|
qemu_irq_raise(s->irq);
|
|
|
|
}
|
2007-05-27 18:36:10 +02:00
|
|
|
} else {
|
2010-02-15 18:39:50 +01:00
|
|
|
if (s->dmaregs[0] & DMA_INTR) {
|
|
|
|
s->dmaregs[0] &= ~DMA_INTR;
|
|
|
|
if (s->dmaregs[0] & DMA_INTREN) {
|
2010-10-31 10:24:14 +01:00
|
|
|
trace_sparc32_dma_set_irq_lower();
|
2010-02-15 18:39:50 +01:00
|
|
|
qemu_irq_lower(s->irq);
|
|
|
|
}
|
|
|
|
}
|
2007-05-27 18:36:10 +02:00
|
|
|
}
|
2006-09-03 18:09:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void espdma_memory_read(void *opaque, uint8_t *buf, int len)
|
|
|
|
{
|
2017-10-14 14:22:21 +02:00
|
|
|
DMADeviceState *s = opaque;
|
2017-10-27 14:09:03 +02:00
|
|
|
IOMMUState *is = (IOMMUState *)s->iommu;
|
2006-09-03 18:09:07 +02:00
|
|
|
|
2017-10-14 14:22:22 +02:00
|
|
|
trace_espdma_memory_read(s->dmaregs[1], len);
|
2017-10-27 14:09:03 +02:00
|
|
|
dma_memory_read(&is->iommu_as, s->dmaregs[1], buf, len);
|
2006-09-03 18:09:07 +02:00
|
|
|
s->dmaregs[1] += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
void espdma_memory_write(void *opaque, uint8_t *buf, int len)
|
|
|
|
{
|
2017-10-14 14:22:21 +02:00
|
|
|
DMADeviceState *s = opaque;
|
2017-10-27 14:09:03 +02:00
|
|
|
IOMMUState *is = (IOMMUState *)s->iommu;
|
2006-09-03 18:09:07 +02:00
|
|
|
|
2017-10-14 14:22:22 +02:00
|
|
|
trace_espdma_memory_write(s->dmaregs[1], len);
|
2017-10-27 14:09:03 +02:00
|
|
|
dma_memory_write(&is->iommu_as, s->dmaregs[1], buf, len);
|
2006-09-03 18:09:07 +02:00
|
|
|
s->dmaregs[1] += len;
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static uint64_t dma_mem_read(void *opaque, hwaddr addr,
|
2011-11-14 10:55:27 +01:00
|
|
|
unsigned size)
|
2006-09-03 18:09:07 +02:00
|
|
|
{
|
2017-10-14 14:22:21 +02:00
|
|
|
DMADeviceState *s = opaque;
|
2006-09-03 18:09:07 +02:00
|
|
|
uint32_t saddr;
|
|
|
|
|
2008-12-15 21:24:25 +01:00
|
|
|
saddr = (addr & DMA_MASK) >> 2;
|
2010-10-31 10:24:14 +01:00
|
|
|
trace_sparc32_dma_mem_readl(addr, s->dmaregs[saddr]);
|
2006-09-03 18:09:07 +02:00
|
|
|
return s->dmaregs[saddr];
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static void dma_mem_write(void *opaque, hwaddr addr,
|
2011-11-14 10:55:27 +01:00
|
|
|
uint64_t val, unsigned size)
|
2006-09-03 18:09:07 +02:00
|
|
|
{
|
2017-10-14 14:22:21 +02:00
|
|
|
DMADeviceState *s = opaque;
|
2006-09-03 18:09:07 +02:00
|
|
|
uint32_t saddr;
|
|
|
|
|
2008-12-15 21:24:25 +01:00
|
|
|
saddr = (addr & DMA_MASK) >> 2;
|
2010-10-31 10:24:14 +01:00
|
|
|
trace_sparc32_dma_mem_writel(addr, s->dmaregs[saddr], val);
|
2006-09-03 18:09:07 +02:00
|
|
|
switch (saddr) {
|
|
|
|
case 0:
|
2010-02-15 18:39:50 +01:00
|
|
|
if (val & DMA_INTREN) {
|
2010-05-22 10:38:56 +02:00
|
|
|
if (s->dmaregs[0] & DMA_INTR) {
|
2010-10-31 10:24:14 +01:00
|
|
|
trace_sparc32_dma_set_irq_raise();
|
2010-02-15 18:39:50 +01:00
|
|
|
qemu_irq_raise(s->irq);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (s->dmaregs[0] & (DMA_INTR | DMA_INTREN)) {
|
2010-10-31 10:24:14 +01:00
|
|
|
trace_sparc32_dma_set_irq_lower();
|
2010-02-15 18:39:50 +01:00
|
|
|
qemu_irq_lower(s->irq);
|
|
|
|
}
|
2007-04-07 20:14:41 +02:00
|
|
|
}
|
2006-09-03 18:09:07 +02:00
|
|
|
if (val & DMA_RESET) {
|
2010-09-11 18:38:33 +02:00
|
|
|
qemu_irq_raise(s->gpio[GPIO_RESET]);
|
|
|
|
qemu_irq_lower(s->gpio[GPIO_RESET]);
|
2007-05-26 19:39:43 +02:00
|
|
|
} else if (val & DMA_DRAIN_FIFO) {
|
|
|
|
val &= ~DMA_DRAIN_FIFO;
|
2006-09-03 18:09:07 +02:00
|
|
|
} else if (val == 0)
|
2007-05-26 19:39:43 +02:00
|
|
|
val = DMA_DRAIN_FIFO;
|
2010-09-11 18:38:33 +02:00
|
|
|
|
|
|
|
if (val & DMA_EN && !(s->dmaregs[0] & DMA_EN)) {
|
2010-10-31 10:24:14 +01:00
|
|
|
trace_sparc32_dma_enable_raise();
|
2010-09-11 18:38:33 +02:00
|
|
|
qemu_irq_raise(s->gpio[GPIO_DMA]);
|
|
|
|
} else if (!(val & DMA_EN) && !!(s->dmaregs[0] & DMA_EN)) {
|
2010-10-31 10:24:14 +01:00
|
|
|
trace_sparc32_dma_enable_lower();
|
2010-09-11 18:38:33 +02:00
|
|
|
qemu_irq_lower(s->gpio[GPIO_DMA]);
|
|
|
|
}
|
|
|
|
|
2010-05-22 10:38:56 +02:00
|
|
|
val &= ~DMA_CSR_RO_MASK;
|
2006-09-03 18:09:07 +02:00
|
|
|
val |= DMA_VER;
|
2010-05-22 10:38:56 +02:00
|
|
|
s->dmaregs[0] = (s->dmaregs[0] & DMA_CSR_RO_MASK) | val;
|
2006-09-03 18:09:07 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
s->dmaregs[0] |= DMA_LOADED;
|
2010-05-22 10:38:56 +02:00
|
|
|
/* fall through */
|
2006-09-03 18:09:07 +02:00
|
|
|
default:
|
2010-05-22 10:38:56 +02:00
|
|
|
s->dmaregs[saddr] = val;
|
2006-09-03 18:09:07 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-14 10:55:27 +01:00
|
|
|
static const MemoryRegionOps dma_mem_ops = {
|
|
|
|
.read = dma_mem_read,
|
|
|
|
.write = dma_mem_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
|
|
|
.valid = {
|
|
|
|
.min_access_size = 4,
|
|
|
|
.max_access_size = 4,
|
|
|
|
},
|
2006-09-03 18:09:07 +02:00
|
|
|
};
|
|
|
|
|
2017-10-14 14:22:21 +02:00
|
|
|
static void sparc32_dma_device_reset(DeviceState *d)
|
2006-09-03 18:09:07 +02:00
|
|
|
{
|
2017-10-14 14:22:21 +02:00
|
|
|
DMADeviceState *s = SPARC32_DMA_DEVICE(d);
|
2006-09-03 18:09:07 +02:00
|
|
|
|
2007-05-26 19:39:43 +02:00
|
|
|
memset(s->dmaregs, 0, DMA_SIZE);
|
2006-09-03 18:09:07 +02:00
|
|
|
s->dmaregs[0] = DMA_VER;
|
|
|
|
}
|
|
|
|
|
2017-10-14 14:22:21 +02:00
|
|
|
static const VMStateDescription vmstate_sparc32_dma_device = {
|
2009-08-28 22:46:15 +02:00
|
|
|
.name ="sparc32_dma",
|
|
|
|
.version_id = 2,
|
|
|
|
.minimum_version_id = 2,
|
2014-04-16 16:01:33 +02:00
|
|
|
.fields = (VMStateField[]) {
|
2017-10-14 14:22:21 +02:00
|
|
|
VMSTATE_UINT32_ARRAY(dmaregs, DMADeviceState, DMA_REGS),
|
2009-08-28 22:46:15 +02:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
2006-09-03 18:09:07 +02:00
|
|
|
|
2017-10-14 14:22:21 +02:00
|
|
|
static void sparc32_dma_device_init(Object *obj)
|
2009-07-15 22:45:19 +02:00
|
|
|
{
|
2017-05-25 15:34:45 +02:00
|
|
|
DeviceState *dev = DEVICE(obj);
|
2017-10-14 14:22:21 +02:00
|
|
|
DMADeviceState *s = SPARC32_DMA_DEVICE(obj);
|
2017-05-25 15:34:45 +02:00
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
2006-09-03 18:09:07 +02:00
|
|
|
|
2013-07-26 16:55:59 +02:00
|
|
|
sysbus_init_irq(sbd, &s->irq);
|
2006-09-03 18:09:07 +02:00
|
|
|
|
2013-07-26 16:55:59 +02:00
|
|
|
sysbus_init_mmio(sbd, &s->iomem);
|
2006-09-03 18:09:07 +02:00
|
|
|
|
2017-10-14 14:22:21 +02:00
|
|
|
object_property_add_link(OBJECT(dev), "iommu", TYPE_SUN4M_IOMMU,
|
|
|
|
(Object **) &s->iommu,
|
|
|
|
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 17:29:22 +02:00
|
|
|
0);
|
2017-10-14 14:22:21 +02:00
|
|
|
|
2013-07-26 16:55:59 +02:00
|
|
|
qdev_init_gpio_in(dev, dma_set_irq, 1);
|
|
|
|
qdev_init_gpio_out(dev, s->gpio, 2);
|
2017-05-25 15:34:45 +02:00
|
|
|
}
|
2009-10-24 21:35:32 +02:00
|
|
|
|
2017-10-14 14:22:21 +02:00
|
|
|
static void sparc32_dma_device_class_init(ObjectClass *klass, void *data)
|
2012-01-24 20:12:29 +01:00
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2017-10-14 14:22:21 +02:00
|
|
|
dc->reset = sparc32_dma_device_reset;
|
|
|
|
dc->vmsd = &vmstate_sparc32_dma_device;
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2017-10-14 14:22:21 +02:00
|
|
|
static const TypeInfo sparc32_dma_device_info = {
|
|
|
|
.name = TYPE_SPARC32_DMA_DEVICE,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
2017-10-14 14:22:21 +02:00
|
|
|
.abstract = true,
|
2017-10-14 14:22:21 +02:00
|
|
|
.instance_size = sizeof(DMADeviceState),
|
|
|
|
.instance_init = sparc32_dma_device_init,
|
|
|
|
.class_init = sparc32_dma_device_class_init,
|
2009-07-15 22:45:19 +02:00
|
|
|
};
|
|
|
|
|
2017-10-14 14:22:21 +02:00
|
|
|
static void sparc32_espdma_device_init(Object *obj)
|
|
|
|
{
|
|
|
|
DMADeviceState *s = SPARC32_DMA_DEVICE(obj);
|
|
|
|
|
|
|
|
memory_region_init_io(&s->iomem, OBJECT(s), &dma_mem_ops, s,
|
|
|
|
"espdma-mmio", DMA_SIZE);
|
|
|
|
}
|
|
|
|
|
2017-10-14 14:22:22 +02:00
|
|
|
static void sparc32_espdma_device_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
DeviceState *d;
|
|
|
|
SysBusESPState *sysbus;
|
|
|
|
ESPState *esp;
|
|
|
|
|
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 07:31:58 +02:00
|
|
|
d = qdev_new(TYPE_ESP);
|
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), "esp", OBJECT(d));
|
2017-10-14 14:22:22 +02:00
|
|
|
sysbus = ESP_STATE(d);
|
|
|
|
esp = &sysbus->esp;
|
|
|
|
esp->dma_memory_read = espdma_memory_read;
|
|
|
|
esp->dma_memory_write = espdma_memory_write;
|
|
|
|
esp->dma_opaque = SPARC32_DMA_DEVICE(dev);
|
|
|
|
sysbus->it_shift = 2;
|
|
|
|
esp->dma_enabled = 1;
|
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 07:32:34 +02:00
|
|
|
sysbus_realize_and_unref(SYS_BUS_DEVICE(d), &error_fatal);
|
2017-10-14 14:22:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sparc32_espdma_device_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
|
|
|
|
dc->realize = sparc32_espdma_device_realize;
|
|
|
|
}
|
|
|
|
|
2017-10-14 14:22:21 +02:00
|
|
|
static const TypeInfo sparc32_espdma_device_info = {
|
|
|
|
.name = TYPE_SPARC32_ESPDMA_DEVICE,
|
|
|
|
.parent = TYPE_SPARC32_DMA_DEVICE,
|
|
|
|
.instance_size = sizeof(ESPDMADeviceState),
|
|
|
|
.instance_init = sparc32_espdma_device_init,
|
2017-10-14 14:22:22 +02:00
|
|
|
.class_init = sparc32_espdma_device_class_init,
|
2017-10-14 14:22:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void sparc32_ledma_device_init(Object *obj)
|
|
|
|
{
|
|
|
|
DMADeviceState *s = SPARC32_DMA_DEVICE(obj);
|
|
|
|
|
|
|
|
memory_region_init_io(&s->iomem, OBJECT(s), &dma_mem_ops, s,
|
2017-10-14 14:22:22 +02:00
|
|
|
"ledma-mmio", DMA_SIZE);
|
2017-10-14 14:22:21 +02:00
|
|
|
}
|
|
|
|
|
2017-10-14 14:22:22 +02:00
|
|
|
static void sparc32_ledma_device_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
DeviceState *d;
|
|
|
|
NICInfo *nd = &nd_table[0];
|
|
|
|
|
2020-07-15 16:04:40 +02:00
|
|
|
/* FIXME use qdev NIC properties instead of nd_table[] */
|
2017-10-14 14:22:22 +02:00
|
|
|
qemu_check_nic_model(nd, TYPE_LANCE);
|
|
|
|
|
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 07:31:58 +02:00
|
|
|
d = qdev_new(TYPE_LANCE);
|
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), "lance", OBJECT(d));
|
2017-10-14 14:22:22 +02:00
|
|
|
qdev_set_nic_properties(d, nd);
|
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 18:05:54 +02:00
|
|
|
object_property_set_link(OBJECT(d), "dma", OBJECT(dev), &error_abort);
|
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 07:32:34 +02:00
|
|
|
sysbus_realize_and_unref(SYS_BUS_DEVICE(d), &error_fatal);
|
2017-10-14 14:22:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sparc32_ledma_device_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
|
|
|
|
dc->realize = sparc32_ledma_device_realize;
|
|
|
|
}
|
|
|
|
|
2017-10-14 14:22:21 +02:00
|
|
|
static const TypeInfo sparc32_ledma_device_info = {
|
|
|
|
.name = TYPE_SPARC32_LEDMA_DEVICE,
|
|
|
|
.parent = TYPE_SPARC32_DMA_DEVICE,
|
|
|
|
.instance_size = sizeof(LEDMADeviceState),
|
|
|
|
.instance_init = sparc32_ledma_device_init,
|
2017-10-14 14:22:22 +02:00
|
|
|
.class_init = sparc32_ledma_device_class_init,
|
2017-10-14 14:22:21 +02:00
|
|
|
};
|
|
|
|
|
2017-10-14 14:22:22 +02:00
|
|
|
static void sparc32_dma_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
SPARC32DMAState *s = SPARC32_DMA(dev);
|
|
|
|
DeviceState *espdma, *esp, *ledma, *lance;
|
|
|
|
SysBusDevice *sbd;
|
|
|
|
Object *iommu;
|
|
|
|
|
|
|
|
iommu = object_resolve_path_type("", TYPE_SUN4M_IOMMU, NULL);
|
|
|
|
if (!iommu) {
|
|
|
|
error_setg(errp, "unable to locate sun4m IOMMU device");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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 07:31:58 +02:00
|
|
|
espdma = qdev_new(TYPE_SPARC32_ESPDMA_DEVICE);
|
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 18:05:54 +02:00
|
|
|
object_property_set_link(OBJECT(espdma), "iommu", iommu, &error_abort);
|
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(s), "espdma", OBJECT(espdma));
|
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 07:32:34 +02:00
|
|
|
sysbus_realize_and_unref(SYS_BUS_DEVICE(espdma), &error_fatal);
|
2017-10-14 14:22:22 +02:00
|
|
|
|
|
|
|
esp = DEVICE(object_resolve_path_component(OBJECT(espdma), "esp"));
|
|
|
|
sbd = SYS_BUS_DEVICE(esp);
|
|
|
|
sysbus_connect_irq(sbd, 0, qdev_get_gpio_in(espdma, 0));
|
|
|
|
qdev_connect_gpio_out(espdma, 0, qdev_get_gpio_in(esp, 0));
|
|
|
|
qdev_connect_gpio_out(espdma, 1, qdev_get_gpio_in(esp, 1));
|
|
|
|
|
|
|
|
sbd = SYS_BUS_DEVICE(espdma);
|
|
|
|
memory_region_add_subregion(&s->dmamem, 0x0,
|
|
|
|
sysbus_mmio_get_region(sbd, 0));
|
|
|
|
|
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 07:31:58 +02:00
|
|
|
ledma = qdev_new(TYPE_SPARC32_LEDMA_DEVICE);
|
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 18:05:54 +02:00
|
|
|
object_property_set_link(OBJECT(ledma), "iommu", iommu, &error_abort);
|
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(s), "ledma", OBJECT(ledma));
|
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 07:32:34 +02:00
|
|
|
sysbus_realize_and_unref(SYS_BUS_DEVICE(ledma), &error_fatal);
|
2017-10-14 14:22:22 +02:00
|
|
|
|
|
|
|
lance = DEVICE(object_resolve_path_component(OBJECT(ledma), "lance"));
|
|
|
|
sbd = SYS_BUS_DEVICE(lance);
|
|
|
|
sysbus_connect_irq(sbd, 0, qdev_get_gpio_in(ledma, 0));
|
|
|
|
qdev_connect_gpio_out(ledma, 0, qdev_get_gpio_in(lance, 0));
|
|
|
|
|
|
|
|
sbd = SYS_BUS_DEVICE(ledma);
|
|
|
|
memory_region_add_subregion(&s->dmamem, 0x10,
|
|
|
|
sysbus_mmio_get_region(sbd, 0));
|
2017-10-14 14:22:22 +02:00
|
|
|
|
|
|
|
/* Add ledma alias to handle SunOS 5.7 - Solaris 9 invalid access bug */
|
|
|
|
memory_region_init_alias(&s->ledma_alias, OBJECT(dev), "ledma-alias",
|
|
|
|
sysbus_mmio_get_region(sbd, 0), 0x4, 0x4);
|
|
|
|
memory_region_add_subregion(&s->dmamem, 0x20, &s->ledma_alias);
|
2017-10-14 14:22:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sparc32_dma_init(Object *obj)
|
|
|
|
{
|
|
|
|
SPARC32DMAState *s = SPARC32_DMA(obj);
|
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
|
|
|
|
|
|
|
memory_region_init(&s->dmamem, OBJECT(s), "dma", DMA_SIZE + DMA_ETH_SIZE);
|
|
|
|
sysbus_init_mmio(sbd, &s->dmamem);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sparc32_dma_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
|
|
|
|
dc->realize = sparc32_dma_realize;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo sparc32_dma_info = {
|
|
|
|
.name = TYPE_SPARC32_DMA,
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(SPARC32DMAState),
|
|
|
|
.instance_init = sparc32_dma_init,
|
|
|
|
.class_init = sparc32_dma_class_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
static void sparc32_dma_register_types(void)
|
2009-07-15 22:45:19 +02:00
|
|
|
{
|
2017-10-14 14:22:21 +02:00
|
|
|
type_register_static(&sparc32_dma_device_info);
|
2017-10-14 14:22:21 +02:00
|
|
|
type_register_static(&sparc32_espdma_device_info);
|
|
|
|
type_register_static(&sparc32_ledma_device_info);
|
2017-10-14 14:22:22 +02:00
|
|
|
type_register_static(&sparc32_dma_info);
|
2006-09-03 18:09:07 +02:00
|
|
|
}
|
2009-07-15 22:45:19 +02:00
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
type_init(sparc32_dma_register_types)
|