From patchwork Mon Dec 12 06:43:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeny Voevodin X-Patchwork-Id: 130642 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 B260EB70B9 for ; Mon, 12 Dec 2011 17:44:28 +1100 (EST) Received: from localhost ([::1]:54186 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RZzcb-0006UL-Rc for incoming@patchwork.ozlabs.org; Mon, 12 Dec 2011 01:44:21 -0500 Received: from eggs.gnu.org ([140.186.70.92]:51744) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RZzc1-0005N7-Ka for qemu-devel@nongnu.org; Mon, 12 Dec 2011 01:43:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RZzby-0002gK-9C for qemu-devel@nongnu.org; Mon, 12 Dec 2011 01:43:45 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:40932) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RZzbx-0002g9-U5 for qemu-devel@nongnu.org; Mon, 12 Dec 2011 01:43:42 -0500 Received: from euspt2 (mailout1.w1.samsung.com [210.118.77.11]) by mailout1.w1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTP id <0LW200EHVW0SRG@mailout1.w1.samsung.com> for qemu-devel@nongnu.org; Mon, 12 Dec 2011 06:43:40 +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 <0LW200LRSW0GC5@spt2.w1.samsung.com> for qemu-devel@nongnu.org; Mon, 12 Dec 2011 06:43:40 +0000 (GMT) Date: Mon, 12 Dec 2011 10:43:22 +0400 From: Evgeny Voevodin In-reply-to: <1323672206-11891-1-git-send-email-e.voevodin@samsung.com> To: qemu-devel@nongnu.org Message-id: <1323672206-11891-11-git-send-email-e.voevodin@samsung.com> MIME-version: 1.0 X-Mailer: git-send-email 1.7.4.1 Content-type: TEXT/PLAIN Content-transfer-encoding: 7BIT References: <1323672206-11891-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.11 Cc: m.kozlov@samsung.com, d.solodkiy@samsung.com, Evgeny Voevodin Subject: [Qemu-devel] [PATCH v3 10/14] 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)