From patchwork Thu Apr 18 20:02:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 789864 Delivered-To: patch@linaro.org Received: by 2002:adf:e6ca:0:b0:346:15ad:a2a with SMTP id y10csp748889wrm; Thu, 18 Apr 2024 13:07:18 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXGU0Y0XNny/UDITctbbkID4ElsTVRzKbqv0kYUqTF+TxAzsLXUz/edOeMXQt8i9M983kxL2rLvteWmUysxfdKj X-Google-Smtp-Source: AGHT+IHXMB+2ftvYV1A0ZooqFWY8RWyCAZLXO9uThtbimx1UCIqQgJSGLkqsR2XbGfvLr1ewKaPE X-Received: by 2002:ad4:540c:0:b0:699:2eb9:9c09 with SMTP id f12-20020ad4540c000000b006992eb99c09mr77903qvt.24.1713470837601; Thu, 18 Apr 2024 13:07:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713470837; cv=none; d=google.com; s=arc-20160816; b=hn5PA+/Oqug5W+fVYkVtZVnAYyIvlhhM1oe0gd7NpJ3m8olkzk5MS5A5FWskThfoGF 9jpEv4EEW7x9okcEUXFWRSHKN4i/JAcANhmVCGEY/P4kFfL3zi+m7Xl2fongLQ8+uL24 oaDgIUALMDLUkj+MBBqKJlDj0R+NmvxKLmmLTVrxS/Rqsb0WELJefS1fYv+M10vbcCmn ow1nbXJOjsxSUhfJsfaoNwc7riuUQ7tNJ3rDYq/vWXVsH6UkeeU9UdonXKPCTz+8yYNh rRNuH3xzFK/iTy/zNl0LmVCtePPnwvmpSIF6uY+BtAENaBcyjBhPXYGWqD1YnY2cck90 x8rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=KR1aj0FSaKCwCGPTE/sjM8kywVPKJqFNADcV61rePSM=; fh=duFCrbmW7QyIwJKOp0blY4kXHchuONJhRN0ZSjkPt6k=; b=lQUN3ONRKx7RAvJbxX1AVRnFQrCIGsN6ENLUkbYo+lq3e30KYe/+cFD1i44Am3Wn9P f2T9kWVy01P8vblQa2wI7pU+17GSrXG/zKa0FYRWpi1HTlBEoumaiKCBPT7rNUziYLzd GfTWfwPOziKKOIw8XA6EyT6NT4+q6zZ4Wr+kPWIAjZNrzF0Y3aE9xfyW/R3AlFUzHja3 N8xLQoPTAhdrJodsJi0NBgu5RhqufYSId8M8VXS7ZVUUh4iDHjkRt8tKYa4OmuQeRYfW ERQi47LW4NFg1vPfedWj6iB/PSkKo4R6ELbvRXDDK/UMmkiyf7jGtRBeSw63BGmXO+jO TupQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 7-20020a0562140d0700b0069b6e13fcaesi2297651qvh.116.2024.04.18.13.07.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 18 Apr 2024 13:07:17 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rxXyc-0001lp-F6; Thu, 18 Apr 2024 16:03:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rxXy5-0001Ys-9I; Thu, 18 Apr 2024 16:02:52 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rxXy2-0005IK-Lp; Thu, 18 Apr 2024 16:02:48 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id B54435FE10; Thu, 18 Apr 2024 23:02:27 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 211C1B93F6; Thu, 18 Apr 2024 23:02:25 +0300 (MSK) Received: (nullmailer pid 952863 invoked by uid 1000); Thu, 18 Apr 2024 20:02:24 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Richard Henderson , Kevin Wolf , Michael Tokarev Subject: [Stable-7.2.11 49/59] hw/block/nand: Factor nand_load_iolen() method out Date: Thu, 18 Apr 2024 23:02:09 +0300 Message-Id: <20240418200224.952785-8-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Reviewed-by: Kevin Wolf Signed-off-by: Philippe Mathieu-Daudé Message-Id: <20240409135944.24997-2-philmd@linaro.org> (cherry picked from commit 7a86544f286d8af4fa5251101c1026ddae92cc3d) Signed-off-by: Michael Tokarev diff --git a/hw/block/nand.c b/hw/block/nand.c index 1aee1cb2b1..4e3d7fb065 100644 --- a/hw/block/nand.c +++ b/hw/block/nand.c @@ -243,9 +243,28 @@ static inline void nand_pushio_byte(NANDFlashState *s, uint8_t value) } } +/* + * nand_load_block: Load block containing (s->addr + @offset). + * Returns length of data available at @offset in this block. + */ +static unsigned nand_load_block(NANDFlashState *s, unsigned offset) +{ + unsigned iolen; + + s->blk_load(s, s->addr, offset); + + iolen = (1 << s->page_shift); + if (s->gnd) { + iolen += 1 << s->oob_shift; + } + assert(offset <= iolen); + iolen -= offset; + + return iolen; +} + static void nand_command(NANDFlashState *s) { - unsigned int offset; switch (s->cmd) { case NAND_CMD_READ0: s->iolen = 0; @@ -271,12 +290,7 @@ static void nand_command(NANDFlashState *s) case NAND_CMD_NOSERIALREAD2: if (!(nand_flash_ids[s->chip_id].options & NAND_SAMSUNG_LP)) break; - offset = s->addr & ((1 << s->addr_shift) - 1); - s->blk_load(s, s->addr, offset); - if (s->gnd) - s->iolen = (1 << s->page_shift) - offset; - else - s->iolen = (1 << s->page_shift) + (1 << s->oob_shift) - offset; + s->iolen = nand_load_block(s, s->addr & ((1 << s->addr_shift) - 1)); break; case NAND_CMD_RESET: @@ -597,12 +611,7 @@ uint32_t nand_getio(DeviceState *dev) if (!s->iolen && s->cmd == NAND_CMD_READ0) { offset = (int) (s->addr & ((1 << s->addr_shift) - 1)) + s->offset; s->offset = 0; - - s->blk_load(s, s->addr, offset); - if (s->gnd) - s->iolen = (1 << s->page_shift) - offset; - else - s->iolen = (1 << s->page_shift) + (1 << s->oob_shift) - offset; + s->iolen = nand_load_block(s, offset); } if (s->ce || s->iolen <= 0) {