From patchwork Wed Jun 15 17:09:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: marcin.krzeminski@nokia.com X-Patchwork-Id: 9178995 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 6A3BC604DB for ; Wed, 15 Jun 2016 17:20:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 562C127D4A for ; Wed, 15 Jun 2016 17:20:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4AB7727EED; Wed, 15 Jun 2016 17:20:22 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 8C2BB27D4A for ; Wed, 15 Jun 2016 17:20:21 +0000 (UTC) Received: from localhost ([::1]:43793 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDEUG-00088n-M5 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 15 Jun 2016 13:20:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50286) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDEJw-0007TM-Pg for qemu-devel@nongnu.org; Wed, 15 Jun 2016 13:09:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bDEJs-0001u1-B3 for qemu-devel@nongnu.org; Wed, 15 Jun 2016 13:09:39 -0400 Received: from mail-db3on0122.outbound.protection.outlook.com ([157.55.234.122]:28608 helo=emea01-db3-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDEJr-0001tZ-Ml for qemu-devel@nongnu.org; Wed, 15 Jun 2016 13:09:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia.onmicrosoft.com; s=selector1-nokia-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=YgM9Xihazy/9WTvV6DR3tYvKIwnQJ1jGNTflBLaOff0=; b=gVTNrmr5NHTEY3KJdbwQ3660FdfXBiN8DQiltxSkp6ipOYRmAM4EXLrg/Km9WElaskxKHdVDiQOaR7wpjYUE3kBMCt5klsxP6i4hctWZISbq7WIsV3xnwD27u7WqBXg3WoDDJoHKwYmb+gZFb59LpQwACNmEcMOqotsAsQ07L3c= Received: from AM2PR07MB0626.eurprd07.prod.outlook.com (10.160.54.153) by AM2PR07MB0627.eurprd07.prod.outlook.com (10.160.54.154) with Microsoft SMTP Server (TLS) id 15.1.511.8; Wed, 15 Jun 2016 17:09:34 +0000 Received: from AM2PR07MB0626.eurprd07.prod.outlook.com ([10.160.54.153]) by AM2PR07MB0626.eurprd07.prod.outlook.com ([10.160.54.153]) with mapi id 15.01.0511.017; Wed, 15 Jun 2016 17:09:34 +0000 From: "Krzeminski, Marcin (Nokia - PL/Wroclaw)" To: =?iso-8859-2?Q?C=E9dric_Le_Goater?= , "qemu-devel@nongnu.org" Thread-Topic: [PATCH 1/9] m25p80: Replace JEDEC ID masking with function. Thread-Index: AQHRxwvVmrDewjgc+ECK67vDQNKGCp/qj/MAgAAzNac= Date: Wed, 15 Jun 2016 17:09:34 +0000 Message-ID: References: <1465998071-7355-1-git-send-email-marcin.krzeminski@nokia.com> <1465998071-7355-2-git-send-email-marcin.krzeminski@nokia.com>, <576160BE.804@kaod.org> In-Reply-To: <576160BE.804@kaod.org> Accept-Language: pl-PL, en-US Content-Language: pl-PL X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=marcin.krzeminski@nokia.com; x-originating-ip: [132.245.228.197] x-ms-office365-filtering-correlation-id: 9b627c5e-2529-4edb-a7d4-08d3953fd2fe x-microsoft-exchange-diagnostics: 1; AM2PR07MB0627; 5:1i0fPL9WMx5BMfdPkWEKFYL1B51ulq99ARgxyBeNeWpsaOoxi5kQsdLF5K3+U7AimQx06h/33ytb6gwuJoTKC8dPv/QW7MVsqODkKjqfuYPVVvgstF4JDqLojjXKU8u5KqkrWax7NKt+O9PdYIQtAA==; 24:97+7BRtHYVNuuZ2Wb015jmyYM9GZchNeIZukuWSJwEmFWAOaGWPdVmqfZIHY58QUOwee9u/+CDy8wwA5YAk9CqOnb7NZZMccAvWrEfkpit0=; 7:g8SiJxE8gxzwsZdd3NbtLoeinUgMoYPeyt5SCCTPJb34kkX9qrP6G7lkUcqgXAPiFk13bbefwF1AH/2Et/MNDhy3xOeIHz2by7IlnU9IokieXcaAfR5QO0nRudh6J2KfQrYQhVfkGPCycghcDj7ObqKiZTOgw/0F0rYqIjOeSJGeRugIzvFJBlB22yatkDXPCGsPFdAIrMV5ibyYe9Gv0w== x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:AM2PR07MB0627; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(35073007944872)(82608151540597)(788757137089); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001); SRVR:AM2PR07MB0627; BCL:0; PCL:0; RULEID:; SRVR:AM2PR07MB0627; x-forefront-prvs: 09749A275C x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6009001)(7916002)(24454002)(189002)(377454003)(199003)(97736004)(11100500001)(9686002)(5002640100001)(229853001)(5001770100001)(101416001)(6116002)(102836003)(19627405001)(3846002)(16236675004)(189998001)(586003)(10400500002)(33656002)(19625215002)(122556002)(19580395003)(74316001)(50986999)(105586002)(106116001)(106356001)(68736007)(87936001)(19580405001)(66066001)(4326007)(76176999)(5003600100002)(54356999)(81156014)(81166006)(2900100001)(2950100001)(8676002)(3660700001)(86362001)(8936002)(92566002)(2906002)(77096005)(2501003)(76576001)(3280700002)(5004730100002)(5008740100001); DIR:OUT; SFP:1102; SCL:1; SRVR:AM2PR07MB0627; H:AM2PR07MB0626.eurprd07.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; received-spf: None (protection.outlook.com: nokia.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: nokia.com X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Jun 2016 17:09:34.3660 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM2PR07MB0627 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 X-Received-From: 157.55.234.122 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 Subject: [Qemu-devel] Odp.: [PATCH 1/9] m25p80: Replace JEDEC ID masking with function. 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: "peter.maydell@linaro.org" , "crosthwaitepeter@gmail.com" , "pawel.lenkow@itlen.com" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP W dniu 15.06.2016 o 16:05, Cédric Le Goater pisze: On 06/15/2016 03:41 PM, marcin.krzeminski@nokia.com wrote: From: Marcin Krzeminski Instead of always reading and comparing jededc ID, replace it by function. Signed-off-by: Marcin Krzeminski Looks good to me. Some minor comments below. Thanks, C. --- hw/block/m25p80.c | 49 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 9 deletions(-) That is why there is a switch here. + switch (get_man(s)) { + case MAN_NUMONYX: s->volatile_cfg = 0; s->volatile_cfg |= VCFG_DUMMY; s->volatile_cfg |= VCFG_WRAP_SEQUENTIAL; @@ -594,6 +619,9 @@ static void reset_memory(Flash *s) if (!(s->nonvolatile_cfg & NVCFG_LOWER_SEGMENT_MASK)) { s->ear = CFG_UPPER_128MB_SEG_ENABLED; } + break; + default: + break; } DB_PRINT_L(0, "Reset done.\n"); @@ -634,9 +662,12 @@ static void decode_new_cmd(Flash *s, uint32_t value) case QOR: case QOR4: s->needed_bytes = get_addr_length(s); - if (((s->pi->jedec >> 16) & 0xFF) == JEDEC_NUMONYX) { - /* Dummy cycles modeled with bytes writes instead of bits */ why remove the comment ? Accidental, it will return in patch 8. Thanks, Marcin + switch (get_man(s)) { + case MAN_NUMONYX: s->needed_bytes += extract32(s->volatile_cfg, 4, 4); + break; + default: + break; } s->pos = 0; s->len = 0; @@ -645,9 +676,9 @@ static void decode_new_cmd(Flash *s, uint32_t value) case DIOR: case DIOR4: - switch ((s->pi->jedec >> 16) & 0xFF) { - case JEDEC_WINBOND: - case JEDEC_SPANSION: + switch (get_man(s)) { + case MAN_WINBOND: + case MAN_SPANSION: s->needed_bytes = 4; break; default: @@ -662,9 +693,9 @@ static void decode_new_cmd(Flash *s, uint32_t value) case QIOR: case QIOR4: - switch ((s->pi->jedec >> 16) & 0xFF) { - case JEDEC_WINBOND: - case JEDEC_SPANSION: + switch (get_man(s)) { + case MAN_WINBOND: + case MAN_SPANSION: s->needed_bytes = 6; break; default: . diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c index 4c856f5..15765f5 100644 --- a/hw/block/m25p80.c +++ b/hw/block/m25p80.c @@ -307,6 +307,14 @@ typedef enum { STATE_READING_DATA, } CMDState; +typedef enum { + MAN_SPANSION, + MAN_MACRONIX, + MAN_NUMONYX, + MAN_WINBOND, + MAN_GENERIC, +} Manufacturer; + typedef struct Flash { SSISlave parent_obj; @@ -350,6 +358,22 @@ typedef struct M25P80Class { #define M25P80_GET_CLASS(obj) \ OBJECT_GET_CLASS(M25P80Class, (obj), TYPE_M25P80) +static inline Manufacturer get_man(Flash *s) +{ + switch (((s->pi->jedec >> 16) & 0xFF)) { + case 0x20: + return MAN_NUMONYX; + case 0xEF: + return MAN_WINBOND; + case 0x01: + return MAN_SPANSION; + case 0xC2: + return MAN_MACRONIX; + default: + return MAN_GENERIC; + } +} + static void blk_sync_complete(void *opaque, int ret) { /* do nothing. Masters do not directly interact with the backing store, @@ -562,7 +586,8 @@ static void reset_memory(Flash *s) s->write_enable = false; s->reset_enable = false; - if (((s->pi->jedec >> 16) & 0xFF) == JEDEC_NUMONYX) { We could have kept the if () In patch 7 here will land reset procedures for Spansion and Macronix.