From patchwork Sun Feb 13 15:10:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Lalaev X-Patchwork-Id: 1592124 X-Patchwork-Delegate: trini@ti.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=emlid.com header.i=@emlid.com header.a=rsa-sha256 header.s=google header.b=K1RR6ZR+; 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) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JxZFs0qCRz9s09 for ; Mon, 14 Feb 2022 04:33:35 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 35DBF83B90; Sun, 13 Feb 2022 18:33:23 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=emlid.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=emlid.com header.i=@emlid.com header.b="K1RR6ZR+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C9E3F83B8D; Sun, 13 Feb 2022 16:11:49 +0100 (CET) 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) (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 7D1F483B84 for ; Sun, 13 Feb 2022 16:11:46 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=emlid.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=andrei.lalaev@emlid.com Received: by mail-lj1-x22a.google.com with SMTP id n24so16259996ljj.10 for ; Sun, 13 Feb 2022 07:11:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emlid.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hnuAPnfTexKCVsCRYEq0GSEMbMtLxw5aoJwps33XhdQ=; b=K1RR6ZR+GElOlYyKayr0BlYcGRVTJFbhMsdBpYQr7CuZcPZRVSb9BjCK4k5n3T3i4h wanspGDbW9yHRbhu+Yg8ZJr54gYqwxcvTwKG/EXMwBRyuqPttJW9MLYeyK30xMqEpYqs 3v/WY61+O7RGZM7FneAshrXqimBuv8hz1nWYP5s3OD1KGhEM9JHZmv9NyeRDEwHni+O0 N8/TszH6mzKSrc1yG0WaGDVQrIIhug2ZEgDWvGEZhdHFxu30st9uC0Eur3ZPnvcxIScj PvTgjJHosM9jFNpSeYO7CyGSXuApd0xJurTFUoRuopoAcaE59owrqidIW91O8X6vkLRa 0QQg== 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=hnuAPnfTexKCVsCRYEq0GSEMbMtLxw5aoJwps33XhdQ=; b=Da+8E5/oISSzb5F9Kdi6lIhrRZEa6yOqdhrMMXiE8QL1Tt4p/FddyrEzccEDp1+mGZ Nh+fyQ042eL+7mmcHSMEw4K90itbbVtqeWyiIsfNVRaBgZrzsoip2pspGwZ2+RdOJvQm X1+wxTozBDAlgSwvkBpX5Y1Z/DiAKw9HWS6jEmmyXA9RbhvyTigNkd/zLMGH6BPBdqQ7 wM+9gpoKfPtmnOYQjDTbyhkQ0bPl5ym74Ej7O7IxUWtY9tBn7Pkte79dLN5v3gKRs8dF MMaZxnXGOAB2TX6IYxiK7J0aGNBCv+cOsBhfEGPiQlJ4Bl0yf0MoDYIGCFmCFGJfhbQC lftA== X-Gm-Message-State: AOAM533AxixxZnSD9kZ4aL1FXLTayIkZXRcBBwGbXcBKaxPKPA02QiAp 9sxsJXHE40sVNoZij3Q2cy2XPDIEgtkDmw== X-Google-Smtp-Source: ABdhPJxVUI3zKmLqqalecv1e8EQKrIoRs1+sN+wFx+i4oFsc6I8kYxv3heb0JvyS2fAAy6hbuRlg/Q== X-Received: by 2002:a2e:50c:: with SMTP id 12mr6400119ljf.461.1644765105523; Sun, 13 Feb 2022 07:11:45 -0800 (PST) Received: from localhost.localdomain (ppp91-122-164-134.pppoe.avangarddsl.ru. [91.122.164.134]) by smtp.gmail.com with ESMTPSA id bi16sm2390774lfb.309.2022.02.13.07.11.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Feb 2022 07:11:45 -0800 (PST) From: Andrei Lalaev To: u-boot@lists.denx.de Cc: andre.przywara@arm.com, jagan@amarulasolutions.com, Andrei Lalaev Subject: [PATCH] arm: sunxi: dram: restore previous value in DRAM Date: Sun, 13 Feb 2022 18:10:14 +0300 Message-Id: <20220213151014.40548-1-andrei.lalaev@emlid.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Mailman-Approved-At: Sun, 13 Feb 2022 18:33:21 +0100 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.5 at phobos.denx.de X-Virus-Status: Clean It's better to restore previous value at offset because otherwise the function can corrupt memory reserved by Linux (e.g. ramoops). Signed-off-by: Andrei Lalaev --- arch/arm/mach-sunxi/dram_helpers.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/arch/arm/mach-sunxi/dram_helpers.c b/arch/arm/mach-sunxi/dram_helpers.c index 2c873192e6..ed6db14f3c 100644 --- a/arch/arm/mach-sunxi/dram_helpers.c +++ b/arch/arm/mach-sunxi/dram_helpers.c @@ -32,12 +32,20 @@ void mctl_await_completion(u32 *reg, u32 mask, u32 val) #ifndef CONFIG_MACH_SUNIV bool mctl_mem_matches(u32 offset) { + ulong addr = CONFIG_SYS_SDRAM_BASE + offset; + u32 prev_val = readl(addr); + bool ret = false; + /* Try to write different values to RAM at two addresses */ writel(0, CONFIG_SYS_SDRAM_BASE); - writel(0xaa55aa55, (ulong)CONFIG_SYS_SDRAM_BASE + offset); + writel(0xaa55aa55, addr); dsb(); /* Check if the same value is actually observed when reading back */ - return readl(CONFIG_SYS_SDRAM_BASE) == - readl((ulong)CONFIG_SYS_SDRAM_BASE + offset); + ret = readl(CONFIG_SYS_SDRAM_BASE) == readl(addr); + + /* Restore previous value */ + writel(prev_val, addr); + + return ret; } #endif