From patchwork Thu Apr 18 17:49:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 789819 Delivered-To: patch@linaro.org Received: by 2002:adf:e6ca:0:b0:346:15ad:a2a with SMTP id y10csp695816wrm; Thu, 18 Apr 2024 10:53:51 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUuwaeSZyhrYqvIf6k8HJn+KGV7pJYBhmZ8nzhmKB7M/0eutl5mI3h9RtYxmN80oSvUATndDHe5Nlmpg5e0d7Vn X-Google-Smtp-Source: AGHT+IHDSelLzueeIjMLBkQa9tlfhjxbyLUuiF5SOEljPUrQ8wqBR4zRmYTcWHy5G5yfR5wnZHdg X-Received: by 2002:a05:6358:7a1:b0:183:645b:cfa4 with SMTP id n33-20020a05635807a100b00183645bcfa4mr4873416rwj.16.1713462831645; Thu, 18 Apr 2024 10:53:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713462831; cv=none; d=google.com; s=arc-20160816; b=KL0SBg72NaxfRZi6hMagk+uj3PWk8fl/bsEwhqKyrKzE7+7QvhqTbaN1PRffMJ5oJ0 WiP/WZFOThSlfGm4E/Hm8oxVCLgdh17vvUVrPSGcnveUgSCVmJuWg9n8BFSmekntyImD 69nWtLGJvzsXISEHQESINmO55a843tI8cf6pDWmlq7rn2svvWmZj00Aig1bZA+KZy4/V qwf24YsKmbZT06XFUCMTtB2vC6pRO0I3x/Lx5Ts3Pj1FUhDUC9CXW1kzK/LOfU+4YxYf oOxRGA2STcKPmDP2BrhihFlk0wK1LNDqewHtAFw1is/DY+Gk3mvaBwbsNPV1tEoGFWb6 kjlg== 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=p/AY3z3JHWEuhmfoeSip7mAKO3NOfEQtGnOFC4DBwLQ=; fh=duFCrbmW7QyIwJKOp0blY4kXHchuONJhRN0ZSjkPt6k=; b=0UISfD88l3wPxiIzPlKP4zq9U541MiyKfFykZmykaAdO4yx5WJMhSHHmqJ2RTpVi6h Mx3oT4m0PrUQVvfSZv6AdxwqDqawcpV6xemHBdOqc3XtfIp8hP2rC4fSu1Rg5R8VSoOX kWr7d6bdPjSP8QiRiA45v0TWLib6NXV4p8+webWQVXZwvyGfkCwjib4gqjU5uRWW1aIy +Wa32Woj+nSrVUgKDLHHzQ6yQXntCjGoNv5wHn5g5ywk9t4ySl8apXMnORzhak2h1zvK sYpOvrImM/hHQ0o8aFaz1MiAV1sgLnQuJmcZsIO6BGf4kA3+/lPTsVjxZZYV+l2P+B5E /Y5A==; 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 n18-20020ac85a12000000b00434ea6f8743si1886851qta.404.2024.04.18.10.53.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 18 Apr 2024 10:53:51 -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 1rxVuL-0000Sr-90; Thu, 18 Apr 2024 13:50:49 -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 1rxVuJ-0000RO-Ql; Thu, 18 Apr 2024 13:50:47 -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 1rxVuI-0007ad-02; Thu, 18 Apr 2024 13:50:47 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id BA3B95FD6E; Thu, 18 Apr 2024 20:50:02 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 21462B9348; Thu, 18 Apr 2024 20:50:00 +0300 (MSK) Received: (nullmailer pid 947845 invoked by uid 1000); Thu, 18 Apr 2024 17:49:55 -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-8.2.3 101/116] hw/block/nand: Factor nand_load_iolen() method out Date: Thu, 18 Apr 2024 20:49:31 +0300 Message-Id: <20240418174955.947730-14-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 9c1b89cfa6..58ef547c5a 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) {