From patchwork Tue Apr 9 13:59:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 787217 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp231025wrs; Tue, 9 Apr 2024 07:01:26 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWVHg946RrQCk5iOGhUtNG1KX9EwJfiUkg7/yfPj4QqiEgmqYhnXYLFXPPa3KwIYqzbH143tzId6GNm7bu7x+bT X-Google-Smtp-Source: AGHT+IHP43CcxvemKLA3I+P5uabXDj/8cmaBAWB8d76UDN0PXa4mRjpGJBS5v64BSLYEYVtvattY X-Received: by 2002:a05:6122:e64:b0:4ca:80c5:7544 with SMTP id bj36-20020a0561220e6400b004ca80c57544mr7324313vkb.4.1712671286397; Tue, 09 Apr 2024 07:01:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712671286; cv=none; d=google.com; s=arc-20160816; b=USrcZo+hd+BWqrQegzkiifcJms+FuhCJBEbRjlH6ampdGyo3b5Ppst7RiYZrKheu2M LSWYwwvVpuDWeIwOVOF0ndzJQNz8PSJyO3jd0Zpt+B/9lODF4FaeCq6pO9gEXCnyDeay ant8GWpZdQ7sX5ZQ4pDLKWhx0+NFDmu0mPYQXJwQOdLD/DfT7xxa+/bM5WdEJ7x1nZCg HmJifZgamqMLrC9Dq1j+XatZjF6FLBZoJGN7GkJ6btaR/zUzCZGbU84TBLaXq9B536ce jwRrM+xStqA4PEC4QFvwaB1E6SoTzYaiKL9yrHJ9v3uEsYU5awj+TbtwzMkc3YLaZRMV VR7A== 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:dkim-signature; bh=3d4Pf+e5xlZoPOTwBIco4FU0UwZBSRn1p8fSkttjbGE=; fh=EbTXCzhZyWMi99XjBGEJxbrHbHiMpVnkFWCwhwmTNvY=; b=KEuOvpeah39xjYZ7sSeYeqS0Wv1JEaIgAg2oILHAjPgwUguds0CMpUn+kj0EigyEaG TVq8ChP9uxSHKA1PeZ7tdbHwfiZM4/8OHXBYFmWUHh18K4JDtJD4XK8bbBZNiyDNXWk2 xAxfBiZQ1YIircVSje5qQccJJ5BVZV0GQpfy95CtEROlb//w6v7G2wuJPMbXavWnwOQP oL7qXKQ2yWC9LAqprMqe0UeXV3G3DbIzRmDvIHx5u7JtnSW4SiAZetLjqmdC4DwkVg+P 7gH8xoulWKoBNVA5mw6adFeLCP203q0h/nIM01UtnKOWk+iUyW3XtNn+GjLmLMNQg41h e+lg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GVKufjhm; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g29-20020a056122099d00b004b7305215b8si1346862vkd.294.2024.04.09.07.01.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 09 Apr 2024 07:01:26 -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; dkim=pass header.i=@linaro.org header.s=google header.b=GVKufjhm; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ruC10-0006mk-0h; Tue, 09 Apr 2024 09:59:58 -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 1ruC0y-0006mJ-Vg for qemu-devel@nongnu.org; Tue, 09 Apr 2024 09:59:56 -0400 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ruC0x-0004LZ-Ea for qemu-devel@nongnu.org; Tue, 09 Apr 2024 09:59:56 -0400 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a51a7d4466bso500384566b.2 for ; Tue, 09 Apr 2024 06:59:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712671193; x=1713275993; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3d4Pf+e5xlZoPOTwBIco4FU0UwZBSRn1p8fSkttjbGE=; b=GVKufjhmH+own+ZgS0uYhLknGR5rjVAaKTk/Np23ilpZg9eAURExMHvSD9enx0nWbz ETpXIN12StbFD4vsIAp6jEgL6wlsYMZr5RXMTZX1uBzZMtd2BHf9/p9TlbsfYDYT07ys eB/RptfwcGnIMFhflW5rXVskxKtE+UCRonhME16I13UsNcroV034PHd8xJSdGdWmWuXy cbwqPC7h2eaWVAg56zK5RKpRS+4eWFKrJEjV5UXSqYwqw2elxCtYUq8oNgQwOeYmH2zf y5gvbVD7gU829g1tteaodN9ep9VI0ra0X4RL6vTzzlk0Jy6ZV7f1dxs0g+T50orPvZuy jLWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712671193; x=1713275993; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3d4Pf+e5xlZoPOTwBIco4FU0UwZBSRn1p8fSkttjbGE=; b=CEM4BHqpTOor5JqOzDZSZmrcWB2yMnSk3eaMfpn38+dssJRm+gqTzOsWOkLIvT8Mtl 9K5xQ5uZHhzQZtBCc8AI9DgCLLwP9F7vSL9tddKIwQ1NCcVPsAnzVYZ28lC9a2dMwU+W P+khUEzzPJf7YkIB68+2voARxXRaDgb0graiVnaUMuMM3lqW/tLJm8WJUN4PP0yNWJuV OCpF69xYUAwP6Rdw4fM8Uz66aIGH8/VXdZJ/YAiW0w8GXOk2Nate9gzq9laSlBtbmj6m /dDSOWL3/dWNXQSrghtqsemrT/8LC23OnMcJpR2SiSZnv44x9aJYA/Ykjcjwj2BPjDha dq2A== X-Gm-Message-State: AOJu0Yxre1pSYRNo05DhHhQqZ/PbGfjWqh+n2QnQ4QRLStKFdJYuXxv5 RX5CwFvA6aq470ATdcZ3VKHuWH5EkSbEqoIYNOd5mNr/3mPI5jg4QOjh+WuAu3g0brg6SgORwJs U X-Received: by 2002:a17:907:84b:b0:a51:df52:5a65 with SMTP id ww11-20020a170907084b00b00a51df525a65mr3604970ejb.2.1712671193421; Tue, 09 Apr 2024 06:59:53 -0700 (PDT) Received: from m1x-phil.lan ([176.176.160.134]) by smtp.gmail.com with ESMTPSA id ld11-20020a170906f94b00b00a51d8a3a632sm2345694ejb.168.2024.04.09.06.59.51 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 09 Apr 2024 06:59:52 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Kevin Wolf Cc: Qiang Liu , qemu-block@nongnu.org, Alexander Bulekov , Hanna Reitz , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Richard Henderson Subject: [PATCH-for-9.0 v2 1/3] hw/block/nand: Factor nand_load_iolen() method out Date: Tue, 9 Apr 2024 15:59:41 +0200 Message-ID: <20240409135944.24997-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240409135944.24997-1-philmd@linaro.org> References: <20240409135944.24997-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62c; envelope-from=philmd@linaro.org; helo=mail-ej1-x62c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.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 Reviewed-by: Richard Henderson Reviewed-by: Kevin Wolf Signed-off-by: Philippe Mathieu-Daudé --- hw/block/nand.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/hw/block/nand.c b/hw/block/nand.c index d1435f2207..f33eb2d552 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) {