From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6699FC433DB for ; Mon, 15 Mar 2021 23:43:41 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CFEC564EE7 for ; Mon, 15 Mar 2021 23:43:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CFEC564EE7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:42078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLws7-00027N-VA for qemu-devel@archiver.kernel.org; Mon, 15 Mar 2021 19:43:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36008) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLwkv-0001u1-Jn for qemu-devel@nongnu.org; Mon, 15 Mar 2021 19:36:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31530) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lLwkr-0006Cs-Uv for qemu-devel@nongnu.org; Mon, 15 Mar 2021 19:36:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615851368; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=muZkQ0IKHf/R89qkeqrt0bz15rr1YQyObQ9tTMk2SlU=; b=Jy8xNlQ7AJDgAwDEzeeYNDJG945sNRPdpW9m4TKyX4yJ/v9JUhO8kDrfsfDuPT1/fSsTjm i39lsoUS6kekSgnS4fahyOUhZwuHNKf6AISg7Q9IyHyyHt2LjpOnvdXxI84CrHLp6p8GDB eqqURGlkY2g2Do9ok9h1J2WT6mL5QFE= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-481-omq0BickNcGz16dxvT1E3w-1; Mon, 15 Mar 2021 19:36:04 -0400 X-MC-Unique: omq0BickNcGz16dxvT1E3w-1 Received: by mail-wm1-f69.google.com with SMTP id r18so8813939wmq.5 for ; Mon, 15 Mar 2021 16:36:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=muZkQ0IKHf/R89qkeqrt0bz15rr1YQyObQ9tTMk2SlU=; b=Ja77cTLX82gieUUIbhyXtyCJ28NW5b7nkRcc9j/DCzh170QWeQn6o+iYiBpCkdnqUR X90wAKaYRZsXsyUNNse67QeuRhQ9Cqa+OjKxil/5x6UVL8AQX4pwNhWVqfGkHaWQ4FCy Bjt/yk4RGmuGXL1PUBnIkoqCJllTdiP9uDiKnALtJsNYNBb2OtiXC+OjUuYCQPUH1psQ tLjaCZQJpXMBGg0KjmwHa5vpmlnnscpvHE0cluBK9zcBazLHedzfqLhVCffwY8w/1W5z sglisJ9/gyQ/5jWF4btlbPT9vuJobo4gmGgOTySN2ft7YFx/WtrljAY0DCNCNNRDCH6E 7eeA== X-Gm-Message-State: AOAM533OXFv9UiPg1ZULIfDU+DzR4i3HdO9X1+h9Agv4FNd4PAUXXX5U OVXFxWGR55xmBCzn0RSw3DUukfiMH8ZqoXDHI6LaqzcN2w1oSalDJETfBZUYioxb9ivsnvGHmsA lthcP9DKvxsaeDXEJoO4QUkzY3giva8U/L5UuKXgRReI/inOR+H7vWsxNCj1ISOGS X-Received: by 2002:adf:fe8d:: with SMTP id l13mr1800325wrr.81.1615851363116; Mon, 15 Mar 2021 16:36:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz31UX5rvsdVFYBr8xk+97EMblstySQgjomcDqO/tQighWgaajZKE3kDgvu5KRqH4ffT+GH4w== X-Received: by 2002:adf:fe8d:: with SMTP id l13mr1800311wrr.81.1615851362923; Mon, 15 Mar 2021 16:36:02 -0700 (PDT) Received: from x1w.redhat.com (17.red-88-21-201.staticip.rima-tde.net. [88.21.201.17]) by smtp.gmail.com with ESMTPSA id j203sm1241688wmj.40.2021.03.15.16.36.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 16:36:02 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 07/11] hw/block/pflash_cfi02: Factor out pflash_reset_state_machine() Date: Tue, 16 Mar 2021 00:35:23 +0100 Message-Id: <20210315233527.2988483-8-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210315233527.2988483-1-philmd@redhat.com> References: <20210315233527.2988483-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-block@nongnu.org, Max Reitz , David Edmondson , Bin Meng , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" There is multiple places resetting the internal state machine. Factor the code out in a new pflash_reset_state_machine() method. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: David Edmondson Reviewed-by: Bin Meng Message-Id: <20210310170528.1184868-8-philmd@redhat.com> --- hw/block/pflash_cfi02.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index 2ba77a0171b..aea47a99c61 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -184,11 +184,17 @@ static void pflash_setup_mappings(PFlashCFI02 *pfl) pfl->rom_mode = true; } +static void pflash_reset_state_machine(PFlashCFI02 *pfl) +{ + trace_pflash_reset(); + pfl->cmd = 0x00; + pfl->wcycle = 0; +} + static void pflash_mode_read_array(PFlashCFI02 *pfl) { trace_pflash_mode_read_array(); - pfl->cmd = 0x00; - pfl->wcycle = 0; + pflash_reset_state_machine(pfl); pfl->rom_mode = true; memory_region_rom_device_set_romd(&pfl->orig_mem, true); } @@ -330,8 +336,7 @@ static uint64_t pflash_read(void *opaque, hwaddr offset, unsigned int width) default: /* This should never happen : reset state & treat it as a read*/ DPRINTF("%s: unknown command state: %x\n", __func__, pfl->cmd); - pfl->wcycle = 0; - pfl->cmd = 0; + pflash_reset_state_machine(pfl); /* fall through to the read code */ case 0x80: /* Erase (unlock) */ /* We accept reads during second unlock sequence... */ @@ -669,8 +674,7 @@ static void pflash_write(void *opaque, hwaddr offset, uint64_t value, } reset_dq3(pfl); timer_del(&pfl->timer); - pfl->wcycle = 0; - pfl->cmd = 0; + pflash_reset_state_machine(pfl); return; } /* @@ -710,10 +714,8 @@ static void pflash_write(void *opaque, hwaddr offset, uint64_t value, /* Reset flash */ reset_flash: - trace_pflash_reset(); pfl->bypass = 0; - pfl->wcycle = 0; - pfl->cmd = 0; + pflash_reset_state_machine(pfl); return; do_bypass: -- 2.26.2