Received: by 10.192.165.148 with SMTP id m20csp3476760imm; Mon, 30 Apr 2018 00:23:20 -0700 (PDT) X-Google-Smtp-Source: AB8JxZojZYmg3xzVjald8lYmhfINeYnEyX/KqE2uWw30JVAyOBwucTnFFno1HIwbG1Ihn1DyDNxs X-Received: by 2002:a17:902:bc4a:: with SMTP id t10-v6mr11437574plz.343.1525073000570; Mon, 30 Apr 2018 00:23:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525073000; cv=none; d=google.com; s=arc-20160816; b=xrUFrWQWiYRlMpfaRHWrE+yE0ohtdUFVtxu38GcXav4qGdKcmgbPa/6W+77MdzcGIX CQHbcVMNwWTHeP2n8V8nOPZhk0srdcmig/ZIstysKxvODV/GwhYF9nwPIb+uNkw3LmIa Bx/aJMcIhR4r20ojNbzv/+cezdEQRTFw4UDsYl1g/V3mn6kR+nXUOGTsfCeuflCAlRYP lCt3sDS6tSOE96xFOhQKMmY+U0eN39l7smOPLt+DO2aCW17TgAKYAVPzr4Zbb4Z7DQXL tXhhsN8LJ3acTXGnxdo/B/11nJqGar4gXnuirqZz80p33npQ8XWaUrOTbCmHRHztLmWw YU/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:to:from:dkim-signature :arc-authentication-results; bh=OkFvhSvtIK/00UjiETgluruIQPyXBcaSZwy3R0bsIRM=; b=IZ8GG1y7rPSB2yw5nioiX8ZZJeM5jNySODuKl6we5eUqaWUAwRROC8CNUNsvn7qID/ zRaVEHG68Iq/vK8/2KghwDK7AIiG+PYYwgOc9HOSPkmcgqWKfHg7KjhaOQCGSC+uzmOn lt1M1sSOB0ZXlh4OJqT23ay2oTWGglYwmtuIJH29jSK7dfvfOLO0Hm47kl3XQiYncoYN wdu2/tzDzC0CdEcCatm20wrD58WUWu3L6h/UgJlPIDfg80Gtn80Ul2jxU/ACyPUTi6Ea /qIMgqeEGc6Vyt7F2BxyqqWiUquCoTwxHoilQ0zCnwAPd/LjW+l8Gl0h9RdlpK7pq6I2 PpGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RYqtfjVp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d9-v6si5882466pga.192.2018.04.30.00.23.06; Mon, 30 Apr 2018 00:23:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RYqtfjVp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752279AbeD3HWp (ORCPT + 99 others); Mon, 30 Apr 2018 03:22:45 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:35205 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751659AbeD3HWf (ORCPT ); Mon, 30 Apr 2018 03:22:35 -0400 Received: by mail-pf0-f196.google.com with SMTP id j5so6086645pfh.2 for ; Mon, 30 Apr 2018 00:22:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:in-reply-to :references; bh=OkFvhSvtIK/00UjiETgluruIQPyXBcaSZwy3R0bsIRM=; b=RYqtfjVpj+uNUixflPKCVtIc9zu7YX1VPVXIr4cVT84WBXsA3yDLbPYjS93nk6i37j WUgBGtEbwimOEvUljRwPtp/JfBijqBz+emlpMEZOak982m6Tyj+UwjOjec77sHLC6W/X iiVgXnK29i4ZeuGFSUhUC7+xKnQNMaub3tmz54SzeDSZqg+bLHrVgE7bUxrmTilK9/D+ tMrKc+US7tz4/XsPEBJ541GtQxUbbOZ6MlPngFH3KKLWL0SMVPvW5tYgRcfnDp0eiFq4 LnrVCDFalfgIZ7VgM5/CUJxhXEHHmphJoIK6qdqSjJnX4YkdvtVB4gfRLsdGfjZCQNEe nydA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=OkFvhSvtIK/00UjiETgluruIQPyXBcaSZwy3R0bsIRM=; b=quRponxiHOtXdha7FwGr+g4HoQdlagxPNh7IOsAu65K+ZhFH7qsPW0iYA8fNi6Ixw7 +hwqK9AzRRe+PqQearcJMgO50QmwR3ocSwZ3VB6FIibgvU+7DEYkSVhfwf8EsoxIz52+ ZVs/5vD4ShlCrrcUBsPXrE9fAcGY3pz++7O3snFuWmsfdX/kaLc4I5XzQIdSENuMB9Ei xZ5dRieXfrdoAM4ujnGybWvJ+k59XflMcuefSM0dMzyWza10y72dhYkaZV4n6MmPhhLw x2barGeckJeEUlKN6xFxZB4ShtzFJtvX1uzaX6rXwaklSmcGxZiPchE2mMF8Y62kvlXU XhRQ== X-Gm-Message-State: ALQs6tAsqW+cL3g0giqQs3JtcrNqIqsG9Ev5pPEnOyHDrNfn4kOLokkE Np7e2WwbNgzr5SHWT3ewfqfwQA== X-Received: by 2002:a63:77c9:: with SMTP id s192-v6mr9174530pgc.51.1525072954750; Mon, 30 Apr 2018 00:22:34 -0700 (PDT) Received: from app09.andestech.com ([118.163.51.199]) by smtp.gmail.com with ESMTPSA id i2-v6sm12243108pgo.57.2018.04.30.00.22.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Apr 2018 00:22:34 -0700 (PDT) From: Greentime Hu X-Google-Original-From: Greentime Hu To: linux-kernel@vger.kernel.org, arnd@arndb.de, greentime@andestech.com, green.hu@gmail.com Subject: [PATCH 3/3] nds32: To fix a cache inconsistency issue by setting correct cacheability of NTC Date: Mon, 30 Apr 2018 15:20:41 +0800 Message-Id: <3638122ebb22882a5967cb1cbc62354a2ec4cc90.1525072601.git.greentime@andestech.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The nds32 architecture will use physical memory when interrupt or exception comes and it will use the setting of NTC0-4. The original implementation didn't consider the DRAM start address may start from 1GB, 2GB or 3GB to cause this issue. It will write the data to DRAM if it is running in physical address however kernel will read the data with virtaul address through data cache. In this case, the data of DRAM is latest. This fix will set the correct cacheability to let kernel write/read the latest data in cache instead of DRAM. Signed-off-by: Greentime Hu --- arch/nds32/include/asm/bitfield.h | 1 + arch/nds32/kernel/head.S | 28 +++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/arch/nds32/include/asm/bitfield.h b/arch/nds32/include/asm/bitfield.h index 28b7d797fd59..8e84fc385b94 100644 --- a/arch/nds32/include/asm/bitfield.h +++ b/arch/nds32/include/asm/bitfield.h @@ -396,6 +396,7 @@ #define MMU_CTL_D8KB 1 #define MMU_CTL_UNA ( 0x1 << MMU_CTL_offUNA ) +#define MMU_CTL_CACHEABLE_NON 0 #define MMU_CTL_CACHEABLE_WB 2 #define MMU_CTL_CACHEABLE_WT 3 diff --git a/arch/nds32/kernel/head.S b/arch/nds32/kernel/head.S index 71f57bd70f3b..c5fdae174ced 100644 --- a/arch/nds32/kernel/head.S +++ b/arch/nds32/kernel/head.S @@ -57,14 +57,32 @@ _nodtb: isb mtsr $r4, $L1_PPTB ! load page table pointer\n" -/* set NTC0 cacheable/writeback, mutliple page size in use */ +#ifdef CONFIG_CPU_DCACHE_DISABLE + #define MMU_CTL_NTCC MMU_CTL_CACHEABLE_NON +#else + #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH + #define MMU_CTL_NTCC MMU_CTL_CACHEABLE_WT + #else + #define MMU_CTL_NTCC MMU_CTL_CACHEABLE_WB + #endif +#endif + +/* set NTC cacheability, mutliple page size in use */ mfsr $r3, $MMU_CTL - li $r0, #~MMU_CTL_mskNTC0 - and $r3, $r3, $r0 +#if CONFIG_MEMORY_START >= 0xc0000000 + ori $r3, $r3, (MMU_CTL_NTCC << MMU_CTL_offNTC3) +#elif CONFIG_MEMORY_START >= 0x80000000 + ori $r3, $r3, (MMU_CTL_NTCC << MMU_CTL_offNTC2) +#elif CONFIG_MEMORY_START >= 0x40000000 + ori $r3, $r3, (MMU_CTL_NTCC << MMU_CTL_offNTC1) +#else + ori $r3, $r3, (MMU_CTL_NTCC << MMU_CTL_offNTC0) +#endif + #ifdef CONFIG_ANDES_PAGE_SIZE_4KB - ori $r3, $r3, #(MMU_CTL_mskMPZIU|(MMU_CTL_CACHEABLE_WB << MMU_CTL_offNTC0)) + ori $r3, $r3, #(MMU_CTL_mskMPZIU) #else - ori $r3, $r3, #(MMU_CTL_mskMPZIU|(MMU_CTL_CACHEABLE_WB << MMU_CTL_offNTC0)|MMU_CTL_D8KB) + ori $r3, $r3, #(MMU_CTL_mskMPZIU|MMU_CTL_D8KB) #endif #ifdef CONFIG_HW_SUPPORT_UNALIGNMENT_ACCESS li $r0, #MMU_CTL_UNA -- 1.9.5