From patchwork Mon Mar 16 00:47:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 11439531 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 93856921 for ; Mon, 16 Mar 2020 00:47:57 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6F753206EB for ; Mon, 16 Mar 2020 00:47:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="FxP7/y3B"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="NMgkpm/q" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6F753206EB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date :Subject:To:From:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7KRLaV+kEXAF7q84utBoscmmSTWg1ujnTF8iXEruO54=; b=FxP7/y3BuElLaL a3EolfLBKMQbbEEguaWKZyk15aPUkfQWe5BgirDCOhHfda8gt9K4hoFPPopc2566w0FsQR2oLQjIO 38voPata4C5nfS/4157P/3hjLMzl4cRFDrGDf3xaits4RM2P3duy+GB7LryXkhANIjqDBJJzLH/fA 34XDtbZspXpETw/Ff3a1dKCFsZNPqH2xroRXN+Jf7zryDmES4nIdCBIllsHu8yPE6yzL9awSWNwYM rjIXypO+o4kRAp6P+fhHe4nmxpw6FyQdfrJJuQSoNAHROLuTezCsXTE2RKdCTHzpsmr+CsDldmzk2 xyDmvh7AzFwRKAhcRbsA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDdv7-0004wM-JG; Mon, 16 Mar 2020 00:47:53 +0000 Received: from esa5.hgst.iphmx.com ([216.71.153.144]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDdv3-0004tB-1b for linux-riscv@lists.infradead.org; Mon, 16 Mar 2020 00:47:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1584319670; x=1615855670; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eQGWzssuGAaGkCaQ3HlUkUUeR/+37HJuTPi3Da/PRzU=; b=NMgkpm/q0FGfHG4Nd4IrCF36MJ9S95+oXKNyJoPMYbrgIy0KBgwgH34b 9t9mJO+qxfXTYRzGgPaLvugap+y2UydWV0VDHxWPZerG/b5uB8Wt4bdYh uWxXESvhvIreG7mB35NeD+vYy3Wb+TA5m3KhAGJrZev52pMdjQDOFqrji cQJaqZ4crFfopupksYXD2eIc0lIpZhtUkgqY8HiytEsGzWCfwI/yG3Pii FVKpEEn0ABmbN63Blyt4gQoSUT6Eq8SzT+a4qV7ASxl/2u4Wv8zZlpNg8 F1LS/W+CaXgCUBhwcu1+5tKDXw/Pani6bWHl25XkgfLDWiRvERmE4KLGY Q==; IronPort-SDR: qTdQqcijN1zVI+i83nVQoY7TTa581o2QPmnsMgvz09yaT0MFqwok25n7C/gWLdljiF9NrqscNy wxuhVbsKawpNeLnqlBQ1cBsCQ5aXW7Xgvi2qVZ9qwe0ssI9jIXk9DbAv/fCRAZ3agI6yT7pN9T j2mzpadGn4DAukNRwbjmzxYjQTtDa4yDtsXDf/17tqqRIKl+mI+4QJC48WyIGBQYXc9i0iogJr ASj+ViM2yZsaI8iT3v0kXLTURBTIjrf1kc03gnytBlGxND4w6GYa1owS7wg7vm8mpcN3L1MWvZ erA= X-IronPort-AV: E=Sophos;i="5.70,558,1574092800"; d="scan'208";a="133011921" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 16 Mar 2020 08:47:48 +0800 IronPort-SDR: uvlLbEndi5ZtcjVt1cG6ex5IZZYhVv6hCMbWVx/qwVPW7PGeMbUBPenOpiSXSdRWUEj6k2qc/v ggj85vvM1fnRKtJO9D4m+2CBiJc+1zOUoEmPd8uydjE3uVPJU/Vx/TCPq/vqkv67/PoIg2CVZJ NTPh3i7ZXJkSeSBjd97KfR+uih45fFQ/uTQ9ccoER17JscOY5se1BhI6tVgV41+4351DLXDKaW ermeoRB2mzs605jKB1b5tLcwSpn0R4CdrkVxyUilof6xe1X3vGrMrLlynGsR7hts2aObZuc+8q o9szOlyOk2YUAiMi2SRhG/AL Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2020 17:39:17 -0700 IronPort-SDR: sytpmjenepGx2cMPW1niwxFNaD2pZgXjQCQCrKhlBQG9jlIRcTwDRhQ0QjGGi6CBXA1PzVB5Ex 33wNXEXQu1N1yv8fOSY3EKOKwhryHNLnVSusWX/lDT2jzFyNzmCDFR9rnHT8da+GXp1tNuJ1fs BoJ//thFOAiUYx2P3oSMn4Fq60EZR+8FHL4tHyxj5H2xyfQsmA3ESpQP07I4hzGHvJO0CFlIH+ OiH9eR9+yoItFdUcu03UI9WG30YD966tTLl098MtX6UFFz9DsPfsbjw4t5anmPq99yEAoJEJrk ims= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 15 Mar 2020 17:47:47 -0700 From: Damien Le Moal To: linux-riscv@lists.infradead.org, Palmer Dabbelt Subject: [PATCH v4 1/9] riscv: Unaligned load/store handling for M_MODE Date: Mon, 16 Mar 2020 09:47:36 +0900 Message-Id: <20200316004744.209292-2-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200316004744.209292-1-damien.lemoal@wdc.com> References: <20200316004744.209292-1-damien.lemoal@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200315_174749_133257_A43DC48D X-CRM114-Status: GOOD ( 15.18 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.153.144 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org Add handlers for unaligned load and store traps that may be generated by applications. Code heavily inspired from the OpenSBI project. Handling of the unaligned access traps is suitable for applications compiled with or without compressed instructions and is independent of the kernel CONFIG_RISCV_ISA_C option value. Signed-off-by: Damien Le Moal Signed-off-by: Anup Patel --- arch/riscv/kernel/Makefile | 2 +- arch/riscv/kernel/traps.c | 27 +- arch/riscv/kernel/traps_misaligned.c | 370 +++++++++++++++++++++++++++ 3 files changed, 395 insertions(+), 4 deletions(-) create mode 100644 arch/riscv/kernel/traps_misaligned.c diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile index f40205cb9a22..97d0c35f8b37 100644 --- a/arch/riscv/kernel/Makefile +++ b/arch/riscv/kernel/Makefile @@ -28,7 +28,7 @@ obj-y += stacktrace.o obj-y += cacheinfo.o obj-$(CONFIG_MMU) += vdso.o vdso/ -obj-$(CONFIG_RISCV_M_MODE) += clint.o +obj-$(CONFIG_RISCV_M_MODE) += clint.o traps_misaligned.o obj-$(CONFIG_FPU) += fpu.o obj-$(CONFIG_SMP) += smpboot.o obj-$(CONFIG_SMP) += smp.o diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c index ffb3d94bf0cc..13e55459d7b0 100644 --- a/arch/riscv/kernel/traps.c +++ b/arch/riscv/kernel/traps.c @@ -97,12 +97,33 @@ DO_ERROR_INFO(do_trap_insn_fault, SIGSEGV, SEGV_ACCERR, "instruction access fault"); DO_ERROR_INFO(do_trap_insn_illegal, SIGILL, ILL_ILLOPC, "illegal instruction"); -DO_ERROR_INFO(do_trap_load_misaligned, - SIGBUS, BUS_ADRALN, "load address misaligned"); DO_ERROR_INFO(do_trap_load_fault, SIGSEGV, SEGV_ACCERR, "load access fault"); +#ifndef CONFIG_RISCV_M_MODE +DO_ERROR_INFO(do_trap_load_misaligned, + SIGBUS, BUS_ADRALN, "Oops - load address misaligned"); DO_ERROR_INFO(do_trap_store_misaligned, - SIGBUS, BUS_ADRALN, "store (or AMO) address misaligned"); + SIGBUS, BUS_ADRALN, "Oops - store (or AMO) address misaligned"); +#else +int handle_misaligned_load(struct pt_regs *regs); +int handle_misaligned_store(struct pt_regs *regs); + +asmlinkage void do_trap_load_misaligned(struct pt_regs *regs) +{ + if (!handle_misaligned_load(regs)) + return; + do_trap_error(regs, SIGBUS, BUS_ADRALN, regs->epc, + "Oops - load address misaligned"); +} + +asmlinkage void do_trap_store_misaligned(struct pt_regs *regs) +{ + if (!handle_misaligned_store(regs)) + return; + do_trap_error(regs, SIGBUS, BUS_ADRALN, regs->epc, + "Oops - store (or AMO) address misaligned"); +} +#endif DO_ERROR_INFO(do_trap_store_fault, SIGSEGV, SEGV_ACCERR, "store (or AMO) access fault"); DO_ERROR_INFO(do_trap_ecall_u, diff --git a/arch/riscv/kernel/traps_misaligned.c b/arch/riscv/kernel/traps_misaligned.c new file mode 100644 index 000000000000..46c4dafe3ba0 --- /dev/null +++ b/arch/riscv/kernel/traps_misaligned.c @@ -0,0 +1,370 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2020 Western Digital Corporation or its affiliates. + */ +#include +#include +#include +#include +#include + +#include +#include +#include + +#define INSN_MATCH_LB 0x3 +#define INSN_MASK_LB 0x707f +#define INSN_MATCH_LH 0x1003 +#define INSN_MASK_LH 0x707f +#define INSN_MATCH_LW 0x2003 +#define INSN_MASK_LW 0x707f +#define INSN_MATCH_LD 0x3003 +#define INSN_MASK_LD 0x707f +#define INSN_MATCH_LBU 0x4003 +#define INSN_MASK_LBU 0x707f +#define INSN_MATCH_LHU 0x5003 +#define INSN_MASK_LHU 0x707f +#define INSN_MATCH_LWU 0x6003 +#define INSN_MASK_LWU 0x707f +#define INSN_MATCH_SB 0x23 +#define INSN_MASK_SB 0x707f +#define INSN_MATCH_SH 0x1023 +#define INSN_MASK_SH 0x707f +#define INSN_MATCH_SW 0x2023 +#define INSN_MASK_SW 0x707f +#define INSN_MATCH_SD 0x3023 +#define INSN_MASK_SD 0x707f + +#define INSN_MATCH_FLW 0x2007 +#define INSN_MASK_FLW 0x707f +#define INSN_MATCH_FLD 0x3007 +#define INSN_MASK_FLD 0x707f +#define INSN_MATCH_FLQ 0x4007 +#define INSN_MASK_FLQ 0x707f +#define INSN_MATCH_FSW 0x2027 +#define INSN_MASK_FSW 0x707f +#define INSN_MATCH_FSD 0x3027 +#define INSN_MASK_FSD 0x707f +#define INSN_MATCH_FSQ 0x4027 +#define INSN_MASK_FSQ 0x707f + +#define INSN_MATCH_C_LD 0x6000 +#define INSN_MASK_C_LD 0xe003 +#define INSN_MATCH_C_SD 0xe000 +#define INSN_MASK_C_SD 0xe003 +#define INSN_MATCH_C_LW 0x4000 +#define INSN_MASK_C_LW 0xe003 +#define INSN_MATCH_C_SW 0xc000 +#define INSN_MASK_C_SW 0xe003 +#define INSN_MATCH_C_LDSP 0x6002 +#define INSN_MASK_C_LDSP 0xe003 +#define INSN_MATCH_C_SDSP 0xe002 +#define INSN_MASK_C_SDSP 0xe003 +#define INSN_MATCH_C_LWSP 0x4002 +#define INSN_MASK_C_LWSP 0xe003 +#define INSN_MATCH_C_SWSP 0xc002 +#define INSN_MASK_C_SWSP 0xe003 + +#define INSN_MATCH_C_FLD 0x2000 +#define INSN_MASK_C_FLD 0xe003 +#define INSN_MATCH_C_FLW 0x6000 +#define INSN_MASK_C_FLW 0xe003 +#define INSN_MATCH_C_FSD 0xa000 +#define INSN_MASK_C_FSD 0xe003 +#define INSN_MATCH_C_FSW 0xe000 +#define INSN_MASK_C_FSW 0xe003 +#define INSN_MATCH_C_FLDSP 0x2002 +#define INSN_MASK_C_FLDSP 0xe003 +#define INSN_MATCH_C_FSDSP 0xa002 +#define INSN_MASK_C_FSDSP 0xe003 +#define INSN_MATCH_C_FLWSP 0x6002 +#define INSN_MASK_C_FLWSP 0xe003 +#define INSN_MATCH_C_FSWSP 0xe002 +#define INSN_MASK_C_FSWSP 0xe003 + +#define INSN_LEN(insn) ((((insn) & 0x3) < 0x3) ? 2 : 4) + +#if defined(CONFIG_64BIT) +#define LOG_REGBYTES 3 +#define XLEN 64 +#else +#define LOG_REGBYTES 2 +#define XLEN 32 +#endif +#define REGBYTES (1 << LOG_REGBYTES) +#define XLEN_MINUS_16 ((XLEN) - 16) + +#define SH_RD 7 +#define SH_RS1 15 +#define SH_RS2 20 +#define SH_RS2C 2 + +#define RV_X(x, s, n) (((x) >> (s)) & ((1 << (n)) - 1)) +#define RVC_LW_IMM(x) ((RV_X(x, 6, 1) << 2) | \ + (RV_X(x, 10, 3) << 3) | \ + (RV_X(x, 5, 1) << 6)) +#define RVC_LD_IMM(x) ((RV_X(x, 10, 3) << 3) | \ + (RV_X(x, 5, 2) << 6)) +#define RVC_LWSP_IMM(x) ((RV_X(x, 4, 3) << 2) | \ + (RV_X(x, 12, 1) << 5) | \ + (RV_X(x, 2, 2) << 6)) +#define RVC_LDSP_IMM(x) ((RV_X(x, 5, 2) << 3) | \ + (RV_X(x, 12, 1) << 5) | \ + (RV_X(x, 2, 3) << 6)) +#define RVC_SWSP_IMM(x) ((RV_X(x, 9, 4) << 2) | \ + (RV_X(x, 7, 2) << 6)) +#define RVC_SDSP_IMM(x) ((RV_X(x, 10, 3) << 3) | \ + (RV_X(x, 7, 3) << 6)) +#define RVC_RS1S(insn) (8 + RV_X(insn, SH_RD, 3)) +#define RVC_RS2S(insn) (8 + RV_X(insn, SH_RS2C, 3)) +#define RVC_RS2(insn) RV_X(insn, SH_RS2C, 5) + +#define SHIFT_RIGHT(x, y) \ + ((y) < 0 ? ((x) << -(y)) : ((x) >> (y))) + +#define REG_MASK \ + ((1 << (5 + LOG_REGBYTES)) - (1 << LOG_REGBYTES)) + +#define REG_OFFSET(insn, pos) \ + (SHIFT_RIGHT((insn), (pos) - LOG_REGBYTES) & REG_MASK) + +#define REG_PTR(insn, pos, regs) \ + (ulong *)((ulong)(regs) + REG_OFFSET(insn, pos)) + +#define GET_RM(insn) (((insn) >> 12) & 7) + +#define GET_RS1(insn, regs) (*REG_PTR(insn, SH_RS1, regs)) +#define GET_RS2(insn, regs) (*REG_PTR(insn, SH_RS2, regs)) +#define GET_RS1S(insn, regs) (*REG_PTR(RVC_RS1S(insn), 0, regs)) +#define GET_RS2S(insn, regs) (*REG_PTR(RVC_RS2S(insn), 0, regs)) +#define GET_RS2C(insn, regs) (*REG_PTR(insn, SH_RS2C, regs)) +#define GET_SP(regs) (*REG_PTR(2, 0, regs)) +#define SET_RD(insn, regs, val) (*REG_PTR(insn, SH_RD, regs) = (val)) +#define IMM_I(insn) ((s32)(insn) >> 20) +#define IMM_S(insn) (((s32)(insn) >> 25 << 5) | \ + (s32)(((insn) >> 7) & 0x1f)) +#define MASK_FUNCT3 0x7000 + +#define GET_PRECISION(insn) (((insn) >> 25) & 3) +#define GET_RM(insn) (((insn) >> 12) & 7) +#define PRECISION_S 0 +#define PRECISION_D 1 + +#define STR(x) XSTR(x) +#define XSTR(x) #x + +#define DECLARE_UNPRIVILEGED_LOAD_FUNCTION(type, insn) \ +static inline type load_##type(const type *addr) \ +{ \ + type val; \ + asm (#insn " %0, %1" \ + : "=&r" (val) : "m" (*addr)); \ + return val; \ +} + +#define DECLARE_UNPRIVILEGED_STORE_FUNCTION(type, insn) \ +static inline void store_##type(type *addr, type val) \ +{ \ + asm volatile (#insn " %0, %1\n" \ + : : "r" (val), "m" (*addr)); \ +} + +DECLARE_UNPRIVILEGED_LOAD_FUNCTION(u8, lbu) +DECLARE_UNPRIVILEGED_LOAD_FUNCTION(u16, lhu) +DECLARE_UNPRIVILEGED_LOAD_FUNCTION(s8, lb) +DECLARE_UNPRIVILEGED_LOAD_FUNCTION(s16, lh) +DECLARE_UNPRIVILEGED_LOAD_FUNCTION(s32, lw) +DECLARE_UNPRIVILEGED_STORE_FUNCTION(u8, sb) +DECLARE_UNPRIVILEGED_STORE_FUNCTION(u16, sh) +DECLARE_UNPRIVILEGED_STORE_FUNCTION(u32, sw) +#if defined(CONFIG_64BIT) +DECLARE_UNPRIVILEGED_LOAD_FUNCTION(u32, lwu) +DECLARE_UNPRIVILEGED_LOAD_FUNCTION(u64, ld) +DECLARE_UNPRIVILEGED_STORE_FUNCTION(u64, sd) +DECLARE_UNPRIVILEGED_LOAD_FUNCTION(ulong, ld) +#else +DECLARE_UNPRIVILEGED_LOAD_FUNCTION(u32, lw) +DECLARE_UNPRIVILEGED_LOAD_FUNCTION(ulong, lw) + +static inline u64 load_u64(const u64 *addr) +{ + return load_u32((u32 *)addr) + + ((u64)load_u32((u32 *)addr + 1) << 32); +} + +static inline void store_u64(u64 *addr, u64 val) +{ + store_u32((u32 *)addr, val); + store_u32((u32 *)addr + 1, val >> 32); +} +#endif + +static inline ulong get_insn(ulong mepc) +{ + register ulong __mepc asm ("a2") = mepc; + ulong val, rvc_mask = 3, tmp; + + asm ("and %[tmp], %[addr], 2\n" + "bnez %[tmp], 1f\n" +#if defined(CONFIG_64BIT) + STR(LWU) " %[insn], (%[addr])\n" +#else + STR(LW) " %[insn], (%[addr])\n" +#endif + "and %[tmp], %[insn], %[rvc_mask]\n" + "beq %[tmp], %[rvc_mask], 2f\n" + "sll %[insn], %[insn], %[xlen_minus_16]\n" + "srl %[insn], %[insn], %[xlen_minus_16]\n" + "j 2f\n" + "1:\n" + "lhu %[insn], (%[addr])\n" + "and %[tmp], %[insn], %[rvc_mask]\n" + "bne %[tmp], %[rvc_mask], 2f\n" + "lhu %[tmp], 2(%[addr])\n" + "sll %[tmp], %[tmp], 16\n" + "add %[insn], %[insn], %[tmp]\n" + "2:" + : [insn] "=&r" (val), [tmp] "=&r" (tmp) + : [addr] "r" (__mepc), [rvc_mask] "r" (rvc_mask), + [xlen_minus_16] "i" (XLEN_MINUS_16)); + + return val; +} + +union reg_data { + u8 data_bytes[8]; + ulong data_ulong; + u64 data_u64; +}; + +int handle_misaligned_load(struct pt_regs *regs) +{ + union reg_data val; + unsigned long epc = regs->epc; + unsigned long insn = get_insn(epc); + unsigned long addr = csr_read(mtval); + int i, fp = 0, shift = 0, len = 0; + + regs->epc = 0; + + if ((insn & INSN_MASK_LW) == INSN_MATCH_LW) { + len = 4; + shift = 8 * (sizeof(unsigned long) - len); +#if defined(CONFIG_64BIT) + } else if ((insn & INSN_MASK_LD) == INSN_MATCH_LD) { + len = 8; + shift = 8 * (sizeof(unsigned long) - len); + } else if ((insn & INSN_MASK_LWU) == INSN_MATCH_LWU) { + len = 4; +#endif + } else if ((insn & INSN_MASK_FLD) == INSN_MATCH_FLD) { + fp = 1; + len = 8; + } else if ((insn & INSN_MASK_FLW) == INSN_MATCH_FLW) { + fp = 1; + len = 4; + } else if ((insn & INSN_MASK_LH) == INSN_MATCH_LH) { + len = 2; + shift = 8 * (sizeof(unsigned long) - len); + } else if ((insn & INSN_MASK_LHU) == INSN_MATCH_LHU) { + len = 2; +#if defined(CONFIG_64BIT) + } else if ((insn & INSN_MASK_C_LD) == INSN_MATCH_C_LD) { + len = 8; + shift = 8 * (sizeof(unsigned long) - len); + insn = RVC_RS2S(insn) << SH_RD; + } else if ((insn & INSN_MASK_C_LDSP) == INSN_MATCH_C_LDSP && + ((insn >> SH_RD) & 0x1f)) { + len = 8; + shift = 8 * (sizeof(unsigned long) - len); +#endif + } else if ((insn & INSN_MASK_C_LW) == INSN_MATCH_C_LW) { + len = 4; + shift = 8 * (sizeof(unsigned long) - len); + insn = RVC_RS2S(insn) << SH_RD; + } else if ((insn & INSN_MASK_C_LWSP) == INSN_MATCH_C_LWSP && + ((insn >> SH_RD) & 0x1f)) { + len = 4; + shift = 8 * (sizeof(unsigned long) - len); + } else if ((insn & INSN_MASK_C_FLD) == INSN_MATCH_C_FLD) { + fp = 1; + len = 8; + insn = RVC_RS2S(insn) << SH_RD; + } else if ((insn & INSN_MASK_C_FLDSP) == INSN_MATCH_C_FLDSP) { + fp = 1; + len = 8; +#if defined(CONFIG_32BIT) + } else if ((insn & INSN_MASK_C_FLW) == INSN_MATCH_C_FLW) { + fp = 1; + len = 4; + insn = RVC_RS2S(insn) << SH_RD; + } else if ((insn & INSN_MASK_C_FLWSP) == INSN_MATCH_C_FLWSP) { + fp = 1; + len = 4; +#endif + } else { + regs->epc = epc; + return -1; + } + + val.data_u64 = 0; + for (i = 0; i < len; i++) + val.data_bytes[i] = load_u8((void *)(addr + i)); + + if (fp) + return -1; + SET_RD(insn, regs, val.data_ulong << shift >> shift); + + regs->epc = epc + INSN_LEN(insn); + + return 0; +} + +int handle_misaligned_store(struct pt_regs *regs) +{ + union reg_data val; + unsigned long epc = regs->epc; + unsigned long insn = get_insn(epc); + unsigned long addr = csr_read(mtval); + int i, len = 0; + + regs->epc = 0; + + val.data_ulong = GET_RS2(insn, regs); + + if ((insn & INSN_MASK_SW) == INSN_MATCH_SW) { + len = 4; +#if defined(CONFIG_64BIT) + } else if ((insn & INSN_MASK_SD) == INSN_MATCH_SD) { + len = 8; +#endif + } else if ((insn & INSN_MASK_SH) == INSN_MATCH_SH) { + len = 2; +#if defined(CONFIG_64BIT) + } else if ((insn & INSN_MASK_C_SD) == INSN_MATCH_C_SD) { + len = 8; + val.data_ulong = GET_RS2S(insn, regs); + } else if ((insn & INSN_MASK_C_SDSP) == INSN_MATCH_C_SDSP && + ((insn >> SH_RD) & 0x1f)) { + len = 8; + val.data_ulong = GET_RS2C(insn, regs); +#endif + } else if ((insn & INSN_MASK_C_SW) == INSN_MATCH_C_SW) { + len = 4; + val.data_ulong = GET_RS2S(insn, regs); + } else if ((insn & INSN_MASK_C_SWSP) == INSN_MATCH_C_SWSP && + ((insn >> SH_RD) & 0x1f)) { + len = 4; + val.data_ulong = GET_RS2C(insn, regs); + } else { + regs->epc = epc; + return -1; + } + + for (i = 0; i < len; i++) + store_u8((void *)(addr + i), val.data_bytes[i]); + + regs->epc = epc + INSN_LEN(insn); + + return 0; +} From patchwork Mon Mar 16 00:47:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 11439533 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DC2CD1667 for ; Mon, 16 Mar 2020 00:48:00 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B9684206BE for ; Mon, 16 Mar 2020 00:48:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="URmdRSlJ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="YgL9B16+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B9684206BE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date :Subject:To:From:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xRy9gX4F7+XvT3xhmTyWyVqkZrULunQaWVKFPuhmMLk=; b=URmdRSlJ3JqHj3 8rYdjpIDHPKeLdgHROqJfq8mdpkuEt1C/Ebr+XpBiiCdot1+AnjKaZfDbBxOCd6TZ1yN03E+wuTp8 sLewTrvbfp+BXK9aOsdm5Q2Y1T0FW7u6l4gqVDqxU11D2j8rruaIK1Hyn+BDvmh3mfhK+V4OWSYcG ekCwZnzLhJDm2SLAo+GYqVcQ9MH/rSp7/FYMehp+kH6n2JRQNDbo30fjfnDBJyoy/QvJhV6jJQWkm ra0ZmwOsK9s8OIiynFyR1AV7QgDEx3BDA8dXK4VLe5ETnXfHhawDdBBJHi/+gGzxFGA/41ItE12Qv q6zcmMr7d4NsH/HAkTKA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDdvA-00050K-Pv; Mon, 16 Mar 2020 00:47:56 +0000 Received: from esa5.hgst.iphmx.com ([216.71.153.144]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDdv4-0004td-As for linux-riscv@lists.infradead.org; Mon, 16 Mar 2020 00:47:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1584319671; x=1615855671; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=g3BptAvMawkXrlgFrkdxrlK/typLe6cL/5thNaNwAuM=; b=YgL9B16+ZMZjcw5bnc54mZzquKAEwlq4D45ybnoTcyNJ4KH9h+f4vYWA X4K6+GaVe8Yc8wUpz3D/BUOXJQ9Eq0cYbTt9xvf+xmqbqPZW5UPjxlbio rIcisr6eAeMseYcJo5lfKYBC3c/Fv3iSGdeDNZTSGVVriGuvv09MVHcRa z0Hw9j4nl815v/x5eGbm9Vxjl/c3V5pBi/V7VDN2yVPryzstvAgxTU0s/ IfKfCBcImdY63D4uPVF09ejSL0vpsnp/oWZHj29dnilaEhGjjXXRG20Fu CRZsa7rsc3zordQ/PiBltCB/qKGjlkEH7/b7zwSJMK3YrSkrRlRpy8Ucs w==; IronPort-SDR: f0F/XXdeFAbxZUHAXx9dyyeM0YNbsV3htC2MngvmjeFlnpMh3MOV3v1YR3sBg045ARRNJvfXqx WIke4UltYzaH5iY0Jdu+KwWNREb5vKYS4Q0bUpIZXBG4qmGOy/ea1uKdf9mZfcYlPn8efXxZYR 0rZBtvTFgcgl77By4TvOzy2VNQ/XjWhi9jsrQAK13xv2tU7BCAwSGfAGWzShax3WsZqUjqjIUS fDV/ayRknrpUo2L/Hq8zWdXRx/vJU2vLTpgwsuEjo2V1WUCS4hpop2Ukdnz1xWp7ZkMBnZCZ4K B5Y= X-IronPort-AV: E=Sophos;i="5.70,558,1574092800"; d="scan'208";a="133011922" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 16 Mar 2020 08:47:49 +0800 IronPort-SDR: rzzyr7pxx7TfPGuWGW01+KfaYKXU7vKjPV9m3ajHMfdFIUfufy1jaqatRvBIepC5+rNEOzvxgt +q+11mplprT4IodVPVq7TA6kEVhWQHSUMUFN8iWOB7mBYFaIBnLp7oKc3h+Si+Y80z6fwZEfhR KDvU88XMYXX04vZhbWOHbSH9bwy8+T8p0uWR6I8cv8vS4jfMP087vFBYC3of7ZK/FHDkStDuxk TCS2eKGDo6/AcQPjyJO1wHXWY+3M6Dn68SOeAyJuS+XgIPb6V3ikNJBnUpH5tbmLheYu2pwoT8 I063w3KsoKyFJAt8TB/f7h6N Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2020 17:39:18 -0700 IronPort-SDR: QcL7zErSlaugp2LflQntCQkCD5BEmRU/cqZE6wG4V05s0OVl8EzQj7ddwGbJaQKV4PmjbOzpsN 98BD4FSycyeVWNCGECqQJY0dTXRgOZvMJHlMv/OZuubuqVWjNA5ICLMTj9HsOR8pxHvnG0JtzI AE42qNPqcrL2hahhabAwA1XGh+ggpKqOwHSKwzgdRi3/v2EgyLTqj3sQxcwsofl9ikGbY2DfsB WxlVO5LQM3g6akhwwYlL7ehyRT+bbOAq2gj1+3pWxFcK14g4nlr1LuDvshKYPwicTwlK8B59Xd xrI= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 15 Mar 2020 17:47:47 -0700 From: Damien Le Moal To: linux-riscv@lists.infradead.org, Palmer Dabbelt Subject: [PATCH v4 2/9] riscv: Add BUILTIN_DTB support Date: Mon, 16 Mar 2020 09:47:37 +0900 Message-Id: <20200316004744.209292-3-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200316004744.209292-1-damien.lemoal@wdc.com> References: <20200316004744.209292-1-damien.lemoal@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200315_174750_384977_16C394ED X-CRM114-Status: GOOD ( 10.20 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.153.144 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org For the NOMMU case, enable a kernel builtin dtb to allow direct kernel loading without a bootloader. This option also allows booting on boards not capable of providing a device tree to the bootloader. Signed-off-by: Damien Le Moal Reviewed-by: Atish Patra --- arch/riscv/Kbuild | 1 + arch/riscv/Kconfig | 19 +++++++++++++++++++ arch/riscv/boot/dts/Makefile | 4 ++++ arch/riscv/kernel/setup.c | 6 ++++++ arch/riscv/mm/init.c | 4 ++++ 5 files changed, 34 insertions(+) diff --git a/arch/riscv/Kbuild b/arch/riscv/Kbuild index d1d0aa70fdf1..988804e430e4 100644 --- a/arch/riscv/Kbuild +++ b/arch/riscv/Kbuild @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-y += kernel/ mm/ net/ +obj-$(CONFIG_USE_BUILTIN_DTB) += boot/dts/ diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 1a3b5a5276be..025f5ba1dd68 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -355,6 +355,25 @@ config CMDLINE_FORCE endchoice +config USE_BUILTIN_DTB + bool "Use builtin DTB" + depends on !MMU + help + Link a device tree blob for particular hardware into the kernel, + suppressing use of the DTB pointer provided by the bootloader. + This option should only be used with hardware or bootloaders that + are not capable of providing a DTB to the kernel, or for + experimental hardware without stable device tree bindings. + +config BUILTIN_DTB_SOURCE + string "Source file for builtin DTB" + default "" + depends on USE_BUILTIN_DTB + help + Base name (without suffix, relative to arch/riscv/boot/dts) for + the a DTS file that will be used to produce the DTB linked into + the kernel. + endmenu menu "Power management options" diff --git a/arch/riscv/boot/dts/Makefile b/arch/riscv/boot/dts/Makefile index dcc3ada78455..0bf2669aa12d 100644 --- a/arch/riscv/boot/dts/Makefile +++ b/arch/riscv/boot/dts/Makefile @@ -1,2 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 +ifneq ($(CONFIG_BUILTIN_DTB_SOURCE),"") +obj-$(CONFIG_USE_BUILTIN_DTB) += $(patsubst "%",%,$(CONFIG_BUILTIN_DTB_SOURCE)).dtb.o +else subdir-y += sifive +endif diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index 0a6d415b0a5a..3e89be9d888c 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -68,7 +68,13 @@ void __init setup_arch(char **cmdline_p) setup_bootmem(); paging_init(); + +#if IS_ENABLED(CONFIG_USE_BUILTIN_DTB) + unflatten_and_copy_device_tree(); +#else unflatten_device_tree(); +#endif + clint_init_boot_cpu(); #ifdef CONFIG_SWIOTLB diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index fab855963c73..51f1ee0a24a6 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -480,7 +480,11 @@ static void __init setup_vm_final(void) #else asmlinkage void __init setup_vm(uintptr_t dtb_pa) { +#if IS_ENABLED(CONFIG_USE_BUILTIN_DTB) + dtb_early_va = __dtb_start; +#else dtb_early_va = (void *)dtb_pa; +#endif } static inline void setup_vm_final(void) From patchwork Mon Mar 16 00:47:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 11439539 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CAB6A921 for ; Mon, 16 Mar 2020 00:48:10 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A7B61205C9 for ; Mon, 16 Mar 2020 00:48:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Z5j01HYv"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="UCFD0lYn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A7B61205C9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date :Subject:To:From:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1AezZ3pP55Joc945ERCB/TKvW7CDwpk+RTJ+XbnCTtA=; b=Z5j01HYvLMKlOl qfHHtpYOxk1XsMAIdxmekzIBGF0eGEsQ5QbbV4Tid4iQgRiCWhG60g0fYW+VNhM09FtJZde13dqIk ICv3euyfDsvw2Z910djuuAPLf3fGIFib7VFR2lMvix2JR0uYYTm0N79PLb90yS48pw6AGQglDXPTc K7TYdAy5clg7YB6WOCFo/zdfp0VuDJ/MYLsNhUL11rpiX0qnWFX6MMdKxkfz/TGBy6mvLtj4wmc5u vdUhBmppEXdyEfATDRqsR6U4GDcIvLtRGoUjEkUr0bSlFnO0+jOLxhm1hukf3MhONhC+f9QcWM/Fd mvi2EtVFGlN24Wpod7Dg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDdvK-0005Bz-Lo; Mon, 16 Mar 2020 00:48:06 +0000 Received: from esa5.hgst.iphmx.com ([216.71.153.144]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDdv5-0004tA-06 for linux-riscv@lists.infradead.org; Mon, 16 Mar 2020 00:47:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1584319672; x=1615855672; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PYhEVpmbjCnBVgw9L4xp6JuupFXA1P8lyt0WquX0Y0w=; b=UCFD0lYnW4Ez1ESPjCmfw06yBFfeXRqlH5K2yCLoePgC5TdGxxBioVeg CGuy+Ewh8zbljyZ5qWASa/cZEHyrF0VzOjZSGrhgXLPADDv3dqgcEHZoo TgHQ5naZXUpkFqqaMnWTJAs7T3UetGFc/zyx0pP9qDD2G4DXaHD9IU79B mDxsGS5tDv24Ac3mIkN6OEU7RpJOt+Fal4V5Bzgs+KXeDhLbHmCgphetD jxMh+KyfRF1GoEl9w6IXYS7xJyoD2PGpq85kcTXWdaKKSS+q8Qv/uOz/t 5EQMKzouYIcIXihSWpDtYpFms5+/FTIAZEdCBKQFi0YOEHy4Z1tpp3JnE g==; IronPort-SDR: nPpLgBbyLiFxNQe740F09Gg6BsxDvkCK5phsn5qoA9OehvvWXbU+EF95iGi5HahOseoUMMSnGb YE+zwS+L4K8WW5u7APKb3aTywZI8zgQ9fw4LeHmaDXB0uC5856qn6cZGsCI7oaJXkzro/a2KmR DLVZ+W+RIxRGP3vi40nhWTSkS12y7/buQGvBQvKzkKA5dP+Ekxc7KL1WGiiPfyaic4sBoxUniJ EbJ3kMGwL1zsBCtP/GdKAaHLHoCtpIyLxhuO5xcvQkGTYdMKqTly9IATUaMP+N1UWYCe68vd8H 7Io= X-IronPort-AV: E=Sophos;i="5.70,558,1574092800"; d="scan'208";a="133011923" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 16 Mar 2020 08:47:49 +0800 IronPort-SDR: t/LV1OSTa+YpUin4V7rfYhzQjWOR4itOB/EBPwRTuV1+sXnLCCzA099Rb1Ezjb3Orf+f+HoXHv 1cf1BNkHbpYqldqWjgj1Q+wBVBC1w1zzzmdIE9GmDQrCeVQQsQnuKMg3TC4xdkiLqEZt5TXdiq LuXjYizzP9tAFW9ffwuNrqfWQkFwMY3qQr6f+tRl6zjn9vGdkw3oTXLH//QwqloVn/XG1FkAFI 7xsuQflfWIZAdvbikBHsOYcWfEgcFWDlWtIrV9JbV0nmf6YSR7Pj57t5HNY6/Fk9+DEP/euaqX b93O7w4sRb2MyHEF5mW6KYFN Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2020 17:39:19 -0700 IronPort-SDR: l2TLJudhnDS2Y5q2wYwobtc1hRM38AzpAABAbsa0OCU7KOLYj5xTxJDpPvTDDEGErG74GCwsMg PBv9dpfJqtW5GNJ3kDHtHCNVyjQETHW4PvTtLBIbKADwJX0Zjwi5Yn974VcHPVC6gGG7CiTrMX UlHjQeDUqRGKDU0tgx+j2i5MySWHRgRjPCuxKbB7Pfb63L7ptBc8KQIqt//Evi+St07WXdVAOu 2nHFj+ZoT9gzyRi2xhmcL8IRoGgbEtB4TFSHey8sXhqICbtrK/LM0HITZQRvtNcNM9EzZ8PLRq Qfk= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 15 Mar 2020 17:47:48 -0700 From: Damien Le Moal To: linux-riscv@lists.infradead.org, Palmer Dabbelt Subject: [PATCH v4 3/9] riscv: Add SOC early init support Date: Mon, 16 Mar 2020 09:47:38 +0900 Message-Id: <20200316004744.209292-4-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200316004744.209292-1-damien.lemoal@wdc.com> References: <20200316004744.209292-1-damien.lemoal@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200315_174751_060891_24AACC73 X-CRM114-Status: GOOD ( 16.10 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.153.144 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org Add a mechanism for early SoC initialization for platforms that need additional hardware initialization not possible through the regular device tree and drivers mechanism. With this, a SoC specific initialization function can be called very early, before DTB parsing is done by parse_dtb() in Linux RISC-V kernel setup code. This can be very useful for early hardware initialization for No-MMU kernels booted directly in M-mode because it is quite likely that no other booting stage exist prior to the No-MMU kernel. Example use of a SoC early initialization is as follows: static void vendor_abc_early_init(const void *fdt) { /* * some early init code here that can use simple matches * against the flat device tree file. */ } SOC_EARLY_INIT_DECLARE("vendor,abc", abc_early_init); This early initialization function is executed only if the flat device tree for the board has a 'compatible = "vendor,abc"' entry; Signed-off-by: Damien Le Moal Signed-off-by: Anup Patel --- arch/riscv/include/asm/soc.h | 23 +++++++++++++++++++++++ arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/head.S | 1 + arch/riscv/kernel/soc.c | 28 ++++++++++++++++++++++++++++ arch/riscv/kernel/vmlinux.lds.S | 6 ++++++ 5 files changed, 59 insertions(+) create mode 100644 arch/riscv/include/asm/soc.h create mode 100644 arch/riscv/kernel/soc.c diff --git a/arch/riscv/include/asm/soc.h b/arch/riscv/include/asm/soc.h new file mode 100644 index 000000000000..7cec1968c8b4 --- /dev/null +++ b/arch/riscv/include/asm/soc.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2020 Western Digital Corporation or its affiliates. + */ + +#ifndef _ASM_RISCV_SOC_H +#define _ASM_RISCV_SOC_H + +#include +#include +#include + +#define SOC_EARLY_INIT_DECLARE(name, compat, fn) \ + static const struct of_device_id __soc_early_init__##name \ + __used __section(__soc_early_init_table) \ + = { .compatible = compat, .data = fn } + +void soc_early_init(void); + +extern unsigned long __soc_early_init_table_start; +extern unsigned long __soc_early_init_table_end; + +#endif diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile index 97d0c35f8b37..e4a22999dbc6 100644 --- a/arch/riscv/kernel/Makefile +++ b/arch/riscv/kernel/Makefile @@ -10,6 +10,7 @@ endif extra-y += head.o extra-y += vmlinux.lds +obj-y += soc.o obj-y += cpu.o obj-y += cpufeature.o obj-y += entry.o diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index 85f2073e7fe4..52ed11b4fda6 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -131,6 +131,7 @@ clear_bss_done: call kasan_early_init #endif /* Start the kernel */ + call soc_early_init call parse_dtb tail start_kernel diff --git a/arch/riscv/kernel/soc.c b/arch/riscv/kernel/soc.c new file mode 100644 index 000000000000..0b3b3dc9ad0f --- /dev/null +++ b/arch/riscv/kernel/soc.c @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2020 Western Digital Corporation or its affiliates. + */ +#include +#include +#include +#include + +/* + * This is called extremly early, before parse_dtb(), to allow initializing + * SoC hardware before memory or any device driver initialization. + */ +void __init soc_early_init(void) +{ + void (*early_fn)(const void *fdt); + const struct of_device_id *s; + const void *fdt = dtb_early_va; + + for (s = (void *)&__soc_early_init_table_start; + (void *)s < (void *)&__soc_early_init_table_end; s++) { + if (!fdt_node_check_compatible(fdt, 0, s->compatible)) { + early_fn = s->data; + early_fn(fdt); + return; + } + } +} diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S index 1e0193ded420..32b160942f40 100644 --- a/arch/riscv/kernel/vmlinux.lds.S +++ b/arch/riscv/kernel/vmlinux.lds.S @@ -24,6 +24,12 @@ SECTIONS HEAD_TEXT_SECTION INIT_TEXT_SECTION(PAGE_SIZE) INIT_DATA_SECTION(16) + . = ALIGN(8); + __soc_early_init_table : { + __soc_early_init_table_start = .; + KEEP(*(__soc_early_init_table)) + __soc_early_init_table_end = .; + } /* we have to discard exit text and such at runtime, not link time */ .exit.text : { From patchwork Mon Mar 16 00:47:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 11439535 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A11D81667 for ; Mon, 16 Mar 2020 00:48:03 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7B0B4206E9 for ; Mon, 16 Mar 2020 00:48:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="gt8yqZvD"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="FX9SrI4+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7B0B4206E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date :Subject:To:From:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=h7kzE/N+jJv1QX/aRJ9EB3ffGY4xt/12EKtAEsR6g5A=; b=gt8yqZvDzDvaj2 uPhHDfIggPNTx0QIJ1vAksMQGd9RQG4LKUaVR2jUjGjBXk2p/DOX4qKTXtkA8Xt+EPqihlFKRjuWF IVkELpHhGqAFambum+TeHGwj+pQ9nLhQKomO061FcWSMoqeiySXMsROwN9A4XKJh7pJVhZpnGXsU1 62OCQR73uoAdApvJLX2wsdFh6KlCJXWbFbx0HLXuLjRTLwloek0WGyHfMFqz//DEi6e1JVso8Qf+5 GNQCGjGog2WcsYjWbQfZG6kM2IRmTRhGL8YdOCjjCfcLW2FKjWan/nFP+P2HtEbk1B8oBkd7rx52+ YonnUhZe+aLOrO1LMkow==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDdvD-00053K-5m; Mon, 16 Mar 2020 00:47:59 +0000 Received: from esa5.hgst.iphmx.com ([216.71.153.144]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDdv5-0004tB-3B for linux-riscv@lists.infradead.org; Mon, 16 Mar 2020 00:47:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1584319672; x=1615855672; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=F9xnIVD67CW+mgp0dGhTX8cKYaJlYsywcXVIcztghww=; b=FX9SrI4+2HLFeO2W96UOsrpECDfjxRo0JW0vPKaRO9H1DpqPGYEa4edr YNXx61rz7AjT9w6/Ksm9gxcCQ4WzIkNU9sTjWIdexm1jJ3sX/iOkKqOEy JVabG9Q8FmV9z9jPS5pZHJjkdDzcGfAIcL679hNZ00Jt+5aEK/2JUScZT ivCPIEl3IjN3NkWK/SzFII7gFAktA1bR7lPbrOsEnphotUhrs0/dOwJ4X JXr0iuBUT39cLlww5Ubmp+semrphvvp5zz0CczmJXIL7zC0cN0HWt67OC /+DON5tWsGUW08hR3UB9OgKVqon7Tebm94PzjoNXCjeF0205wX5nqXp7i g==; IronPort-SDR: 6I6R+9ghjJ3LneBpH3/27OczDDVVORbaiiXW06TM6UH793pktNHWCaBzMDYfgOVmmzR0Bi3Pgo bQ7VcwoaF/EbDG6Z/ejUD0ZtwV+tTxKTUAu3ft3v5vSIUnWcsjC0youafu8YpilIhBUaDxqkpO Xzxs3Juo2Qmb2q8h1FoJYGqvslPgMPfstDLaZaHtXUxuiRfhjs6c8hm394NagfG6kOQoA4Czpd gwcBxQpGTDDb6Tp5SD+YvBGtRnGrqWL/KrVxLyfUy8I8yqinx011S+wbE41dDdUpzW+60vWODj RGw= X-IronPort-AV: E=Sophos;i="5.70,558,1574092800"; d="scan'208";a="133011924" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 16 Mar 2020 08:47:50 +0800 IronPort-SDR: SWhlEJAXwDpXTUgYqe05MihDBNIQAAMuHz8L3kZ5R5YVZyZqByjOnbbkM1X5otE86LthhcSzT4 OkeWMfy13aiSuVsl2dtTsQlHlGrL+5+LUuhOsXZUPOkCzXP35nLS6T/cuA91PlhSSx8Re2ASUW NivUGqIydG9CpMyPrl6z3feBojinDhDJjJU1mhVxvp9thJnfpPjerwafX7XJM/Jo3/uNrB3Amv +etBdqslw48MOeuaOetz/bkc1QXWpKbCIqsquXeXVyXrgiXTaea5tDd0izMqE0CMTTFTem/FsQ JlnnYO7GTfH1/b7WLsSKv8nX Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2020 17:39:20 -0700 IronPort-SDR: 3+Q1HQwMewi/WMqf42ixdtuRUi8JfA0jJMJbe5rNei4kJ/x1prTEP/PgZh5ffiA0MOtunFXiPE VOE8CRTyFn01ckVPF/dtwahuLELSPPSUau9aIyvz1iT47HopRTaXXGKCadD63ijf/PZYMLzBNc kl/ecBy8crXBnJ5L6xJsR0Y49+nTpjrAz/gfKVbgFJgOie6di+9TCBmuxI6ZcCzuQkqK5SD5Hh hWNEvzkd5YIRU3f0jgSjRhfHa9AMCB6MGrK3vsiYOcVGwTggahH+MSRF2MGqI8UaI/iyKE1uNa wY8= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 15 Mar 2020 17:47:49 -0700 From: Damien Le Moal To: linux-riscv@lists.infradead.org, Palmer Dabbelt Subject: [PATCH v4 4/9] riscv: Add Kendryte K210 SoC support Date: Mon, 16 Mar 2020 09:47:39 +0900 Message-Id: <20200316004744.209292-5-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200316004744.209292-1-damien.lemoal@wdc.com> References: <20200316004744.209292-1-damien.lemoal@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200315_174751_174957_222533C6 X-CRM114-Status: GOOD ( 19.74 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.153.144 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org From: Christoph Hellwig Add support for the Kendryte K210 RISC-V SoC. For now, this support only provides a simple sysctl driver allowing to setup the CPU and uart clock. This support is enabled through the new Kconfig option SOC_KENDRYTE and defines the config option CONFIG_K210_SYSCTL to enable the K210 SoC sysctl driver compilation. The sysctl driver also registers an early SoC initialization function allowing enabling the general purpose use of the 2MB of SRAM normally reserved for the SoC AI engine. This initialization function is automatically called before the dt early initialization using the flat dt root node compatible property matching the value "kendryte,k210". Signed-off-by: Christoph Hellwig Signed-off-by: Damien Le Moal --- arch/riscv/Kconfig.socs | 6 + drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/kendryte/Kconfig | 14 ++ drivers/soc/kendryte/Makefile | 3 + drivers/soc/kendryte/k210-sysctl.c | 248 +++++++++++++++++++++++++++++ 6 files changed, 273 insertions(+) create mode 100644 drivers/soc/kendryte/Kconfig create mode 100644 drivers/soc/kendryte/Makefile create mode 100644 drivers/soc/kendryte/k210-sysctl.c diff --git a/arch/riscv/Kconfig.socs b/arch/riscv/Kconfig.socs index 3078b2de0b2d..69071578e181 100644 --- a/arch/riscv/Kconfig.socs +++ b/arch/riscv/Kconfig.socs @@ -34,4 +34,10 @@ config SOC_VIRT help This enables support for QEMU Virt Machine. +config SOC_KENDRYTE + bool "Kendryte K210 SoC" + depends on !MMU + help + This enables support for Kendryte K210 SoC platform hardware. + endmenu diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig index 1778f8c62861..425ab6f7e375 100644 --- a/drivers/soc/Kconfig +++ b/drivers/soc/Kconfig @@ -22,5 +22,6 @@ source "drivers/soc/ux500/Kconfig" source "drivers/soc/versatile/Kconfig" source "drivers/soc/xilinx/Kconfig" source "drivers/soc/zte/Kconfig" +source "drivers/soc/kendryte/Kconfig" endmenu diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile index 8b49d782a1ab..af58063bb989 100644 --- a/drivers/soc/Makefile +++ b/drivers/soc/Makefile @@ -28,3 +28,4 @@ obj-$(CONFIG_ARCH_U8500) += ux500/ obj-$(CONFIG_PLAT_VERSATILE) += versatile/ obj-y += xilinx/ obj-$(CONFIG_ARCH_ZX) += zte/ +obj-$(CONFIG_SOC_KENDRYTE) += kendryte/ diff --git a/drivers/soc/kendryte/Kconfig b/drivers/soc/kendryte/Kconfig new file mode 100644 index 000000000000..49785b1b0217 --- /dev/null +++ b/drivers/soc/kendryte/Kconfig @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: GPL-2.0 + +if SOC_KENDRYTE + +config K210_SYSCTL + bool "Kendryte K210 system controller" + default y + depends on RISCV + help + Enables controlling the K210 various clocks and to enable + general purpose use of the extra 2MB of SRAM normally + reserved for the AI engine. + +endif diff --git a/drivers/soc/kendryte/Makefile b/drivers/soc/kendryte/Makefile new file mode 100644 index 000000000000..002d9ce95c0d --- /dev/null +++ b/drivers/soc/kendryte/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_K210_SYSCTL) += k210-sysctl.o diff --git a/drivers/soc/kendryte/k210-sysctl.c b/drivers/soc/kendryte/k210-sysctl.c new file mode 100644 index 000000000000..4608fbca20e1 --- /dev/null +++ b/drivers/soc/kendryte/k210-sysctl.c @@ -0,0 +1,248 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 Christoph Hellwig. + * Copyright (c) 2019 Western Digital Corporation or its affiliates. + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#define K210_SYSCTL_CLK0_FREQ 26000000UL + +/* Registers base address */ +#define K210_SYSCTL_SYSCTL_BASE_ADDR 0x50440000ULL + +/* Registers */ +#define K210_SYSCTL_PLL0 0x08 +#define K210_SYSCTL_PLL1 0x0c +/* clkr: 4bits, clkf1: 6bits, clkod: 4bits, bwadj: 4bits */ +#define PLL_RESET (1 << 20) +#define PLL_PWR (1 << 21) +#define PLL_INTFB (1 << 22) +#define PLL_BYPASS (1 << 23) +#define PLL_TEST (1 << 24) +#define PLL_OUT_EN (1 << 25) +#define PLL_TEST_EN (1 << 26) +#define K210_SYSCTL_PLL_LOCK 0x18 +#define PLL0_LOCK1 (1 << 0) +#define PLL0_LOCK2 (1 << 1) +#define PLL0_SLIP_CLEAR (1 << 2) +#define PLL0_TEST_CLK_OUT (1 << 3) +#define PLL1_LOCK1 (1 << 8) +#define PLL1_LOCK2 (1 << 9) +#define PLL1_SLIP_CLEAR (1 << 10) +#define PLL1_TEST_CLK_OUT (1 << 11) +#define PLL2_LOCK1 (1 << 16) +#define PLL2_LOCK2 (1 << 16) +#define PLL2_SLIP_CLEAR (1 << 18) +#define PLL2_TEST_CLK_OUT (1 << 19) +#define K210_SYSCTL_CLKSEL0 0x20 +#define CLKSEL_ACLK (1 << 0) +#define K210_SYSCTL_CLKEN_CENT 0x28 +#define CLKEN_CPU (1 << 0) +#define CLKEN_SRAM0 (1 << 1) +#define CLKEN_SRAM1 (1 << 2) +#define CLKEN_APB0 (1 << 3) +#define CLKEN_APB1 (1 << 4) +#define CLKEN_APB2 (1 << 5) +#define K210_SYSCTL_CLKEN_PERI 0x2c +#define CLKEN_ROM (1 << 0) +#define CLKEN_DMA (1 << 1) +#define CLKEN_AI (1 << 2) +#define CLKEN_DVP (1 << 3) +#define CLKEN_FFT (1 << 4) +#define CLKEN_GPIO (1 << 5) +#define CLKEN_SPI0 (1 << 6) +#define CLKEN_SPI1 (1 << 7) +#define CLKEN_SPI2 (1 << 8) +#define CLKEN_SPI3 (1 << 9) +#define CLKEN_I2S0 (1 << 10) +#define CLKEN_I2S1 (1 << 11) +#define CLKEN_I2S2 (1 << 12) +#define CLKEN_I2C0 (1 << 13) +#define CLKEN_I2C1 (1 << 14) +#define CLKEN_I2C2 (1 << 15) +#define CLKEN_UART1 (1 << 16) +#define CLKEN_UART2 (1 << 17) +#define CLKEN_UART3 (1 << 18) +#define CLKEN_AES (1 << 19) +#define CLKEN_FPIO (1 << 20) +#define CLKEN_TIMER0 (1 << 21) +#define CLKEN_TIMER1 (1 << 22) +#define CLKEN_TIMER2 (1 << 23) +#define CLKEN_WDT0 (1 << 24) +#define CLKEN_WDT1 (1 << 25) +#define CLKEN_SHA (1 << 26) +#define CLKEN_OTP (1 << 27) +#define CLKEN_RTC (1 << 29) + +struct k210_sysctl { + void __iomem *regs; + struct clk_hw hw; +}; + +static void k210_set_bits(u32 val, void __iomem *reg) +{ + writel(readl(reg) | val, reg); +} + +static void k210_clear_bits(u32 val, void __iomem *reg) +{ + writel(readl(reg) & ~val, reg); +} + +static void k210_pll1_enable(void __iomem *regs) +{ + u32 val; + + val = readl(regs + K210_SYSCTL_PLL1); + val &= ~GENMASK(19, 0); /* clkr1 = 0 */ + val |= FIELD_PREP(GENMASK(9, 4), 0x3B); /* clkf1 = 59 */ + val |= FIELD_PREP(GENMASK(13, 10), 0x3); /* clkod1 = 3 */ + val |= FIELD_PREP(GENMASK(19, 14), 0x3B); /* bwadj1 = 59 */ + writel(val, regs + K210_SYSCTL_PLL1); + + k210_clear_bits(PLL_BYPASS, regs + K210_SYSCTL_PLL1); + k210_set_bits(PLL_PWR, regs + K210_SYSCTL_PLL1); + + /* + * Reset the pll. The magic NOPs come from the Kendryte reference SDK. + */ + k210_clear_bits(PLL_RESET, regs + K210_SYSCTL_PLL1); + k210_set_bits(PLL_RESET, regs + K210_SYSCTL_PLL1); + nop(); + nop(); + k210_clear_bits(PLL_RESET, regs + K210_SYSCTL_PLL1); + + for (;;) { + val = readl(regs + K210_SYSCTL_PLL_LOCK); + if (val & PLL1_LOCK2) + break; + writel(val | PLL1_SLIP_CLEAR, regs + K210_SYSCTL_PLL_LOCK); + } + + k210_set_bits(PLL_OUT_EN, regs + K210_SYSCTL_PLL1); +} + +static unsigned long k210_sysctl_clk_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct k210_sysctl *s = container_of(hw, struct k210_sysctl, hw); + u32 clksel0, pll0; + u64 pll0_freq, clkr0, clkf0, clkod0; + + /* + * If the clock selector is not set, use the base frequency. + * Otherwise, use PLL0 frequency with a frequency divisor. + */ + clksel0 = readl(s->regs + K210_SYSCTL_CLKSEL0); + if (!(clksel0 & CLKSEL_ACLK)) + return K210_SYSCTL_CLK0_FREQ; + + /* + * Get PLL0 frequency: + * freq = base frequency * clkf0 / (clkr0 * clkod0) + */ + pll0 = readl(s->regs + K210_SYSCTL_PLL0); + clkr0 = 1 + FIELD_GET(GENMASK(3, 0), pll0); + clkf0 = 1 + FIELD_GET(GENMASK(9, 4), pll0); + clkod0 = 1 + FIELD_GET(GENMASK(13, 10), pll0); + pll0_freq = clkf0 * K210_SYSCTL_CLK0_FREQ / (clkr0 * clkod0); + + /* Get the frequency divisor from the clock selector */ + return pll0_freq / (2ULL << FIELD_GET(0x00000006, clksel0)); +} + +static const struct clk_ops k210_sysctl_clk_ops = { + .recalc_rate = k210_sysctl_clk_recalc_rate, +}; + +static const struct clk_init_data k210_clk_init_data = { + .name = "k210-sysctl-pll1", + .ops = &k210_sysctl_clk_ops, +}; + +static int k210_sysctl_probe(struct platform_device *pdev) +{ + struct k210_sysctl *s; + int error; + + pr_info("Kendryte K210 SoC sysctl\n"); + + s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL); + if (!s) + return -ENOMEM; + + s->regs = devm_ioremap_resource(&pdev->dev, + platform_get_resource(pdev, IORESOURCE_MEM, 0)); + if (IS_ERR(s->regs)) + return PTR_ERR(s->regs); + + s->hw.init = &k210_clk_init_data; + error = devm_clk_hw_register(&pdev->dev, &s->hw); + if (error) { + dev_err(&pdev->dev, "failed to register clk"); + return error; + } + + error = devm_of_clk_add_hw_provider(&pdev->dev, of_clk_hw_simple_get, + &s->hw); + if (error) { + dev_err(&pdev->dev, "adding clk provider failed\n"); + return error; + } + + return 0; +} + +static const struct of_device_id k210_sysctl_of_match[] = { + { .compatible = "kendryte,k210-sysctl", }, + {} +}; + +static struct platform_driver k210_sysctl_driver = { + .driver = { + .name = "k210-sysctl", + .of_match_table = k210_sysctl_of_match, + }, + .probe = k210_sysctl_probe, +}; + +static int __init k210_sysctl_init(void) +{ + return platform_driver_register(&k210_sysctl_driver); +} +core_initcall(k210_sysctl_init); + +/* + * This needs to be called very early during initialization, given that + * PLL1 needs to be enabled to be able to use all SRAM. + */ +static void __init k210_soc_early_init(const void *fdt) +{ + void __iomem *regs; + + regs = ioremap(K210_SYSCTL_SYSCTL_BASE_ADDR, 0x1000); + if (!regs) + panic("K210 sysctl ioremap"); + + /* Enable PLL1 to make the KPU SRAM useable */ + k210_pll1_enable(regs); + + k210_set_bits(PLL_OUT_EN, regs + K210_SYSCTL_PLL0); + + k210_set_bits(CLKEN_CPU | CLKEN_SRAM0 | CLKEN_SRAM1, + regs + K210_SYSCTL_CLKEN_CENT); + k210_set_bits(CLKEN_ROM | CLKEN_TIMER0 | CLKEN_RTC, + regs + K210_SYSCTL_CLKEN_PERI); + + k210_set_bits(CLKSEL_ACLK, regs + K210_SYSCTL_CLKSEL0); + + iounmap(regs); +} +SOC_EARLY_INIT_DECLARE(generic_k210, "kendryte,k210", k210_soc_early_init); From patchwork Mon Mar 16 00:47:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 11439537 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 44446921 for ; Mon, 16 Mar 2020 00:48:06 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 21392205C9 for ; Mon, 16 Mar 2020 00:48:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="LVJtMx7C"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="nmqQUSpC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 21392205C9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date :Subject:To:From:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sOM3aEmjEqWWOAVUA5kLxhBWRDkm4mIPbH4c62vvABo=; b=LVJtMx7CDrNBMl 89bouyfMxZEcoGvbpZWMvTPxDjvF+mh9zdyjbPbo/y9ebjm2HUG0Clx4WLgb3UvUtFlecpqkKedyq /OEJ3zw/5yEMMq1L0LmIfM3l3aTnXwEDEfb3vUlWjwIC5fbp2B1rU2V+TJCHFWH2NRj6e8kuTKta8 5sNg8QPSXXBelgqKwncVhlZpUc4O4HzenJD3suMc5XPKePddVeTnexvNpWMDtOV5yVbbw3xFHHPqH wKnzBQKHWTwpXZoZlFcE7HEH2Kp5yJ61QBepGCbnaZvw0yK0kPCQxsEhKQzUDEboqx3N47x21EbEN Y4zxQ6VMOzq4tsyS/Whg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDdvG-00057H-NT; Mon, 16 Mar 2020 00:48:02 +0000 Received: from esa5.hgst.iphmx.com ([216.71.153.144]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDdv6-0004td-N8 for linux-riscv@lists.infradead.org; Mon, 16 Mar 2020 00:47:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1584319673; x=1615855673; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ntv2epMPlTVdoKFDBWuow5pGs7sY9f+O3nNQNhnjiU8=; b=nmqQUSpCP2Piq0Z1dx/LkZeKCM30VjVwI/Y8Z4SMiyIuQIHkwaeEbYNh q9ZDx2V4ZBNYlSD8KdFwAsfYgdAkoiI+0zn+5A10YpVqcD1dadFQknvRZ q1cYfxC+mU/pmrbW5kzWHAlY00+/636IU5zUeF2mgyWfaFAxmq9KhQ4nm rFdZfWWefTae09c95yyxOE2ZMtsRYs7RlD/J5+pgN9Unwz8R36V2yqEf4 Hf3vbgsGiKhcpM48URDRYdXBPY3iy+cD7QrKQHFRs6hem3u9p4HRt6PjN xPXTWQSOsgqlx9vmHrVrYALuL0qs+5mGeE5Brck6J+Q28zQMf+zt39Z4a Q==; IronPort-SDR: A3rgdcmompXTJJWufYEwuV9nFW+/8LCvo0XpzMe9U/JBziHOUZvzgNco7xIf3PiZ6jzPC3e81b WIDKEb4Wz6LjCinWlCQ8FFVR8Cf6v1zJ9GyPi82pwPGxJ7Cu6Xdh0eB73vhwg/2i07Prmq/MLj R1Mb+NFSSqSdSDpHePrvaLIIsSlJsZoalZR+7HZ1JiBisZU4lAeEFxPZStYdAhbcd+6bNgeoaF FaDxGLwivi/oIrbUMyM72u1LfloNDo7ht9lTBg55WWmNJTeshcZbCN7H8BEgw4J7Smxy+7OEps QYs= X-IronPort-AV: E=Sophos;i="5.70,558,1574092800"; d="scan'208";a="133011925" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 16 Mar 2020 08:47:51 +0800 IronPort-SDR: qb3Jzckd4miCX56z2gZ9jGfdLVrxS85wu1IoeQ7Ut0rT8aeGbp+dNi2zdODgSoOj8H9n9sekzR Y835IVDpOiuCN/zZ8BLiS2en2Mv5of5jB1pRNDDlRFpmXM+LZ0zytCWsRtsvu0eDD/hkZGJN/V +yIo8zxMDZw1N1nlQLIrHvd+2f2TkWwjpaW8fQ4J2j4m46UzsCqHFbImcVGs2Wc3aF1NzO52ET 5ceF04Ht6RSeN32PNb8SI0Md4nR/2DGPhogbPpiD7IP8TidgAFOa7Iebec+Pqfo30UUjgv8QLV LVYNKvRpfXoF4Mcg+xnF6OGb Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2020 17:39:21 -0700 IronPort-SDR: uECJb4fk5IPWZFo2ZGUE5KyiJVPICrcQzTwBMamwMkOosccYIN16NLSKcC2MgbIPyoe/3Fq8Bh ulnqgFSMzO41hPN8SCvXuvakEtTu7UDtOswqzg/ISX6ydS4sXd7Nqnignl0He0POIUzaNx6Vj8 1x8vE/PuS143xSOiuGGiq7NjPaYb5mYp97a3J6WbEgYKUZtDN2gqx4rTFuPKSotREKgMbWeIH6 Zqk6+iNeKLjWGsxMlUoWBnqJV84AZ9+BvcrAbIUZmKfrjXWQItXe3ztBPwbT8X/5JQNUru51MY 3e4= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 15 Mar 2020 17:47:50 -0700 From: Damien Le Moal To: linux-riscv@lists.infradead.org, Palmer Dabbelt Subject: [PATCH v4 5/9] riscv: Select required drivers for Kendryte SOC Date: Mon, 16 Mar 2020 09:47:40 +0900 Message-Id: <20200316004744.209292-6-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200316004744.209292-1-damien.lemoal@wdc.com> References: <20200316004744.209292-1-damien.lemoal@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200315_174752_798595_47F8D135 X-CRM114-Status: UNSURE ( 7.64 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.153.144 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org This patch selects drivers required for the Kendryte K210 SOC. Since K210 SoC based boards do not provide a device tree, this patch also enables the BUILTIN_DTB option. Signed-off-by: Damien Le Moal Reviewed-by: Anup Patel Reviewed-by: Palmer Dabbelt --- arch/riscv/Kconfig.socs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/riscv/Kconfig.socs b/arch/riscv/Kconfig.socs index 69071578e181..a843100124ae 100644 --- a/arch/riscv/Kconfig.socs +++ b/arch/riscv/Kconfig.socs @@ -37,6 +37,10 @@ config SOC_VIRT config SOC_KENDRYTE bool "Kendryte K210 SoC" depends on !MMU + select BUILTIN_DTB + select SERIAL_SIFIVE if TTY + select SERIAL_SIFIVE_CONSOLE if TTY + select SIFIVE_PLIC help This enables support for Kendryte K210 SoC platform hardware. From patchwork Mon Mar 16 00:47:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 11439541 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E39FC1667 for ; Mon, 16 Mar 2020 00:48:14 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B8BDD206BE for ; Mon, 16 Mar 2020 00:48:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="KTpkskf+"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="fIZ3nbgS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B8BDD206BE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date :Subject:To:From:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=gXV1vZXcAPhAHJmvdqpXTOyAJ4vUnMtYRXSr9nbeS/8=; b=KTpkskf+r2QmxC KAihY34ccztAQyIajp/SCgqO9LYZgQFysSDB96hQmQX9uB36GvHRNkrQ6UZ71axGHeAuuRBanyh/c s5JUJq056Q6w21RgjpKxcVVTveqSgOXc/EyAacaxfCZAayYRogb6yEmS7M8TkVCGj1WHrKhSDVIbx AdMfZLAFLGAPUDnmAiGqZIZpfaN4BBwC8UXnBneBdhHatm9Jv3nr1fblZbps03p30b+mZHEJWkskS aYC/Ts6ervKxZXpANbJYzqGDeu9wn4gQFHh9Gt9qK9Cffq44zpWLY+tsOfVk3cfYWDmN2crlXBDIj H7kkmgsqZsR0xzT4rzAw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDdvO-0005Fv-AW; Mon, 16 Mar 2020 00:48:10 +0000 Received: from esa5.hgst.iphmx.com ([216.71.153.144]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDdv7-0004tA-AA for linux-riscv@lists.infradead.org; Mon, 16 Mar 2020 00:47:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1584319674; x=1615855674; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BDo2sBvHlU3CR5McHQ6Yn49Lu9d+VWJ6PFc0nIwO1Qc=; b=fIZ3nbgSBWCjK9zNMYAAPaP/uThFFWcrg+bSepe2suenYp8OsLv8Ex8M WTTVRu29KWlN/5c6/zJOB1kc+g2X8+f5PQV8Jktu2O4AfigAUaaS3Owll EQIIoLa6FI8oT4ZxuePdyVmJ5WRyA4y1+tCZbkcmaDSKgLwB8EF9Ug+Yc SdpWzy5yS16l7B4ldnX3VzYv5H6nMWmZonWGcZDNGslgmHmnpdD+qw9d1 uG12DDI0V8+Iz2cbgJGbFUU9DV4GN6vghNsWyPiNYEG/hv3qLeKud3Hci YjP+Mqr8JW2MGILyfSlmxqI+53k02BcoHrYMLUq2DT0UscBo0lYhB16Wu g==; IronPort-SDR: yL6jZBn79ywVna+5N+Vs4pF7ylJuFVYu/NBePXFeXvX8JXq1ElR9v9XofhHCxq8hOwTaxd30dy d7BhovbEKOcwzdca7rCao1XTc4NZFzzAk9v2PnkaTlF1lf3Tmwjw21vrpdQEA0VhW/35iWMBUR ZQIZDMr9sx6LP5jEr7m3kpFKilJuJ8Meowf/R43sgCE3m0RQzezHMFEqHxsAIQX7yLY6VVb/Ny ZdxrPXlp8iExL9vKo2qMUwppi1RLoZAI1N0rKX/5Rdab9fKhXHAuCrF/7G8o6Y2eYaucJlnJq+ B3g= X-IronPort-AV: E=Sophos;i="5.70,558,1574092800"; d="scan'208";a="133011926" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 16 Mar 2020 08:47:52 +0800 IronPort-SDR: lIf6+iWC02/RAqp0SodS7cLmBN6gIj7MpEwnuXFj/wGMtD6HDVD2wCrcUbKvRZa01cVl+f5ljK PL1603fEZ+cJBi7hfS8My6WW50EdlipGNTbSJTyR0FGN8VDPPpjEDb3QhQD0SLktDbO9HC9H5H rm7Y3kgp0VigjgWvFJ+g4d+OpCel8qVkKMNoePhOIoP+ywZ6TMx+fHiT0APOzC7VSn8dIwcHSc hMNzkqEWSv/nDbN1LxvdJEuJSH0kqhQWi2OLJUWTW3vpAPzwUAr+VkNnLY7i0euKccPLr4wcGv ieJoctqZH+iwqspr6siinDwQ Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2020 17:39:21 -0700 IronPort-SDR: QSj9Do7OCAwanHxvn9fIr1Dr6pje8VkqgWIFPtk1hvR2UmvuidUoAnMM7KvNxtOVsD94O3ejUH mjFsA4jERQDQAgxwHEHXOG4ayExKn9lStNtdxH2VbevrfCpR3ocvh4CJGcyEATDQeR4gv28fu6 4G8ObBINonf+VciDDxU34aTpS7q2ltfqmAmpYG0oiVMQH0hMk6F3qFe5w02fEeTlU3WU4baCwM AJtXy+ShLcBNmffAO69yQoBXyRNH/axWQnrNOc4VkyrtTM7QwP4Htxh2rJF1Q+J9hJbTtLpeyX U1M= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 15 Mar 2020 17:47:51 -0700 From: Damien Le Moal To: linux-riscv@lists.infradead.org, Palmer Dabbelt Subject: [PATCH v4 6/9] riscv: Add Kendryte K210 device tree Date: Mon, 16 Mar 2020 09:47:41 +0900 Message-Id: <20200316004744.209292-7-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200316004744.209292-1-damien.lemoal@wdc.com> References: <20200316004744.209292-1-damien.lemoal@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200315_174753_391367_D185BF98 X-CRM114-Status: GOOD ( 15.12 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.153.144 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org Add a generic device tree for Kendryte K210 SoC based boards. This is for now a very simple device tree describing the core elements of the SoC. This is suitable (and tested) for the Kendryte KD233 development board, the Sipeed MAIX M1 Dan Dock board and the Sipeed MAIXDUINO board. Signed-off-by: Damien Le Moal Reviewed-by: Sean Anderson --- arch/riscv/boot/dts/Makefile | 1 + arch/riscv/boot/dts/kendryte/Makefile | 2 + arch/riscv/boot/dts/kendryte/k210.dts | 23 +++++ arch/riscv/boot/dts/kendryte/k210.dtsi | 123 +++++++++++++++++++++++++ include/dt-bindings/clock/k210-clk.h | 20 ++++ 5 files changed, 169 insertions(+) create mode 100644 arch/riscv/boot/dts/kendryte/Makefile create mode 100644 arch/riscv/boot/dts/kendryte/k210.dts create mode 100644 arch/riscv/boot/dts/kendryte/k210.dtsi create mode 100644 include/dt-bindings/clock/k210-clk.h diff --git a/arch/riscv/boot/dts/Makefile b/arch/riscv/boot/dts/Makefile index 0bf2669aa12d..87815557f2db 100644 --- a/arch/riscv/boot/dts/Makefile +++ b/arch/riscv/boot/dts/Makefile @@ -3,4 +3,5 @@ ifneq ($(CONFIG_BUILTIN_DTB_SOURCE),"") obj-$(CONFIG_USE_BUILTIN_DTB) += $(patsubst "%",%,$(CONFIG_BUILTIN_DTB_SOURCE)).dtb.o else subdir-y += sifive +subdir-y += kendryte endif diff --git a/arch/riscv/boot/dts/kendryte/Makefile b/arch/riscv/boot/dts/kendryte/Makefile new file mode 100644 index 000000000000..815444e69e89 --- /dev/null +++ b/arch/riscv/boot/dts/kendryte/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0 +dtb-$(CONFIG_SOC_KENDRYTE) += k210.dtb diff --git a/arch/riscv/boot/dts/kendryte/k210.dts b/arch/riscv/boot/dts/kendryte/k210.dts new file mode 100644 index 000000000000..0d1f28fce6b2 --- /dev/null +++ b/arch/riscv/boot/dts/kendryte/k210.dts @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2020 Western Digital Corporation or its affiliates. + */ + +/dts-v1/; + +#include "k210.dtsi" + +/ { + model = "Kendryte K210 generic"; + compatible = "kendryte,k210"; + + chosen { + bootargs = "earlycon console=ttySIF0"; + stdout-path = "serial0"; + }; +}; + +&uarths0 { + status = "okay"; +}; + diff --git a/arch/riscv/boot/dts/kendryte/k210.dtsi b/arch/riscv/boot/dts/kendryte/k210.dtsi new file mode 100644 index 000000000000..c1df56ccb8d5 --- /dev/null +++ b/arch/riscv/boot/dts/kendryte/k210.dtsi @@ -0,0 +1,123 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2019 Sean Anderson + * Copyright (C) 2020 Western Digital Corporation or its affiliates. + */ +#include + +/ { + /* + * Although the K210 is a 64-bit CPU, the address bus is only 32-bits + * wide, and the upper half of all addresses is ignored. + */ + #address-cells = <1>; + #size-cells = <1>; + compatible = "kendryte,k210"; + + aliases { + serial0 = &uarths0; + }; + + /* + * The K210 has an sv39 MMU following the priviledge specification v1.9. + * Since this is a non-ratified draft specification, the kernel does not + * support it and the K210 support enabled only for the !MMU case. + * Be consistent with this by setting the CPUs MMU type to "none". + */ + cpus { + #address-cells = <1>; + #size-cells = <0>; + timebase-frequency = <7800000>; + cpu0: cpu@0 { + device_type = "cpu"; + reg = <0>; + compatible = "kendryte,k210", "sifive,rocket0", "riscv"; + riscv,isa = "rv64imafdc"; + mmu-type = "none"; + i-cache-size = <0x8000>; + i-cache-block-size = <64>; + d-cache-size = <0x8000>; + d-cache-block-size = <64>; + clocks = <&sysctl K210_CLK_CPU>; + clock-frequency = <390000000>; + cpu0_intc: interrupt-controller { + #interrupt-cells = <1>; + interrupt-controller; + compatible = "riscv,cpu-intc"; + }; + }; + cpu1: cpu@1 { + device_type = "cpu"; + reg = <1>; + compatible = "kendryte,k210", "sifive,rocket0", "riscv"; + riscv,isa = "rv64imafdc"; + mmu-type = "none"; + i-cache-size = <0x8000>; + i-cache-block-size = <64>; + d-cache-size = <0x8000>; + d-cache-block-size = <64>; + clocks = <&sysctl K210_CLK_CPU>; + clock-frequency = <390000000>; + cpu1_intc: interrupt-controller { + #interrupt-cells = <1>; + interrupt-controller; + compatible = "riscv,cpu-intc"; + }; + }; + }; + + sram: memory@80000000 { + device_type = "memory"; + reg = <0x80000000 0x400000>, + <0x80400000 0x200000>, + <0x80600000 0x200000>; + reg-names = "sram0", "sram1", "aisram"; + }; + + clocks { + in0: oscillator { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <26000000>; + }; + }; + + soc { + #address-cells = <1>; + #size-cells = <1>; + compatible = "kendryte,k210-soc", "simple-bus"; + ranges; + interrupt-parent = <&plic0>; + + sysctl: sysctl@50440000 { + compatible = "kendryte,k210-sysctl", "simple-mfd"; + reg = <0x50440000 0x1000>; + #clock-cells = <1>; + }; + + clint0: interrupt-controller@2000000 { + compatible = "riscv,clint0"; + reg = <0x2000000 0xC000>; + interrupts-extended = <&cpu0_intc 3>, <&cpu1_intc 3>; + clocks = <&sysctl K210_CLK_ACLK>; + }; + + plic0: interrupt-controller@c000000 { + #interrupt-cells = <1>; + interrupt-controller; + compatible = "kendryte,k210-plic0", "riscv,plic0"; + reg = <0xC000000 0x4000000>; + interrupts-extended = <&cpu0_intc 11>, <&cpu0_intc 0xffffffff>, + <&cpu1_intc 11>, <&cpu1_intc 0xffffffff>; + riscv,ndev = <65>; + riscv,max-priority = <7>; + }; + + uarths0: serial@38000000 { + compatible = "kendryte,k210-uarths", "sifive,uart0"; + reg = <0x38000000 0x1000>; + interrupts = <33>; + clocks = <&sysctl K210_CLK_CPU>; + }; + }; +}; diff --git a/include/dt-bindings/clock/k210-clk.h b/include/dt-bindings/clock/k210-clk.h new file mode 100644 index 000000000000..5a2fd64d1a49 --- /dev/null +++ b/include/dt-bindings/clock/k210-clk.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2019-20 Sean Anderson + * Copyright (c) 2020 Western Digital Corporation or its affiliates. + */ +#ifndef K210_CLK_H +#define K210_CLK_H + +/* + * Arbitrary identifiers for clocks. + * The structure is: in0 -> pll0 -> aclk -> cpu + * + * Since we use the hardware defaults for now, set all these to the same clock. + */ +#define K210_CLK_PLL0 0 +#define K210_CLK_PLL1 0 +#define K210_CLK_ACLK 0 +#define K210_CLK_CPU 0 + +#endif /* K210_CLK_H */ From patchwork Mon Mar 16 00:47:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 11439545 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 61A42921 for ; Mon, 16 Mar 2020 00:48:21 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3EE30205C9 for ; Mon, 16 Mar 2020 00:48:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Mni1r3eK"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="CoNJYbE5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3EE30205C9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date :Subject:To:From:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=MeYBuFuarrS2jqjo1NZBvAYwKqxBQ4CQJDmuhvtaLvM=; b=Mni1r3eKoSgouZ mwk9zkram5XoFTbFe5GHYq+cdmfHAv6UwK5cKM7kkpTV4PAIr5OQUprydE3ZKDtq+yXqtwa3+x4NQ fVQWo9hibXNifWOfEREb/Q4YRGB58GXlSzwXyAccrOSFgYS/pSMoKFzeSIs5cOfsuo9nUFY42w3wV IaW8EFubC5QTLU09y7VRRj/U2DC1qgoJ831xIAyg4ABTU5NTvsUNjiPyhv7eQWPfW3qbls58lRrA9 oUxD5w99QoIrfCzxmQN3UQcM5uCIpmuNF+IF5kSbl4b1UON5TY0+opfG4SudyX54AO6mjtsEdJn7Y GCbvGuis0H65R6OBajeA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDdvU-0005NW-S6; Mon, 16 Mar 2020 00:48:16 +0000 Received: from esa5.hgst.iphmx.com ([216.71.153.144]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDdv7-0004tB-MQ for linux-riscv@lists.infradead.org; Mon, 16 Mar 2020 00:47:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1584319674; x=1615855674; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Pl1TKwoc4AJIuIZudJ75PGAeBGt3OPtarJZ5vuLVVGw=; b=CoNJYbE5/LNhpB3+XaaYNvNYDXUwaKLdOjTI8lIiWs0fXfqLnWSSJxyN +7B1ygmSWXnSPYt2isqyR9Pnu3YFHPORbBn82hIwuIbyAyFuq5V+2/uWf z2Mb+R0CmE/zrSCoTG8Dr6lL7BOF4rHoHEtOSK1bD65MMgpTGRyRwv68C vF6G/ZI9kpBjbYaJDnojocvVisTH/p/K2LUUHSg4ZVELehPjArAksh20H Qwl6RJA19ahWk2vx3JkbO/glw2UFTV66a2fVgyWcre9pZ42B/4kW7dHv/ FQUbRCCLdlyH4f7dA+JreF4xO5Z0/GxJcfKS6ZEwELbf98Sctd0Ced63H Q==; IronPort-SDR: EzuD6O3TVF2uSD/FR0mAHF2HWvTRa+zJRe9n4mFH6LycH46fxYixxxZBsTCHOOJUIGihKCh05Z RKsJ/LPPSx6oXxtmsL2m+LTtFpJrpv9uGyrp3D0pb9AgMHS2YDn4d/S+2j9bNj58YfSD38vD38 UaWRHse/KlfzKGYsoO/TJvJT2m1kqg5bucZuzaNwkymm7jZXvOu8TtuNlANt15CMGC/TfkFs4v 4htkq/56NCnM+qXyCWVNBFuCCFy/RIsOSE+19R6N9h9W0iC8BzSPRw1cYKz+0otpQb9oCxhb7n XTc= X-IronPort-AV: E=Sophos;i="5.70,558,1574092800"; d="scan'208";a="133011927" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 16 Mar 2020 08:47:52 +0800 IronPort-SDR: lZ2QFrXpsYQrd5EH2YTKZrhUToZZoHS4Sd+2nMvOzlWg+1V65vYN4zTdv9kfwCFsbxcqCXcXt+ gK9cMdV4qvCVMkifxqFjtYCzzXiK6z+1JIIB2tvBPmiP0trfq5VKoQgr9FkMTWi8RrtNXPXhNP Q+GK7Etp8qgmwdMz1vGSogIKwxSY+SZ4ItoDVlJOgfZHd25zJSDbI4fEJu9KVLkYXZTWKk+kiG 9OFT1lcP4sWtnM3nM+91Nv0nrf9gQEPOMy1dFKiNbins/w/WSM/knfSJD+CaXFJ7k6Dm4ACLa+ iM4wei8lxfJp1ao+eZSWNSkR Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2020 17:39:22 -0700 IronPort-SDR: YWLh9oXPXFZc3FenF7uLXPaXT6kZh/AGoaZ4yn5+Go7zySBka3A0m9n+2OAS3d7TR9xfle19yC Q98F2MiSKUmkFKUe45gHeTd9zWblZLMpsG+iW7CEQs73F/SJWHPNpFDQS3guiGk9Cnvix3wguB TVquIkA5MvJKszfaLtFyjiu0P6rKMXecRbm5wBrbJM5gJRIKNMd7rC5AG0iBsuofZ1nAGMwFLD LAo9NxlcldWFtAVpa5g3fIzd2XB7pWBJ2/WVT43BJyYrdOHnH4QP0iqECauYHF1+tbVzJe5evC v94= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 15 Mar 2020 17:47:51 -0700 From: Damien Le Moal To: linux-riscv@lists.infradead.org, Palmer Dabbelt Subject: [PATCH v4 7/9] riscv: Kendryte K210 default config Date: Mon, 16 Mar 2020 09:47:42 +0900 Message-Id: <20200316004744.209292-8-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200316004744.209292-1-damien.lemoal@wdc.com> References: <20200316004744.209292-1-damien.lemoal@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200315_174753_816853_385CE4F4 X-CRM114-Status: UNSURE ( 8.73 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -1.7 (-) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-1.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.153.144 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.8 UPPERCASE_50_75 message body is 50-75% uppercase X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org This patch adds a defconfig file to build No-MMU kernels meant for boards based on the Kendryte K210 SoC. Signed-off-by: Damien Le Moal --- arch/riscv/configs/nommu_k210_defconfig | 68 +++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 arch/riscv/configs/nommu_k210_defconfig diff --git a/arch/riscv/configs/nommu_k210_defconfig b/arch/riscv/configs/nommu_k210_defconfig new file mode 100644 index 000000000000..632aa2f95e57 --- /dev/null +++ b/arch/riscv/configs/nommu_k210_defconfig @@ -0,0 +1,68 @@ +# CONFIG_CPU_ISOLATION is not set +CONFIG_LOG_BUF_SHIFT=15 +CONFIG_PRINTK_SAFE_LOG_BUF_SHIFT=12 +CONFIG_BLK_DEV_INITRD=y +CONFIG_INITRAMFS_SOURCE="" +CONFIG_INITRAMFS_FORCE=y +# CONFIG_RD_BZIP2 is not set +# CONFIG_RD_LZMA is not set +# CONFIG_RD_XZ is not set +# CONFIG_RD_LZO is not set +# CONFIG_RD_LZ4 is not set +# CONFIG_BOOT_CONFIG is not set +CONFIG_CC_OPTIMIZE_FOR_SIZE=y +# CONFIG_SYSFS_SYSCALL is not set +# CONFIG_FHANDLE is not set +# CONFIG_BASE_FULL is not set +# CONFIG_EPOLL is not set +# CONFIG_SIGNALFD is not set +# CONFIG_TIMERFD is not set +# CONFIG_EVENTFD is not set +# CONFIG_AIO is not set +# CONFIG_IO_URING is not set +# CONFIG_ADVISE_SYSCALLS is not set +# CONFIG_MEMBARRIER is not set +# CONFIG_KALLSYMS is not set +CONFIG_EMBEDDED=y +# CONFIG_VM_EVENT_COUNTERS is not set +# CONFIG_COMPAT_BRK is not set +CONFIG_SLOB=y +# CONFIG_SLAB_MERGE_DEFAULT is not set +# CONFIG_MMU is not set +CONFIG_SOC_KENDRYTE=y +CONFIG_MAXPHYSMEM_2GB=y +CONFIG_SMP=y +CONFIG_NR_CPUS=2 +CONFIG_CMDLINE="earlycon console=ttySIF0" +CONFIG_CMDLINE_FORCE=y +CONFIG_USE_BUILTIN_DTB=y +CONFIG_BUILTIN_DTB_SOURCE="kendryte/k210" +# CONFIG_BLOCK is not set +CONFIG_BINFMT_FLAT=y +# CONFIG_COREDUMP is not set +CONFIG_DEVTMPFS=y +CONFIG_DEVTMPFS_MOUNT=y +# CONFIG_FW_LOADER is not set +# CONFIG_ALLOW_DEV_COREDUMP is not set +# CONFIG_INPUT_KEYBOARD is not set +# CONFIG_INPUT_MOUSE is not set +# CONFIG_SERIO is not set +# CONFIG_LEGACY_PTYS is not set +# CONFIG_LDISC_AUTOLOAD is not set +# CONFIG_DEVMEM is not set +# CONFIG_HW_RANDOM is not set +# CONFIG_HWMON is not set +# CONFIG_VGA_CONSOLE is not set +# CONFIG_HID is not set +# CONFIG_USB_SUPPORT is not set +# CONFIG_VIRTIO_MENU is not set +# CONFIG_DNOTIFY is not set +# CONFIG_INOTIFY_USER is not set +# CONFIG_MISC_FILESYSTEMS is not set +CONFIG_LSM="[]" +CONFIG_PRINTK_TIME=y +# CONFIG_DEBUG_MISC is not set +# CONFIG_SCHED_DEBUG is not set +# CONFIG_RCU_TRACE is not set +# CONFIG_FTRACE is not set +# CONFIG_RUNTIME_TESTING_MENU is not set From patchwork Mon Mar 16 00:47:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 11439543 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8C6051667 for ; Mon, 16 Mar 2020 00:48:16 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 694CD205C9 for ; Mon, 16 Mar 2020 00:48:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="bzqWpN+r"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="lcNFDlIq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 694CD205C9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date :Subject:To:From:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CDWSVzXiCp2itkwZMAA0MvyMfEpgbIfTNklRLHFcdKs=; b=bzqWpN+rKy74AW kuO7XuHnIDl/yafmxbbvNVC94YtEI7K6TpFVc0UwKkqaP3c86PyCrP1PQZ0NaoTMNrDDDyZhqvEB7 cerh7gsd4m3Nlu07i6tQJhQrhEPTu+jOaRvBxBOBJuNG+k/jgBvI2FdSVt7srGJd2wxSv8ubC5E7W FEuDxkLveBq5AL6M8Uu+5qnBgY6H4kh1YE7da8HGS1rUM5/9FlzPKJYDaFWsd1IL53ghP1KhieemZ h9xrsD6y797A7PRb4LRMC3njljj2lYrI7vF5Yl4uoxgVdA/ANkOen9D3rSz4iMTCTu+AvEpI2hBqo lW37nRx/jxolE2b4Onew==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDdvS-0005K3-2F; Mon, 16 Mar 2020 00:48:14 +0000 Received: from esa5.hgst.iphmx.com ([216.71.153.144]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDdv8-0004td-9I for linux-riscv@lists.infradead.org; Mon, 16 Mar 2020 00:47:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1584319675; x=1615855675; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YnJDxVTvCfMa7CzXSBcHLammnRkBJq+coceO+e/SqCk=; b=lcNFDlIqjPVVvpCwTpk2KHjDIJMeoYRM2uTqWjcprEWlBv0hnqcrIlwH mVRcmFh/DAMZq2A/hyxNvGbZlqwgtUjGkMRg7vs6n/GMVR1DRx4gEs9O9 lPdehrUFGEV7gmbx6sQJ4ySRvgTgMNP/AFGx6S8WSfnukuqtQAaqao7Fd r+k3tPDH6b8HLSHLYRevsc767jxTVYUQCK9IzDz0SPCuPwof3+ro4P4lG pcaOwVWV0Gs7GymvINcfaD8tTocovMPg7e38jmTnSbfo6VBZiCdDySBhn k28K17iSGspXPUdDSiIuOhAwDccXBA9LqXmXMBWPLabBc0zMwLjJF0p6g g==; IronPort-SDR: YlXEtdJr4SgyEiyXjPd8vkEXx4O+9NcHYWpZx/ZTTsn+koy9dwAj85xtWoJXdGrOs+kueOpzFb c469GAo7nwr7dHt1aNk2RRqIuSEGjmZoVOrtxAmeZvtBOh6Twhora31ssHOgKKD0PsgaWGRTaj xT5WtLuzpihWMn038xVRJ51r0H/kwf/8ANBSCjEK8M69SzgtuEjNUSYz1x4WjfC/Z6hY2Z9lwm DcBq26Z16N8YBqpzzkipQ82c3rMShY6XkKIuq568sLAqQ/ex+iMfYmYC/2AM0Z3Xy7RHKpDZC2 NCc= X-IronPort-AV: E=Sophos;i="5.70,558,1574092800"; d="scan'208";a="133011929" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 16 Mar 2020 08:47:53 +0800 IronPort-SDR: vSfv/HH5vXPIcoHW4rkHo9mnRVECFfwml5M2pxKLWfK0NK9Nb2cqphYX/VYVYB5USQDIu3SAiP 6Coq1BWwvA4xAV/pQ8mSKFyFk8Ns8DiBzIBfb1Qi5UTxEfgJ1eWjdYReg27CJnKZyrHsRlNBv3 UQNEqquVhJd1fnQt075jwLSdm4J4e7HMKRVI8NUAFX8U1O8mLv35ttzmBd3OQmlb6vi5e+5nwZ 59Bw3qmE0bbEmZXBLO4wfPCVki7kesTzDqHVdHniW90IbD1O6Fo2+0W+YnB8v2Fe3hFwsmcEU0 t64K8/DVP11NTWEuu8N1t/Jf Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2020 17:39:23 -0700 IronPort-SDR: hH0EtFGyLYOPavj4+ahJiq1l2iT4Bb3gwiHr1zoPg4I1Vv62zTGrYCXP3RBtNZS4SMwARpc9ol ZNzFtx0Xzd73yExNgHei66XBRLHsB2u7ExyOcAQeRwrsvqvXE3on4M9Etp+Y06BGgXhraRZO1G VFyVOYZ65afpmKywWBmRUfS2MAPF0Ezs2aLGwCH+eq1Axw+Eoc4zy2TlSxmYtu7W7Tvcu+WLOG fLHbA/0Xf8gYfSGp/mu2qzshSCCzcBhQWAUHjVgFttdnsXpo8C9EgfTAY89DpDEDJEEUDXndOG Tp8= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 15 Mar 2020 17:47:52 -0700 From: Damien Le Moal To: linux-riscv@lists.infradead.org, Palmer Dabbelt Subject: [PATCH v4 8/9] riscv: create a loader.bin boot image for Kendryte SoC Date: Mon, 16 Mar 2020 09:47:43 +0900 Message-Id: <20200316004744.209292-9-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200316004744.209292-1-damien.lemoal@wdc.com> References: <20200316004744.209292-1-damien.lemoal@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200315_174754_347460_4B9E05D9 X-CRM114-Status: UNSURE ( 8.77 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.153.144 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org From: Christoph Hellwig Create the loader.bin bootable image file that can be loaded into Kendryte K210 based boards using the kflash.py tool with the command: kflash.py/kflash.py -t arch/riscv/boot/loader.bin Signed-off-by: Christoph Hellwig Signed-off-by: Damien Le Moal Reviewed-by: Anup Patel Reviewed-by: Palmer Dabbelt --- arch/riscv/Makefile | 6 +++--- arch/riscv/boot/Makefile | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index 259cb53d7f20..fb6e37db836d 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -85,12 +85,12 @@ PHONY += vdso_install vdso_install: $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso $@ -ifeq ($(CONFIG_RISCV_M_MODE),y) -KBUILD_IMAGE := $(boot)/loader +ifeq ($(CONFIG_RISCV_M_MODE)$(CONFIG_SOC_KENDRYTE),yy) +KBUILD_IMAGE := $(boot)/loader.bin else KBUILD_IMAGE := $(boot)/Image.gz endif -BOOT_TARGETS := Image Image.gz loader +BOOT_TARGETS := Image Image.gz loader loader.bin all: $(notdir $(KBUILD_IMAGE)) diff --git a/arch/riscv/boot/Makefile b/arch/riscv/boot/Makefile index 36db8145f9f4..3530c59b3ea7 100644 --- a/arch/riscv/boot/Makefile +++ b/arch/riscv/boot/Makefile @@ -41,6 +41,9 @@ $(obj)/Image.lzma: $(obj)/Image FORCE $(obj)/Image.lzo: $(obj)/Image FORCE $(call if_changed,lzo) +$(obj)/loader.bin: $(obj)/loader FORCE + $(call if_changed,objcopy) + install: $(CONFIG_SHELL) $(srctree)/$(src)/install.sh $(KERNELRELEASE) \ $(obj)/Image System.map "$(INSTALL_PATH)" From patchwork Mon Mar 16 00:47:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 11439547 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 44A811667 for ; Mon, 16 Mar 2020 00:48:24 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1E9BE205C9 for ; Mon, 16 Mar 2020 00:48:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="deL/PSi/"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="hEZLSHCR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1E9BE205C9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date :Subject:To:From:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=F69v8XTdHZ30B4/dHJdRfAieRn3JWVwNbulDFMvhBJ8=; b=deL/PSi/KS8ri3 s/t+2paqpfAtY3WCpJn91SQBMivkUHw5HSgfgU5JqHJw0IYsRYDRmmOoI9DyQpy6Jn82+3xpvAKI2 Ad3vq9623GJKrHubO70sg2peJ/hYij6THU7cPNzyewJsj62WPIkEbSofkLLRY4wzZFLTl0D50pE5X SCIeJMqR8UUqj5w/n3Qz0uWf1sSmavEc8ppYW3WrxzkNHZ80etWXHYLOnz2ERV7WI+wkJd/11L29l azdLMb9ePanLqHrwPT1yogO8A0ttMgcYAK3lYPqhCDi7ssv5M1hgSds76juV2L5DTq2iK+wFjnkPm tUweQbdHxmWBCuk0FC8A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDdvY-0005Rc-TU; Mon, 16 Mar 2020 00:48:20 +0000 Received: from esa5.hgst.iphmx.com ([216.71.153.144]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDdv9-0004tA-Jn for linux-riscv@lists.infradead.org; Mon, 16 Mar 2020 00:47:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1584319676; x=1615855676; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=q5JGE8apGK/+Swg/3+OMCUqtdJVbM3GkTEzcVZ/wkd8=; b=hEZLSHCR8lz5dr0bRB/eD/lPMapD6RgFVjSi6ClDDE4lLxYstimoul7a utptiAWIiBkOzr9oZkPJVqfLgLDjRCc9G7YvBIthj9BzOvxYGwSyFxRhp MqerE2VoNk+YfjQ6206Ng9FimSjQfLeKQrqUx5ZsiFS22KhyY8aBCSzGG SNhlB/u95vzQL8QNWHNrNV9UlllfUiOBSHJuXIXgJqojc61pFc9XLVQux 4ynDfUH3h4VuE0ErutvCn7EH+YsJxoNcqFVjH/nq/koezXznw18uVrlTz bqhaaDOCdz4VC+Wm7CQK/KFxLGhQusFVRpAM0IIJcP6o8pSneWeDfT6xs w==; IronPort-SDR: euU/bpXuJ4S4f7/KuSpcwI/fIa1aK3vJxsj2FFxUVcORJcrQX+37hTPvvayaSn64iLMKbq0LGx D65kPdPIpURgG4gO5yyID/rt2++35RXJ6kEABQypyQ+1yTor4yKF0wwpsuTLKwLMnGfu6qkMex Iob0SzFGKiOfFZjPDcHWvsgRICcFfCHdptGi8/3ibbKimONBDL4ptCM9yHM9hENs73bR72XKpK hAjkxf0re17SXA2s3Z8K9hQ4ejSUCO9mXa2HJIChTUJXiDsqexmPAiy1lRLRr5UFpMKhSWifzw eGo= X-IronPort-AV: E=Sophos;i="5.70,558,1574092800"; d="scan'208";a="133011931" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 16 Mar 2020 08:47:54 +0800 IronPort-SDR: MSpl1w8eQS2weJqYScHQDRMFB+/xsxDLxmUS7Dn9rh3xdnb+oenqbvA8PcMUZ+y096QhUkrLyM 8i6Dr1M4ZQ9D1ZAVU4kZOXYBtWuTO4G4GX0xu3n9dYrLHg3XPjO4dL34smIh3csKFN4njfIp01 YNWul4hVjCdjpNy6/2XV4SdFrBNnZT0g1F2GBlMM7bC7j0cQk1f6pCgciXQ1+BX4aEBEXR0mY2 XewinXzllD4r3GoSv/QcBrZ5Y9Cfurt6GT2bqJQVeVqlwVuGHo6KS93U7VQGqibJPQl5tfFa38 CEnQ6Rxd6KZ4vJPiynBNUIQ3 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2020 17:39:24 -0700 IronPort-SDR: PS4gG+T+uSbpGfGZAxpjWSz/PeIjHQ5LgoXg59bCu89KaB9aHH9Xw4Sjj4Vlit40bKMzy14S1e greCBG88VMmahuDklZ7tc39Y9+k3/cKhRW/tfLlQDmhOft+Tp+QleQ6+WPV3RjGYki9QgsGLvO 4nuyCdLjizjzov9ubL1IkTudoCt56A/8/m0pYKARxzEK66tTR0QwdL9bD8xd1QF6rIhbtwPzVc 8nsjfoq+rMBMtMZubfoQWrdbZacr32zIRYJI4kAnFLGKFx+e4ByUUBsb9wgwKesvQe+K9bmrid Z1I= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 15 Mar 2020 17:47:53 -0700 From: Damien Le Moal To: linux-riscv@lists.infradead.org, Palmer Dabbelt Subject: [PATCH v4 9/9] riscv: Do not initialize PMP on Kendryte SoC Date: Mon, 16 Mar 2020 09:47:44 +0900 Message-Id: <20200316004744.209292-10-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200316004744.209292-1-damien.lemoal@wdc.com> References: <20200316004744.209292-1-damien.lemoal@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200315_174755_684140_7D4628D1 X-CRM114-Status: GOOD ( 10.36 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.153.144 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org Commit c68a9032299e ("riscv: set pmp configuration if kernel is running in M-mode") added PMP initialization to M-Mode. While this patch is valid for any SoC following the ratified riscv specifications, the Kendryte K210 SoC is based on earlier unstable specifications and does not seem to support PMP initialization (the SoC crashes if CSR_PMPADDR0 or CSR_PMPCFG0 are accessed). Since all physical memory access works fine on this SoC without any explicit PMP initialization, avoid the SoC crash by not touching the PMP CSRs. Signed-off-by: Damien Le Moal Reviewed-by: Atish Patra --- arch/riscv/kernel/head.S | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index 52ed11b4fda6..1a5defdc33d2 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -58,11 +58,17 @@ _start_kernel: /* Reset all registers except ra, a0, a1 */ call reset_regs - /* Setup a PMP to permit access to all of memory. */ + /* + * For M-mode, setup PMP to permit access to all of memory. + * This should however not be done for the Kendryte K210 SoC as this + * causes a crash (this SoC follows older unstable specification). + */ +#ifndef CONFIG_SOC_KENDRYTE li a0, -1 csrw CSR_PMPADDR0, a0 li a0, (PMP_A_NAPOT | PMP_R | PMP_W | PMP_X) csrw CSR_PMPCFG0, a0 +#endif /* * The hartid in a0 is expected later on, and we have no firmware