From patchwork Sun Aug 5 10:44:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Angelo Dureghello X-Patchwork-Id: 953516 X-Patchwork-Delegate: jason.jin@freescale.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sysam.it Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41jy943l1Cz9s3q for ; Sun, 5 Aug 2018 20:45:10 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id AD73CC21E68; Sun, 5 Aug 2018 10:45:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=RDNS_DYNAMIC autolearn=no autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 8249FC21C2F; Sun, 5 Aug 2018 10:45:02 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 0D279C21C2F; Sun, 5 Aug 2018 10:45:02 +0000 (UTC) Received: from sysam.it (ec2-18-194-220-216.eu-central-1.compute.amazonaws.com [18.194.220.216]) by lists.denx.de (Postfix) with ESMTP id BCB4AC21C27 for ; Sun, 5 Aug 2018 10:45:01 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by sysam.it (Postfix) with ESMTP id 959EF21CAB; Sun, 5 Aug 2018 10:45:01 +0000 (UTC) Received: from sysam.it ([127.0.0.1]) by localhost (sysam.it [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mjOGCSgAbdyo; Sun, 5 Aug 2018 10:45:00 +0000 (UTC) Received: from localhost.localdomain (host237-227-dynamic.44-79-r.retail.telecomitalia.it [79.44.227.237]) by sysam.it (Postfix) with ESMTPSA id B66AA21C9C; Sun, 5 Aug 2018 10:45:00 +0000 (UTC) From: Angelo Dureghello To: angelo@sysam.it Date: Sun, 5 Aug 2018 12:44:56 +0200 Message-Id: <20180805104456.20338-1-angelo@sysam.it> X-Mailer: git-send-email 2.18.0 Cc: u-boot@lists.denx.de, alison.wang@freescale.com Subject: [U-Boot] [PATCH] m68k: fix multiple memory accesses on swap operations X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" On a u32 val = __sw32(*addr); multiple memory accesses are not welcome, since "addr" may be an IO peripheral register address. This patch changes __sw16/32 to perform a single memory access for the source value. Signed-off-by: Angelo Dureghello --- arch/m68k/include/asm/byteorder.h | 34 ++++++++++++++++++------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/arch/m68k/include/asm/byteorder.h b/arch/m68k/include/asm/byteorder.h index eb03b6a053..9179622250 100644 --- a/arch/m68k/include/asm/byteorder.h +++ b/arch/m68k/include/asm/byteorder.h @@ -10,21 +10,28 @@ #include #ifdef __GNUC__ -#define __sw16(x) \ - ((__u16)( \ - (((__u16)(x) & (__u16)0x00ffU) << 8) | \ - (((__u16)(x) & (__u16)0xff00U) >> 8) )) -#define __sw32(x) \ - ((__u32)( \ - (((__u32)(x)) << 24) | \ - (((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \ - (((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \ - (((__u32)(x)) >> 24) )) + +static inline __u32 __sw32(__u32 x) +{ + __u32 v = x; + + return v << 24 | + (v & (__u32)0x0000ff00UL) << 8 | + (v & (__u32)0x00ff0000UL) >> 8 | + v >> 24; +} + +static inline __u16 __sw16(__u16 x) +{ + __u16 v = x; + + return (v & (__u16)0x00ffU) << 8 | + (v & (__u16)0xff00U) >> 8; +} static __inline__ unsigned ld_le16(const volatile unsigned short *addr) { - unsigned result = *addr; - return __sw16(result); + return __sw16(*addr); } static __inline__ void st_le16(volatile unsigned short *addr, @@ -35,8 +42,7 @@ static __inline__ void st_le16(volatile unsigned short *addr, static __inline__ unsigned ld_le32(const volatile unsigned *addr) { - unsigned result = *addr; - return __sw32(result); + return __sw32(*addr); } static __inline__ void st_le32(volatile unsigned *addr, const unsigned val)