From patchwork Mon Jan 8 12:53: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: 760763 Delivered-To: patch@linaro.org Received: by 2002:a5d:6e02:0:b0:337:62d3:c6d5 with SMTP id h2csp867784wrz; Mon, 8 Jan 2024 04:54:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IEFCQthQ9ZMkdO3xjc5GeffYJ/CyacEYWYUNl4ieAfb2dEdCTIi3g7rjDW35fiiANFOcgkT X-Received: by 2002:a05:622a:14ca:b0:428:3bee:ea2d with SMTP id u10-20020a05622a14ca00b004283beeea2dmr5379453qtx.96.1704718481097; Mon, 08 Jan 2024 04:54:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704718481; cv=none; d=google.com; s=arc-20160816; b=aMYeNL8JHHUTKUUxG3z/FEEy2AjH7gek3tlzndH3T5P6zcReGx/5Fs0rhy7StPUcAa kheAFe3DonTDVKoLfg/wJGh1o6Ajn81DwabrkHbJstte+TgcxEWRdmX60/+XGkTlzKQC DjSTcumVpR/drR6paxjB+2BkAJrly6J260PCDJ+91DcdpmG3WcNv2+rWI3i+jbMK2O8i BSwSWWnw7ajmWGLRqxJuluIxWsPopH+0dfIajjFlWfozcE9gtVyXPeR9MhbLIWreKiGW JlrG46JkiikeBPo8qrgLRJmYi/XWF0gs00Kj5CBb6ZFSby4GisBDX6P+FmVmVicdNLh7 Q8TQ== 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=ghVWFLUr6713RIktIzJDLwjlFUwvU8dITI3EJerUt6E=; fh=ot/AHU6TwUyk96ZCKy1yVPJbrRHdtPsmBCo02SyURJs=; b=pNMfg/N0zUpMuM6O3+MSHVr9xYE3t4hgbK70KSaGeh/mTbNgcnY8SncMYpN0YzCmw3 HmYkA33EvRi8RHHSvV7X0icfmD+plhQzPezsg94+CLVsucavwp96nLOZ3yL8A5UTgXt6 gH9Nn7deAY0gY033UzUQT1iU3UicLqtHNHIJ+JxeCh+sGokjSiWEyQD8Qi+n5inNd+r/ n8t72yhTu5mJ51Zbbo2LskVvreRWtgGFFMiZoIjLJHKlRlEyNKRzIesHFnjvCSDWcWSp oKzJk5sS/7S4MD4EtA02pnWRX07G2aEaLzLvl/yzs3193GNiHlKN+3fNKdHlTORs62gk 8Siw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cE7lqjDI; 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 o15-20020a05622a044f00b0042753fdb817si7785504qtx.449.2024.01.08.04.54.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Jan 2024 04:54:41 -0800 (PST) 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=cE7lqjDI; 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 1rMp8d-0002tw-Ca; Mon, 08 Jan 2024 07:53:55 -0500 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 1rMp8c-0002tR-2J for qemu-devel@nongnu.org; Mon, 08 Jan 2024 07:53:54 -0500 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rMp8a-0006H4-Ef for qemu-devel@nongnu.org; Mon, 08 Jan 2024 07:53:53 -0500 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40e43e48a16so13298135e9.2 for ; Mon, 08 Jan 2024 04:53:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704718431; x=1705323231; 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=ghVWFLUr6713RIktIzJDLwjlFUwvU8dITI3EJerUt6E=; b=cE7lqjDIiL85o7NwwIR0GAfIWwo31IejvK/kRERHRmSjrzksbF+toE2N+a4j370YKg Qdd+tOKyfFe7rcTYNXnk97z2S2oyX5nL+akdA+Z6Rw1AgyqBhBGeLc8//anhHjdhi+WY jW7v4R93E0Y+4ReyGen5N9gpnfF9LAJzPN6jhuvGtkxi3pS6F9dtKJwoshfvniEj31QX IXITi/byUXRWi8M5yDhNEuYQnJP4qSmmQPt2nGwgUo7wf6YkQU86n6ECnxylFZ459Q9a iEVChatIC3RuNKLpHYJNQ+BiPGzQ16BBdZP2uLhFNs+hLmDzhHnGkO2m8Kb2ntMFCbRF gGSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704718431; x=1705323231; 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=ghVWFLUr6713RIktIzJDLwjlFUwvU8dITI3EJerUt6E=; b=LjT4MZufjp0o4q7Kq2ZY/fxXW8be6ykS1POskv/ZA2f0dRSUQNFtnR3aerynp7Dcx0 9lLpGplrICnzDDZRRRFZs226fEgi1dUrdsLkN+GowLq0hMk3nvcQwtSq55neW6xS2EhE mUSk7KdMVhDy3GcSnBzY5uUQT4RoNHQfyWfMgtobBw93IVR7weRIUGMHYOiCEszrf4VW ic+phndbklzxlycM/8h30b7w4Kk1SzDsByxwdHO3Sc2TzjgmmehI1qPPzt1JM2SDLTQ6 yBL/mSrZ88cOXCgaAxwHYx8XuAy2kii4Lag+H3O6+QfENAan+0Pd5Y6xBV+1nBe2t+Yb egMg== X-Gm-Message-State: AOJu0YyNawnIQqx8Jbp2cyGtjzoY5Zy0c0IxgEpFHO6tYmd1nUH83dpv ySjZBMQpgImx8S6tWgJyxfwJBnwFPjGOsRfbJIikd9HjNFg= X-Received: by 2002:a7b:c4d1:0:b0:40e:4aed:ad27 with SMTP id g17-20020a7bc4d1000000b0040e4aedad27mr125789wmk.144.1704718430674; Mon, 08 Jan 2024 04:53:50 -0800 (PST) Received: from localhost.localdomain ([176.176.175.62]) by smtp.gmail.com with ESMTPSA id l42-20020a05600c1d2a00b004030e8ff964sm11004600wms.34.2024.01.08.04.53.49 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 08 Jan 2024 04:53:50 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Gerd Hoffmann , qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Kevin Wolf , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 1/2] hw/block/pflash_cfi01: Use the LD/ST API in pflash_data_read/write Date: Mon, 8 Jan 2024 13:53:41 +0100 Message-ID: <20240108125342.48298-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240108125342.48298-1-philmd@linaro.org> References: <20240108125342.48298-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=philmd@linaro.org; helo=mail-wm1-x32e.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, T_SCC_BODY_TEXT_LINE=-0.01 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 Similarly to commit c3d25271b2 ("hw/block/pflash_cfi02: Use the ldst API in pflash_write") for CFI type 2, use the LD/ST API for CFI type 1. Signed-off-by: Philippe Mathieu-Daudé --- hw/block/pflash_cfi01.c | 63 ++++++----------------------------------- 1 file changed, 8 insertions(+), 55 deletions(-) diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index 3e2dc08bd7..ce63ba43b6 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -225,34 +225,10 @@ static uint32_t pflash_data_read(PFlashCFI01 *pfl, hwaddr offset, uint32_t ret; p = pfl->storage; - switch (width) { - case 1: - ret = p[offset]; - break; - case 2: - if (be) { - ret = p[offset] << 8; - ret |= p[offset + 1]; - } else { - ret = p[offset]; - ret |= p[offset + 1] << 8; - } - break; - case 4: - if (be) { - ret = p[offset] << 24; - ret |= p[offset + 1] << 16; - ret |= p[offset + 2] << 8; - ret |= p[offset + 3]; - } else { - ret = p[offset]; - ret |= p[offset + 1] << 8; - ret |= p[offset + 2] << 16; - ret |= p[offset + 3] << 24; - } - break; - default: - abort(); + if (be) { + ret = ldn_be_p(p, width); + } else { + ret = ldn_le_p(p, width); } trace_pflash_data_read(pfl->name, offset, width, ret); return ret; @@ -406,34 +382,11 @@ static inline void pflash_data_write(PFlashCFI01 *pfl, hwaddr offset, uint8_t *p = pfl->storage; trace_pflash_data_write(pfl->name, offset, width, value, pfl->counter); - switch (width) { - case 1: - p[offset] = value; - break; - case 2: - if (be) { - p[offset] = value >> 8; - p[offset + 1] = value; - } else { - p[offset] = value; - p[offset + 1] = value >> 8; - } - break; - case 4: - if (be) { - p[offset] = value >> 24; - p[offset + 1] = value >> 16; - p[offset + 2] = value >> 8; - p[offset + 3] = value; - } else { - p[offset] = value; - p[offset + 1] = value >> 8; - p[offset + 2] = value >> 16; - p[offset + 3] = value >> 24; - } - break; + if (be) { + stn_be_p(p, width, value); + } else { + stn_le_p(p, width, value); } - } static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,