2011-03-14 11:13:55 +01:00
|
|
|
/*
|
|
|
|
* QEMU model of Xilinx AXI-DMA block.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011 Edgar E. Iglesias.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2016-01-26 19:17:28 +01:00
|
|
|
#include "qemu/osdep.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/sysbus.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 09:01:28 +01:00
|
|
|
#include "qapi/error.h"
|
2012-12-17 18:20:00 +01:00
|
|
|
#include "qemu/timer.h"
|
2019-08-12 07:23:48 +02:00
|
|
|
#include "hw/hw.h"
|
2019-08-12 07:23:42 +02:00
|
|
|
#include "hw/irq.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/ptimer.h"
|
2019-08-12 07:23:51 +02:00
|
|
|
#include "hw/qdev-properties.h"
|
2012-12-17 18:20:00 +01:00
|
|
|
#include "qemu/log.h"
|
2019-05-23 16:35:07 +02:00
|
|
|
#include "qemu/module.h"
|
2011-03-14 11:13:55 +01:00
|
|
|
|
2020-05-06 10:25:08 +02:00
|
|
|
#include "sysemu/dma.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/stream.h"
|
2020-09-03 22:43:22 +02:00
|
|
|
#include "qom/object.h"
|
2011-03-14 11:13:55 +01:00
|
|
|
|
|
|
|
#define D(x)
|
|
|
|
|
2013-04-16 02:22:02 +02:00
|
|
|
#define TYPE_XILINX_AXI_DMA "xlnx.axi-dma"
|
2013-04-16 02:25:57 +02:00
|
|
|
#define TYPE_XILINX_AXI_DMA_DATA_STREAM "xilinx-axi-dma-data-stream"
|
2013-04-16 02:28:35 +02:00
|
|
|
#define TYPE_XILINX_AXI_DMA_CONTROL_STREAM "xilinx-axi-dma-control-stream"
|
2013-04-16 02:22:02 +02:00
|
|
|
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(XilinxAXIDMA, XILINX_AXI_DMA)
|
2013-04-16 02:22:02 +02:00
|
|
|
|
2020-09-10 09:01:28 +02:00
|
|
|
typedef struct XilinxAXIDMAStreamSink XilinxAXIDMAStreamSink;
|
|
|
|
DECLARE_INSTANCE_CHECKER(XilinxAXIDMAStreamSink, XILINX_AXI_DMA_DATA_STREAM,
|
2020-08-31 23:07:33 +02:00
|
|
|
TYPE_XILINX_AXI_DMA_DATA_STREAM)
|
2013-04-16 02:25:57 +02:00
|
|
|
|
2020-09-10 09:01:28 +02:00
|
|
|
DECLARE_INSTANCE_CHECKER(XilinxAXIDMAStreamSink, XILINX_AXI_DMA_CONTROL_STREAM,
|
2020-08-31 23:07:33 +02:00
|
|
|
TYPE_XILINX_AXI_DMA_CONTROL_STREAM)
|
2013-04-16 02:28:35 +02:00
|
|
|
|
2011-03-14 11:13:55 +01:00
|
|
|
#define R_DMACR (0x00 / 4)
|
|
|
|
#define R_DMASR (0x04 / 4)
|
|
|
|
#define R_CURDESC (0x08 / 4)
|
|
|
|
#define R_TAILDESC (0x10 / 4)
|
|
|
|
#define R_MAX (0x30 / 4)
|
|
|
|
|
2013-04-16 02:28:35 +02:00
|
|
|
#define CONTROL_PAYLOAD_WORDS 5
|
|
|
|
#define CONTROL_PAYLOAD_SIZE (CONTROL_PAYLOAD_WORDS * (sizeof(uint32_t)))
|
|
|
|
|
2013-04-16 02:21:23 +02:00
|
|
|
|
2011-03-14 11:13:55 +01:00
|
|
|
enum {
|
|
|
|
DMACR_RUNSTOP = 1,
|
|
|
|
DMACR_TAILPTR_MODE = 2,
|
|
|
|
DMACR_RESET = 4
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
DMASR_HALTED = 1,
|
|
|
|
DMASR_IDLE = 2,
|
|
|
|
DMASR_IOC_IRQ = 1 << 12,
|
|
|
|
DMASR_DLY_IRQ = 1 << 13,
|
|
|
|
|
|
|
|
DMASR_IRQ_MASK = 7 << 12
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SDesc {
|
|
|
|
uint64_t nxtdesc;
|
|
|
|
uint64_t buffer_address;
|
|
|
|
uint64_t reserved;
|
|
|
|
uint32_t control;
|
|
|
|
uint32_t status;
|
2013-04-16 02:28:35 +02:00
|
|
|
uint8_t app[CONTROL_PAYLOAD_SIZE];
|
2011-03-14 11:13:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
SDESC_CTRL_EOF = (1 << 26),
|
|
|
|
SDESC_CTRL_SOF = (1 << 27),
|
|
|
|
|
|
|
|
SDESC_CTRL_LEN_MASK = (1 << 23) - 1
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
SDESC_STATUS_EOF = (1 << 26),
|
|
|
|
SDESC_STATUS_SOF_BIT = 27,
|
|
|
|
SDESC_STATUS_SOF = (1 << SDESC_STATUS_SOF_BIT),
|
|
|
|
SDESC_STATUS_COMPLETE = (1 << 31)
|
|
|
|
};
|
|
|
|
|
2012-08-10 05:16:11 +02:00
|
|
|
struct Stream {
|
2020-05-06 10:25:08 +02:00
|
|
|
struct XilinxAXIDMA *dma;
|
2011-03-14 11:13:55 +01:00
|
|
|
ptimer_state *ptimer;
|
|
|
|
qemu_irq irq;
|
|
|
|
|
|
|
|
int nr;
|
|
|
|
|
2020-05-06 10:25:12 +02:00
|
|
|
bool sof;
|
2011-03-14 11:13:55 +01:00
|
|
|
struct SDesc desc;
|
|
|
|
unsigned int complete_cnt;
|
|
|
|
uint32_t regs[R_MAX];
|
2013-04-16 02:28:35 +02:00
|
|
|
uint8_t app[20];
|
2016-10-17 20:22:16 +02:00
|
|
|
unsigned char txbuf[16 * 1024];
|
2011-03-14 11:13:55 +01:00
|
|
|
};
|
|
|
|
|
2020-09-10 09:01:28 +02:00
|
|
|
struct XilinxAXIDMAStreamSink {
|
2013-04-16 02:25:57 +02:00
|
|
|
Object parent;
|
|
|
|
|
|
|
|
struct XilinxAXIDMA *dma;
|
|
|
|
};
|
|
|
|
|
2011-03-14 11:13:55 +01:00
|
|
|
struct XilinxAXIDMA {
|
|
|
|
SysBusDevice busdev;
|
2011-11-15 11:26:54 +01:00
|
|
|
MemoryRegion iomem;
|
2020-05-06 10:25:08 +02:00
|
|
|
MemoryRegion *dma_mr;
|
|
|
|
AddressSpace as;
|
|
|
|
|
2011-03-14 11:13:55 +01:00
|
|
|
uint32_t freqhz;
|
2020-09-10 09:01:27 +02:00
|
|
|
StreamSink *tx_data_dev;
|
|
|
|
StreamSink *tx_control_dev;
|
2020-09-10 09:01:28 +02:00
|
|
|
XilinxAXIDMAStreamSink rx_data_dev;
|
|
|
|
XilinxAXIDMAStreamSink rx_control_dev;
|
2011-03-14 11:13:55 +01:00
|
|
|
|
2012-08-10 05:16:11 +02:00
|
|
|
struct Stream streams[2];
|
2013-04-16 02:27:55 +02:00
|
|
|
|
|
|
|
StreamCanPushNotifyFn notify;
|
|
|
|
void *notify_opaque;
|
2011-03-14 11:13:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2015-09-08 23:45:14 +02:00
|
|
|
* Helper calls to extract info from descriptors and other trivial
|
2011-03-14 11:13:55 +01:00
|
|
|
* state from regs.
|
|
|
|
*/
|
|
|
|
static inline int stream_desc_sof(struct SDesc *d)
|
|
|
|
{
|
|
|
|
return d->control & SDESC_CTRL_SOF;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int stream_desc_eof(struct SDesc *d)
|
|
|
|
{
|
|
|
|
return d->control & SDESC_CTRL_EOF;
|
|
|
|
}
|
|
|
|
|
2012-08-10 05:16:11 +02:00
|
|
|
static inline int stream_resetting(struct Stream *s)
|
2011-03-14 11:13:55 +01:00
|
|
|
{
|
|
|
|
return !!(s->regs[R_DMACR] & DMACR_RESET);
|
|
|
|
}
|
|
|
|
|
2012-08-10 05:16:11 +02:00
|
|
|
static inline int stream_running(struct Stream *s)
|
2011-03-14 11:13:55 +01:00
|
|
|
{
|
|
|
|
return s->regs[R_DMACR] & DMACR_RUNSTOP;
|
|
|
|
}
|
|
|
|
|
2012-08-10 05:16:11 +02:00
|
|
|
static inline int stream_idle(struct Stream *s)
|
2011-03-14 11:13:55 +01:00
|
|
|
{
|
|
|
|
return !!(s->regs[R_DMASR] & DMASR_IDLE);
|
|
|
|
}
|
|
|
|
|
2012-08-10 05:16:11 +02:00
|
|
|
static void stream_reset(struct Stream *s)
|
2011-03-14 11:13:55 +01:00
|
|
|
{
|
|
|
|
s->regs[R_DMASR] = DMASR_HALTED; /* starts up halted. */
|
2011-04-28 17:20:42 +02:00
|
|
|
s->regs[R_DMACR] = 1 << 16; /* Starts with one in compl threshold. */
|
2020-05-06 10:25:12 +02:00
|
|
|
s->sof = true;
|
2011-03-14 11:13:55 +01:00
|
|
|
}
|
|
|
|
|
2011-04-28 17:20:42 +02:00
|
|
|
/* Map an offset addr into a channel index. */
|
2012-10-23 12:30:10 +02:00
|
|
|
static inline int streamid_from_addr(hwaddr addr)
|
2011-03-14 11:13:55 +01:00
|
|
|
{
|
|
|
|
int sid;
|
|
|
|
|
|
|
|
sid = addr / (0x30);
|
|
|
|
sid &= 1;
|
|
|
|
return sid;
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static void stream_desc_load(struct Stream *s, hwaddr addr)
|
2011-03-14 11:13:55 +01:00
|
|
|
{
|
|
|
|
struct SDesc *d = &s->desc;
|
|
|
|
|
2020-05-06 10:25:08 +02:00
|
|
|
address_space_read(&s->dma->as, addr, MEMTXATTRS_UNSPECIFIED, d, sizeof *d);
|
2011-03-14 11:13:55 +01:00
|
|
|
|
|
|
|
/* Convert from LE into host endianness. */
|
|
|
|
d->buffer_address = le64_to_cpu(d->buffer_address);
|
|
|
|
d->nxtdesc = le64_to_cpu(d->nxtdesc);
|
|
|
|
d->control = le32_to_cpu(d->control);
|
|
|
|
d->status = le32_to_cpu(d->status);
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static void stream_desc_store(struct Stream *s, hwaddr addr)
|
2011-03-14 11:13:55 +01:00
|
|
|
{
|
|
|
|
struct SDesc *d = &s->desc;
|
|
|
|
|
|
|
|
/* Convert from host endianness into LE. */
|
|
|
|
d->buffer_address = cpu_to_le64(d->buffer_address);
|
|
|
|
d->nxtdesc = cpu_to_le64(d->nxtdesc);
|
|
|
|
d->control = cpu_to_le32(d->control);
|
|
|
|
d->status = cpu_to_le32(d->status);
|
2020-05-06 10:25:08 +02:00
|
|
|
address_space_write(&s->dma->as, addr, MEMTXATTRS_UNSPECIFIED,
|
|
|
|
d, sizeof *d);
|
2011-03-14 11:13:55 +01:00
|
|
|
}
|
|
|
|
|
2012-08-10 05:16:11 +02:00
|
|
|
static void stream_update_irq(struct Stream *s)
|
2011-03-14 11:13:55 +01:00
|
|
|
{
|
|
|
|
unsigned int pending, mask, irq;
|
|
|
|
|
|
|
|
pending = s->regs[R_DMASR] & DMASR_IRQ_MASK;
|
|
|
|
mask = s->regs[R_DMACR] & DMASR_IRQ_MASK;
|
|
|
|
|
|
|
|
irq = pending & mask;
|
|
|
|
|
|
|
|
qemu_set_irq(s->irq, !!irq);
|
|
|
|
}
|
|
|
|
|
2012-08-10 05:16:11 +02:00
|
|
|
static void stream_reload_complete_cnt(struct Stream *s)
|
2011-03-14 11:13:55 +01:00
|
|
|
{
|
|
|
|
unsigned int comp_th;
|
|
|
|
comp_th = (s->regs[R_DMACR] >> 16) & 0xff;
|
|
|
|
s->complete_cnt = comp_th;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void timer_hit(void *opaque)
|
|
|
|
{
|
2012-08-10 05:16:11 +02:00
|
|
|
struct Stream *s = opaque;
|
2011-03-14 11:13:55 +01:00
|
|
|
|
|
|
|
stream_reload_complete_cnt(s);
|
|
|
|
s->regs[R_DMASR] |= DMASR_DLY_IRQ;
|
|
|
|
stream_update_irq(s);
|
|
|
|
}
|
|
|
|
|
2012-08-10 05:16:11 +02:00
|
|
|
static void stream_complete(struct Stream *s)
|
2011-03-14 11:13:55 +01:00
|
|
|
{
|
|
|
|
unsigned int comp_delay;
|
|
|
|
|
|
|
|
/* Start the delayed timer. */
|
2019-10-17 15:21:22 +02:00
|
|
|
ptimer_transaction_begin(s->ptimer);
|
2011-03-14 11:13:55 +01:00
|
|
|
comp_delay = s->regs[R_DMACR] >> 24;
|
|
|
|
if (comp_delay) {
|
|
|
|
ptimer_stop(s->ptimer);
|
|
|
|
ptimer_set_count(s->ptimer, comp_delay);
|
|
|
|
ptimer_run(s->ptimer, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
s->complete_cnt--;
|
|
|
|
if (s->complete_cnt == 0) {
|
|
|
|
/* Raise the IOC irq. */
|
|
|
|
s->regs[R_DMASR] |= DMASR_IOC_IRQ;
|
|
|
|
stream_reload_complete_cnt(s);
|
|
|
|
}
|
2019-10-17 15:21:22 +02:00
|
|
|
ptimer_transaction_commit(s->ptimer);
|
2011-03-14 11:13:55 +01:00
|
|
|
}
|
|
|
|
|
2020-09-10 09:01:27 +02:00
|
|
|
static void stream_process_mem2s(struct Stream *s, StreamSink *tx_data_dev,
|
|
|
|
StreamSink *tx_control_dev)
|
2011-03-14 11:13:55 +01:00
|
|
|
{
|
|
|
|
uint32_t prev_d;
|
2020-05-06 10:25:11 +02:00
|
|
|
uint32_t txlen;
|
|
|
|
uint64_t addr;
|
|
|
|
bool eop;
|
2011-03-14 11:13:55 +01:00
|
|
|
|
|
|
|
if (!stream_running(s) || stream_idle(s)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
stream_desc_load(s, s->regs[R_CURDESC]);
|
|
|
|
|
|
|
|
if (s->desc.status & SDESC_STATUS_COMPLETE) {
|
2013-04-16 02:26:37 +02:00
|
|
|
s->regs[R_DMASR] |= DMASR_HALTED;
|
2011-03-14 11:13:55 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stream_desc_sof(&s->desc)) {
|
2020-05-06 10:25:09 +02:00
|
|
|
stream_push(tx_control_dev, s->desc.app, sizeof(s->desc.app), true);
|
2011-03-14 11:13:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
txlen = s->desc.control & SDESC_CTRL_LEN_MASK;
|
|
|
|
|
2020-05-06 10:25:11 +02:00
|
|
|
eop = stream_desc_eof(&s->desc);
|
|
|
|
addr = s->desc.buffer_address;
|
|
|
|
while (txlen) {
|
|
|
|
unsigned int len;
|
|
|
|
|
|
|
|
len = txlen > sizeof s->txbuf ? sizeof s->txbuf : txlen;
|
|
|
|
address_space_read(&s->dma->as, addr,
|
|
|
|
MEMTXATTRS_UNSPECIFIED,
|
|
|
|
s->txbuf, len);
|
|
|
|
stream_push(tx_data_dev, s->txbuf, len, eop && len == txlen);
|
|
|
|
txlen -= len;
|
|
|
|
addr += len;
|
|
|
|
}
|
2011-03-14 11:13:55 +01:00
|
|
|
|
2020-05-06 10:25:11 +02:00
|
|
|
if (eop) {
|
2011-03-14 11:13:55 +01:00
|
|
|
stream_complete(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the descriptor. */
|
|
|
|
s->desc.status = txlen | SDESC_STATUS_COMPLETE;
|
|
|
|
stream_desc_store(s, s->regs[R_CURDESC]);
|
|
|
|
|
|
|
|
/* Advance. */
|
|
|
|
prev_d = s->regs[R_CURDESC];
|
|
|
|
s->regs[R_CURDESC] = s->desc.nxtdesc;
|
|
|
|
if (prev_d == s->regs[R_TAILDESC]) {
|
|
|
|
s->regs[R_DMASR] |= DMASR_IDLE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-16 02:27:55 +02:00
|
|
|
static size_t stream_process_s2mem(struct Stream *s, unsigned char *buf,
|
2020-05-06 10:25:12 +02:00
|
|
|
size_t len, bool eop)
|
2011-03-14 11:13:55 +01:00
|
|
|
{
|
|
|
|
uint32_t prev_d;
|
|
|
|
unsigned int rxlen;
|
2013-04-16 02:27:55 +02:00
|
|
|
size_t pos = 0;
|
2011-03-14 11:13:55 +01:00
|
|
|
|
|
|
|
if (!stream_running(s) || stream_idle(s)) {
|
2013-04-16 02:27:55 +02:00
|
|
|
return 0;
|
2011-03-14 11:13:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
while (len) {
|
|
|
|
stream_desc_load(s, s->regs[R_CURDESC]);
|
|
|
|
|
|
|
|
if (s->desc.status & SDESC_STATUS_COMPLETE) {
|
2013-04-16 02:26:37 +02:00
|
|
|
s->regs[R_DMASR] |= DMASR_HALTED;
|
2011-03-14 11:13:55 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rxlen = s->desc.control & SDESC_CTRL_LEN_MASK;
|
|
|
|
if (rxlen > len) {
|
|
|
|
/* It fits. */
|
|
|
|
rxlen = len;
|
|
|
|
}
|
|
|
|
|
2020-05-06 10:25:08 +02:00
|
|
|
address_space_write(&s->dma->as, s->desc.buffer_address,
|
|
|
|
MEMTXATTRS_UNSPECIFIED, buf + pos, rxlen);
|
2011-03-14 11:13:55 +01:00
|
|
|
len -= rxlen;
|
|
|
|
pos += rxlen;
|
|
|
|
|
|
|
|
/* Update the descriptor. */
|
2020-05-06 10:25:12 +02:00
|
|
|
if (eop) {
|
2011-03-14 11:13:55 +01:00
|
|
|
stream_complete(s);
|
2013-04-16 02:28:35 +02:00
|
|
|
memcpy(s->desc.app, s->app, sizeof(s->desc.app));
|
2011-03-14 11:13:55 +01:00
|
|
|
s->desc.status |= SDESC_STATUS_EOF;
|
|
|
|
}
|
|
|
|
|
2020-05-06 10:25:12 +02:00
|
|
|
s->desc.status |= s->sof << SDESC_STATUS_SOF_BIT;
|
2011-03-14 11:13:55 +01:00
|
|
|
s->desc.status |= SDESC_STATUS_COMPLETE;
|
|
|
|
stream_desc_store(s, s->regs[R_CURDESC]);
|
2020-05-06 10:25:12 +02:00
|
|
|
s->sof = eop;
|
2011-03-14 11:13:55 +01:00
|
|
|
|
|
|
|
/* Advance. */
|
|
|
|
prev_d = s->regs[R_CURDESC];
|
|
|
|
s->regs[R_CURDESC] = s->desc.nxtdesc;
|
|
|
|
if (prev_d == s->regs[R_TAILDESC]) {
|
|
|
|
s->regs[R_DMASR] |= DMASR_IDLE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-04-16 02:27:55 +02:00
|
|
|
|
|
|
|
return pos;
|
2011-03-14 11:13:55 +01:00
|
|
|
}
|
|
|
|
|
2013-04-16 02:22:41 +02:00
|
|
|
static void xilinx_axidma_reset(DeviceState *dev)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
XilinxAXIDMA *s = XILINX_AXI_DMA(dev);
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
stream_reset(&s->streams[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-16 02:28:35 +02:00
|
|
|
static size_t
|
2020-09-10 09:01:27 +02:00
|
|
|
xilinx_axidma_control_stream_push(StreamSink *obj, unsigned char *buf,
|
2020-05-06 10:25:09 +02:00
|
|
|
size_t len, bool eop)
|
2013-04-16 02:28:35 +02:00
|
|
|
{
|
2020-09-10 09:01:28 +02:00
|
|
|
XilinxAXIDMAStreamSink *cs = XILINX_AXI_DMA_CONTROL_STREAM(obj);
|
2013-04-16 02:28:35 +02:00
|
|
|
struct Stream *s = &cs->dma->streams[1];
|
|
|
|
|
|
|
|
if (len != CONTROL_PAYLOAD_SIZE) {
|
|
|
|
hw_error("AXI DMA requires %d byte control stream payload\n",
|
|
|
|
(int)CONTROL_PAYLOAD_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(s->app, buf, len);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2013-04-16 02:27:55 +02:00
|
|
|
static bool
|
2020-09-10 09:01:27 +02:00
|
|
|
xilinx_axidma_data_stream_can_push(StreamSink *obj,
|
2013-04-16 02:27:55 +02:00
|
|
|
StreamCanPushNotifyFn notify,
|
|
|
|
void *notify_opaque)
|
|
|
|
{
|
2020-09-10 09:01:28 +02:00
|
|
|
XilinxAXIDMAStreamSink *ds = XILINX_AXI_DMA_DATA_STREAM(obj);
|
2013-04-16 02:27:55 +02:00
|
|
|
struct Stream *s = &ds->dma->streams[1];
|
|
|
|
|
|
|
|
if (!stream_running(s) || stream_idle(s)) {
|
|
|
|
ds->dma->notify = notify;
|
|
|
|
ds->dma->notify_opaque = notify_opaque;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-04-16 02:27:16 +02:00
|
|
|
static size_t
|
2020-09-10 09:01:27 +02:00
|
|
|
xilinx_axidma_data_stream_push(StreamSink *obj, unsigned char *buf, size_t len,
|
2020-05-06 10:25:09 +02:00
|
|
|
bool eop)
|
2011-03-14 11:13:55 +01:00
|
|
|
{
|
2020-09-10 09:01:28 +02:00
|
|
|
XilinxAXIDMAStreamSink *ds = XILINX_AXI_DMA_DATA_STREAM(obj);
|
2013-04-16 02:25:57 +02:00
|
|
|
struct Stream *s = &ds->dma->streams[1];
|
2013-04-16 02:27:55 +02:00
|
|
|
size_t ret;
|
2011-03-14 11:13:55 +01:00
|
|
|
|
2020-05-06 10:25:12 +02:00
|
|
|
ret = stream_process_s2mem(s, buf, len, eop);
|
2011-03-14 11:13:55 +01:00
|
|
|
stream_update_irq(s);
|
2013-04-16 02:27:55 +02:00
|
|
|
return ret;
|
2011-03-14 11:13:55 +01:00
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static uint64_t axidma_read(void *opaque, hwaddr addr,
|
2011-11-15 11:26:54 +01:00
|
|
|
unsigned size)
|
2011-03-14 11:13:55 +01:00
|
|
|
{
|
2013-04-16 02:21:23 +02:00
|
|
|
XilinxAXIDMA *d = opaque;
|
2012-08-10 05:16:11 +02:00
|
|
|
struct Stream *s;
|
2011-03-14 11:13:55 +01:00
|
|
|
uint32_t r = 0;
|
|
|
|
int sid;
|
|
|
|
|
|
|
|
sid = streamid_from_addr(addr);
|
|
|
|
s = &d->streams[sid];
|
|
|
|
|
|
|
|
addr = addr % 0x30;
|
|
|
|
addr >>= 2;
|
|
|
|
switch (addr) {
|
|
|
|
case R_DMACR:
|
|
|
|
/* Simulate one cycles reset delay. */
|
|
|
|
s->regs[addr] &= ~DMACR_RESET;
|
|
|
|
r = s->regs[addr];
|
|
|
|
break;
|
|
|
|
case R_DMASR:
|
|
|
|
s->regs[addr] &= 0xffff;
|
|
|
|
s->regs[addr] |= (s->complete_cnt & 0xff) << 16;
|
|
|
|
s->regs[addr] |= (ptimer_get_count(s->ptimer) & 0xff) << 24;
|
|
|
|
r = s->regs[addr];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
r = s->regs[addr];
|
|
|
|
D(qemu_log("%s ch=%d addr=" TARGET_FMT_plx " v=%x\n",
|
|
|
|
__func__, sid, addr * 4, r));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static void axidma_write(void *opaque, hwaddr addr,
|
2011-11-15 11:26:54 +01:00
|
|
|
uint64_t value, unsigned size)
|
2011-03-14 11:13:55 +01:00
|
|
|
{
|
2013-04-16 02:21:23 +02:00
|
|
|
XilinxAXIDMA *d = opaque;
|
2012-08-10 05:16:11 +02:00
|
|
|
struct Stream *s;
|
2011-03-14 11:13:55 +01:00
|
|
|
int sid;
|
|
|
|
|
|
|
|
sid = streamid_from_addr(addr);
|
|
|
|
s = &d->streams[sid];
|
|
|
|
|
|
|
|
addr = addr % 0x30;
|
|
|
|
addr >>= 2;
|
|
|
|
switch (addr) {
|
|
|
|
case R_DMACR:
|
|
|
|
/* Tailptr mode is always on. */
|
|
|
|
value |= DMACR_TAILPTR_MODE;
|
|
|
|
/* Remember our previous reset state. */
|
|
|
|
value |= (s->regs[addr] & DMACR_RESET);
|
|
|
|
s->regs[addr] = value;
|
|
|
|
|
|
|
|
if (value & DMACR_RESET) {
|
|
|
|
stream_reset(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((value & 1) && !stream_resetting(s)) {
|
|
|
|
/* Start processing. */
|
|
|
|
s->regs[R_DMASR] &= ~(DMASR_HALTED | DMASR_IDLE);
|
|
|
|
}
|
|
|
|
stream_reload_complete_cnt(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case R_DMASR:
|
|
|
|
/* Mask away write to clear irq lines. */
|
|
|
|
value &= ~(value & DMASR_IRQ_MASK);
|
|
|
|
s->regs[addr] = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case R_TAILDESC:
|
|
|
|
s->regs[addr] = value;
|
|
|
|
s->regs[R_DMASR] &= ~DMASR_IDLE; /* Not idle. */
|
|
|
|
if (!sid) {
|
2013-04-16 02:28:35 +02:00
|
|
|
stream_process_mem2s(s, d->tx_data_dev, d->tx_control_dev);
|
2011-03-14 11:13:55 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
D(qemu_log("%s: ch=%d addr=" TARGET_FMT_plx " v=%x\n",
|
2013-01-26 21:54:35 +01:00
|
|
|
__func__, sid, addr * 4, (unsigned)value));
|
2011-03-14 11:13:55 +01:00
|
|
|
s->regs[addr] = value;
|
|
|
|
break;
|
|
|
|
}
|
2013-04-16 02:27:55 +02:00
|
|
|
if (sid == 1 && d->notify) {
|
2013-06-07 05:05:38 +02:00
|
|
|
StreamCanPushNotifyFn notifytmp = d->notify;
|
2013-04-16 02:27:55 +02:00
|
|
|
d->notify = NULL;
|
2013-06-07 05:05:38 +02:00
|
|
|
notifytmp(d->notify_opaque);
|
2013-04-16 02:27:55 +02:00
|
|
|
}
|
2011-03-14 11:13:55 +01:00
|
|
|
stream_update_irq(s);
|
|
|
|
}
|
|
|
|
|
2011-11-15 11:26:54 +01:00
|
|
|
static const MemoryRegionOps axidma_ops = {
|
|
|
|
.read = axidma_read,
|
|
|
|
.write = axidma_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2011-03-14 11:13:55 +01:00
|
|
|
};
|
|
|
|
|
2013-04-16 02:23:20 +02:00
|
|
|
static void xilinx_axidma_realize(DeviceState *dev, Error **errp)
|
2011-03-14 11:13:55 +01:00
|
|
|
{
|
2013-04-16 02:22:02 +02:00
|
|
|
XilinxAXIDMA *s = XILINX_AXI_DMA(dev);
|
2020-09-10 09:01:28 +02:00
|
|
|
XilinxAXIDMAStreamSink *ds = XILINX_AXI_DMA_DATA_STREAM(&s->rx_data_dev);
|
|
|
|
XilinxAXIDMAStreamSink *cs = XILINX_AXI_DMA_CONTROL_STREAM(
|
2013-04-16 02:28:35 +02:00
|
|
|
&s->rx_control_dev);
|
2020-05-06 10:25:08 +02:00
|
|
|
int i;
|
2013-04-16 02:25:57 +02:00
|
|
|
|
|
|
|
object_property_add_link(OBJECT(ds), "dma", TYPE_XILINX_AXI_DMA,
|
qom: Make QOM link property unref optional
Some object_property_add_link() callers expect property deletion to
unref the link property object. Other callers expect to manage the
refcount themselves. The former are currently broken and therefore leak
the link property object.
This patch adds a flags argument to object_property_add_link() so the
caller can specify which refcount behavior they require. The new
OBJ_PROP_LINK_UNREF_ON_RELEASE flag causes the link pointer to be
unreferenced when the property is deleted.
This fixes refcount leaks in qdev.c, xilinx_axidma.c, xilinx_axienet.c,
s390-virtio-bus.c, virtio-pci.c, virtio-rng.c, and ui/console.c.
Rationale for refcount behavior:
* hw/core/qdev.c
- bus children are explicitly unreferenced, don't interfere
- parent_bus is essentially a read-only property that doesn't hold a
refcount, don't unref
- hotplug_handler is leaked, do unref
* hw/dma/xilinx_axidma.c
- rx stream "dma" links are set using set_link, therefore they
need unref
- tx streams are set using set_link, therefore they need unref
* hw/net/xilinx_axienet.c
- same reasoning as hw/dma/xilinx_axidma.c
* hw/pcmcia/pxa2xx.c
- pxa2xx bypasses set_link and therefore does not use refcounts
* hw/s390x/s390-virtio-bus.c
* hw/virtio/virtio-pci.c
* hw/virtio/virtio-rng.c
* ui/console.c
- set_link is used and there is no explicit unref, do unref
Cc: Peter Crosthwaite <peter.crosthwaite@petalogix.com>
Cc: Alexander Graf <agraf@suse.de>
Cc: Anthony Liguori <aliguori@amazon.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
2014-03-19 08:58:55 +01:00
|
|
|
(Object **)&ds->dma,
|
2014-03-19 08:58:56 +01:00
|
|
|
object_property_allow_set_link,
|
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
|
|
|
OBJ_PROP_LINK_STRONG);
|
2013-04-16 02:28:35 +02:00
|
|
|
object_property_add_link(OBJECT(cs), "dma", TYPE_XILINX_AXI_DMA,
|
qom: Make QOM link property unref optional
Some object_property_add_link() callers expect property deletion to
unref the link property object. Other callers expect to manage the
refcount themselves. The former are currently broken and therefore leak
the link property object.
This patch adds a flags argument to object_property_add_link() so the
caller can specify which refcount behavior they require. The new
OBJ_PROP_LINK_UNREF_ON_RELEASE flag causes the link pointer to be
unreferenced when the property is deleted.
This fixes refcount leaks in qdev.c, xilinx_axidma.c, xilinx_axienet.c,
s390-virtio-bus.c, virtio-pci.c, virtio-rng.c, and ui/console.c.
Rationale for refcount behavior:
* hw/core/qdev.c
- bus children are explicitly unreferenced, don't interfere
- parent_bus is essentially a read-only property that doesn't hold a
refcount, don't unref
- hotplug_handler is leaked, do unref
* hw/dma/xilinx_axidma.c
- rx stream "dma" links are set using set_link, therefore they
need unref
- tx streams are set using set_link, therefore they need unref
* hw/net/xilinx_axienet.c
- same reasoning as hw/dma/xilinx_axidma.c
* hw/pcmcia/pxa2xx.c
- pxa2xx bypasses set_link and therefore does not use refcounts
* hw/s390x/s390-virtio-bus.c
* hw/virtio/virtio-pci.c
* hw/virtio/virtio-rng.c
* ui/console.c
- set_link is used and there is no explicit unref, do unref
Cc: Peter Crosthwaite <peter.crosthwaite@petalogix.com>
Cc: Alexander Graf <agraf@suse.de>
Cc: Anthony Liguori <aliguori@amazon.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
2014-03-19 08:58:55 +01:00
|
|
|
(Object **)&cs->dma,
|
2014-03-19 08:58:56 +01:00
|
|
|
object_property_allow_set_link,
|
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
|
|
|
OBJ_PROP_LINK_STRONG);
|
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(ds), "dma", OBJECT(s), &error_abort);
|
|
|
|
object_property_set_link(OBJECT(cs), "dma", OBJECT(s), &error_abort);
|
2013-04-16 02:25:57 +02:00
|
|
|
|
2011-03-14 11:13:55 +01:00
|
|
|
for (i = 0; i < 2; i++) {
|
2014-08-18 02:53:12 +02:00
|
|
|
struct Stream *st = &s->streams[i];
|
|
|
|
|
2020-05-06 10:25:08 +02:00
|
|
|
st->dma = s;
|
2014-08-18 02:53:12 +02:00
|
|
|
st->nr = i;
|
2019-10-17 15:21:22 +02:00
|
|
|
st->ptimer = ptimer_init(timer_hit, st, PTIMER_POLICY_DEFAULT);
|
|
|
|
ptimer_transaction_begin(st->ptimer);
|
2014-08-18 02:53:12 +02:00
|
|
|
ptimer_set_freq(st->ptimer, s->freqhz);
|
2019-10-17 15:21:22 +02:00
|
|
|
ptimer_transaction_commit(st->ptimer);
|
2011-03-14 11:13:55 +01:00
|
|
|
}
|
2020-05-06 10:25:08 +02:00
|
|
|
|
|
|
|
address_space_init(&s->as,
|
|
|
|
s->dma_mr ? s->dma_mr : get_system_memory(), "dma");
|
2011-03-14 11:13:55 +01:00
|
|
|
}
|
|
|
|
|
2013-04-16 02:23:20 +02:00
|
|
|
static void xilinx_axidma_init(Object *obj)
|
2012-08-10 05:16:11 +02:00
|
|
|
{
|
2013-04-16 02:22:02 +02:00
|
|
|
XilinxAXIDMA *s = XILINX_AXI_DMA(obj);
|
2013-04-16 02:23:20 +02:00
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
2012-08-10 05:16:11 +02:00
|
|
|
|
2019-08-23 16:32:48 +02:00
|
|
|
object_initialize_child(OBJECT(s), "axistream-connected-target",
|
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 07:32:25 +02:00
|
|
|
&s->rx_data_dev, TYPE_XILINX_AXI_DMA_DATA_STREAM);
|
2019-08-23 16:32:48 +02:00
|
|
|
object_initialize_child(OBJECT(s), "axistream-control-connected-target",
|
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 07:32:25 +02:00
|
|
|
&s->rx_control_dev,
|
|
|
|
TYPE_XILINX_AXI_DMA_CONTROL_STREAM);
|
2020-05-06 10:25:08 +02:00
|
|
|
object_property_add_link(obj, "dma", TYPE_MEMORY_REGION,
|
|
|
|
(Object **)&s->dma_mr,
|
|
|
|
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
|
|
|
OBJ_PROP_LINK_STRONG);
|
2013-04-16 02:25:57 +02:00
|
|
|
|
2013-04-16 02:23:20 +02:00
|
|
|
sysbus_init_irq(sbd, &s->streams[0].irq);
|
|
|
|
sysbus_init_irq(sbd, &s->streams[1].irq);
|
|
|
|
|
2013-06-07 03:25:08 +02:00
|
|
|
memory_region_init_io(&s->iomem, obj, &axidma_ops, s,
|
2013-04-16 02:23:20 +02:00
|
|
|
"xlnx.axi-dma", R_MAX * 4 * 2);
|
|
|
|
sysbus_init_mmio(sbd, &s->iomem);
|
2012-08-10 05:16:11 +02:00
|
|
|
}
|
|
|
|
|
2012-01-24 20:12:29 +01:00
|
|
|
static Property axidma_properties[] = {
|
2013-04-16 02:21:23 +02:00
|
|
|
DEFINE_PROP_UINT32("freqhz", XilinxAXIDMA, freqhz, 50000000),
|
2017-09-07 14:54:51 +02:00
|
|
|
DEFINE_PROP_LINK("axistream-connected", XilinxAXIDMA,
|
2020-09-10 09:01:27 +02:00
|
|
|
tx_data_dev, TYPE_STREAM_SINK, StreamSink *),
|
2017-09-07 14:54:51 +02:00
|
|
|
DEFINE_PROP_LINK("axistream-control-connected", XilinxAXIDMA,
|
2020-09-10 09:01:27 +02:00
|
|
|
tx_control_dev, TYPE_STREAM_SINK, StreamSink *),
|
2012-01-24 20:12:29 +01:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void axidma_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2013-04-16 02:23:20 +02:00
|
|
|
dc->realize = xilinx_axidma_realize,
|
2013-04-16 02:22:41 +02:00
|
|
|
dc->reset = xilinx_axidma_reset;
|
2020-01-10 16:30:32 +01:00
|
|
|
device_class_set_props(dc, axidma_properties);
|
2013-04-16 02:25:57 +02:00
|
|
|
}
|
|
|
|
|
2020-09-10 09:01:27 +02:00
|
|
|
static StreamSinkClass xilinx_axidma_data_stream_class = {
|
2013-04-16 02:27:55 +02:00
|
|
|
.push = xilinx_axidma_data_stream_push,
|
|
|
|
.can_push = xilinx_axidma_data_stream_can_push,
|
|
|
|
};
|
|
|
|
|
2020-09-10 09:01:27 +02:00
|
|
|
static StreamSinkClass xilinx_axidma_control_stream_class = {
|
2013-04-16 02:28:35 +02:00
|
|
|
.push = xilinx_axidma_control_stream_push,
|
|
|
|
};
|
|
|
|
|
2013-04-16 02:25:57 +02:00
|
|
|
static void xilinx_axidma_stream_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2020-09-10 09:01:27 +02:00
|
|
|
StreamSinkClass *ssc = STREAM_SINK_CLASS(klass);
|
2013-04-16 02:25:57 +02:00
|
|
|
|
2020-09-10 09:01:27 +02:00
|
|
|
ssc->push = ((StreamSinkClass *)data)->push;
|
|
|
|
ssc->can_push = ((StreamSinkClass *)data)->can_push;
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo axidma_info = {
|
2013-04-16 02:22:02 +02:00
|
|
|
.name = TYPE_XILINX_AXI_DMA,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
2013-04-16 02:21:23 +02:00
|
|
|
.instance_size = sizeof(XilinxAXIDMA),
|
2011-12-08 04:34:16 +01:00
|
|
|
.class_init = axidma_class_init,
|
2013-04-16 02:23:20 +02:00
|
|
|
.instance_init = xilinx_axidma_init,
|
2013-04-16 02:25:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static const TypeInfo xilinx_axidma_data_stream_info = {
|
|
|
|
.name = TYPE_XILINX_AXI_DMA_DATA_STREAM,
|
|
|
|
.parent = TYPE_OBJECT,
|
2020-09-10 09:01:28 +02:00
|
|
|
.instance_size = sizeof(XilinxAXIDMAStreamSink),
|
2013-04-16 02:25:57 +02:00
|
|
|
.class_init = xilinx_axidma_stream_class_init,
|
2013-04-16 02:27:55 +02:00
|
|
|
.class_data = &xilinx_axidma_data_stream_class,
|
2012-08-10 05:16:11 +02:00
|
|
|
.interfaces = (InterfaceInfo[]) {
|
2020-09-10 09:01:27 +02:00
|
|
|
{ TYPE_STREAM_SINK },
|
2012-08-10 05:16:11 +02:00
|
|
|
{ }
|
|
|
|
}
|
2011-03-14 11:13:55 +01:00
|
|
|
};
|
|
|
|
|
2013-04-16 02:28:35 +02:00
|
|
|
static const TypeInfo xilinx_axidma_control_stream_info = {
|
|
|
|
.name = TYPE_XILINX_AXI_DMA_CONTROL_STREAM,
|
|
|
|
.parent = TYPE_OBJECT,
|
2020-09-10 09:01:28 +02:00
|
|
|
.instance_size = sizeof(XilinxAXIDMAStreamSink),
|
2013-04-16 02:28:35 +02:00
|
|
|
.class_init = xilinx_axidma_stream_class_init,
|
|
|
|
.class_data = &xilinx_axidma_control_stream_class,
|
|
|
|
.interfaces = (InterfaceInfo[]) {
|
2020-09-10 09:01:27 +02:00
|
|
|
{ TYPE_STREAM_SINK },
|
2013-04-16 02:28:35 +02:00
|
|
|
{ }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
static void xilinx_axidma_register_types(void)
|
2011-03-14 11:13:55 +01:00
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
type_register_static(&axidma_info);
|
2013-04-16 02:25:57 +02:00
|
|
|
type_register_static(&xilinx_axidma_data_stream_info);
|
2013-04-16 02:28:35 +02:00
|
|
|
type_register_static(&xilinx_axidma_control_stream_info);
|
2011-03-14 11:13:55 +01:00
|
|
|
}
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
type_init(xilinx_axidma_register_types)
|