From patchwork Sat Jan 28 07:46:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rahul Pathak X-Patchwork-Id: 1733212 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=0WYILwXk; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=YTaIo9sB; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P3mk32Y5lz23hJ for ; Sat, 28 Jan 2023 18:47:07 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=epwdxS1G4qJPScx0VsqrQjxsC3wfpTWmrJgkMvMz0dM=; b=0WYILwXkzcu7bw I6AK/TLCloVnWgzZHaBh3TFaeLMhLz+JCqZGl/iCDlcH+Wdk7enRp5DalLYTxMbUcFLRAgh86/dZe nDACBf6P+eg1XbtC6G0vBt6Q1nboP32dLAi4TAmITzHQk/SrYbyAmU9JCmRziC/Ts5MH1Jath9EA7 ln1aUWD61ki/DX1uktExGZkjLugwg2sC1sBmsQCiFJAyeq5FIGSTtQeroAfUc9bXIP548IwUqoyQ3 9uBMP68BNfjh5hk820Q69Pns8XH9nJfwG7NVn1aSeSnKqfCnIPtPI+iaunQhm55daOjXho8v5QJ70 6LE4o/MWK+HhKzbjDhiQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLfvK-00HPA9-Ht; Sat, 28 Jan 2023 07:46:54 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLfvI-00HP91-1E for opensbi@lists.infradead.org; Sat, 28 Jan 2023 07:46:53 +0000 Received: by mail-pj1-x102d.google.com with SMTP id nm12-20020a17090b19cc00b0022c2155cc0bso6730792pjb.4 for ; Fri, 27 Jan 2023 23:46:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=UB7L1ceuYTxTb/YEnnw1eh/YdQyt33pSoAodzcerDjo=; b=YTaIo9sBYjlFfuBbJEpC7lyI1kikM5RzoX82XvPcu0If0wqX8X2uRuQCLo9yVl5xiJ xfTJtt0zQE4ILO0AOyWv1xKDnHJFHo8T7KGmDuFBjjcBHuwzEa4hhi9VzX5LRWViKZEQ LXrddEoDXrtyrUCzgFY8273kgV9Y9XwgqB9uFPJN1fFUEVxfrZPYD6llAahaIvm8szLH eV5jmzZ39bkb3zrvMGR1kQliDP9+oYeLRmASILNtN6iJl0+diEEqpHsIUhmTIf7kv/dy hsoC7GHZorq1QZWqMtVD+KuzWR5vXfcord5ut0xqeQgS//vFMuchL58ByyGSBdQ5pE+q sg7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=UB7L1ceuYTxTb/YEnnw1eh/YdQyt33pSoAodzcerDjo=; b=upYL+zH+rB7rdI0z5znaEeHRzf7buwzF/czPXsSE9TKkkNlzyRKDiy1NfyeVyQhqaz Ka9CXRn1+ZFl6UUkEAea4uhi8j4jdPQU0SfXUC1N1mZXjvthm+zzaNNUvrfg7GfZ9ftR JBSuGT5lvsCU71WjFd4JDI+Op1dvZPfet0AABCw9mcVrZErwSE5IHMOzMoLQI92haIs/ Csn6ZU+d2S5mGBsNRPdx7VYF79qr4oWBqfiYeK3OGoPbWfAO5KzAUQsD8floe7yIZL57 bIi9s47bKNioU3GmLyil/evGkH1jlPY2dqRCo8gTRgooypWl3FS5z1p05hjClGQdzJK3 U3zQ== X-Gm-Message-State: AFqh2kqFmOY9qsic5b31NHBFT3s6fSwD1jlNrV/7fFIRhZMkJOu8QzBB zxk05aOv0RU+m5YSxhsFvKgvpc73ZJAKR5dM4pU= X-Google-Smtp-Source: AMrXdXsi2G6T+mNeYtF5s3yS35r81SyNFx92fe2ezzfeDdTwf9+6zWcoEKZ+VmQmlJW/ebqbt4xGgg== X-Received: by 2002:a17:90a:2f89:b0:219:6619:848a with SMTP id t9-20020a17090a2f8900b002196619848amr44584149pjd.36.1674892010026; Fri, 27 Jan 2023 23:46:50 -0800 (PST) Received: from rpathak-ThinkPad-T490.dc1.ventanamicro.com ([2405:201:1010:106f:9f64:b4f8:8cb:de3b]) by smtp.googlemail.com with ESMTPSA id k24-20020a637b58000000b00476dc914262sm3401920pgn.1.2023.01.27.23.46.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 23:46:49 -0800 (PST) From: Rahul Pathak To: opensbi@lists.infradead.org Cc: rpathak@ventanamicro.com, rpathakmailbox@gmail.com Subject: [PATCH 2/2] lib: utils/fdt: Use byteorder conversion functions in libfdt_env.h Date: Sat, 28 Jan 2023 13:16:17 +0530 Message-Id: <20230128074617.1917265-3-rpathak@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230128074617.1917265-1-rpathak@ventanamicro.com> References: <20230128074617.1917265-1-rpathak@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230127_234652_101001_E36EA23E X-CRM114-Status: UNSURE ( 7.66 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: FDT follows big-endian and CPU can be little or big endian as per the implementation. libfdt_env.h defines function for conversion between fdt and cpu byteorder according to the endianness. Currently, libfdt_env.h defines custom byte swapping macros and then undefines them. Instead, use the generic endianness conversion functions Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:102d listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org FDT follows big-endian and CPU can be little or big endian as per the implementation. libfdt_env.h defines function for conversion between fdt and cpu byteorder according to the endianness. Currently, libfdt_env.h defines custom byte swapping macros and then undefines them. Instead, use the generic endianness conversion functions Signed-off-by: Rahul Pathak Reviewed-by: Xiang W --- lib/utils/libfdt/libfdt_env.h | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/lib/utils/libfdt/libfdt_env.h b/lib/utils/libfdt/libfdt_env.h index f9d9c6783c52..e5ad7698efca 100644 --- a/lib/utils/libfdt/libfdt_env.h +++ b/lib/utils/libfdt/libfdt_env.h @@ -9,6 +9,7 @@ #include #include +#include #define INT_MAX ((int)(~0U >> 1)) #define UINT_MAX ((unsigned int)~0U) @@ -41,45 +42,35 @@ typedef uint16_t FDT_BITWISE fdt16_t; typedef uint32_t FDT_BITWISE fdt32_t; typedef uint64_t FDT_BITWISE fdt64_t; -#define EXTRACT_BYTE(x, n) ((unsigned long long)((uint8_t *)&x)[n]) -#define CPU_TO_FDT16(x) ((EXTRACT_BYTE(x, 0) << 8) | EXTRACT_BYTE(x, 1)) -#define CPU_TO_FDT32(x) ((EXTRACT_BYTE(x, 0) << 24) | (EXTRACT_BYTE(x, 1) << 16) | \ - (EXTRACT_BYTE(x, 2) << 8) | EXTRACT_BYTE(x, 3)) -#define CPU_TO_FDT64(x) ((EXTRACT_BYTE(x, 0) << 56) | (EXTRACT_BYTE(x, 1) << 48) | \ - (EXTRACT_BYTE(x, 2) << 40) | (EXTRACT_BYTE(x, 3) << 32) | \ - (EXTRACT_BYTE(x, 4) << 24) | (EXTRACT_BYTE(x, 5) << 16) | \ - (EXTRACT_BYTE(x, 6) << 8) | EXTRACT_BYTE(x, 7)) - static inline uint16_t fdt16_to_cpu(fdt16_t x) { - return (FDT_FORCE uint16_t)CPU_TO_FDT16(x); + return (FDT_FORCE uint16_t)be16_to_cpu(x); } + static inline fdt16_t cpu_to_fdt16(uint16_t x) { - return (FDT_FORCE fdt16_t)CPU_TO_FDT16(x); + return (FDT_FORCE fdt16_t)cpu_to_be16(x); } static inline uint32_t fdt32_to_cpu(fdt32_t x) { - return (FDT_FORCE uint32_t)CPU_TO_FDT32(x); + return (FDT_FORCE uint32_t)be32_to_cpu(x); } + static inline fdt32_t cpu_to_fdt32(uint32_t x) { - return (FDT_FORCE fdt32_t)CPU_TO_FDT32(x); + return (FDT_FORCE fdt32_t)cpu_to_be32(x); } static inline uint64_t fdt64_to_cpu(fdt64_t x) { - return (FDT_FORCE uint64_t)CPU_TO_FDT64(x); + return (FDT_FORCE uint64_t)be64_to_cpu(x); } + static inline fdt64_t cpu_to_fdt64(uint64_t x) { - return (FDT_FORCE fdt64_t)CPU_TO_FDT64(x); + return (FDT_FORCE fdt64_t)cpu_to_be64(x); } -#undef CPU_TO_FDT64 -#undef CPU_TO_FDT32 -#undef CPU_TO_FDT16 -#undef EXTRACT_BYTE #ifdef __APPLE__ #include