From patchwork Fri May 20 13:05:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Herv=C3=A9_Poussineau?= X-Patchwork-Id: 9129443 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 29C4F6048B for ; Fri, 20 May 2016 13:06:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C7EF27BF4 for ; Fri, 20 May 2016 13:06:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1140627C23; Fri, 20 May 2016 13:06:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B993027BF4 for ; Fri, 20 May 2016 13:06:08 +0000 (UTC) Received: from localhost ([::1]:54769 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3k7y-0002Fk-NG for patchwork-qemu-devel@patchwork.kernel.org; Fri, 20 May 2016 09:06:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53260) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3k7f-0002F3-KU for qemu-devel@nongnu.org; Fri, 20 May 2016 09:05:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b3k7Z-0004SO-KZ for qemu-devel@nongnu.org; Fri, 20 May 2016 09:05:46 -0400 Received: from smtp2-g21.free.fr ([212.27.42.2]:58827) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3k7Z-0004Pi-Ba for qemu-devel@nongnu.org; Fri, 20 May 2016 09:05:41 -0400 Received: from localhost.localdomain (unknown [82.227.227.196]) by smtp2-g21.free.fr (Postfix) with ESMTP id BB2212003E8; Fri, 20 May 2016 12:56:15 +0200 (CEST) From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= To: qemu-devel@nongnu.org Date: Fri, 20 May 2016 15:05:03 +0200 Message-Id: <1463749503-27374-1-git-send-email-hpoussin@reactos.org> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 212.27.42.2 Subject: [Qemu-devel] [PATCH] gt64xxx: access right I/O port when activating byte swapping X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Herv=C3=A9=20Poussineau?= , Leon Alrae , Aurelien Jarno Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Incidentally, this fixes YAMON on big endian guest. Signed-off-by: Hervé Poussineau --- hw/mips/gt64xxx_pci.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/hw/mips/gt64xxx_pci.c b/hw/mips/gt64xxx_pci.c index 3f4523d..c76ee88 100644 --- a/hw/mips/gt64xxx_pci.c +++ b/hw/mips/gt64xxx_pci.c @@ -177,6 +177,7 @@ /* PCI Internal */ #define GT_PCI0_CMD (0xc00 >> 2) +#define GT_CMD_MWORDSWAP (1 << 10) #define GT_PCI0_TOR (0xc04 >> 2) #define GT_PCI0_BS_SCS10 (0xc08 >> 2) #define GT_PCI0_BS_SCS32 (0xc0c >> 2) @@ -294,6 +295,62 @@ static void gt64120_isd_mapping(GT64120State *s) memory_region_add_subregion(get_system_memory(), s->ISD_start, &s->ISD_mem); } +static uint64_t gt64120_pci_io_read(void *opaque, hwaddr addr, + unsigned int size) +{ + GT64120State *s = opaque; + uint8_t buf[4]; + + if (s->regs[GT_PCI0_CMD] & GT_CMD_MWORDSWAP) { + addr = (addr & ~3) + 4 - size - (addr & 3); + } + + address_space_read(&address_space_io, addr, MEMTXATTRS_UNSPECIFIED, + buf, size); + + if (size == 1) { + return buf[0]; + } else if (size == 2) { + return lduw_le_p(buf); + } else if (size == 4) { + return ldl_le_p(buf); + } else { + g_assert_not_reached(); + } +} + +static void gt64120_pci_io_write(void *opaque, hwaddr addr, uint64_t data, + unsigned int size) +{ + GT64120State *s = opaque; + uint8_t buf[4]; + + if (s->regs[GT_PCI0_CMD] & GT_CMD_MWORDSWAP) { + addr = (addr & ~3) + 4 - size - (addr & 3); + } + + if (size == 1) { + buf[0] = data; + } else if (size == 2) { + stw_le_p(buf, data); + } else if (size == 4) { + stl_le_p(buf, data); + } else { + g_assert_not_reached(); + } + + address_space_write(&address_space_io, addr, MEMTXATTRS_UNSPECIFIED, + buf, size); +} + +static const MemoryRegionOps gt64120_pci_io_ops = { + .read = gt64120_pci_io_read, + .write = gt64120_pci_io_write, + .endianness = DEVICE_LITTLE_ENDIAN, + .impl.max_access_size = 4, + .valid.unaligned = true, +}; + static void gt64120_pci_mapping(GT64120State *s) { /* Update PCI0IO mapping */ @@ -308,8 +365,9 @@ static void gt64120_pci_mapping(GT64120State *s) s->PCI0IO_length = ((s->regs[GT_PCI0IOHD] + 1) - (s->regs[GT_PCI0IOLD] & 0x7f)) << 21; if (s->PCI0IO_length) { - memory_region_init_alias(&s->PCI0IO_mem, OBJECT(s), "pci0-io", - get_system_io(), 0, s->PCI0IO_length); + memory_region_init_io(&s->PCI0IO_mem, OBJECT(s), + >64120_pci_io_ops, + s, "pci0-io", s->PCI0IO_length); memory_region_add_subregion(get_system_memory(), s->PCI0IO_start, &s->PCI0IO_mem); }