2011-03-14 18:13:55 +08: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.
|
|
|
|
*/
|
|
|
|
|
2013-02-04 22:40:22 +08:00
|
|
|
#include "hw/sysbus.h"
|
2012-12-18 01:20:00 +08:00
|
|
|
#include "qemu/timer.h"
|
2013-02-04 22:40:22 +08:00
|
|
|
#include "hw/ptimer.h"
|
2012-12-18 01:20:00 +08:00
|
|
|
#include "qemu/log.h"
|
2013-04-16 08:23:20 +08:00
|
|
|
#include "qapi/qmp/qerror.h"
|
2011-03-14 18:13:55 +08:00
|
|
|
|
2013-02-04 22:40:22 +08:00
|
|
|
#include "hw/stream.h"
|
2011-03-14 18:13:55 +08:00
|
|
|
|
|
|
|
#define D(x)
|
|
|
|
|
2013-04-16 08:22:02 +08:00
|
|
|
#define TYPE_XILINX_AXI_DMA "xlnx.axi-dma"
|
2013-04-16 08:25:57 +08:00
|
|
|
#define TYPE_XILINX_AXI_DMA_DATA_STREAM "xilinx-axi-dma-data-stream"
|
2013-04-16 08:28:35 +08:00
|
|
|
#define TYPE_XILINX_AXI_DMA_CONTROL_STREAM "xilinx-axi-dma-control-stream"
|
2013-04-16 08:22:02 +08:00
|
|
|
|
|
|
|
#define XILINX_AXI_DMA(obj) \
|
|
|
|
OBJECT_CHECK(XilinxAXIDMA, (obj), TYPE_XILINX_AXI_DMA)
|
|
|
|
|
2013-04-16 08:25:57 +08:00
|
|
|
#define XILINX_AXI_DMA_DATA_STREAM(obj) \
|
|
|
|
OBJECT_CHECK(XilinxAXIDMAStreamSlave, (obj),\
|
|
|
|
TYPE_XILINX_AXI_DMA_DATA_STREAM)
|
|
|
|
|
2013-04-16 08:28:35 +08:00
|
|
|
#define XILINX_AXI_DMA_CONTROL_STREAM(obj) \
|
|
|
|
OBJECT_CHECK(XilinxAXIDMAStreamSlave, (obj),\
|
|
|
|
TYPE_XILINX_AXI_DMA_CONTROL_STREAM)
|
|
|
|
|
2011-03-14 18:13:55 +08: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 08:28:35 +08:00
|
|
|
#define CONTROL_PAYLOAD_WORDS 5
|
|
|
|
#define CONTROL_PAYLOAD_SIZE (CONTROL_PAYLOAD_WORDS * (sizeof(uint32_t)))
|
|
|
|
|
2013-04-16 08:21:23 +08:00
|
|
|
typedef struct XilinxAXIDMA XilinxAXIDMA;
|
2013-04-16 08:25:57 +08:00
|
|
|
typedef struct XilinxAXIDMAStreamSlave XilinxAXIDMAStreamSlave;
|
2013-04-16 08:21:23 +08:00
|
|
|
|
2011-03-14 18:13:55 +08: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 08:28:35 +08:00
|
|
|
uint8_t app[CONTROL_PAYLOAD_SIZE];
|
2011-03-14 18:13:55 +08: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 11:16:11 +08:00
|
|
|
struct Stream {
|
2011-03-14 18:13:55 +08:00
|
|
|
QEMUBH *bh;
|
|
|
|
ptimer_state *ptimer;
|
|
|
|
qemu_irq irq;
|
|
|
|
|
|
|
|
int nr;
|
|
|
|
|
|
|
|
struct SDesc desc;
|
|
|
|
int pos;
|
|
|
|
unsigned int complete_cnt;
|
|
|
|
uint32_t regs[R_MAX];
|
2013-04-16 08:28:35 +08:00
|
|
|
uint8_t app[20];
|
2011-03-14 18:13:55 +08:00
|
|
|
};
|
|
|
|
|
2013-04-16 08:25:57 +08:00
|
|
|
struct XilinxAXIDMAStreamSlave {
|
|
|
|
Object parent;
|
|
|
|
|
|
|
|
struct XilinxAXIDMA *dma;
|
|
|
|
};
|
|
|
|
|
2011-03-14 18:13:55 +08:00
|
|
|
struct XilinxAXIDMA {
|
|
|
|
SysBusDevice busdev;
|
2011-11-15 18:26:54 +08:00
|
|
|
MemoryRegion iomem;
|
2011-03-14 18:13:55 +08:00
|
|
|
uint32_t freqhz;
|
2013-04-16 08:28:35 +08:00
|
|
|
StreamSlave *tx_data_dev;
|
|
|
|
StreamSlave *tx_control_dev;
|
2013-04-16 08:25:57 +08:00
|
|
|
XilinxAXIDMAStreamSlave rx_data_dev;
|
2013-04-16 08:28:35 +08:00
|
|
|
XilinxAXIDMAStreamSlave rx_control_dev;
|
2011-03-14 18:13:55 +08:00
|
|
|
|
2012-08-10 11:16:11 +08:00
|
|
|
struct Stream streams[2];
|
2013-04-16 08:27:55 +08:00
|
|
|
|
|
|
|
StreamCanPushNotifyFn notify;
|
|
|
|
void *notify_opaque;
|
2011-03-14 18:13:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper calls to extract info from desriptors and other trivial
|
|
|
|
* 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 11:16:11 +08:00
|
|
|
static inline int stream_resetting(struct Stream *s)
|
2011-03-14 18:13:55 +08:00
|
|
|
{
|
|
|
|
return !!(s->regs[R_DMACR] & DMACR_RESET);
|
|
|
|
}
|
|
|
|
|
2012-08-10 11:16:11 +08:00
|
|
|
static inline int stream_running(struct Stream *s)
|
2011-03-14 18:13:55 +08:00
|
|
|
{
|
|
|
|
return s->regs[R_DMACR] & DMACR_RUNSTOP;
|
|
|
|
}
|
|
|
|
|
2012-08-10 11:16:11 +08:00
|
|
|
static inline int stream_halted(struct Stream *s)
|
2011-03-14 18:13:55 +08:00
|
|
|
{
|
|
|
|
return s->regs[R_DMASR] & DMASR_HALTED;
|
|
|
|
}
|
|
|
|
|
2012-08-10 11:16:11 +08:00
|
|
|
static inline int stream_idle(struct Stream *s)
|
2011-03-14 18:13:55 +08:00
|
|
|
{
|
|
|
|
return !!(s->regs[R_DMASR] & DMASR_IDLE);
|
|
|
|
}
|
|
|
|
|
2012-08-10 11:16:11 +08:00
|
|
|
static void stream_reset(struct Stream *s)
|
2011-03-14 18:13:55 +08:00
|
|
|
{
|
|
|
|
s->regs[R_DMASR] = DMASR_HALTED; /* starts up halted. */
|
2011-04-28 23:20:42 +08:00
|
|
|
s->regs[R_DMACR] = 1 << 16; /* Starts with one in compl threshold. */
|
2011-03-14 18:13:55 +08:00
|
|
|
}
|
|
|
|
|
2011-04-28 23:20:42 +08:00
|
|
|
/* Map an offset addr into a channel index. */
|
2012-10-23 18:30:10 +08:00
|
|
|
static inline int streamid_from_addr(hwaddr addr)
|
2011-03-14 18:13:55 +08:00
|
|
|
{
|
|
|
|
int sid;
|
|
|
|
|
|
|
|
sid = addr / (0x30);
|
|
|
|
sid &= 1;
|
|
|
|
return sid;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_ENET
|
|
|
|
static void stream_desc_show(struct SDesc *d)
|
|
|
|
{
|
|
|
|
qemu_log("buffer_addr = " PRIx64 "\n", d->buffer_address);
|
|
|
|
qemu_log("nxtdesc = " PRIx64 "\n", d->nxtdesc);
|
|
|
|
qemu_log("control = %x\n", d->control);
|
|
|
|
qemu_log("status = %x\n", d->status);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-10-23 18:30:10 +08:00
|
|
|
static void stream_desc_load(struct Stream *s, hwaddr addr)
|
2011-03-14 18:13:55 +08:00
|
|
|
{
|
|
|
|
struct SDesc *d = &s->desc;
|
|
|
|
|
2013-04-13 02:53:58 +08:00
|
|
|
cpu_physical_memory_read(addr, d, sizeof *d);
|
2011-03-14 18:13:55 +08: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 18:30:10 +08:00
|
|
|
static void stream_desc_store(struct Stream *s, hwaddr addr)
|
2011-03-14 18:13:55 +08: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);
|
2013-04-13 02:53:58 +08:00
|
|
|
cpu_physical_memory_write(addr, d, sizeof *d);
|
2011-03-14 18:13:55 +08:00
|
|
|
}
|
|
|
|
|
2012-08-10 11:16:11 +08:00
|
|
|
static void stream_update_irq(struct Stream *s)
|
2011-03-14 18:13:55 +08: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 11:16:11 +08:00
|
|
|
static void stream_reload_complete_cnt(struct Stream *s)
|
2011-03-14 18:13:55 +08: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 11:16:11 +08:00
|
|
|
struct Stream *s = opaque;
|
2011-03-14 18:13:55 +08:00
|
|
|
|
|
|
|
stream_reload_complete_cnt(s);
|
|
|
|
s->regs[R_DMASR] |= DMASR_DLY_IRQ;
|
|
|
|
stream_update_irq(s);
|
|
|
|
}
|
|
|
|
|
2012-08-10 11:16:11 +08:00
|
|
|
static void stream_complete(struct Stream *s)
|
2011-03-14 18:13:55 +08:00
|
|
|
{
|
|
|
|
unsigned int comp_delay;
|
|
|
|
|
|
|
|
/* Start the delayed timer. */
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-16 08:28:35 +08:00
|
|
|
static void stream_process_mem2s(struct Stream *s, StreamSlave *tx_data_dev,
|
|
|
|
StreamSlave *tx_control_dev)
|
2011-03-14 18:13:55 +08:00
|
|
|
{
|
|
|
|
uint32_t prev_d;
|
|
|
|
unsigned char txbuf[16 * 1024];
|
|
|
|
unsigned int txlen;
|
|
|
|
|
|
|
|
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 08:26:37 +08:00
|
|
|
s->regs[R_DMASR] |= DMASR_HALTED;
|
2011-03-14 18:13:55 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stream_desc_sof(&s->desc)) {
|
|
|
|
s->pos = 0;
|
2013-04-16 08:28:35 +08:00
|
|
|
stream_push(tx_control_dev, s->desc.app, sizeof(s->desc.app));
|
2011-03-14 18:13:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
txlen = s->desc.control & SDESC_CTRL_LEN_MASK;
|
|
|
|
if ((txlen + s->pos) > sizeof txbuf) {
|
|
|
|
hw_error("%s: too small internal txbuf! %d\n", __func__,
|
|
|
|
txlen + s->pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
cpu_physical_memory_read(s->desc.buffer_address,
|
|
|
|
txbuf + s->pos, txlen);
|
|
|
|
s->pos += txlen;
|
|
|
|
|
|
|
|
if (stream_desc_eof(&s->desc)) {
|
2013-04-16 08:28:35 +08:00
|
|
|
stream_push(tx_data_dev, txbuf, s->pos);
|
2011-03-14 18:13:55 +08:00
|
|
|
s->pos = 0;
|
|
|
|
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 08:27:55 +08:00
|
|
|
static size_t stream_process_s2mem(struct Stream *s, unsigned char *buf,
|
2013-04-16 08:28:35 +08:00
|
|
|
size_t len)
|
2011-03-14 18:13:55 +08:00
|
|
|
{
|
|
|
|
uint32_t prev_d;
|
|
|
|
unsigned int rxlen;
|
2013-04-16 08:27:55 +08:00
|
|
|
size_t pos = 0;
|
2011-03-14 18:13:55 +08:00
|
|
|
int sof = 1;
|
|
|
|
|
|
|
|
if (!stream_running(s) || stream_idle(s)) {
|
2013-04-16 08:27:55 +08:00
|
|
|
return 0;
|
2011-03-14 18:13:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
while (len) {
|
|
|
|
stream_desc_load(s, s->regs[R_CURDESC]);
|
|
|
|
|
|
|
|
if (s->desc.status & SDESC_STATUS_COMPLETE) {
|
2013-04-16 08:26:37 +08:00
|
|
|
s->regs[R_DMASR] |= DMASR_HALTED;
|
2011-03-14 18:13:55 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rxlen = s->desc.control & SDESC_CTRL_LEN_MASK;
|
|
|
|
if (rxlen > len) {
|
|
|
|
/* It fits. */
|
|
|
|
rxlen = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
cpu_physical_memory_write(s->desc.buffer_address, buf + pos, rxlen);
|
|
|
|
len -= rxlen;
|
|
|
|
pos += rxlen;
|
|
|
|
|
|
|
|
/* Update the descriptor. */
|
|
|
|
if (!len) {
|
|
|
|
stream_complete(s);
|
2013-04-16 08:28:35 +08:00
|
|
|
memcpy(s->desc.app, s->app, sizeof(s->desc.app));
|
2011-03-14 18:13:55 +08:00
|
|
|
s->desc.status |= SDESC_STATUS_EOF;
|
|
|
|
}
|
|
|
|
|
|
|
|
s->desc.status |= sof << SDESC_STATUS_SOF_BIT;
|
|
|
|
s->desc.status |= SDESC_STATUS_COMPLETE;
|
|
|
|
stream_desc_store(s, s->regs[R_CURDESC]);
|
|
|
|
sof = 0;
|
|
|
|
|
|
|
|
/* 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 08:27:55 +08:00
|
|
|
|
|
|
|
return pos;
|
2011-03-14 18:13:55 +08:00
|
|
|
}
|
|
|
|
|
2013-04-16 08:22:41 +08: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 08:28:35 +08:00
|
|
|
static size_t
|
|
|
|
xilinx_axidma_control_stream_push(StreamSlave *obj, unsigned char *buf,
|
|
|
|
size_t len)
|
|
|
|
{
|
|
|
|
XilinxAXIDMAStreamSlave *cs = XILINX_AXI_DMA_CONTROL_STREAM(obj);
|
|
|
|
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 08:27:55 +08:00
|
|
|
static bool
|
|
|
|
xilinx_axidma_data_stream_can_push(StreamSlave *obj,
|
|
|
|
StreamCanPushNotifyFn notify,
|
|
|
|
void *notify_opaque)
|
|
|
|
{
|
|
|
|
XilinxAXIDMAStreamSlave *ds = XILINX_AXI_DMA_DATA_STREAM(obj);
|
|
|
|
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 08:27:16 +08:00
|
|
|
static size_t
|
2013-04-16 08:28:35 +08:00
|
|
|
xilinx_axidma_data_stream_push(StreamSlave *obj, unsigned char *buf, size_t len)
|
2011-03-14 18:13:55 +08:00
|
|
|
{
|
2013-04-16 08:25:57 +08:00
|
|
|
XilinxAXIDMAStreamSlave *ds = XILINX_AXI_DMA_DATA_STREAM(obj);
|
|
|
|
struct Stream *s = &ds->dma->streams[1];
|
2013-04-16 08:27:55 +08:00
|
|
|
size_t ret;
|
2011-03-14 18:13:55 +08:00
|
|
|
|
2013-04-16 08:28:35 +08:00
|
|
|
ret = stream_process_s2mem(s, buf, len);
|
2011-03-14 18:13:55 +08:00
|
|
|
stream_update_irq(s);
|
2013-04-16 08:27:55 +08:00
|
|
|
return ret;
|
2011-03-14 18:13:55 +08:00
|
|
|
}
|
|
|
|
|
2012-10-23 18:30:10 +08:00
|
|
|
static uint64_t axidma_read(void *opaque, hwaddr addr,
|
2011-11-15 18:26:54 +08:00
|
|
|
unsigned size)
|
2011-03-14 18:13:55 +08:00
|
|
|
{
|
2013-04-16 08:21:23 +08:00
|
|
|
XilinxAXIDMA *d = opaque;
|
2012-08-10 11:16:11 +08:00
|
|
|
struct Stream *s;
|
2011-03-14 18:13:55 +08: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 18:30:10 +08:00
|
|
|
static void axidma_write(void *opaque, hwaddr addr,
|
2011-11-15 18:26:54 +08:00
|
|
|
uint64_t value, unsigned size)
|
2011-03-14 18:13:55 +08:00
|
|
|
{
|
2013-04-16 08:21:23 +08:00
|
|
|
XilinxAXIDMA *d = opaque;
|
2012-08-10 11:16:11 +08:00
|
|
|
struct Stream *s;
|
2011-03-14 18:13:55 +08: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 08:28:35 +08:00
|
|
|
stream_process_mem2s(s, d->tx_data_dev, d->tx_control_dev);
|
2011-03-14 18:13:55 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
D(qemu_log("%s: ch=%d addr=" TARGET_FMT_plx " v=%x\n",
|
2013-01-27 04:54:35 +08:00
|
|
|
__func__, sid, addr * 4, (unsigned)value));
|
2011-03-14 18:13:55 +08:00
|
|
|
s->regs[addr] = value;
|
|
|
|
break;
|
|
|
|
}
|
2013-04-16 08:27:55 +08:00
|
|
|
if (sid == 1 && d->notify) {
|
|
|
|
d->notify(d->notify_opaque);
|
|
|
|
d->notify = NULL;
|
|
|
|
}
|
2011-03-14 18:13:55 +08:00
|
|
|
stream_update_irq(s);
|
|
|
|
}
|
|
|
|
|
2011-11-15 18:26:54 +08:00
|
|
|
static const MemoryRegionOps axidma_ops = {
|
|
|
|
.read = axidma_read,
|
|
|
|
.write = axidma_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2011-03-14 18:13:55 +08:00
|
|
|
};
|
|
|
|
|
2013-04-16 08:23:20 +08:00
|
|
|
static void xilinx_axidma_realize(DeviceState *dev, Error **errp)
|
2011-03-14 18:13:55 +08:00
|
|
|
{
|
2013-04-16 08:22:02 +08:00
|
|
|
XilinxAXIDMA *s = XILINX_AXI_DMA(dev);
|
2013-04-16 08:25:57 +08:00
|
|
|
XilinxAXIDMAStreamSlave *ds = XILINX_AXI_DMA_DATA_STREAM(&s->rx_data_dev);
|
2013-04-16 08:28:35 +08:00
|
|
|
XilinxAXIDMAStreamSlave *cs = XILINX_AXI_DMA_CONTROL_STREAM(
|
|
|
|
&s->rx_control_dev);
|
2013-04-16 08:25:57 +08:00
|
|
|
Error *local_errp = NULL;
|
|
|
|
|
|
|
|
object_property_add_link(OBJECT(ds), "dma", TYPE_XILINX_AXI_DMA,
|
|
|
|
(Object **)&ds->dma, &local_errp);
|
2013-04-16 08:28:35 +08:00
|
|
|
object_property_add_link(OBJECT(cs), "dma", TYPE_XILINX_AXI_DMA,
|
|
|
|
(Object **)&cs->dma, &local_errp);
|
2013-04-16 08:25:57 +08:00
|
|
|
if (local_errp) {
|
|
|
|
goto xilinx_axidma_realize_fail;
|
|
|
|
}
|
|
|
|
object_property_set_link(OBJECT(ds), OBJECT(s), "dma", &local_errp);
|
2013-04-16 08:28:35 +08:00
|
|
|
object_property_set_link(OBJECT(cs), OBJECT(s), "dma", &local_errp);
|
2013-04-16 08:25:57 +08:00
|
|
|
if (local_errp) {
|
|
|
|
goto xilinx_axidma_realize_fail;
|
|
|
|
}
|
|
|
|
|
2011-03-14 18:13:55 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
s->streams[i].nr = i;
|
|
|
|
s->streams[i].bh = qemu_bh_new(timer_hit, &s->streams[i]);
|
|
|
|
s->streams[i].ptimer = ptimer_init(s->streams[i].bh);
|
|
|
|
ptimer_set_freq(s->streams[i].ptimer, s->freqhz);
|
|
|
|
}
|
2013-04-16 08:25:57 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
xilinx_axidma_realize_fail:
|
|
|
|
if (!*errp) {
|
|
|
|
*errp = local_errp;
|
|
|
|
}
|
2011-03-14 18:13:55 +08:00
|
|
|
}
|
|
|
|
|
2013-04-16 08:23:20 +08:00
|
|
|
static void xilinx_axidma_init(Object *obj)
|
2012-08-10 11:16:11 +08:00
|
|
|
{
|
2013-04-16 08:22:02 +08:00
|
|
|
XilinxAXIDMA *s = XILINX_AXI_DMA(obj);
|
2013-04-16 08:23:20 +08:00
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
2013-04-16 08:25:57 +08:00
|
|
|
Error *errp = NULL;
|
2012-08-10 11:16:11 +08:00
|
|
|
|
|
|
|
object_property_add_link(obj, "axistream-connected", TYPE_STREAM_SLAVE,
|
2013-04-16 08:28:35 +08:00
|
|
|
(Object **) &s->tx_data_dev, &errp);
|
|
|
|
assert_no_error(errp);
|
|
|
|
object_property_add_link(obj, "axistream-control-connected",
|
|
|
|
TYPE_STREAM_SLAVE,
|
|
|
|
(Object **) &s->tx_control_dev, &errp);
|
|
|
|
assert_no_error(errp);
|
2013-04-16 08:23:20 +08:00
|
|
|
|
2013-04-16 08:25:57 +08:00
|
|
|
object_initialize(&s->rx_data_dev, TYPE_XILINX_AXI_DMA_DATA_STREAM);
|
2013-04-16 08:28:35 +08:00
|
|
|
object_initialize(&s->rx_control_dev, TYPE_XILINX_AXI_DMA_CONTROL_STREAM);
|
2013-04-16 08:25:57 +08:00
|
|
|
object_property_add_child(OBJECT(s), "axistream-connected-target",
|
|
|
|
(Object *)&s->rx_data_dev, &errp);
|
|
|
|
assert_no_error(errp);
|
2013-04-16 08:28:35 +08:00
|
|
|
object_property_add_child(OBJECT(s), "axistream-control-connected-target",
|
|
|
|
(Object *)&s->rx_control_dev, &errp);
|
|
|
|
assert_no_error(errp);
|
2013-04-16 08:25:57 +08:00
|
|
|
|
2013-04-16 08:23:20 +08:00
|
|
|
sysbus_init_irq(sbd, &s->streams[0].irq);
|
|
|
|
sysbus_init_irq(sbd, &s->streams[1].irq);
|
|
|
|
|
|
|
|
memory_region_init_io(&s->iomem, &axidma_ops, s,
|
|
|
|
"xlnx.axi-dma", R_MAX * 4 * 2);
|
|
|
|
sysbus_init_mmio(sbd, &s->iomem);
|
2012-08-10 11:16:11 +08:00
|
|
|
}
|
|
|
|
|
2012-01-25 03:12:29 +08:00
|
|
|
static Property axidma_properties[] = {
|
2013-04-16 08:21:23 +08:00
|
|
|
DEFINE_PROP_UINT32("freqhz", XilinxAXIDMA, freqhz, 50000000),
|
2012-01-25 03:12:29 +08:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void axidma_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 11:34:16 +08:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-25 03:12:29 +08:00
|
|
|
|
2013-04-16 08:23:20 +08:00
|
|
|
dc->realize = xilinx_axidma_realize,
|
2013-04-16 08:22:41 +08:00
|
|
|
dc->reset = xilinx_axidma_reset;
|
2011-12-08 11:34:16 +08:00
|
|
|
dc->props = axidma_properties;
|
2013-04-16 08:25:57 +08:00
|
|
|
}
|
|
|
|
|
2013-04-16 08:27:55 +08:00
|
|
|
static StreamSlaveClass xilinx_axidma_data_stream_class = {
|
|
|
|
.push = xilinx_axidma_data_stream_push,
|
|
|
|
.can_push = xilinx_axidma_data_stream_can_push,
|
|
|
|
};
|
|
|
|
|
2013-04-16 08:28:35 +08:00
|
|
|
static StreamSlaveClass xilinx_axidma_control_stream_class = {
|
|
|
|
.push = xilinx_axidma_control_stream_push,
|
|
|
|
};
|
|
|
|
|
2013-04-16 08:25:57 +08:00
|
|
|
static void xilinx_axidma_stream_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
StreamSlaveClass *ssc = STREAM_SLAVE_CLASS(klass);
|
|
|
|
|
2013-04-16 08:27:55 +08:00
|
|
|
ssc->push = ((StreamSlaveClass *)data)->push;
|
|
|
|
ssc->can_push = ((StreamSlaveClass *)data)->can_push;
|
2012-01-25 03:12:29 +08:00
|
|
|
}
|
|
|
|
|
2013-01-10 23:19:07 +08:00
|
|
|
static const TypeInfo axidma_info = {
|
2013-04-16 08:22:02 +08:00
|
|
|
.name = TYPE_XILINX_AXI_DMA,
|
2011-12-08 11:34:16 +08:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
2013-04-16 08:21:23 +08:00
|
|
|
.instance_size = sizeof(XilinxAXIDMA),
|
2011-12-08 11:34:16 +08:00
|
|
|
.class_init = axidma_class_init,
|
2013-04-16 08:23:20 +08:00
|
|
|
.instance_init = xilinx_axidma_init,
|
2013-04-16 08:25:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static const TypeInfo xilinx_axidma_data_stream_info = {
|
|
|
|
.name = TYPE_XILINX_AXI_DMA_DATA_STREAM,
|
|
|
|
.parent = TYPE_OBJECT,
|
|
|
|
.instance_size = sizeof(struct XilinxAXIDMAStreamSlave),
|
|
|
|
.class_init = xilinx_axidma_stream_class_init,
|
2013-04-16 08:27:55 +08:00
|
|
|
.class_data = &xilinx_axidma_data_stream_class,
|
2012-08-10 11:16:11 +08:00
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ TYPE_STREAM_SLAVE },
|
|
|
|
{ }
|
|
|
|
}
|
2011-03-14 18:13:55 +08:00
|
|
|
};
|
|
|
|
|
2013-04-16 08:28:35 +08:00
|
|
|
static const TypeInfo xilinx_axidma_control_stream_info = {
|
|
|
|
.name = TYPE_XILINX_AXI_DMA_CONTROL_STREAM,
|
|
|
|
.parent = TYPE_OBJECT,
|
|
|
|
.instance_size = sizeof(struct XilinxAXIDMAStreamSlave),
|
|
|
|
.class_init = xilinx_axidma_stream_class_init,
|
|
|
|
.class_data = &xilinx_axidma_control_stream_class,
|
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ TYPE_STREAM_SLAVE },
|
|
|
|
{ }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-09 22:20:55 +08:00
|
|
|
static void xilinx_axidma_register_types(void)
|
2011-03-14 18:13:55 +08:00
|
|
|
{
|
2011-12-08 11:34:16 +08:00
|
|
|
type_register_static(&axidma_info);
|
2013-04-16 08:25:57 +08:00
|
|
|
type_register_static(&xilinx_axidma_data_stream_info);
|
2013-04-16 08:28:35 +08:00
|
|
|
type_register_static(&xilinx_axidma_control_stream_info);
|
2011-03-14 18:13:55 +08:00
|
|
|
}
|
|
|
|
|
2012-02-09 22:20:55 +08:00
|
|
|
type_init(xilinx_axidma_register_types)
|