From patchwork Tue Dec 22 13:45:17 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 41611 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B9D5FB7BBD for ; Wed, 23 Dec 2009 00:46:34 +1100 (EST) Received: from localhost ([127.0.0.1]:38340 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NN54I-0003ze-QM for incoming@patchwork.ozlabs.org; Tue, 22 Dec 2009 08:46:30 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NN53G-0003pH-4l for qemu-devel@nongnu.org; Tue, 22 Dec 2009 08:45:26 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NN53B-0003oQ-5w for qemu-devel@nongnu.org; Tue, 22 Dec 2009 08:45:25 -0500 Received: from [199.232.76.173] (port=43532 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NN53A-0003oF-W9 for qemu-devel@nongnu.org; Tue, 22 Dec 2009 08:45:21 -0500 Received: from cantor.suse.de ([195.135.220.2]:38446 helo=mx1.suse.de) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NN53A-0001ot-F9 for qemu-devel@nongnu.org; Tue, 22 Dec 2009 08:45:21 -0500 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.suse.de (Postfix) with ESMTP id 6645C9417A; Tue, 22 Dec 2009 14:45:18 +0100 (CET) From: Alexander Graf To: qemu-devel@nongnu.org Date: Tue, 22 Dec 2009 14:45:17 +0100 Message-Id: <1261489517-29509-1-git-send-email-agraf@suse.de> X-Mailer: git-send-email 1.6.0.2 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.4-2.6 Cc: Laurent Vivier , Aurelien Jarno Subject: [Qemu-devel] [PATCH] Always swap endianness in DBDMA X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When we get an MMIO request, we always get variables in host endianness. The only time we need to actually reverse byte order is when we read bytes from guest memory. Apparently the DBDMA implementation is different there. A lot of the logic in there depends on values being big endian. Now, qemu does all the conversion in the MMIO handlers for us already though, so it turns out that we're in the same byte order from a C point of view, but cpu_to_be32 and be32_to_cpu end up being nops. This makes the code work differently on x86 (little endian) than on ppc (big endian). On x86 it works, on ppc it doesn't. This patch (while being seriously hacky and ugly) makes dbdma emulation work on ppc hosts. I'll leave the real fixing to someone else. Signed-off-by: Alexander Graf CC: Laurent Vivier --- V1 -> V2: - s/cpu_to_be32/dbdma_cpu_to_be32/g - s/be32_to_cpu/dbdma_be32_to_cpu/g --- hw/mac_dbdma.c | 86 ++++++++++++++++++++++++++++++------------------------- 1 files changed, 47 insertions(+), 39 deletions(-) diff --git a/hw/mac_dbdma.c b/hw/mac_dbdma.c index 98dccfd..555983a 100644 --- a/hw/mac_dbdma.c +++ b/hw/mac_dbdma.c @@ -40,6 +40,14 @@ #include "isa.h" #include "mac_dbdma.h" +/* + * XXX This is just plain wrong. Apparently we don't want to have big endian + * values, but reversed endian ones. The code as is doesn't work on big + * endian hosts. With these defines it does. + */ +#define dbdma_cpu_to_be32 bswap32 +#define dbdma_be32_to_cpu bswap32 + /* debug DBDMA */ //#define DEBUG_DBDMA @@ -184,19 +192,19 @@ static void dump_dbdma_cmd(dbdma_cmd *cmd) static void dbdma_cmdptr_load(DBDMA_channel *ch) { DBDMA_DPRINTF("dbdma_cmdptr_load 0x%08x\n", - be32_to_cpu(ch->regs[DBDMA_CMDPTR_LO])); - cpu_physical_memory_read(be32_to_cpu(ch->regs[DBDMA_CMDPTR_LO]), + dbdma_be32_to_cpu(ch->regs[DBDMA_CMDPTR_LO])); + cpu_physical_memory_read(dbdma_be32_to_cpu(ch->regs[DBDMA_CMDPTR_LO]), (uint8_t*)&ch->current, sizeof(dbdma_cmd)); } static void dbdma_cmdptr_save(DBDMA_channel *ch) { DBDMA_DPRINTF("dbdma_cmdptr_save 0x%08x\n", - be32_to_cpu(ch->regs[DBDMA_CMDPTR_LO])); + dbdma_be32_to_cpu(ch->regs[DBDMA_CMDPTR_LO])); 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)); - cpu_physical_memory_write(be32_to_cpu(ch->regs[DBDMA_CMDPTR_LO]), + cpu_physical_memory_write(dbdma_be32_to_cpu(ch->regs[DBDMA_CMDPTR_LO]), (uint8_t*)&ch->current, sizeof(dbdma_cmd)); } @@ -204,8 +212,8 @@ static void kill_channel(DBDMA_channel *ch) { DBDMA_DPRINTF("kill_channel\n"); - ch->regs[DBDMA_STATUS] |= cpu_to_be32(DEAD); - ch->regs[DBDMA_STATUS] &= cpu_to_be32(~ACTIVE); + ch->regs[DBDMA_STATUS] |= dbdma_cpu_to_be32(DEAD); + ch->regs[DBDMA_STATUS] &= dbdma_cpu_to_be32(~ACTIVE); qemu_irq_raise(ch->irq); } @@ -230,10 +238,10 @@ static void conditional_interrupt(DBDMA_channel *ch) return; } - status = be32_to_cpu(ch->regs[DBDMA_STATUS]) & DEVSTAT; + status = dbdma_be32_to_cpu(ch->regs[DBDMA_STATUS]) & DEVSTAT; - sel_mask = (be32_to_cpu(ch->regs[DBDMA_INTR_SEL]) >> 16) & 0x0f; - sel_value = be32_to_cpu(ch->regs[DBDMA_INTR_SEL]) & 0x0f; + sel_mask = (dbdma_be32_to_cpu(ch->regs[DBDMA_INTR_SEL]) >> 16) & 0x0f; + sel_value = dbdma_be32_to_cpu(ch->regs[DBDMA_INTR_SEL]) & 0x0f; cond = (status & sel_mask) == (sel_value & sel_mask); @@ -268,10 +276,10 @@ static int conditional_wait(DBDMA_channel *ch) return 1; } - status = be32_to_cpu(ch->regs[DBDMA_STATUS]) & DEVSTAT; + status = dbdma_be32_to_cpu(ch->regs[DBDMA_STATUS]) & DEVSTAT; - sel_mask = (be32_to_cpu(ch->regs[DBDMA_WAIT_SEL]) >> 16) & 0x0f; - sel_value = be32_to_cpu(ch->regs[DBDMA_WAIT_SEL]) & 0x0f; + sel_mask = (dbdma_be32_to_cpu(ch->regs[DBDMA_WAIT_SEL]) >> 16) & 0x0f; + sel_value = dbdma_be32_to_cpu(ch->regs[DBDMA_WAIT_SEL]) & 0x0f; cond = (status & sel_mask) == (sel_value & sel_mask); @@ -292,10 +300,10 @@ static void next(DBDMA_channel *ch) { uint32_t cp; - ch->regs[DBDMA_STATUS] &= cpu_to_be32(~BT); + ch->regs[DBDMA_STATUS] &= dbdma_cpu_to_be32(~BT); - cp = be32_to_cpu(ch->regs[DBDMA_CMDPTR_LO]); - ch->regs[DBDMA_CMDPTR_LO] = cpu_to_be32(cp + sizeof(dbdma_cmd)); + cp = dbdma_be32_to_cpu(ch->regs[DBDMA_CMDPTR_LO]); + ch->regs[DBDMA_CMDPTR_LO] = dbdma_cpu_to_be32(cp + sizeof(dbdma_cmd)); dbdma_cmdptr_load(ch); } @@ -304,7 +312,7 @@ static void branch(DBDMA_channel *ch) dbdma_cmd *current = &ch->current; ch->regs[DBDMA_CMDPTR_LO] = current->cmd_dep; - ch->regs[DBDMA_STATUS] |= cpu_to_be32(BT); + ch->regs[DBDMA_STATUS] |= dbdma_cpu_to_be32(BT); dbdma_cmdptr_load(ch); } @@ -331,10 +339,10 @@ static void conditional_branch(DBDMA_channel *ch) return; } - status = be32_to_cpu(ch->regs[DBDMA_STATUS]) & DEVSTAT; + status = dbdma_be32_to_cpu(ch->regs[DBDMA_STATUS]) & DEVSTAT; - sel_mask = (be32_to_cpu(ch->regs[DBDMA_BRANCH_SEL]) >> 16) & 0x0f; - sel_value = be32_to_cpu(ch->regs[DBDMA_BRANCH_SEL]) & 0x0f; + sel_mask = (dbdma_be32_to_cpu(ch->regs[DBDMA_BRANCH_SEL]) >> 16) & 0x0f; + sel_value = dbdma_be32_to_cpu(ch->regs[DBDMA_BRANCH_SEL]) & 0x0f; cond = (status & sel_mask) == (sel_value & sel_mask); @@ -365,19 +373,19 @@ static void dbdma_end(DBDMA_io *io) if (conditional_wait(ch)) goto wait; - current->xfer_status = cpu_to_le16(be32_to_cpu(ch->regs[DBDMA_STATUS])); - current->res_count = cpu_to_le16(be32_to_cpu(io->len)); + current->xfer_status = cpu_to_le16(dbdma_be32_to_cpu(ch->regs[DBDMA_STATUS])); + current->res_count = cpu_to_le16(dbdma_be32_to_cpu(io->len)); dbdma_cmdptr_save(ch); if (io->is_last) - ch->regs[DBDMA_STATUS] &= cpu_to_be32(~FLUSH); + ch->regs[DBDMA_STATUS] &= dbdma_cpu_to_be32(~FLUSH); conditional_interrupt(ch); conditional_branch(ch); wait: ch->processing = 0; - if ((ch->regs[DBDMA_STATUS] & cpu_to_be32(RUN)) && - (ch->regs[DBDMA_STATUS] & cpu_to_be32(ACTIVE))) + if ((ch->regs[DBDMA_STATUS] & dbdma_cpu_to_be32(RUN)) && + (ch->regs[DBDMA_STATUS] & dbdma_cpu_to_be32(ACTIVE))) channel_run(ch); } @@ -456,9 +464,9 @@ static void load_word(DBDMA_channel *ch, int key, uint32_t addr, if (conditional_wait(ch)) goto wait; - current->xfer_status = cpu_to_le16(be32_to_cpu(ch->regs[DBDMA_STATUS])); + current->xfer_status = cpu_to_le16(dbdma_be32_to_cpu(ch->regs[DBDMA_STATUS])); dbdma_cmdptr_save(ch); - ch->regs[DBDMA_STATUS] &= cpu_to_be32(~FLUSH); + ch->regs[DBDMA_STATUS] &= dbdma_cpu_to_be32(~FLUSH); conditional_interrupt(ch); next(ch); @@ -494,9 +502,9 @@ static void store_word(DBDMA_channel *ch, int key, uint32_t addr, if (conditional_wait(ch)) goto wait; - current->xfer_status = cpu_to_le16(be32_to_cpu(ch->regs[DBDMA_STATUS])); + current->xfer_status = cpu_to_le16(dbdma_be32_to_cpu(ch->regs[DBDMA_STATUS])); dbdma_cmdptr_save(ch); - ch->regs[DBDMA_STATUS] &= cpu_to_be32(~FLUSH); + ch->regs[DBDMA_STATUS] &= dbdma_cpu_to_be32(~FLUSH); conditional_interrupt(ch); next(ch); @@ -512,7 +520,7 @@ static void nop(DBDMA_channel *ch) if (conditional_wait(ch)) goto wait; - current->xfer_status = cpu_to_le16(be32_to_cpu(ch->regs[DBDMA_STATUS])); + current->xfer_status = cpu_to_le16(dbdma_be32_to_cpu(ch->regs[DBDMA_STATUS])); dbdma_cmdptr_save(ch); conditional_interrupt(ch); @@ -524,7 +532,7 @@ wait: static void stop(DBDMA_channel *ch) { - ch->regs[DBDMA_STATUS] &= cpu_to_be32(~(ACTIVE|DEAD|FLUSH)); + ch->regs[DBDMA_STATUS] &= dbdma_cpu_to_be32(~(ACTIVE|DEAD|FLUSH)); /* the stop command does not increment command pointer */ } @@ -541,7 +549,7 @@ static void channel_run(DBDMA_channel *ch) /* clear WAKE flag at command fetch */ - ch->regs[DBDMA_STATUS] &= cpu_to_be32(~WAKE); + ch->regs[DBDMA_STATUS] &= dbdma_cpu_to_be32(~WAKE); cmd = le16_to_cpu(current->command) & COMMAND_MASK; @@ -618,7 +626,7 @@ static void DBDMA_run (DBDMA_channel *ch) int channel; for (channel = 0; channel < DBDMA_CHANNELS; channel++, ch++) { - uint32_t status = be32_to_cpu(ch->regs[DBDMA_STATUS]); + uint32_t status = dbdma_be32_to_cpu(ch->regs[DBDMA_STATUS]); if (!ch->processing && (status & RUN) && (status & ACTIVE)) channel_run(ch); } @@ -660,12 +668,12 @@ dbdma_control_write(DBDMA_channel *ch) uint16_t mask, value; uint32_t status; - mask = (be32_to_cpu(ch->regs[DBDMA_CONTROL]) >> 16) & 0xffff; - value = be32_to_cpu(ch->regs[DBDMA_CONTROL]) & 0xffff; + mask = (dbdma_be32_to_cpu(ch->regs[DBDMA_CONTROL]) >> 16) & 0xffff; + value = dbdma_be32_to_cpu(ch->regs[DBDMA_CONTROL]) & 0xffff; value &= (RUN | PAUSE | FLUSH | WAKE | DEVSTAT); - status = be32_to_cpu(ch->regs[DBDMA_STATUS]); + status = dbdma_be32_to_cpu(ch->regs[DBDMA_STATUS]); status = (value & mask) | (status & ~mask); @@ -677,14 +685,14 @@ dbdma_control_write(DBDMA_channel *ch) } if (status & PAUSE) status &= ~ACTIVE; - if ((be32_to_cpu(ch->regs[DBDMA_STATUS]) & RUN) && !(status & RUN)) { + if ((dbdma_be32_to_cpu(ch->regs[DBDMA_STATUS]) & RUN) && !(status & RUN)) { /* RUN is cleared */ status &= ~(ACTIVE|DEAD); } DBDMA_DPRINTF(" status 0x%08x\n", status); - ch->regs[DBDMA_STATUS] = cpu_to_be32(status); + ch->regs[DBDMA_STATUS] = dbdma_cpu_to_be32(status); if (status & ACTIVE) qemu_bh_schedule(dbdma_bh); @@ -706,7 +714,7 @@ static void dbdma_writel (void *opaque, /* cmdptr cannot be modified if channel is RUN or ACTIVE */ if (reg == DBDMA_CMDPTR_LO && - (ch->regs[DBDMA_STATUS] & cpu_to_be32(RUN | ACTIVE))) + (ch->regs[DBDMA_STATUS] & dbdma_cpu_to_be32(RUN | ACTIVE))) return; ch->regs[reg] = value; @@ -717,7 +725,7 @@ static void dbdma_writel (void *opaque, break; case DBDMA_CMDPTR_LO: /* 16-byte aligned */ - ch->regs[DBDMA_CMDPTR_LO] &= cpu_to_be32(~0xf); + ch->regs[DBDMA_CMDPTR_LO] &= dbdma_cpu_to_be32(~0xf); dbdma_cmdptr_load(ch); break; case DBDMA_STATUS: