Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp343954pxb; Thu, 27 Jan 2022 23:50:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJz/zjbhKq4st/s5whsOwywScy/fzRFbpEVbIRkP+GIqPRSYR9G8Tv7mEEea2uvveY7c0guC X-Received: by 2002:a17:903:230e:: with SMTP id d14mr7233561plh.4.1643356233544; Thu, 27 Jan 2022 23:50:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643356233; cv=none; d=google.com; s=arc-20160816; b=BwWd8A7uJ7h2MB8QN6mqo07JqoFt725DX8cXpyAVV+18d3C99U5V5b925u/xBqiSoQ 962ba+0LlarN24tJSbVQLCR4VhECAHkgV0M2mLRRQ9Bzb10yR3QytI06K8X9OFEyy7HI Qpl9gaznq/hHCVPUB6G2h3eYaNbvdtmH30h+NRC1W2THiik7GRA1FMlWqNXWGx2d0PvF EdA3bYkMzqY3Sq0y9mfw9sSjwqZYY6VVpUOmtGUg09l2+gqSqh0SYK2/d610vBf/VTBT tK5huchnwX/0XRG0RJ8QwJ36axTdS6Tzanxky6NrzxEliliLId5d0wZox6P2oAHWfMb1 XnFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=gJZZLOxnD8kmokAB8VPKkSjw/jaMZwsPa/qIRliw3IE=; b=iARjN4aF1SF81954QSMllq9Yxk766zvQ8d0mtzWiMIQsg90SaI1brbRnpB4SA2LnPI WC4IZDlZjtKIxgwaaEjJImJXCCQgaT916xMTdCnO2SEeOzBhxc8c7/ezt1/sV+UVSDs5 thjEpsw1H4D5YudUWsDruCUJEmJCOU4xtXyAdCnukveys2pemUcQizrQyCc7WO3cGQnm 1JOq2X4eOXJzEGhhVovE2hgl5/APrebUN6KFm/7v9fkMS/kya4o+NcWKT0p+JODzqC5Y FmcY3ojkTv65ZI+g/EnRMSFoEUj09kqgpaojkvINLyZDSUurXaQN496H5KWhJjYivPvY oj6Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x24si3972626pln.422.2022.01.27.23.50.21; Thu, 27 Jan 2022 23:50:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243181AbiA0PRc (ORCPT + 99 others); Thu, 27 Jan 2022 10:17:32 -0500 Received: from out28-197.mail.aliyun.com ([115.124.28.197]:40751 "EHLO out28-197.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242976AbiA0PRR (ORCPT ); Thu, 27 Jan 2022 10:17:17 -0500 X-Alimail-AntiSpam: AC=CONTINUE;BC=0.08545136|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_regular_dialog|0.0149326-0.000578924-0.984489;FP=0|0|0|0|0|-1|-1|-1;HT=ay29a033018047213;MF=icenowy@nucleisys.com;NM=1;PH=DS;RN=10;RT=10;SR=0;TI=SMTPD_---.Mj85P.l_1643296632; Received: from ice-e5v2.lan(mailfrom:icenowy@nucleisys.com fp:SMTPD_---.Mj85P.l_1643296632) by smtp.aliyun-inc.com(33.45.46.134); Thu, 27 Jan 2022 23:17:14 +0800 From: Icenowy Zheng To: Rob Herring , Palmer Dabbelt , Paul Walmsley , Albert Ou Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-riscv@lists.infradead.org, linux-serial@vger.kernel.org, linux-spi@vger.kernel.org, Icenowy Zheng Subject: [PATCH 10/12] RISC-V: workaround Nuclei UX600 cores with broken SATP CSR Date: Thu, 27 Jan 2022 23:16:45 +0800 Message-Id: <20220127151647.2375449-11-icenowy@nucleisys.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220127151647.2375449-1-icenowy@nucleisys.com> References: <20220127151647.2375449-1-icenowy@nucleisys.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Current release of Nuclei UX600 CPU cores have two errata against RISC-V Privledged Specification 1.10: one is left over mvendorid value (not the JEDEC ID), the other, which is a more breaking one that needs to be workaround in software, is that satp will accept written value with MODE=9 (Sv48, which is not supported by UX600), and silently change it to MODE=8 (Sv39). As current kernel MMU initialization code relies on the behavior defined on the spec (reject write request with unsupported MODE value and do not change the CSR's value at all) to detect the existence of Sv48, the erratum breaks the Sv48 detection code. As both two errata are to be fixed in the next revision, use the first to detect the existence of the second at runtime, and force Sv39 when these errata are detected. Signed-off-by: Icenowy Zheng --- arch/riscv/include/asm/vendorid_list.h | 1 + arch/riscv/mm/init.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/arch/riscv/include/asm/vendorid_list.h b/arch/riscv/include/asm/vendorid_list.h index 9d934215b3c8..47ff43795d70 100644 --- a/arch/riscv/include/asm/vendorid_list.h +++ b/arch/riscv/include/asm/vendorid_list.h @@ -6,5 +6,6 @@ #define ASM_VENDOR_LIST_H #define SIFIVE_VENDOR_ID 0x489 +#define NUCLEI_OLD_VENDOR_ID 0x2d33 #endif diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index cf4d018b7d66..0085b14ae265 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include "../kernel/head.h" @@ -591,6 +593,21 @@ static __init void set_satp_mode(void) u64 identity_satp, hw_satp; uintptr_t set_satp_mode_pmd; + if (sbi_get_mvendorid() == NUCLEI_OLD_VENDOR_ID) { + /* + * Old Nuclei UX600 processor releases have broken + * implementation of SATP register which prevents + * proper runtime detection of Sv48 existence. In + * addition these processor releases have an old + * vendor id instead of proper JEDEC ID. + * + * As these releases do not support Sv48 at all, + * force Sv39 on them. + */ + disable_pgtable_l4(); + return; + } + set_satp_mode_pmd = ((unsigned long)set_satp_mode) & PMD_MASK; create_pgd_mapping(early_pg_dir, set_satp_mode_pmd, (uintptr_t)early_pud, -- 2.30.2