Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp4442952imd; Tue, 30 Oct 2018 01:55:11 -0700 (PDT) X-Google-Smtp-Source: AJdET5ex2kd43i5v+xFjsCVTd5mh0ySFUB43M3cmZifC8rB19/F6cpIz6M0s94N6pfL3lAC61d+n X-Received: by 2002:a63:1302:: with SMTP id i2-v6mr17566262pgl.380.1540889710962; Tue, 30 Oct 2018 01:55:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540889710; cv=none; d=google.com; s=arc-20160816; b=mMG5KbagTVr1O6FOBRkcqXLzre7PrzkjFJA+mRvzrEb7x0EjT2BbgFe84FrUZyGhxI /Fnus1I7e/7PyJQ97gC3DeENlTnsdH+0Ri9FjO1t08PsY0AIqGsgisqr2kBVSIhptTpr k3gXfxoq+jVL40nftudi7JX/NiobkMbo6d14IbhaWIjVnZX7LlfvXgetChosC5c3mkl2 ZgYGMGDO1YWKGIrExELgwBkvpp6HEfVqpaMiHl/6/aPJes5c/Qjvb4x5xUF9fr7V1Lt6 7SoanRBcTqe7gswAW6boWWqM5YLnwXkexqUIfPGNU3bY//VpWpvcGiw/IzzDFTuEfCG7 sI0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=Ws4k0+iWvaSxBQZjkoFm85LkUbtapasJJTmJBZgJnNw=; b=T82MOgOHRkKXMTF5aQZjdzOa1XnjORFVoWkW9Bq0G3TNI3C0K4r7KncC2v63BMOVbx V6ywuJOWwQovOb44lWanH0Z16oZODazqfbywL+v+/86qN2GhCZXl9TR770jlPMix+tLg nD2+UwgiUnauuQEg/jcl2s+ZT2offBXtAjQqHZB2hPYDm10ynytLCxSBH0HM2Slj6dMn Ebxh3vBpDrRyIqLD7Nkv0DqOMzeX5XINO00LEshrbxpbR5kRG7J63TlyQHJgIb0Bg4eX 2gBNVLk7Q9GE4ZZtvZUoiK+60mwijj7SgpRu9GTlZ5mYSxSnbk1HZ3QnvdOUdsX6HaoF dHUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=Xh+qt6Hy; 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=NONE dis=NONE) header.from=synopsys.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s1-v6si21569609plr.141.2018.10.30.01.54.55; Tue, 30 Oct 2018 01:55:10 -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=@synopsys.com header.s=mail header.b=Xh+qt6Hy; 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=NONE dis=NONE) header.from=synopsys.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726686AbeJ3Rq6 (ORCPT + 99 others); Tue, 30 Oct 2018 13:46:58 -0400 Received: from us01smtprelay-2.synopsys.com ([198.182.47.9]:47260 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726189AbeJ3Rq6 (ORCPT ); Tue, 30 Oct 2018 13:46:58 -0400 Received: from mailhost.synopsys.com (mailhost1.synopsys.com [10.12.238.239]) by smtprelay.synopsys.com (Postfix) with ESMTP id DB0B424E13CB; Tue, 30 Oct 2018 01:54:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1540889665; bh=HAuedeMPUolDy6DroXVPsVEUrGok5dzG1jRl67dLYRg=; h=From:To:Cc:Subject:Date:From; b=Xh+qt6HyL/NZvmkOYcfI3sHwEC3ghY0w4ahDS6VpcuXeVSUPNlqaqqZAaEPKHpYk5 D4eRXTS8EANmMV8/ws2oGe3Mf4Xe+ZlDnjVw/8dodM79sUxBrkFjEQNivmAumrhCzW qFSib1yL3A8XG4vyxPWqzXRa8R2KrYjDkM8JxrwCcIkMpUiLwJQ66mwTLMr9aNfgwX e87OjcFJNdtCOeocCZub77/IpaHs7NxnA+9nA7BAx1PDTuTxFgo4dYHh393BsVccjX mdU6G4xUI7KllRmt1rzwn0Qcw7y2DJ8Rv3c/1w0e4StdeCDNF+DIj6NhohHMTUdY9P VKxGECvWIu1Bw== Received: from paltsev-e7480.internal.synopsys.com (paltsev-e7480.internal.synopsys.com [10.121.3.38]) by mailhost.synopsys.com (Postfix) with ESMTP id 4E8C25DF3; Tue, 30 Oct 2018 01:54:24 -0700 (PDT) From: Eugeniy Paltsev To: linux-snps-arc@lists.infradead.org, Vineet Gupta Cc: linux-kernel@vger.kernel.org, Alexey Brodkin , Eugeniy Paltsev Subject: [PATCH v2] ARC: IOC: panic if kernel was started with previously enabled IOC Date: Tue, 30 Oct 2018 11:54:21 +0300 Message-Id: <20181030085421.7657-1-Eugeniy.Paltsev@synopsys.com> X-Mailer: git-send-email 2.14.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If IOC was already enabled (due to bootloader) it technically needs to be reconfigured with aperture base,size corresponding to Linux memory map which will certainly be different than uboot's. But disabling and reenabling IOC when DMA might be potentially active is tricky business. To avoid random memory issues later, just panic here and ask user to upgrade bootloader to one which doesn't enable IOC. This was actually seen as issue on some of the HSDK board with a version of uboot which enabled IOC. There were random issues later with starting of X or peripherals etc. Also while I'm at it, replace hardcoded bits in ARC_REG_IO_COH_PARTIAL and ARC_REG_IO_COH_ENABLE registers by definitions. Inspired by: https://lkml.org/lkml/2018/1/19/557 Signed-off-by: Eugeniy Paltsev --- Changes v1->v2: * Fix regression: check for IOC existence before accessing to any IOC register. arch/arc/include/asm/cache.h | 2 ++ arch/arc/mm/cache.c | 25 ++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/arch/arc/include/asm/cache.h b/arch/arc/include/asm/cache.h index ff7d3232764a..f393b663413e 100644 --- a/arch/arc/include/asm/cache.h +++ b/arch/arc/include/asm/cache.h @@ -113,7 +113,9 @@ extern unsigned long perip_base, perip_end; /* IO coherency related Auxiliary registers */ #define ARC_REG_IO_COH_ENABLE 0x500 +#define ARC_IO_COH_ENABLE_BIT BIT(0) #define ARC_REG_IO_COH_PARTIAL 0x501 +#define ARC_IO_COH_PARTIAL_BIT BIT(0) #define ARC_REG_IO_COH_AP0_BASE 0x508 #define ARC_REG_IO_COH_AP0_SIZE 0x509 diff --git a/arch/arc/mm/cache.c b/arch/arc/mm/cache.c index f2701c13a66b..1b913c90676a 100644 --- a/arch/arc/mm/cache.c +++ b/arch/arc/mm/cache.c @@ -1144,6 +1144,25 @@ noinline void __init arc_ioc_setup(void) { unsigned int ioc_base, mem_sz; + /* + * Disabling and reconfiguring of IOC are quite a tricky actions because + * nobody knows what happens if there're IOC-ahndled tarnsactions in + * flight when we're disabling IOC. + * + * And the problem is external DMA masters [that were initialized and + * set in a bootlaoder that was executed before we got here] might + * continue to send data to memory even at this point and we have + * no way to prevent that. + * + * That said it's much safer to not enable IOC at all anywhere before + * Linux kernel. + */ + if (read_aux_reg(ARC_REG_IO_COH_ENABLE) & ARC_IO_COH_ENABLE_BIT) + panic("kernel was started with previously enabled IOC!\n"); + + if (!ioc_enable) + return; + /* * As for today we don't support both IOC and ZONE_HIGHMEM enabled * simultaneously. This happens because as of today IOC aperture covers @@ -1187,8 +1206,8 @@ noinline void __init arc_ioc_setup(void) panic("IOC Aperture start must be aligned to the size of the aperture"); write_aux_reg(ARC_REG_IO_COH_AP0_BASE, ioc_base >> 12); - write_aux_reg(ARC_REG_IO_COH_PARTIAL, 1); - write_aux_reg(ARC_REG_IO_COH_ENABLE, 1); + write_aux_reg(ARC_REG_IO_COH_PARTIAL, ARC_IO_COH_PARTIAL_BIT); + write_aux_reg(ARC_REG_IO_COH_ENABLE, ARC_IO_COH_ENABLE_BIT); /* Re-enable L1 dcache */ __dc_enable(); @@ -1265,7 +1284,7 @@ void __init arc_cache_init_master(void) if (is_isa_arcv2() && l2_line_sz && !slc_enable) arc_slc_disable(); - if (is_isa_arcv2() && ioc_enable) + if (is_isa_arcv2() && ioc_exists) arc_ioc_setup(); if (is_isa_arcv2() && l2_line_sz && slc_enable) { -- 2.14.5