From patchwork Mon Oct 18 03:50:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Hu X-Patchwork-Id: 1542531 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=nM60HExh; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HXvp065Khz9sRN for ; Mon, 18 Oct 2021 22:31:04 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7572083460; Mon, 18 Oct 2021 13:31:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.b="nM60HExh"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 77BCC83455; Mon, 18 Oct 2021 05:50:44 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3BDAD8341D for ; Mon, 18 Oct 2021 05:50:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=nick.hu@sifive.com Received: by mail-pg1-x52d.google.com with SMTP id t7so214520pgl.9 for ; Sun, 17 Oct 2021 20:50:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=66xViBRWgLiBE+qfah6gvcKqSwwtQf9HMCJNZ0TXP0Y=; b=nM60HExhIit5d45DRu9H/oVq0BJiDorWDn2MWylHolDpjpRzqY5hWATPsDeSix0IzI vQJ7QaGYMm4G87fMP7p/A2U8+PavlJ9W7FFSlpdJZ4xjGtr1jN4TMVIfE3ItYZhqLeCY G05MWtkHj/ZRGj2LDbkC2hEw97+8xywzlEeK1AjVJn/w4UJvPNtX1xqQNj3q2mCCIFUe RAT9LRI5ciAavuLrA7BKA8S4H6f/E1bmaMBmSBGBX9YcWOMqILtIJrkqvyal6QckZGBw JSu4KRUb6o6nq1Dm2q+rg+KviMrZNwlkGMDZqLnVneGj39nnZiRaBY3oNB2nD6g4wPiB 2Dxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=66xViBRWgLiBE+qfah6gvcKqSwwtQf9HMCJNZ0TXP0Y=; b=AzBXVB4Ryx8S/d8CfMuQwJpY/YUVBJLsGAt/nUrKYzWIzViwsKcF1xd1FCF+01ZTMA s9O7JYxux7F1P6brZcH6Zxptf47feVnH1yoIwSjfERyAjxAm4baAe2FR9Zf8//X9fVCc Ey7MJ6OycWRQv4g772fIPsRepoedTe+fidP5AzR9JO0dgm/XjS5A/+0guROxCjanvliG kKz57Ee2R01Wrz0S4neVSgoHwAu5uIGYbLl54D2f1gt5QDl30WawcfnBk/6bcvHsk8SD ULwmKm5NnYGV460frrrP/0gxZb+atWe1zX1vqoRzYhgVYaLW9WbM8jtaSRS42EmhFZMr tbkQ== X-Gm-Message-State: AOAM531t1AI0HUnHW2e4v8OG/t5pNkqtPn/Y6jbIajgIuvRuDAXDBH7+ pOns43WHhx3g6EItxzZ5a8E19HsbGbxjeA== X-Google-Smtp-Source: ABdhPJzBa5AvOnIHl49VHXmgXVpRD0lqcpiYgdR4QjYpYHIR6KUGIPJBGgoAxcI9E02iTTza6bZquA== X-Received: by 2002:a05:6a00:ac8:b029:320:a6bb:880d with SMTP id c8-20020a056a000ac8b0290320a6bb880dmr25776534pfl.41.1634529039163; Sun, 17 Oct 2021 20:50:39 -0700 (PDT) Received: from hsinchu16.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id m10sm17427302pjs.21.2021.10.17.20.50.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 20:50:38 -0700 (PDT) From: Nick Hu To: u-boot@lists.denx.de, rick@andestech.com, ycliang@andestech.com, greentime.hu@sifive.com, zong.li@sifive.com, vincent.chen@sifive.com Cc: Nick Hu Subject: [PATCH] riscv: Avoid io read/write cause wrong result Date: Mon, 18 Oct 2021 11:50:05 +0800 Message-Id: <20211018035005.16842-1-nick.hu@sifive.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mailman-Approved-At: Mon, 18 Oct 2021 13:30:59 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean io read/write may cause wrong result because they may read/write data from/to register instead of memory. Add 'volatile' to avoid it. Signed-off-by: Nick Hu Reviewed-by: Leo Yu-Chi Liang Reviewed-by: Bin Meng --- arch/riscv/include/asm/io.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/arch/riscv/include/asm/io.h b/arch/riscv/include/asm/io.h index acf5a96449..3540773c4f 100644 --- a/arch/riscv/include/asm/io.h +++ b/arch/riscv/include/asm/io.h @@ -44,15 +44,15 @@ static inline phys_addr_t map_to_sysmem(const void *ptr) * read/writes. We define __arch_*[bl] here, and leave __arch_*w * to the architecture specific code. */ -#define __arch_getb(a) (*(unsigned char *)(a)) -#define __arch_getw(a) (*(unsigned short *)(a)) -#define __arch_getl(a) (*(unsigned int *)(a)) -#define __arch_getq(a) (*(unsigned long long *)(a)) - -#define __arch_putb(v, a) (*(unsigned char *)(a) = (v)) -#define __arch_putw(v, a) (*(unsigned short *)(a) = (v)) -#define __arch_putl(v, a) (*(unsigned int *)(a) = (v)) -#define __arch_putq(v, a) (*(unsigned long long *)(a) = (v)) +#define __arch_getb(a) (*(volatile unsigned char *)(a)) +#define __arch_getw(a) (*(volatile unsigned short *)(a)) +#define __arch_getl(a) (*(volatile unsigned int *)(a)) +#define __arch_getq(a) (*(volatile unsigned long long *)(a)) + +#define __arch_putb(v, a) (*(volatile unsigned char *)(a) = (v)) +#define __arch_putw(v, a) (*(volatile unsigned short *)(a) = (v)) +#define __arch_putl(v, a) (*(volatile unsigned int *)(a) = (v)) +#define __arch_putq(v, a) (*(volatile unsigned long long *)(a) = (v)) #define __raw_writeb(v, a) __arch_putb(v, a) #define __raw_writew(v, a) __arch_putw(v, a)