From patchwork Sat Feb 2 23:40:06 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Grant Likely X-Patchwork-Id: 217713 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CBC962C0092 for ; Sun, 3 Feb 2013 10:40:54 +1100 (EST) Received: from localhost ([::1]:45810 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1mhY-0001ls-Ur for incoming@patchwork.ozlabs.org; Sat, 02 Feb 2013 18:40:52 -0500 Received: from eggs.gnu.org ([208.118.235.92]:50867) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1mh7-0001Lb-24 for qemu-devel@nongnu.org; Sat, 02 Feb 2013 18:40:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U1mh4-0000oi-2x for qemu-devel@nongnu.org; Sat, 02 Feb 2013 18:40:24 -0500 Received: from mail-wi0-f171.google.com ([209.85.212.171]:33021) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1mh3-0000oN-Ta for qemu-devel@nongnu.org; Sat, 02 Feb 2013 18:40:22 -0500 Received: by mail-wi0-f171.google.com with SMTP id hn17so504258wib.16 for ; Sat, 02 Feb 2013 15:40:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:mime-version:content-type :content-transfer-encoding:x-gm-message-state; bh=fjUceThiPV4YAqpazns65IqkvRcNkL69YUOoqX/fpFo=; b=fsu+vYLuuNTCTfEpL0bd/fSWR3Ekps42BssPyvEmH0XX3MKcJdQ808SpxtPYNkxwY3 9xZ6xKQY3Bidv6nRcBf1ynniPoMXbRORSPskd7exfN2j26bqVZEiUKe+TFgSZMWx84nv 0/EWyhM4/2kbVsZidq2co4pN6rZR7PCdsSsPp1injdEY2VYXG1dJDB/PQXqCqzbU17Jg 3Fktk6yBuRPudRjCKetrJnXtgllPkmjxYcp8zyPvKZSorAr5X4lfuM49k/MyTiPB1TX/ otPrGBbdAiqVTiljXlEyddpI4HktMMkrF1jZgQlk20XXu6I1i8AW9s6BQnaHIopssUpm EaFQ== X-Received: by 10.194.240.233 with SMTP id wd9mr28288031wjc.54.1359848420872; Sat, 02 Feb 2013 15:40:20 -0800 (PST) Received: from localhost (host86-136-235-200.range86-136.btcentralplus.com. [86.136.235.200]) by mx.google.com with ESMTPS id fx5sm12728827wib.11.2013.02.02.15.40.18 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 02 Feb 2013 15:40:20 -0800 (PST) Received: by localhost (Postfix, from userid 1000) id 687143E0ED8; Sat, 2 Feb 2013 23:40:17 +0000 (GMT) From: Grant Likely To: qemu-devel@nongnu.org Date: Sat, 2 Feb 2013 23:40:06 +0000 Message-Id: <1359848409-1106-6-git-send-email-grant.likely@secretlab.ca> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1359848409-1106-1-git-send-email-grant.likely@secretlab.ca> References: <1359848409-1106-1-git-send-email-grant.likely@secretlab.ca> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQkoRZQWeKQiTZHhfD0l5M+J+T0uWCSqYgPn12IlVsSK60Hx0OR4IUurnxtEKZsj4ygCpcKY X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.212.171 Cc: Peter Maydell , Anthony Liguori , Grant Likely , Paul Brook , "Edgar E. Iglesias" , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [PATCH V3 5/8] hw/mdio: Mask out read-only bits. 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 The RST and ANEG_RST bits are commands, not settings. An operating system will get confused (or at least u-boot does) if those bits remain set after writing to them. Therefore, mask them out on write. Similarly, no bits in the ID1, ID2, and remote capability registers are writeable; so mask them out also. Cc: Peter Maydell Cc: Paul Brook Cc: Edgar E. Iglesias Cc: Anthony Liguori Cc: Andreas Färber Signed-off-by: Grant Likely --- hw/mdio.c | 16 ++++++++++++---- hw/mdio.h | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/hw/mdio.c b/hw/mdio.c index 040ecf6..45e271f 100644 --- a/hw/mdio.c +++ b/hw/mdio.c @@ -109,17 +109,24 @@ static unsigned int mdio_phy_read(struct qemu_phy *phy, unsigned int req) static void mdio_phy_write(struct qemu_phy *phy, unsigned int req, unsigned int data) { - int regnum; + int regnum = req & 0x1f; + uint16_t mask = phy->regs_readonly_mask[regnum]; - regnum = req & 0x1f; - D(printf("%s reg[%d] = %x\n", __func__, regnum, data)); + D(printf("%s reg[%d] = %x; mask=%x\n", __func__, regnum, data, mask)); switch (regnum) { default: - phy->regs[regnum] = data; + phy->regs[regnum] = (phy->regs[regnum] & mask) | (data & ~mask); break; } } +static const uint16_t default_readonly_mask[32] = { + [PHY_CTRL] = PHY_CTRL_RST | PHY_CTRL_ANEG_RST, + [PHY_ID1] = 0xffff, + [PHY_ID2] = 0xffff, + [PHY_LP_ABILITY] = 0xffff, +}; + void mdio_phy_init(struct qemu_phy *phy, uint16_t id1, uint16_t id2) { phy->regs[PHY_CTRL] = 0x3100; @@ -128,6 +135,7 @@ void mdio_phy_init(struct qemu_phy *phy, uint16_t id1, uint16_t id2) phy->regs[PHY_ID2] = id2; /* Autonegotiation advertisement reg. */ phy->regs[PHY_AUTONEG_ADV] = 0x01e1; + phy->regs_readonly_mask = default_readonly_mask; phy->link = 1; phy->read = mdio_phy_read; diff --git a/hw/mdio.h b/hw/mdio.h index 427c9ed..0a6c20a 100644 --- a/hw/mdio.h +++ b/hw/mdio.h @@ -55,6 +55,7 @@ struct qemu_phy { uint32_t regs[NUM_PHY_REGS]; + const uint16_t *regs_readonly_mask; /* 0=writable, 1=read-only */ int link;