From nobody Tue Nov 26 18:32:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1705664674; cv=none; d=zohomail.com; s=zohoarc; b=TDZaBnXurDByQpIwfk+Q5tEYXjqmlNXe1Lpdjm2ijArdk/1gRhYXgBktJFdP364/GZHnNJpOetRxENCRMQkmRzmnqdXbrH1KGwNc1/7Hugd7NivIe4T+opRLgo1XdXqokubautByEnLcdr7wri0WLcU66+xRwJS14VHWJQ/M8vg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705664674; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XRUeXWyyJ392ZohYjYrcHzpfLxHyioAU0c9SeFp2B+4=; b=ckxquV0DLF/r9krPOFH4v24uHltQceUHx5jbSlcCnt8kOipcB2/rLzDCbOYb1yZ9ZHZ9ko/3cVAHa1KwB6K+meTo1Nb2UO5CNDoSG8syOsJ/6T5I9pQNaYf8ewNVmO1sukX+EZfDNzRzje1q/st4r+9yNlZBxdWYlB8ZHsbdDq0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1705664674258479.3391685052102; Fri, 19 Jan 2024 03:44:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQnAv-0003ai-5f; Fri, 19 Jan 2024 06:36:41 -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 1rQnAt-0003ZV-Ik for qemu-devel@nongnu.org; Fri, 19 Jan 2024 06:36:39 -0500 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rQnAq-0002om-QM for qemu-devel@nongnu.org; Fri, 19 Jan 2024 06:36:39 -0500 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-337c5bcf79fso602782f8f.2 for ; Fri, 19 Jan 2024 03:36:36 -0800 (PST) Received: from localhost.localdomain (91-163-26-170.subs.proxad.net. [91.163.26.170]) by smtp.gmail.com with ESMTPSA id r20-20020a05600c35d400b0040d8eca092esm32803585wmq.47.2024.01.19.03.36.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 19 Jan 2024 03:36:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705664194; x=1706268994; 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=XRUeXWyyJ392ZohYjYrcHzpfLxHyioAU0c9SeFp2B+4=; b=U8SlidXbM8Y2dQEorClOwMLGiJs+pXPpw6EGVS1qq8ORi+ImOMGHZamC+MRDYO+jGI N1sd7Ndd2QUt0jYauMwXKT1wt0ppuxLuwXvIQ+lQHkb9KLtQ8oIKKT7o9BTvZZ9oHu8U PLPUpZwqsJ4djhBgmW5vLoY1eq0tJ1l9P8/u0oAN65ga9HrLO7NnHU+esySc5FMyz8T4 zpq22KCSjXEuIZqzyTXBmXDTJHyc32UfjHH96lbAym3pNJ6zBgv0qWxdH2i/R3gB2ucI VUeAz7yCSPu1GwjaM3JlmtrE7IYJp5VIjCmN3ElJ0xjEfzwjEkLKE/43O7DAaTQ25q46 aUdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705664194; x=1706268994; 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=XRUeXWyyJ392ZohYjYrcHzpfLxHyioAU0c9SeFp2B+4=; b=IIoxR9Vlf10m5EC8XeegzjFB1+s/mALZG4J6511ZyJns8QuJqLoEMu9xBcNuY2v4qr sJGDdz6PFV6IJw/SpiFBrXM2/nc0JKgRL3BP9qS2o1uyVGokYcwAdZ6+u7Mi98RY3Rt3 JxvnmBXVjOhZ3cB5rB4JUk7W4OJXDZldretoP4ok/HulOrzhLN+SGRjVjQFcPI51K8iR /pdMiGIvtZD3stCni7fZXLGNW8/ngnGbDlBQ7C/YlkeqfVfE5tq5xaInSFeEGOvKWfOE /0Q7j1rvogsBxuWNhfT+6txnsyUP0vPJWD6HQjsBqpltGC2Yc5ltGiDuW16E6K8uX1B6 jSgw== X-Gm-Message-State: AOJu0YxKyz1xideED9UMoEQhKukPKN7gWkmm5kbMax4GTqgCfgcILc0J Ose1jhBrJCKK0oyx618IGh6VDhUdE9Sew6Io+UhvkOk48sGegtahlrMIMuhUJsAn3VD/KyVkLxA jiPqAJg== X-Google-Smtp-Source: AGHT+IGj75N26ZT3ZOq7omXVoZFMqbnYR23Hs+dWcYwTne9hE7wDiuiR0snF9EPNVkl2lhYt9iYgSQ== X-Received: by 2002:a7b:c3d4:0:b0:40e:89a4:27dc with SMTP id t20-20020a7bc3d4000000b0040e89a427dcmr1430853wmj.106.1705664194508; Fri, 19 Jan 2024 03:36:34 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, qemu-block@nongnu.org, qemu-arm@nongnu.org, Gerd Hoffmann , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Kevin Wolf , Hanna Reitz Subject: [PULL 19/36] hw/pflash: use ldn_{be,le}_p and stn_{be,le}_p Date: Fri, 19 Jan 2024 12:34:48 +0100 Message-ID: <20240119113507.31951-20-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240119113507.31951-1-philmd@linaro.org> References: <20240119113507.31951-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=philmd@linaro.org; helo=mail-wr1-x42b.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1705664675063100003 From: Gerd Hoffmann Use the helper functions we have to read/write multi-byte values in correct byte order. Suggested-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Gerd Hoffmann Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-ID: <20240108160900.104835-3-kraxel@redhat.com> Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- 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 67f1c9773a..8434a45cab 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, hw= addr offset, uint32_t ret; =20 p =3D pfl->storage; - switch (width) { - case 1: - ret =3D p[offset]; - break; - case 2: - if (be) { - ret =3D p[offset] << 8; - ret |=3D p[offset + 1]; - } else { - ret =3D p[offset]; - ret |=3D p[offset + 1] << 8; - } - break; - case 4: - if (be) { - ret =3D p[offset] << 24; - ret |=3D p[offset + 1] << 16; - ret |=3D p[offset + 2] << 8; - ret |=3D p[offset + 3]; - } else { - ret =3D p[offset]; - ret |=3D p[offset + 1] << 8; - ret |=3D p[offset + 2] << 16; - ret |=3D p[offset + 3] << 24; - } - break; - default: - abort(); + if (be) { + ret =3D ldn_be_p(p + offset, width); + } else { + ret =3D ldn_le_p(p + offset, width); } trace_pflash_data_read(pfl->name, offset, width, ret); return ret; @@ -408,34 +384,11 @@ static inline void pflash_data_write(PFlashCFI01 *pfl= , hwaddr offset, trace_pflash_data_write(pfl->name, offset, width, value, pfl->counter); p =3D pfl->storage + offset; =20 - switch (width) { - case 1: - p[0] =3D value; - break; - case 2: - if (be) { - p[0] =3D value >> 8; - p[1] =3D value; - } else { - p[0] =3D value; - p[1] =3D value >> 8; - } - break; - case 4: - if (be) { - p[0] =3D value >> 24; - p[1] =3D value >> 16; - p[2] =3D value >> 8; - p[3] =3D value; - } else { - p[0] =3D value; - p[1] =3D value >> 8; - p[2] =3D value >> 16; - p[3] =3D value >> 24; - } - break; + if (be) { + stn_be_p(p, width, value); + } else { + stn_le_p(p, width, value); } - } =20 static void pflash_write(PFlashCFI01 *pfl, hwaddr offset, --=20 2.41.0