2007-10-29 07:42:18 +08:00
|
|
|
/*
|
|
|
|
* PowerMac descriptor-based DMA emulation
|
|
|
|
*
|
|
|
|
* Copyright (c) 2005-2007 Fabrice Bellard
|
|
|
|
* Copyright (c) 2007 Jocelyn Mayer
|
2009-01-31 04:39:32 +08:00
|
|
|
* Copyright (c) 2009 Laurent Vivier
|
|
|
|
*
|
|
|
|
* some parts from linux-2.6.28, arch/powerpc/include/asm/dbdma.h
|
|
|
|
*
|
|
|
|
* Definitions for using the Apple Descriptor-Based DMA controller
|
|
|
|
* in Power Macintosh computers.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1996 Paul Mackerras.
|
|
|
|
*
|
|
|
|
* some parts from mol 0.9.71
|
|
|
|
*
|
|
|
|
* Descriptor based DMA emulation
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998-2004 Samuel Rydh (samuel@ibrium.se)
|
2007-10-29 07:42:18 +08: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.
|
|
|
|
*/
|
2013-02-04 22:40:22 +08:00
|
|
|
#include "hw/hw.h"
|
2013-02-06 00:06:20 +08:00
|
|
|
#include "hw/isa/isa.h"
|
|
|
|
#include "hw/ppc/mac_dbdma.h"
|
2012-12-18 01:20:00 +08:00
|
|
|
#include "qemu/main-loop.h"
|
2007-10-29 07:42:18 +08:00
|
|
|
|
2008-12-24 17:38:16 +08:00
|
|
|
/* debug DBDMA */
|
|
|
|
//#define DEBUG_DBDMA
|
|
|
|
|
|
|
|
#ifdef DEBUG_DBDMA
|
2009-05-14 01:53:17 +08:00
|
|
|
#define DBDMA_DPRINTF(fmt, ...) \
|
|
|
|
do { printf("DBDMA: " fmt , ## __VA_ARGS__); } while (0)
|
2008-12-24 17:38:16 +08:00
|
|
|
#else
|
2009-05-14 01:53:17 +08:00
|
|
|
#define DBDMA_DPRINTF(fmt, ...)
|
2008-12-24 17:38:16 +08:00
|
|
|
#endif
|
|
|
|
|
2009-01-31 04:39:32 +08:00
|
|
|
/*
|
|
|
|
*/
|
|
|
|
|
2013-06-30 08:22:41 +08:00
|
|
|
static DBDMAState *dbdma_from_ch(DBDMA_channel *ch)
|
|
|
|
{
|
|
|
|
return container_of(ch, DBDMAState, channels[ch->channel]);
|
|
|
|
}
|
|
|
|
|
2009-01-31 04:39:32 +08:00
|
|
|
#ifdef DEBUG_DBDMA
|
|
|
|
static void dump_dbdma_cmd(dbdma_cmd *cmd)
|
|
|
|
{
|
|
|
|
printf("dbdma_cmd %p\n", cmd);
|
|
|
|
printf(" req_count 0x%04x\n", le16_to_cpu(cmd->req_count));
|
|
|
|
printf(" command 0x%04x\n", le16_to_cpu(cmd->command));
|
|
|
|
printf(" phy_addr 0x%08x\n", le32_to_cpu(cmd->phy_addr));
|
|
|
|
printf(" cmd_dep 0x%08x\n", le32_to_cpu(cmd->cmd_dep));
|
|
|
|
printf(" res_count 0x%04x\n", le16_to_cpu(cmd->res_count));
|
|
|
|
printf(" xfer_status 0x%04x\n", le16_to_cpu(cmd->xfer_status));
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void dump_dbdma_cmd(dbdma_cmd *cmd)
|
2007-10-29 07:42:18 +08:00
|
|
|
{
|
2009-01-31 04:39:32 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
static void dbdma_cmdptr_load(DBDMA_channel *ch)
|
|
|
|
{
|
|
|
|
DBDMA_DPRINTF("dbdma_cmdptr_load 0x%08x\n",
|
2009-12-24 08:00:41 +08:00
|
|
|
ch->regs[DBDMA_CMDPTR_LO]);
|
|
|
|
cpu_physical_memory_read(ch->regs[DBDMA_CMDPTR_LO],
|
2013-04-13 02:53:58 +08:00
|
|
|
&ch->current, sizeof(dbdma_cmd));
|
2007-10-29 07:42:18 +08:00
|
|
|
}
|
|
|
|
|
2009-01-31 04:39:32 +08:00
|
|
|
static void dbdma_cmdptr_save(DBDMA_channel *ch)
|
2007-10-29 07:42:18 +08:00
|
|
|
{
|
2009-01-31 04:39:32 +08:00
|
|
|
DBDMA_DPRINTF("dbdma_cmdptr_save 0x%08x\n",
|
2009-12-24 08:00:41 +08:00
|
|
|
ch->regs[DBDMA_CMDPTR_LO]);
|
2009-01-31 04:39:32 +08:00
|
|
|
DBDMA_DPRINTF("xfer_status 0x%08x res_count 0x%04x\n",
|
|
|
|
le16_to_cpu(ch->current.xfer_status),
|
|
|
|
le16_to_cpu(ch->current.res_count));
|
2009-12-24 08:00:41 +08:00
|
|
|
cpu_physical_memory_write(ch->regs[DBDMA_CMDPTR_LO],
|
2013-04-13 02:53:58 +08:00
|
|
|
&ch->current, sizeof(dbdma_cmd));
|
2007-10-29 07:42:18 +08:00
|
|
|
}
|
|
|
|
|
2009-01-31 04:39:32 +08:00
|
|
|
static void kill_channel(DBDMA_channel *ch)
|
2007-10-29 07:42:18 +08:00
|
|
|
{
|
2009-01-31 04:39:32 +08:00
|
|
|
DBDMA_DPRINTF("kill_channel\n");
|
|
|
|
|
2009-12-24 08:00:41 +08:00
|
|
|
ch->regs[DBDMA_STATUS] |= DEAD;
|
|
|
|
ch->regs[DBDMA_STATUS] &= ~ACTIVE;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
|
|
|
qemu_irq_raise(ch->irq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void conditional_interrupt(DBDMA_channel *ch)
|
|
|
|
{
|
|
|
|
dbdma_cmd *current = &ch->current;
|
|
|
|
uint16_t intr;
|
|
|
|
uint16_t sel_mask, sel_value;
|
|
|
|
uint32_t status;
|
|
|
|
int cond;
|
|
|
|
|
2013-06-30 07:23:45 +08:00
|
|
|
DBDMA_DPRINTF("%s\n", __func__);
|
2009-01-31 04:39:32 +08:00
|
|
|
|
2009-03-03 17:14:10 +08:00
|
|
|
intr = le16_to_cpu(current->command) & INTR_MASK;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
|
|
|
switch(intr) {
|
|
|
|
case INTR_NEVER: /* don't interrupt */
|
|
|
|
return;
|
|
|
|
case INTR_ALWAYS: /* always interrupt */
|
|
|
|
qemu_irq_raise(ch->irq);
|
2013-06-30 07:23:45 +08:00
|
|
|
DBDMA_DPRINTF("%s: raise\n", __func__);
|
2009-01-31 04:39:32 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-12-24 08:00:41 +08:00
|
|
|
status = ch->regs[DBDMA_STATUS] & DEVSTAT;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
2009-12-24 08:00:41 +08:00
|
|
|
sel_mask = (ch->regs[DBDMA_INTR_SEL] >> 16) & 0x0f;
|
|
|
|
sel_value = ch->regs[DBDMA_INTR_SEL] & 0x0f;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
|
|
|
cond = (status & sel_mask) == (sel_value & sel_mask);
|
|
|
|
|
|
|
|
switch(intr) {
|
|
|
|
case INTR_IFSET: /* intr if condition bit is 1 */
|
2013-06-30 07:23:45 +08:00
|
|
|
if (cond) {
|
2009-01-31 04:39:32 +08:00
|
|
|
qemu_irq_raise(ch->irq);
|
2013-06-30 07:23:45 +08:00
|
|
|
DBDMA_DPRINTF("%s: raise\n", __func__);
|
|
|
|
}
|
2009-01-31 04:39:32 +08:00
|
|
|
return;
|
|
|
|
case INTR_IFCLR: /* intr if condition bit is 0 */
|
2013-06-30 07:23:45 +08:00
|
|
|
if (!cond) {
|
2009-01-31 04:39:32 +08:00
|
|
|
qemu_irq_raise(ch->irq);
|
2013-06-30 07:23:45 +08:00
|
|
|
DBDMA_DPRINTF("%s: raise\n", __func__);
|
|
|
|
}
|
2009-01-31 04:39:32 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int conditional_wait(DBDMA_channel *ch)
|
|
|
|
{
|
|
|
|
dbdma_cmd *current = &ch->current;
|
|
|
|
uint16_t wait;
|
|
|
|
uint16_t sel_mask, sel_value;
|
|
|
|
uint32_t status;
|
|
|
|
int cond;
|
|
|
|
|
|
|
|
DBDMA_DPRINTF("conditional_wait\n");
|
|
|
|
|
2009-03-03 17:14:10 +08:00
|
|
|
wait = le16_to_cpu(current->command) & WAIT_MASK;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
|
|
|
switch(wait) {
|
|
|
|
case WAIT_NEVER: /* don't wait */
|
|
|
|
return 0;
|
|
|
|
case WAIT_ALWAYS: /* always wait */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-12-24 08:00:41 +08:00
|
|
|
status = ch->regs[DBDMA_STATUS] & DEVSTAT;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
2009-12-24 08:00:41 +08:00
|
|
|
sel_mask = (ch->regs[DBDMA_WAIT_SEL] >> 16) & 0x0f;
|
|
|
|
sel_value = ch->regs[DBDMA_WAIT_SEL] & 0x0f;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
|
|
|
cond = (status & sel_mask) == (sel_value & sel_mask);
|
|
|
|
|
|
|
|
switch(wait) {
|
|
|
|
case WAIT_IFSET: /* wait if condition bit is 1 */
|
|
|
|
if (cond)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
case WAIT_IFCLR: /* wait if condition bit is 0 */
|
|
|
|
if (!cond)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void next(DBDMA_channel *ch)
|
|
|
|
{
|
|
|
|
uint32_t cp;
|
|
|
|
|
2009-12-24 08:00:41 +08:00
|
|
|
ch->regs[DBDMA_STATUS] &= ~BT;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
2009-12-24 08:00:41 +08:00
|
|
|
cp = ch->regs[DBDMA_CMDPTR_LO];
|
|
|
|
ch->regs[DBDMA_CMDPTR_LO] = cp + sizeof(dbdma_cmd);
|
2009-01-31 04:39:32 +08:00
|
|
|
dbdma_cmdptr_load(ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void branch(DBDMA_channel *ch)
|
|
|
|
{
|
|
|
|
dbdma_cmd *current = &ch->current;
|
|
|
|
|
|
|
|
ch->regs[DBDMA_CMDPTR_LO] = current->cmd_dep;
|
2009-12-24 08:00:41 +08:00
|
|
|
ch->regs[DBDMA_STATUS] |= BT;
|
2009-01-31 04:39:32 +08:00
|
|
|
dbdma_cmdptr_load(ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void conditional_branch(DBDMA_channel *ch)
|
|
|
|
{
|
|
|
|
dbdma_cmd *current = &ch->current;
|
|
|
|
uint16_t br;
|
|
|
|
uint16_t sel_mask, sel_value;
|
|
|
|
uint32_t status;
|
|
|
|
int cond;
|
|
|
|
|
|
|
|
DBDMA_DPRINTF("conditional_branch\n");
|
|
|
|
|
|
|
|
/* check if we must branch */
|
|
|
|
|
2009-03-03 17:14:10 +08:00
|
|
|
br = le16_to_cpu(current->command) & BR_MASK;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
|
|
|
switch(br) {
|
|
|
|
case BR_NEVER: /* don't branch */
|
|
|
|
next(ch);
|
|
|
|
return;
|
|
|
|
case BR_ALWAYS: /* always branch */
|
|
|
|
branch(ch);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-12-24 08:00:41 +08:00
|
|
|
status = ch->regs[DBDMA_STATUS] & DEVSTAT;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
2009-12-24 08:00:41 +08:00
|
|
|
sel_mask = (ch->regs[DBDMA_BRANCH_SEL] >> 16) & 0x0f;
|
|
|
|
sel_value = ch->regs[DBDMA_BRANCH_SEL] & 0x0f;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
|
|
|
cond = (status & sel_mask) == (sel_value & sel_mask);
|
|
|
|
|
|
|
|
switch(br) {
|
|
|
|
case BR_IFSET: /* branch if condition bit is 1 */
|
|
|
|
if (cond)
|
|
|
|
branch(ch);
|
|
|
|
else
|
|
|
|
next(ch);
|
|
|
|
return;
|
|
|
|
case BR_IFCLR: /* branch if condition bit is 0 */
|
|
|
|
if (!cond)
|
|
|
|
branch(ch);
|
|
|
|
else
|
|
|
|
next(ch);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-03 17:14:10 +08:00
|
|
|
static void channel_run(DBDMA_channel *ch);
|
2009-01-31 04:39:32 +08:00
|
|
|
|
2009-03-03 17:14:10 +08:00
|
|
|
static void dbdma_end(DBDMA_io *io)
|
2009-01-31 04:39:32 +08:00
|
|
|
{
|
|
|
|
DBDMA_channel *ch = io->channel;
|
|
|
|
dbdma_cmd *current = &ch->current;
|
|
|
|
|
2013-06-30 07:23:45 +08:00
|
|
|
DBDMA_DPRINTF("%s\n", __func__);
|
|
|
|
|
2009-03-03 17:14:10 +08:00
|
|
|
if (conditional_wait(ch))
|
|
|
|
goto wait;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
2009-12-24 08:00:41 +08:00
|
|
|
current->xfer_status = cpu_to_le16(ch->regs[DBDMA_STATUS]);
|
|
|
|
current->res_count = cpu_to_le16(io->len);
|
2009-03-03 17:14:10 +08:00
|
|
|
dbdma_cmdptr_save(ch);
|
2009-03-04 15:20:40 +08:00
|
|
|
if (io->is_last)
|
2009-12-24 08:00:41 +08:00
|
|
|
ch->regs[DBDMA_STATUS] &= ~FLUSH;
|
2009-03-03 17:14:10 +08:00
|
|
|
|
|
|
|
conditional_interrupt(ch);
|
|
|
|
conditional_branch(ch);
|
2009-01-31 04:39:32 +08:00
|
|
|
|
2009-03-03 17:14:10 +08:00
|
|
|
wait:
|
2013-06-30 08:47:20 +08:00
|
|
|
/* Indicate that we're ready for a new DMA round */
|
|
|
|
ch->io.processing = false;
|
|
|
|
|
2009-12-24 08:00:41 +08:00
|
|
|
if ((ch->regs[DBDMA_STATUS] & RUN) &&
|
|
|
|
(ch->regs[DBDMA_STATUS] & ACTIVE))
|
2009-03-03 17:14:10 +08:00
|
|
|
channel_run(ch);
|
2009-01-31 04:39:32 +08:00
|
|
|
}
|
|
|
|
|
2009-03-03 17:14:10 +08:00
|
|
|
static void start_output(DBDMA_channel *ch, int key, uint32_t addr,
|
2009-01-31 04:39:32 +08:00
|
|
|
uint16_t req_count, int is_last)
|
|
|
|
{
|
|
|
|
DBDMA_DPRINTF("start_output\n");
|
|
|
|
|
|
|
|
/* KEY_REGS, KEY_DEVICE and KEY_STREAM
|
|
|
|
* are not implemented in the mac-io chip
|
|
|
|
*/
|
|
|
|
|
|
|
|
DBDMA_DPRINTF("addr 0x%x key 0x%x\n", addr, key);
|
|
|
|
if (!addr || key > KEY_STREAM3) {
|
|
|
|
kill_channel(ch);
|
2009-03-03 17:14:10 +08:00
|
|
|
return;
|
2009-01-31 04:39:32 +08:00
|
|
|
}
|
|
|
|
|
2009-03-03 17:14:10 +08:00
|
|
|
ch->io.addr = addr;
|
2009-01-31 04:39:32 +08:00
|
|
|
ch->io.len = req_count;
|
|
|
|
ch->io.is_last = is_last;
|
2009-03-03 17:14:10 +08:00
|
|
|
ch->io.dma_end = dbdma_end;
|
|
|
|
ch->io.is_dma_out = 1;
|
2013-06-30 08:47:20 +08:00
|
|
|
ch->io.processing = true;
|
2010-02-10 00:37:07 +08:00
|
|
|
if (ch->rw) {
|
|
|
|
ch->rw(&ch->io);
|
|
|
|
}
|
2009-01-31 04:39:32 +08:00
|
|
|
}
|
|
|
|
|
2009-03-03 17:14:10 +08:00
|
|
|
static void start_input(DBDMA_channel *ch, int key, uint32_t addr,
|
2009-01-31 04:39:32 +08:00
|
|
|
uint16_t req_count, int is_last)
|
|
|
|
{
|
|
|
|
DBDMA_DPRINTF("start_input\n");
|
|
|
|
|
|
|
|
/* KEY_REGS, KEY_DEVICE and KEY_STREAM
|
|
|
|
* are not implemented in the mac-io chip
|
|
|
|
*/
|
|
|
|
|
2013-06-30 07:23:45 +08:00
|
|
|
DBDMA_DPRINTF("addr 0x%x key 0x%x\n", addr, key);
|
2009-01-31 04:39:32 +08:00
|
|
|
if (!addr || key > KEY_STREAM3) {
|
|
|
|
kill_channel(ch);
|
2009-03-03 17:14:10 +08:00
|
|
|
return;
|
2009-01-31 04:39:32 +08:00
|
|
|
}
|
|
|
|
|
2009-03-03 17:14:10 +08:00
|
|
|
ch->io.addr = addr;
|
2009-01-31 04:39:32 +08:00
|
|
|
ch->io.len = req_count;
|
|
|
|
ch->io.is_last = is_last;
|
2009-03-03 17:14:10 +08:00
|
|
|
ch->io.dma_end = dbdma_end;
|
|
|
|
ch->io.is_dma_out = 0;
|
2013-06-30 08:47:20 +08:00
|
|
|
ch->io.processing = true;
|
2010-02-10 00:37:07 +08:00
|
|
|
if (ch->rw) {
|
|
|
|
ch->rw(&ch->io);
|
|
|
|
}
|
2009-01-31 04:39:32 +08:00
|
|
|
}
|
|
|
|
|
2009-03-03 17:14:10 +08:00
|
|
|
static void load_word(DBDMA_channel *ch, int key, uint32_t addr,
|
2009-01-31 04:39:32 +08:00
|
|
|
uint16_t len)
|
|
|
|
{
|
|
|
|
dbdma_cmd *current = &ch->current;
|
|
|
|
uint32_t val;
|
|
|
|
|
|
|
|
DBDMA_DPRINTF("load_word\n");
|
|
|
|
|
|
|
|
/* only implements KEY_SYSTEM */
|
|
|
|
|
|
|
|
if (key != KEY_SYSTEM) {
|
|
|
|
printf("DBDMA: LOAD_WORD, unimplemented key %x\n", key);
|
|
|
|
kill_channel(ch);
|
2009-03-03 17:14:10 +08:00
|
|
|
return;
|
2009-01-31 04:39:32 +08:00
|
|
|
}
|
|
|
|
|
2013-04-13 02:53:58 +08:00
|
|
|
cpu_physical_memory_read(addr, &val, len);
|
2009-01-31 04:39:32 +08:00
|
|
|
|
|
|
|
if (len == 2)
|
|
|
|
val = (val << 16) | (current->cmd_dep & 0x0000ffff);
|
|
|
|
else if (len == 1)
|
|
|
|
val = (val << 24) | (current->cmd_dep & 0x00ffffff);
|
|
|
|
|
|
|
|
current->cmd_dep = val;
|
|
|
|
|
|
|
|
if (conditional_wait(ch))
|
2009-03-03 17:14:10 +08:00
|
|
|
goto wait;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
2009-12-24 08:00:41 +08:00
|
|
|
current->xfer_status = cpu_to_le16(ch->regs[DBDMA_STATUS]);
|
2009-01-31 04:39:32 +08:00
|
|
|
dbdma_cmdptr_save(ch);
|
2009-12-24 08:00:41 +08:00
|
|
|
ch->regs[DBDMA_STATUS] &= ~FLUSH;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
|
|
|
conditional_interrupt(ch);
|
|
|
|
next(ch);
|
|
|
|
|
2009-03-03 17:14:10 +08:00
|
|
|
wait:
|
2013-06-30 08:22:41 +08:00
|
|
|
DBDMA_kick(dbdma_from_ch(ch));
|
2009-01-31 04:39:32 +08:00
|
|
|
}
|
|
|
|
|
2009-03-03 17:14:10 +08:00
|
|
|
static void store_word(DBDMA_channel *ch, int key, uint32_t addr,
|
2009-01-31 04:39:32 +08:00
|
|
|
uint16_t len)
|
|
|
|
{
|
|
|
|
dbdma_cmd *current = &ch->current;
|
|
|
|
uint32_t val;
|
|
|
|
|
|
|
|
DBDMA_DPRINTF("store_word\n");
|
|
|
|
|
|
|
|
/* only implements KEY_SYSTEM */
|
|
|
|
|
|
|
|
if (key != KEY_SYSTEM) {
|
|
|
|
printf("DBDMA: STORE_WORD, unimplemented key %x\n", key);
|
|
|
|
kill_channel(ch);
|
2009-03-03 17:14:10 +08:00
|
|
|
return;
|
2009-01-31 04:39:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
val = current->cmd_dep;
|
|
|
|
if (len == 2)
|
|
|
|
val >>= 16;
|
|
|
|
else if (len == 1)
|
|
|
|
val >>= 24;
|
|
|
|
|
2013-04-13 02:53:58 +08:00
|
|
|
cpu_physical_memory_write(addr, &val, len);
|
2009-01-31 04:39:32 +08:00
|
|
|
|
|
|
|
if (conditional_wait(ch))
|
2009-03-03 17:14:10 +08:00
|
|
|
goto wait;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
2009-12-24 08:00:41 +08:00
|
|
|
current->xfer_status = cpu_to_le16(ch->regs[DBDMA_STATUS]);
|
2009-01-31 04:39:32 +08:00
|
|
|
dbdma_cmdptr_save(ch);
|
2009-12-24 08:00:41 +08:00
|
|
|
ch->regs[DBDMA_STATUS] &= ~FLUSH;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
|
|
|
conditional_interrupt(ch);
|
|
|
|
next(ch);
|
|
|
|
|
2009-03-03 17:14:10 +08:00
|
|
|
wait:
|
2013-06-30 08:22:41 +08:00
|
|
|
DBDMA_kick(dbdma_from_ch(ch));
|
2009-01-31 04:39:32 +08:00
|
|
|
}
|
|
|
|
|
2009-03-03 17:14:10 +08:00
|
|
|
static void nop(DBDMA_channel *ch)
|
2009-01-31 04:39:32 +08:00
|
|
|
{
|
|
|
|
dbdma_cmd *current = &ch->current;
|
|
|
|
|
|
|
|
if (conditional_wait(ch))
|
2009-03-03 17:14:10 +08:00
|
|
|
goto wait;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
2009-12-24 08:00:41 +08:00
|
|
|
current->xfer_status = cpu_to_le16(ch->regs[DBDMA_STATUS]);
|
2009-01-31 04:39:32 +08:00
|
|
|
dbdma_cmdptr_save(ch);
|
|
|
|
|
|
|
|
conditional_interrupt(ch);
|
|
|
|
conditional_branch(ch);
|
|
|
|
|
2009-03-03 17:14:10 +08:00
|
|
|
wait:
|
2013-06-30 08:22:41 +08:00
|
|
|
DBDMA_kick(dbdma_from_ch(ch));
|
2007-10-29 07:42:18 +08:00
|
|
|
}
|
|
|
|
|
2009-03-03 17:14:10 +08:00
|
|
|
static void stop(DBDMA_channel *ch)
|
2007-10-29 07:42:18 +08:00
|
|
|
{
|
2009-12-24 08:00:41 +08:00
|
|
|
ch->regs[DBDMA_STATUS] &= ~(ACTIVE|DEAD|FLUSH);
|
2009-01-31 04:39:32 +08:00
|
|
|
|
|
|
|
/* the stop command does not increment command pointer */
|
2007-10-29 07:42:18 +08:00
|
|
|
}
|
|
|
|
|
2009-03-03 17:14:10 +08:00
|
|
|
static void channel_run(DBDMA_channel *ch)
|
2007-10-29 07:42:18 +08:00
|
|
|
{
|
2009-01-31 04:39:32 +08:00
|
|
|
dbdma_cmd *current = &ch->current;
|
|
|
|
uint16_t cmd, key;
|
|
|
|
uint16_t req_count;
|
|
|
|
uint32_t phy_addr;
|
|
|
|
|
|
|
|
DBDMA_DPRINTF("channel_run\n");
|
|
|
|
dump_dbdma_cmd(current);
|
|
|
|
|
|
|
|
/* clear WAKE flag at command fetch */
|
|
|
|
|
2009-12-24 08:00:41 +08:00
|
|
|
ch->regs[DBDMA_STATUS] &= ~WAKE;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
|
|
|
cmd = le16_to_cpu(current->command) & COMMAND_MASK;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case DBDMA_NOP:
|
2009-03-03 17:14:10 +08:00
|
|
|
nop(ch);
|
2013-06-30 07:45:22 +08:00
|
|
|
return;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
|
|
|
case DBDMA_STOP:
|
2009-03-03 17:14:10 +08:00
|
|
|
stop(ch);
|
2013-06-30 07:45:22 +08:00
|
|
|
return;
|
2009-01-31 04:39:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
key = le16_to_cpu(current->command) & 0x0700;
|
|
|
|
req_count = le16_to_cpu(current->req_count);
|
|
|
|
phy_addr = le32_to_cpu(current->phy_addr);
|
|
|
|
|
|
|
|
if (key == KEY_STREAM4) {
|
|
|
|
printf("command %x, invalid key 4\n", cmd);
|
|
|
|
kill_channel(ch);
|
2009-03-03 17:14:10 +08:00
|
|
|
return;
|
2009-01-31 04:39:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case OUTPUT_MORE:
|
2009-03-03 17:14:10 +08:00
|
|
|
start_output(ch, key, phy_addr, req_count, 0);
|
2013-06-30 07:45:22 +08:00
|
|
|
return;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
|
|
|
case OUTPUT_LAST:
|
2009-03-03 17:14:10 +08:00
|
|
|
start_output(ch, key, phy_addr, req_count, 1);
|
2013-06-30 07:45:22 +08:00
|
|
|
return;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
|
|
|
case INPUT_MORE:
|
2009-03-03 17:14:10 +08:00
|
|
|
start_input(ch, key, phy_addr, req_count, 0);
|
2013-06-30 07:45:22 +08:00
|
|
|
return;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
|
|
|
case INPUT_LAST:
|
2009-03-03 17:14:10 +08:00
|
|
|
start_input(ch, key, phy_addr, req_count, 1);
|
2013-06-30 07:45:22 +08:00
|
|
|
return;
|
2009-01-31 04:39:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (key < KEY_REGS) {
|
|
|
|
printf("command %x, invalid key %x\n", cmd, key);
|
|
|
|
key = KEY_SYSTEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* for LOAD_WORD and STORE_WORD, req_count is on 3 bits
|
|
|
|
* and BRANCH is invalid
|
|
|
|
*/
|
|
|
|
|
|
|
|
req_count = req_count & 0x0007;
|
|
|
|
if (req_count & 0x4) {
|
|
|
|
req_count = 4;
|
|
|
|
phy_addr &= ~3;
|
|
|
|
} else if (req_count & 0x2) {
|
|
|
|
req_count = 2;
|
|
|
|
phy_addr &= ~1;
|
|
|
|
} else
|
|
|
|
req_count = 1;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case LOAD_WORD:
|
2009-03-03 17:14:10 +08:00
|
|
|
load_word(ch, key, phy_addr, req_count);
|
2013-06-30 07:45:22 +08:00
|
|
|
return;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
|
|
|
case STORE_WORD:
|
2009-03-03 17:14:10 +08:00
|
|
|
store_word(ch, key, phy_addr, req_count);
|
2013-06-30 07:45:22 +08:00
|
|
|
return;
|
2009-01-31 04:39:32 +08:00
|
|
|
}
|
2007-10-29 07:42:18 +08:00
|
|
|
}
|
|
|
|
|
2010-12-03 07:04:02 +08:00
|
|
|
static void DBDMA_run(DBDMAState *s)
|
2009-01-31 04:39:32 +08:00
|
|
|
{
|
|
|
|
int channel;
|
|
|
|
|
2010-12-03 07:04:02 +08:00
|
|
|
for (channel = 0; channel < DBDMA_CHANNELS; channel++) {
|
|
|
|
DBDMA_channel *ch = &s->channels[channel];
|
|
|
|
uint32_t status = ch->regs[DBDMA_STATUS];
|
2013-06-30 08:47:20 +08:00
|
|
|
if (!ch->io.processing && (status & RUN) && (status & ACTIVE)) {
|
2010-12-03 07:04:02 +08:00
|
|
|
channel_run(ch);
|
|
|
|
}
|
2009-01-31 04:39:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DBDMA_run_bh(void *opaque)
|
|
|
|
{
|
2010-12-03 07:04:02 +08:00
|
|
|
DBDMAState *s = opaque;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
|
|
|
DBDMA_DPRINTF("DBDMA_run_bh\n");
|
|
|
|
|
2010-12-03 07:04:02 +08:00
|
|
|
DBDMA_run(s);
|
2009-01-31 04:39:32 +08:00
|
|
|
}
|
|
|
|
|
2013-06-30 08:18:54 +08:00
|
|
|
void DBDMA_kick(DBDMAState *dbdma)
|
|
|
|
{
|
2013-06-30 08:22:41 +08:00
|
|
|
qemu_bh_schedule(dbdma->bh);
|
2013-06-30 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
2009-01-31 04:39:32 +08:00
|
|
|
void DBDMA_register_channel(void *dbdma, int nchan, qemu_irq irq,
|
2009-03-04 15:20:40 +08:00
|
|
|
DBDMA_rw rw, DBDMA_flush flush,
|
2009-01-31 04:39:32 +08:00
|
|
|
void *opaque)
|
|
|
|
{
|
2010-12-03 07:04:02 +08:00
|
|
|
DBDMAState *s = dbdma;
|
|
|
|
DBDMA_channel *ch = &s->channels[nchan];
|
2009-01-31 04:39:32 +08:00
|
|
|
|
|
|
|
DBDMA_DPRINTF("DBDMA_register_channel 0x%x\n", nchan);
|
|
|
|
|
|
|
|
ch->irq = irq;
|
|
|
|
ch->channel = nchan;
|
2009-03-03 17:14:10 +08:00
|
|
|
ch->rw = rw;
|
2009-03-04 15:20:40 +08:00
|
|
|
ch->flush = flush;
|
2009-01-31 04:39:32 +08:00
|
|
|
ch->io.opaque = opaque;
|
|
|
|
ch->io.channel = ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dbdma_control_write(DBDMA_channel *ch)
|
|
|
|
{
|
|
|
|
uint16_t mask, value;
|
|
|
|
uint32_t status;
|
|
|
|
|
2009-12-24 08:00:41 +08:00
|
|
|
mask = (ch->regs[DBDMA_CONTROL] >> 16) & 0xffff;
|
|
|
|
value = ch->regs[DBDMA_CONTROL] & 0xffff;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
|
|
|
value &= (RUN | PAUSE | FLUSH | WAKE | DEVSTAT);
|
|
|
|
|
2009-12-24 08:00:41 +08:00
|
|
|
status = ch->regs[DBDMA_STATUS];
|
2009-01-31 04:39:32 +08:00
|
|
|
|
|
|
|
status = (value & mask) | (status & ~mask);
|
|
|
|
|
|
|
|
if (status & WAKE)
|
|
|
|
status |= ACTIVE;
|
|
|
|
if (status & RUN) {
|
|
|
|
status |= ACTIVE;
|
|
|
|
status &= ~DEAD;
|
|
|
|
}
|
|
|
|
if (status & PAUSE)
|
|
|
|
status &= ~ACTIVE;
|
2009-12-24 08:00:41 +08:00
|
|
|
if ((ch->regs[DBDMA_STATUS] & RUN) && !(status & RUN)) {
|
2009-01-31 04:39:32 +08:00
|
|
|
/* RUN is cleared */
|
|
|
|
status &= ~(ACTIVE|DEAD);
|
2013-02-21 15:34:11 +08:00
|
|
|
if ((status & FLUSH) && ch->flush) {
|
|
|
|
ch->flush(&ch->io);
|
|
|
|
status &= ~FLUSH;
|
|
|
|
}
|
2009-01-31 04:39:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DBDMA_DPRINTF(" status 0x%08x\n", status);
|
|
|
|
|
2009-12-24 08:00:41 +08:00
|
|
|
ch->regs[DBDMA_STATUS] = status;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
2013-06-30 08:22:41 +08:00
|
|
|
if (status & ACTIVE) {
|
|
|
|
DBDMA_kick(dbdma_from_ch(ch));
|
|
|
|
}
|
|
|
|
if ((status & FLUSH) && ch->flush) {
|
2009-03-04 15:20:40 +08:00
|
|
|
ch->flush(&ch->io);
|
2013-06-30 08:22:41 +08:00
|
|
|
}
|
2009-01-31 04:39:32 +08:00
|
|
|
}
|
|
|
|
|
2012-10-23 18:30:10 +08:00
|
|
|
static void dbdma_write(void *opaque, hwaddr addr,
|
2011-08-08 21:09:17 +08:00
|
|
|
uint64_t value, unsigned size)
|
2009-01-31 04:39:32 +08:00
|
|
|
{
|
|
|
|
int channel = addr >> DBDMA_CHANNEL_SHIFT;
|
2010-12-03 07:04:02 +08:00
|
|
|
DBDMAState *s = opaque;
|
|
|
|
DBDMA_channel *ch = &s->channels[channel];
|
2009-01-31 04:39:32 +08:00
|
|
|
int reg = (addr - (channel << DBDMA_CHANNEL_SHIFT)) >> 2;
|
|
|
|
|
2013-06-30 07:53:05 +08:00
|
|
|
DBDMA_DPRINTF("writel 0x" TARGET_FMT_plx " <= 0x%08"PRIx64"\n",
|
|
|
|
addr, value);
|
2009-01-31 04:39:32 +08:00
|
|
|
DBDMA_DPRINTF("channel 0x%x reg 0x%x\n",
|
|
|
|
(uint32_t)addr >> DBDMA_CHANNEL_SHIFT, reg);
|
|
|
|
|
2013-06-30 07:53:51 +08:00
|
|
|
/* cmdptr cannot be modified if channel is ACTIVE */
|
2009-01-31 04:39:32 +08:00
|
|
|
|
2013-06-30 07:53:51 +08:00
|
|
|
if (reg == DBDMA_CMDPTR_LO && (ch->regs[DBDMA_STATUS] & ACTIVE)) {
|
2013-06-30 07:45:22 +08:00
|
|
|
return;
|
2013-06-30 07:53:51 +08:00
|
|
|
}
|
2009-01-31 04:39:32 +08:00
|
|
|
|
|
|
|
ch->regs[reg] = value;
|
|
|
|
|
|
|
|
switch(reg) {
|
|
|
|
case DBDMA_CONTROL:
|
|
|
|
dbdma_control_write(ch);
|
|
|
|
break;
|
|
|
|
case DBDMA_CMDPTR_LO:
|
|
|
|
/* 16-byte aligned */
|
2009-12-24 08:00:41 +08:00
|
|
|
ch->regs[DBDMA_CMDPTR_LO] &= ~0xf;
|
2009-01-31 04:39:32 +08:00
|
|
|
dbdma_cmdptr_load(ch);
|
|
|
|
break;
|
|
|
|
case DBDMA_STATUS:
|
|
|
|
case DBDMA_INTR_SEL:
|
|
|
|
case DBDMA_BRANCH_SEL:
|
|
|
|
case DBDMA_WAIT_SEL:
|
|
|
|
/* nothing to do */
|
|
|
|
break;
|
|
|
|
case DBDMA_XFER_MODE:
|
|
|
|
case DBDMA_CMDPTR_HI:
|
|
|
|
case DBDMA_DATA2PTR_HI:
|
|
|
|
case DBDMA_DATA2PTR_LO:
|
|
|
|
case DBDMA_ADDRESS_HI:
|
|
|
|
case DBDMA_BRANCH_ADDR_HI:
|
|
|
|
case DBDMA_RES1:
|
|
|
|
case DBDMA_RES2:
|
|
|
|
case DBDMA_RES3:
|
|
|
|
case DBDMA_RES4:
|
|
|
|
/* unused */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 18:30:10 +08:00
|
|
|
static uint64_t dbdma_read(void *opaque, hwaddr addr,
|
2011-08-08 21:09:17 +08:00
|
|
|
unsigned size)
|
2007-10-29 07:42:18 +08:00
|
|
|
{
|
2009-01-31 04:39:32 +08:00
|
|
|
uint32_t value;
|
|
|
|
int channel = addr >> DBDMA_CHANNEL_SHIFT;
|
2010-12-03 07:04:02 +08:00
|
|
|
DBDMAState *s = opaque;
|
|
|
|
DBDMA_channel *ch = &s->channels[channel];
|
2009-01-31 04:39:32 +08:00
|
|
|
int reg = (addr - (channel << DBDMA_CHANNEL_SHIFT)) >> 2;
|
2008-12-24 17:38:16 +08:00
|
|
|
|
2009-01-31 04:39:32 +08:00
|
|
|
value = ch->regs[reg];
|
|
|
|
|
|
|
|
DBDMA_DPRINTF("readl 0x" TARGET_FMT_plx " => 0x%08x\n", addr, value);
|
|
|
|
DBDMA_DPRINTF("channel 0x%x reg 0x%x\n",
|
|
|
|
(uint32_t)addr >> DBDMA_CHANNEL_SHIFT, reg);
|
|
|
|
|
|
|
|
switch(reg) {
|
|
|
|
case DBDMA_CONTROL:
|
|
|
|
value = 0;
|
|
|
|
break;
|
|
|
|
case DBDMA_STATUS:
|
|
|
|
case DBDMA_CMDPTR_LO:
|
|
|
|
case DBDMA_INTR_SEL:
|
|
|
|
case DBDMA_BRANCH_SEL:
|
|
|
|
case DBDMA_WAIT_SEL:
|
|
|
|
/* nothing to do */
|
|
|
|
break;
|
|
|
|
case DBDMA_XFER_MODE:
|
|
|
|
case DBDMA_CMDPTR_HI:
|
|
|
|
case DBDMA_DATA2PTR_HI:
|
|
|
|
case DBDMA_DATA2PTR_LO:
|
|
|
|
case DBDMA_ADDRESS_HI:
|
|
|
|
case DBDMA_BRANCH_ADDR_HI:
|
|
|
|
/* unused */
|
|
|
|
value = 0;
|
|
|
|
break;
|
|
|
|
case DBDMA_RES1:
|
|
|
|
case DBDMA_RES2:
|
|
|
|
case DBDMA_RES3:
|
|
|
|
case DBDMA_RES4:
|
|
|
|
/* reserved */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
2007-10-29 07:42:18 +08:00
|
|
|
}
|
|
|
|
|
2011-08-08 21:09:17 +08:00
|
|
|
static const MemoryRegionOps dbdma_ops = {
|
|
|
|
.read = dbdma_read,
|
|
|
|
.write = dbdma_write,
|
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
|
|
|
.valid = {
|
|
|
|
.min_access_size = 4,
|
|
|
|
.max_access_size = 4,
|
|
|
|
},
|
2007-10-29 07:42:18 +08:00
|
|
|
};
|
|
|
|
|
2010-12-03 07:07:26 +08:00
|
|
|
static const VMStateDescription vmstate_dbdma_channel = {
|
|
|
|
.name = "dbdma_channel",
|
|
|
|
.version_id = 0,
|
|
|
|
.minimum_version_id = 0,
|
|
|
|
.minimum_version_id_old = 0,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT32_ARRAY(regs, struct DBDMA_channel, DBDMA_REGS),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
2009-01-31 04:39:32 +08:00
|
|
|
|
2010-12-03 07:07:26 +08:00
|
|
|
static const VMStateDescription vmstate_dbdma = {
|
|
|
|
.name = "dbdma",
|
|
|
|
.version_id = 2,
|
|
|
|
.minimum_version_id = 2,
|
|
|
|
.minimum_version_id_old = 2,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_STRUCT_ARRAY(channels, DBDMAState, DBDMA_CHANNELS, 1,
|
|
|
|
vmstate_dbdma_channel, DBDMA_channel),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
2008-12-31 03:01:19 +08:00
|
|
|
|
2008-12-29 02:27:10 +08:00
|
|
|
static void dbdma_reset(void *opaque)
|
|
|
|
{
|
2010-12-03 07:04:02 +08:00
|
|
|
DBDMAState *s = opaque;
|
2009-01-31 04:39:32 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < DBDMA_CHANNELS; i++)
|
2010-12-03 07:04:02 +08:00
|
|
|
memset(s->channels[i].regs, 0, DBDMA_SIZE);
|
2008-12-29 02:27:10 +08:00
|
|
|
}
|
|
|
|
|
2011-08-08 21:09:17 +08:00
|
|
|
void* DBDMA_init (MemoryRegion **dbdma_mem)
|
2007-10-29 07:42:18 +08:00
|
|
|
{
|
2010-12-03 07:04:02 +08:00
|
|
|
DBDMAState *s;
|
2009-01-31 04:39:32 +08:00
|
|
|
|
2011-08-21 11:09:37 +08:00
|
|
|
s = g_malloc0(sizeof(DBDMAState));
|
2009-01-31 04:39:32 +08:00
|
|
|
|
2013-06-06 17:41:28 +08:00
|
|
|
memory_region_init_io(&s->mem, NULL, &dbdma_ops, s, "dbdma", 0x1000);
|
2011-08-08 21:09:17 +08:00
|
|
|
*dbdma_mem = &s->mem;
|
2010-12-03 07:07:26 +08:00
|
|
|
vmstate_register(NULL, -1, &vmstate_dbdma, s);
|
2009-06-27 15:25:07 +08:00
|
|
|
qemu_register_reset(dbdma_reset, s);
|
2009-01-31 04:39:32 +08:00
|
|
|
|
2013-06-30 08:22:41 +08:00
|
|
|
s->bh = qemu_bh_new(DBDMA_run_bh, s);
|
2009-01-31 04:39:32 +08:00
|
|
|
|
|
|
|
return s;
|
2007-10-29 07:42:18 +08:00
|
|
|
}
|