From patchwork Fri Dec 9 13:34:38 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeny Voevodin X-Patchwork-Id: 130382 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BBCC8B6F65 for ; Sat, 10 Dec 2011 00:55:41 +1100 (EST) Received: from localhost ([::1]:42282 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RZ0cq-0007FB-Fb for incoming@patchwork.ozlabs.org; Fri, 09 Dec 2011 08:36:32 -0500 Received: from eggs.gnu.org ([140.186.70.92]:34555) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RZ0bo-0004gV-MI for qemu-devel@nongnu.org; Fri, 09 Dec 2011 08:35:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RZ0bj-0000ZA-0y for qemu-devel@nongnu.org; Fri, 09 Dec 2011 08:35:28 -0500 Received: from mailout4.w1.samsung.com ([210.118.77.14]:31162) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RZ0bi-0000Yn-DD for qemu-devel@nongnu.org; Fri, 09 Dec 2011 08:35:22 -0500 MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: TEXT/PLAIN Received: from euspt2 ([210.118.77.14]) by mailout4.w1.samsung.com (Sun Java(tm) System Messaging Server 6.3-8.04 (built Jul 29 2009; 32bit)) with ESMTP id <0LVX004XJV2XGD50@mailout4.w1.samsung.com> for qemu-devel@nongnu.org; Fri, 09 Dec 2011 13:35:21 +0000 (GMT) Received: from evvoevodinPC.rnd.samsung.ru ([106.109.8.48]) by spt2.w1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTPA id <0LVX00MANV28B5@spt2.w1.samsung.com> for qemu-devel@nongnu.org; Fri, 09 Dec 2011 13:35:21 +0000 (GMT) Date: Fri, 09 Dec 2011 17:34:38 +0400 From: Evgeny Voevodin In-reply-to: <1323437682-28792-1-git-send-email-e.voevodin@samsung.com> To: qemu-devel@nongnu.org Message-id: <1323437682-28792-12-git-send-email-e.voevodin@samsung.com> X-Mailer: git-send-email 1.7.4.1 References: <1323437682-28792-1-git-send-email-e.voevodin@samsung.com> X-detected-operating-system: by eggs.gnu.org: Solaris 9.1 X-Received-From: 210.118.77.14 Cc: m.kozlov@samsung.com, d.solodkiy@samsung.com, Evgeny Voevodin Subject: [Qemu-devel] [PATCH 11/15] hw/lan9118: Add basic 16-bit mode support. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Evgeny Voevodin --- hw/devices.h | 2 +- hw/lan9118.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 109 insertions(+), 8 deletions(-) diff --git a/hw/devices.h b/hw/devices.h index 1a55c1e..24cae4c 100644 --- a/hw/devices.h +++ b/hw/devices.h @@ -10,7 +10,7 @@ struct MemoryRegion; void smc91c111_init(NICInfo *, uint32_t, qemu_irq); /* lan9118.c */ -void lan9118_init(NICInfo *, uint32_t, qemu_irq); +DeviceState *lan9118_init(NICInfo *, uint32_t, qemu_irq); /* tsc210x.c */ uWireSlave *tsc2102_init(qemu_irq pint); diff --git a/hw/lan9118.c b/hw/lan9118.c index ee8b2ea..e44e5f8 100644 --- a/hw/lan9118.c +++ b/hw/lan9118.c @@ -212,6 +212,17 @@ typedef struct { int rxp_offset; int rxp_size; int rxp_pad; + + uint32_t write_word_prev_offset; + uint32_t write_word_n; + uint16_t write_word_l; + uint16_t write_word_h; + uint32_t read_word_prev_offset; + uint32_t read_word_n; + uint32_t read_long; + + uint32_t mode_16bit; + } lan9118_state; static void lan9118_update(lan9118_state *s) @@ -345,6 +356,9 @@ static void lan9118_reset(DeviceState *d) s->mac_mii_data = 0; s->mac_flow = 0; + s->read_word_n = 0; + s->write_word_n = 0; + phy_reset(s); s->eeprom_writable = 0; @@ -896,11 +910,11 @@ static void lan9118_tick(void *opaque) } static void lan9118_writel(void *opaque, target_phys_addr_t offset, - uint64_t val, unsigned size) + uint32_t val) { lan9118_state *s = (lan9118_state *)opaque; offset &= 0xff; - + //DPRINTF("Write reg 0x%02x = 0x%08x\n", (int)offset, val); if (offset >= 0x20 && offset < 0x40) { /* TX FIFO */ @@ -1029,8 +1043,47 @@ static void lan9118_writel(void *opaque, target_phys_addr_t offset, lan9118_update(s); } -static uint64_t lan9118_readl(void *opaque, target_phys_addr_t offset, - unsigned size) +static void lan9118_writew(void *opaque, target_phys_addr_t offset, + uint32_t val) +{ + lan9118_state *s = (lan9118_state *)opaque; + offset &= 0xff; + + if (s->write_word_prev_offset != (offset & ~0x3)) { + /* New offset, reset word counter */ + s->write_word_n = 0; + s->write_word_prev_offset = offset & ~0x3; + } + + if (offset & 0x2) { + s->write_word_h = val; + } else { + s->write_word_l = val; + } + + //DPRINTF("Writew reg 0x%02x = 0x%08x\n", (int)offset, val); + s->write_word_n++; + if (s->write_word_n == 2) { + s->write_word_n = 0; + lan9118_writel(s, offset & ~3, s->write_word_l + + (s->write_word_h << 16)); + } +} + +static void lan9118_write(void *opaque, target_phys_addr_t offset, + uint64_t val, unsigned size) +{ + switch (size) { + case 2: + return lan9118_writew(opaque, offset, (uint32_t)val); + case 4: + return lan9118_writel(opaque, offset, (uint32_t)val); + } + + hw_error("lan9118_write: Bad size 0x%x\n", size); +} + +static uint32_t lan9118_readl(void *opaque, target_phys_addr_t offset) { lan9118_state *s = (lan9118_state *)opaque; @@ -1065,6 +1118,9 @@ static uint64_t lan9118_readl(void *opaque, target_phys_addr_t offset, case CSR_TX_CFG: return s->tx_cfg; case CSR_HW_CFG: + if (s->mode_16bit) { + return s->hw_cfg & ~0x4; + } return s->hw_cfg | 0x4; case CSR_RX_DP_CTRL: return 0; @@ -1103,9 +1159,51 @@ static uint64_t lan9118_readl(void *opaque, target_phys_addr_t offset, return 0; } +static uint32_t lan9118_readw(void *opaque, target_phys_addr_t offset) +{ + lan9118_state *s = (lan9118_state *)opaque; + uint32_t val; + + if (s->read_word_prev_offset != (offset & ~0x3)) { + /* New offset, reset word counter */ + s->read_word_n = 0; + s->read_word_prev_offset = offset & ~0x3; + } + + s->read_word_n++; + if (s->read_word_n == 1) { + s->read_long = lan9118_readl(s, offset & ~3); + } else { + s->read_word_n = 0; + } + + if (offset & 2) { + val = s->read_long >> 16; + } else { + val = s->read_long & 0xFFFF; + } + + //DPRINTF("Readw reg 0x%02x, val 0x%x\n", (int)offset, val); + return val; +} + +static uint64_t lan9118_read(void *opaque, target_phys_addr_t offset, + unsigned size) +{ + switch (size) { + case 2: + return lan9118_readw(opaque, offset); + case 4: + return lan9118_readl(opaque, offset); + } + + hw_error("lan9118_read: Bad size 0x%x\n", size); + return 0; +} + static const MemoryRegionOps lan9118_mem_ops = { - .read = lan9118_readl, - .write = lan9118_writel, + .read = lan9118_read, + .write = lan9118_write, .endianness = DEVICE_NATIVE_ENDIAN, }; @@ -1162,6 +1260,7 @@ static SysBusDeviceInfo lan9118_info = { .qdev.reset = lan9118_reset, .qdev.props = (Property[]) { DEFINE_NIC_PROPERTIES(lan9118_state, conf), + DEFINE_PROP_UINT32("mode_16bit", lan9118_state, mode_16bit, 0), DEFINE_PROP_END_OF_LIST(), } }; @@ -1173,7 +1272,7 @@ static void lan9118_register_devices(void) /* Legacy helper function. Should go away when machine config files are implemented. */ -void lan9118_init(NICInfo *nd, uint32_t base, qemu_irq irq) +DeviceState *lan9118_init(NICInfo *nd, uint32_t base, qemu_irq irq) { DeviceState *dev; SysBusDevice *s; @@ -1185,6 +1284,8 @@ void lan9118_init(NICInfo *nd, uint32_t base, qemu_irq irq) s = sysbus_from_qdev(dev); sysbus_mmio_map(s, 0, base); sysbus_connect_irq(s, 0, irq); + + return dev; } device_init(lan9118_register_devices)