From patchwork Fri Mar 13 09:16:31 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: 11436415 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 1007D1392 for ; Fri, 13 Mar 2020 09:17:02 +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 DD3FC206FA for ; Fri, 13 Mar 2020 09:17:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="T6h2/P7Q"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="l/w89+U5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DD3FC206FA 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=T6h2/P7Q3O9Ox2 RkD2C0gyTX9abzEUCIaIWJmJP8+pGUsfW1rL2v60n53sIYUvTkAarL6c7ZyZFiMMoyZ2nHWGSkbF4 hp2Wrc6nFFyXZMwZs6fv82Y3xBwQcOY98PJaq/nQz+Op2WDoXSIOnWb1XqwXQJl7Ak8l3lggvcaRR gn1VzgYhQP4HYEB5rOUWshpvN2CA0Wvi21OykPFTFp89mbjG3Z1pRuQiQgKruqN9DnMiOlHFAmGEc 57DEUmYZEmkNPXJ0EFpXqtF1I3gmoF9DeGj2+jFoezF+0Uy1Eb/aNremYthBeC+R25g5eKoT7TN4N rsviADWnp9+flTW9Q3Lw==; 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 1jCgR7-0006V3-5V; Fri, 13 Mar 2020 09:16:57 +0000 Received: from esa1.hgst.iphmx.com ([68.232.141.245]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jCgQs-0006Ig-Rw for linux-riscv@lists.infradead.org; Fri, 13 Mar 2020 09:16:47 +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=1584091002; x=1615627002; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eQGWzssuGAaGkCaQ3HlUkUUeR/+37HJuTPi3Da/PRzU=; b=l/w89+U5oxbxwz6InK46syxyc+ly9WGnUH8O7kKyI4UTrciSWvMh8DmF zMMpBgNbiKeOjlFXCS2tB+R7jBDcExYKF8ILmMACl+7GLXTgJUyCJ4hGL /IZ3ftMnUu9q1kajctzOGB2IzZOFX6brbmA9xeVK0osGHcJrZ9QtNUQk8 FZb+LPa7zcYtKnYsOcS6BLx6vG3WKZfaPhSPbz3M7pzd+OdDX2viMbAeh TMUZ7fan8ZYH7gVgTyRtNK9HDxFB7l4wWWXPH03aPE6i5z9f7/Bg1C9w0 FBirSNAaS/haE8jcbSEJh60de8Uynp0ym98TQV8PYyJEE4dOIpSAhi7Md w==; IronPort-SDR: 3OuUS8TZZBxkVIn69Zethhtlhzwtz8PvIsYF2DSObMwDoYcW4IkOJ0kJHQ0ORjocAXgejCYbQ9 lerxIGSyujceIQ2w05azesI4iqbjIJlMiH2vKbKtQPvU/mKsjIoBvJW/uMr4muwV4yoXpNmHqT AMrfRnzDVFMKTp6f9u5x9UIxrQwaUTSYfanp8QMH8baDq0xgvz0/mYGdMmgmc30f+a+c0LnnVd 0C87A7Bwwybuc2l6wT7s2mhBsznPZZJEeGhboo4eF1Vy3Bx8z+LOyWNZ+JfEZ02zW+waLAU3Nh NZg= X-IronPort-AV: E=Sophos;i="5.70,548,1574092800"; d="scan'208";a="240669773" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 13 Mar 2020 17:16:41 +0800 IronPort-SDR: Eevx37uTwY1u1K5jA4ZuJee4EbScNvVJC1X0fBWPRjIi1+q4ApmxEachh/f1gsqn7W4k5X59eP Ip/o3lcFWF5zIjHhYnjCq3ybsLFgE8m21aaIA9M7WKTK5tYViVKMf38u+BTQKnx6S+7OyZQQoL rnxQ7FV9RQJOgBZT13HAj561aPISAIL+isF5yi6SUe+pMj1fryymTjJOSs3d2SQIbAgxdAGvwG Y5gel3AaPCD6gKWyaE5dbhiCXg1ab350dq5HULUhfvUTc9jzmAjolyzU6unLvlWyFowWk9sIfI nTD6QORtUp1KykEGJitmjxG0 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2020 02:08:40 -0700 IronPort-SDR: oWkLDwS17n8K8P9Z+i16yB+74KmHgUTVkT/uCz0C29wkYwFcHEzt+sgZcP3RznJ6xkmRNPd5p5 CvjBT4172/xTALULTWxNrU9pDm741OWbAXeI8h82vU74TB39Qqrc3Hr7gWHCVYV5jT84Nvs4Ti lki4t0oTnD9PDWUqKo7s9koe44ADSUSpn9KH4/Px2uYxof2NPtZxVJUuqJce6FIeQTwIeB5P29 kOf+59wDLAlg4UeIe053Wkqc/GyTG0qjCQJJlgW1JtcQQNXZrbQRe/p0ZTm3uxvrjqsvk/7hnq qfo= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Mar 2020 02:16:40 -0700 From: Damien Le Moal To: linux-riscv@lists.infradead.org, Palmer Dabbelt Subject: [PATCH v3 1/9] riscv: Unaligned load/store handling for M_MODE Date: Fri, 13 Mar 2020 18:16:31 +0900 Message-Id: <20200313091639.87862-2-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200313091639.87862-1-damien.lemoal@wdc.com> References: <20200313091639.87862-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-20200313_021642_939467_37CF2840 X-CRM114-Status: GOOD ( 15.59 ) 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 [68.232.141.245 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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 Fri Mar 13 09:16:32 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: 11436411 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 87DE0921 for ; Fri, 13 Mar 2020 09:16:53 +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 647A8206FA for ; Fri, 13 Mar 2020 09:16:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="rkMYmL5g"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="KbeR6zFm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 647A8206FA 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=rkMYmL5gZRHdKt BhW9gLhi+pWmct6ksusv9OO7SO2imgSjMhfiVvMTVZ2eKbKlTfhO4i/Vxd9gNGxWQaKO4FHEpAgUV dNziKMinf244UfIMNiF5JWH8mnx9VtDfoITybmUdKxYE3eNkEkOX3dd+2OX76n+tcBHzKpmSOW/bR okmitVMM7WII9L0H8qK4Fu0OAFxevEF8ycVv29I21CMdY/BpM/GVPFzFnyeTwxe3q1a4wfkLsvHzg WNfP5iREUTbHNvvuekqL2QfMe/6IZ73HRmNm/xoMuuDZS/wiQiQVoj/ukkOUcpSwhfjmSA8SxThAZ QGdhJ/19wg/kTlVhxcuA==; 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 1jCgQz-0006NQ-MI; Fri, 13 Mar 2020 09:16:49 +0000 Received: from esa1.hgst.iphmx.com ([68.232.141.245]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jCgQu-0006JH-Og for linux-riscv@lists.infradead.org; Fri, 13 Mar 2020 09:16:46 +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=1584091004; x=1615627004; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=g3BptAvMawkXrlgFrkdxrlK/typLe6cL/5thNaNwAuM=; b=KbeR6zFmjYUYldDxfOrqfk+vgOgmznDo3ECFKTryeyhTKwcKy65kQ2Pt /ECny9HFvJZS903egR/qt9CtLE9MmN/2/BiFvgbRTT3W9jDVrtgP2HpSG VuDqC23dBT1JyGsXL2Zf+mVQgQqp441rMtWM998/ApsXNtCAVqKipfbni 1sDMpBLCpaIRh+10H1NlU0tomjpNJZLElloE9WOdCKgeCgtSsij9XHPk8 eYbwmHMOuiIqlxhQmWQYw+TVYea7aMW+SHAktBUXL6kylyfNuXpN0qXbP kMHjukBuMVDfGkvx+iVqW7UoPjVaUw7pxAH7DSYiFl6sl4s9k8pP6Ltri Q==; IronPort-SDR: MJfeDsT6lzlhDIQTB+U3g/o5kNfFKIi17oxGauMrObVSNK6mQszrp8P7RxO6oyDDA6Rnl3UgMX oawl9TMonyynH26HiD+L/2os2XLmOQyDGBcahDhIhrepH1nBnzTtfwOGi9ZkJB6cIYv04Zm82h s+d6HfHicgCilcRWCAdR+tHEI5dujHxJIrGy+2nJDxyv50mK+ZmUsX/sOE4dCLXxi5eirnZReX SFtrCG3R29DFDnHL4PlcqHYyFstASP2vpiMiLhZX5KprFon9VLxIjhOziApD5okquJUWU5cbOz elA= X-IronPort-AV: E=Sophos;i="5.70,548,1574092800"; d="scan'208";a="240669774" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 13 Mar 2020 17:16:42 +0800 IronPort-SDR: IBLmXiJP3Aewv7/BIkooY95wQeIkGlWqEOsyahV38vmJOn4zjm5N33Mr3lHuzlf12/neXC1XMT RDGdhUcgGezFxwhilVWtTh1u09/vEdvhy9zaNLfZptYdickgLpWqdMLqFzgC+EhcsWHHOMPS1C 1Ovrj8gDcTyD3/eCN1zyLBlqvaddYBq1ODM9Q9Zm+S4GT27x0Gc/HBQP9FYt5MgBri1iaqpzUi Ma7mg25YQ/9iQCTRp8dubg5taPkpOqlX2oEjMOx02yfWtNqh0j/fz1/CGhKUvSU0qZ+QwztmrK Dbo3lbV1ywKJd2Lp7zSa82fF Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2020 02:08:41 -0700 IronPort-SDR: 5zZeTNh/R+JbxS1t5Kj9tW0ezpZa1AJ29trRkU6jju1Estb6VzGfotUVlRLnCYlxELDrYF/ww/ KKtwxnJq5Ch7rebeLu760cR/z6yWxiz/tVcDF8Odh/KMfDzrnKE5PDP0EXxrZyfDSCs4sA719P RRqFdK30hy65wfpDgHmQQlPyq9OoxpyHpvWPZkR/CJj7TX3A6sACLPA661ZpNKKUxYIvBoz7CL /NAmK7nCl8r7j03gsLzOeo5FEDbIPWKmBvCdMBM1enwJv07bWH/JDMnd7WIqxOMfOaHLYGuqU5 iGc= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Mar 2020 02:16:41 -0700 From: Damien Le Moal To: linux-riscv@lists.infradead.org, Palmer Dabbelt Subject: [PATCH v3 2/9] riscv: Add BUILTIN_DTB support Date: Fri, 13 Mar 2020 18:16:32 +0900 Message-Id: <20200313091639.87862-3-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200313091639.87862-1-damien.lemoal@wdc.com> References: <20200313091639.87862-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-20200313_021644_809339_571F7F51 X-CRM114-Status: GOOD ( 10.55 ) 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 [68.232.141.245 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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 Fri Mar 13 09:16:33 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: 11436413 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 EDD121392 for ; Fri, 13 Mar 2020 09:16:55 +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 CB6C820746 for ; Fri, 13 Mar 2020 09:16:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="buDNR6Vm"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="hG7/eCgu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CB6C820746 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=uAoXpaIwBdolv+ectXmP3OxR5Lj8/GvNetdhx+uCMYs=; b=buDNR6VmKnQpdx OWxPYyK8NdPbKusr5t7WFK3O1zjiF51DPDToPhUsl3Hc8/TVAqhX7ooXfnucOSvG0SmXNGWtyZRx9 FW1wkTuio7f8aN2hRUnUURmV1jGMsSc8MfwMKZsF2x03UNPxRht5oouZfiQ4yaUdUguceKwUMpIZo 7nvK/nufAYdIJ+lr60C+Kr2AS2ATCYmj3Tt+LB+q/fJydXoWAQusYG+A/A3aSjp0dSZZC7a1BpWnt XK4hkzZu/bpgRlnU+khfkl9G1oXnYbRrY/T8lRpg2tBB/IVx0fmRxrTUdeDaDv6DJh2q6+XGq6AkT tOdLCjr8FkagfRszHzhg==; 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 1jCgR2-0006QD-Jq; Fri, 13 Mar 2020 09:16:52 +0000 Received: from esa1.hgst.iphmx.com ([68.232.141.245]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jCgQu-0006IT-Vo for linux-riscv@lists.infradead.org; Fri, 13 Mar 2020 09:16:46 +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=1584091004; x=1615627004; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jAefqkoaquO57lJsa577UesLDIa+4Gs9zh9QSrMT0Nc=; b=hG7/eCgu2SubwQRJgAEgNvQVoxl0QkFx2rRihdDZojPzVqFSjCDxEYjp DTOi9do/zWX7b+fUYnJpsU4MeHxX4Kbam3zGeeSzDRfT2enelbAvagkhc 8+HLbKoRhStnqwiAgqkRduwuCTbgjUUR2EA1CjwT3bqG5QROHxXmicOv6 F6YTnDC8TZ4pSJbf2LSlGXB25sRhNorwZXYE9d76TQEqXkBIve0pV/5Qq jnOQP4uMgztg0UPCSHn598NaYGbhL3fVKNgS4DG/TbG5IsGsMdZmUPhQb lbGuSUgwSo4yP7QRDHt3NuIZb2qAjtUa+0S0XkfHCzkc3eW5BdhiLZP1H Q==; IronPort-SDR: uJxTQgRNT06InyQpg3OB0xNBjvjDXK//k9i9mM125PVcPvMlO8cCsc9xNhx13yNUfRPvdHYPXY aa1JLZuOJM6by9tBTczPaYwsJPzr9rWGRfam8qOerFwr3HxuGU79FBw2auKN6g5+vIjTOLPW5b ic0NW2DYAm3EJDZextRiVArUHyuGWwBQpyghSH7E6XfhkSyb7NunLMt4NooZFG42UarTd/yOkr yhcSbaLYh+KdJ3WQOxy1ed89pJpIVL5Z1sa3QOX5CNheEUnccKeit3++KEnmezWW5IN1WQhTZe zHc= X-IronPort-AV: E=Sophos;i="5.70,548,1574092800"; d="scan'208";a="240669775" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 13 Mar 2020 17:16:43 +0800 IronPort-SDR: 29DIq7rIjp7x6FHzPnKQSRSdlHEsJwpaGNWVsc0PrEHJ8u4I9texyHGyjgjPMHkrtkGvnSoVx2 nMwYajxLHTScXz7WwyZFXctPEfl9DjGbIiHUMtY11n5oGaYubbT1W6IJWtsAHKKyqyG+MhO4Sg ygeOmjwK4dYyUgoXlAt2AyXIQ/XhO+Hhdn+Mz1yLKrZQ7OruM8slgeTM3l7aiT59e8fG+Lwpmf nHD2YnCkAvAoQ5e17CFi/XRTIiYNdjZq+nbWp4gxEyANt3dVfav3YhEHeHgOCD3E+lzAhtTHJF 6UUtgmYiQap7sga2a0RuaveN Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2020 02:08:42 -0700 IronPort-SDR: JZmr4HJrIcbAfifJ2Gsftk9QwgnSb+/7RIPrUoLFzd3ZQC2rvZzlTVoRjzStxMyI9gjGQcN6zJ D174jSBWKfsPrjlbtmBYSOlytmjKmpUUUwFB0yaA3eQqQ+5xypsJe6G+4I7cxy1rgzisP8MQ27 72EJOz6voaa/ngxFW1rDiZI9ZqE0wu03hbUm78FudvX6JXMRg93lbgphiD14oGU9237SJX31ia hyTKCU/VollAc8z6l0BaSwM1DiYBXWx4YfGAAgU34WcnLrDhNgapXo+bG9aN5lNm9gz9/GY9rH c30= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Mar 2020 02:16:42 -0700 From: Damien Le Moal To: linux-riscv@lists.infradead.org, Palmer Dabbelt Subject: [PATCH v3 3/9] riscv: Add SOC early init support Date: Fri, 13 Mar 2020 18:16:33 +0900 Message-Id: <20200313091639.87862-4-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200313091639.87862-1-damien.lemoal@wdc.com> References: <20200313091639.87862-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-20200313_021645_046113_A444EA60 X-CRM114-Status: GOOD ( 16.26 ) 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 [68.232.141.245 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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 Reviewed-by: Palmer Dabbelt Reviewed-by: Atish Patra --- 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..9b8c332cbe76 --- /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(compat, fn) \ + static const struct of_device_id __soc_early_init \ + __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 Fri Mar 13 09:16:34 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: 11436419 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 B5F731392 for ; Fri, 13 Mar 2020 09:17:08 +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 8C8C3206FA for ; Fri, 13 Mar 2020 09:17:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="XppYVZSn"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="E0YrYuBt" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8C8C3206FA 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=61lis+J7vuLEk4pOuulRTvC220wB6K0I4RGsBE0rNrU=; b=XppYVZSnRX9yvS AA/BSpK3b7TZ+O3r7h4TLTUPVuuxEUlGa2QYvMudJPcOQpg32m4YBt/lEpv9iPqbM36vO08vtpyoI QWZdN8sDT1wwWDilmbeeaDLaksar1rv+PPBh0oy2mBJncjPySdGKOlfqFPswmoiqiB9o7RAU+CZRP hK4Wyt8XCAg+X2J268/iKhwAHSIud6QFX2BWvgI8CgYMOLNfTg4g0zJeN/n0704bPPZs53russiRQ PmFPP4I+WXD4xrawz8+UNDSuMBSEIVwQwOA6ri6Nhl2NGeWTbxtEPfO8FtJunSq0Qjvms190YExXY kNI+oRmM0N+cq3NvVJbQ==; 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 1jCgRE-0006c4-Bt; Fri, 13 Mar 2020 09:17:04 +0000 Received: from esa1.hgst.iphmx.com ([68.232.141.245]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jCgQw-0006JH-MG for linux-riscv@lists.infradead.org; Fri, 13 Mar 2020 09:16:49 +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=1584091006; x=1615627006; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=32jhvoPPiNpCB2OgkgDcP2gZp5Vlek6qTPSTvmMtcrE=; b=E0YrYuBtLxbbuon9CFdXYobCJJ2CiDNMwL2t2a6lYhifTJnw9tLI2Ac9 hlg6GyQ+i8vYZvfq0r5xzYv5nrYZ3djF7PTfosDITcfOyF2wuEC8RnFyI M6/+ezV2DX6laZ0cwRaAyVszRtt7lzu02oL6uPWkpVmtMRVNZFJnIzGlb uLcp2vv3asz2uP+eqC8fF9tXe1UAFtrubAT5i+n01CZrJ2TdmU+6CNuul aWBxwYk/4P6r7FRzEdlAaTuIV6O26DJHkOgsYmxhAZ5zaLY/Dd7YFrdEh tIZod6lj6y9GpROJr5uuZMXKv3XqInIZ4gFVr8SYtxzuYOZz1cGX7YoaQ A==; IronPort-SDR: RgqiGjtcWiVqPUB95d0dAiO0biXSYk8mzZ4RPGC/CQV1QCM+mSsbYnvAbh7vLV66nN6jiEZ9zM nseY+vBK6zihPhxCIfi/th5PK2XnFNMLHAMESwIlZvoaQ33aDW+wsYOINUrNNU6ZLB+YcoaDnY muv9fo8p+vr2WnCtilVlKF/Q6ok72M8pTOWkqIMK6EdRVznZuIrcAn4bZB5E37CnZZfAn/PH90 FxQUNV4bKWVYQ386KsEsr35FKOWQYer1Ddo7apGN15RUh+j7rdPHR5LE5ZDgISz3yr4KSkvzwZ CGw= X-IronPort-AV: E=Sophos;i="5.70,548,1574092800"; d="scan'208";a="240669777" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 13 Mar 2020 17:16:44 +0800 IronPort-SDR: SvyAs8B9hW7WvKByF/QIIXxUAEz3bbZJA6Vu7mtoD9mub8eH3kPBM7vDpov2NYcpJ5sBVsmN9Z CF+I6Zvehc49BCZYQ9Kx8E1mzOF/9fOjXyZmLOTyuR3jtLtoJ1imCELU4GBAQ8xXyQxTAzkPci MHNjAY7LnGnRz0aqxOdgqJ8qum4ZRpfKGENvrciMEmcwhrvlAGXYM8OZvV9r6xxsoPWVTks62T vjdRQo/Pn2+57EdxoFFq4b4f5QblnxzeYsyddS59e6/DliLEE49mqsmpO0I3/7A9vFAOnWh7vo kAejbdvSBX5bwSjNtGBIU0mv Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2020 02:08:42 -0700 IronPort-SDR: 9KC4HlFXKSk+v7zoeg7qOMQjvGTwgSUJiqgMYzncpVDnWFsu2VqwMANEM3H5xvHGdLm5WHbTbk G8mT13Uc+CA+F9a7zCdKKBMlE0hjdoWQzvJ+jb8Z5F2c5cOrP6u+nUHQf/pfr9Fvr7JfXc6oKB 1JkgP7kqWJwT2FftMNettGdPI4FKWuycPsOXBKELi6tT9evMFKl7nQDNINgZBxWE1c9jC+shNF QxNMnvOmJcmIdQtRN1kxbfBaMhtrjvInpshkwaphyBWkC9J2vd9xYJcvXLWhauwezJwiwFWiLf 3CY= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Mar 2020 02:16:43 -0700 From: Damien Le Moal To: linux-riscv@lists.infradead.org, Palmer Dabbelt Subject: [PATCH v3 4/9] riscv: Add Kendryte K210 SoC support Date: Fri, 13 Mar 2020 18:16:34 +0900 Message-Id: <20200313091639.87862-5-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200313091639.87862-1-damien.lemoal@wdc.com> References: <20200313091639.87862-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-20200313_021646_767050_8ABFBD3F X-CRM114-Status: GOOD ( 20.06 ) 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 [68.232.141.245 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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..caaae6618f8f --- /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("kendryte,k210", k210_soc_early_init); From patchwork Fri Mar 13 09:16:35 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: 11436417 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 457F1921 for ; Fri, 13 Mar 2020 09:17:05 +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 239B72073E for ; Fri, 13 Mar 2020 09:17:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="IU/6PPKT"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="VlGg49bh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 239B72073E 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=IU/6PPKTU0M6v4 nPBzc9O/xBzR3mZFrXVznJnDYnv6yggtR4oWO41fgmu/fPQcK6sDWSWjGjr37825nBKYGzrktWHDa 6NARTcivamBB9GPyUEvB71MgaDKjGbfilnFga78q2tYamDSMW2nXvCDAPDQFqoPbi46Q2Muumm0kU sSo1IgGwyt87CbG+9U2dV24jrEAwee8xhxNJdtN40VUfHY/Q78MLb9tkmLiplj49aVJY7nnoT28/A lCiT7Ibe5cQTWneaxa3DohzT3Ts5M/PB1YnEYfuN35jd1ByaC+k4LeedU9rc7RqGSLfLamAICc/zL wG0pYwaXa6nQ7MIArv8g==; 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 1jCgRB-0006ZF-WD; Fri, 13 Mar 2020 09:17:02 +0000 Received: from esa1.hgst.iphmx.com ([68.232.141.245]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jCgQw-0006IT-Oy for linux-riscv@lists.infradead.org; Fri, 13 Mar 2020 09:16:48 +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=1584091006; x=1615627006; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ntv2epMPlTVdoKFDBWuow5pGs7sY9f+O3nNQNhnjiU8=; b=VlGg49bhN2v5G3MsYg/RVvxgGBBPZtbPqFxfMw7cFTlS1hmajLPncSmI 5TvtMF4cUzfmF+VsvAlkCe3pUBantdMEliVpZKobcxAXDwbKFNLzMU6s2 EQcxhYOJcZpGgocZ54EHGiCtnoirVwFkggZYzv6WBJ36/IJNJRpYVpqYb GF5wbFHQFo00dBWAjBBfnnOu5912UfUPa+ea9JYIuKLkXcc8EeVAoDDqW Ss60+e9Ti1wx9Xry7GdWoZVd3sl40/eNeTnGnzbbfXtTKeCPL89NVYf0f 3D3F7m+X1vVQ5zfZ/h2vpfpkz6jKNnQymZUkGgP8q2VUJ4/AHQ8R8TJKF Q==; IronPort-SDR: EERDX+TShpdi/KT71w+boZbmLyzR4wX/5qB9l04xJb3AFT2V1/uiSBbjgWG9JrJK26YvLvUlSF fA2z/mnSGrnuBxfsQAs5xSdvda7MfWAHFnU4MkaV9r97m6JAVrDlVLov7O6Uo9IiX0FXIpfsfL SKGk/Co3UUcTaY1nJ8XaPHP5G15lS4XYxAMYPr/Pi9AvP0PXSa6lg4n71JPHzU186jbZgsem7Z TLHOGYKCel9IrQfMPNHKYdrxcuN2ie+qcCf3wIKgbwJ5TQggOyJj2e62YZ5rNK+nkfsFQUgRXW Ag0= X-IronPort-AV: E=Sophos;i="5.70,548,1574092800"; d="scan'208";a="240669781" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 13 Mar 2020 17:16:45 +0800 IronPort-SDR: vKzUOKykboqHtmXhXkmw9Bp1siLOyVFAB6xSwn30Qz+2fSIn5VERKvYG40uBa+XzbhUOxcgYPE MlyL2eYqncKAby2moadhWH431Gov1koHcGz8v8LHILBtIUia6LV0LgYtgCXHvOJ9+xAAvArEsn eVSoaOx67QO2QG1r/7bf3IKaPHzZ0yX/c2+2NBHnPhVzZ5m/LI9zd+9uz5UX7D8WA9REdXhkdQ Ng0qsDuSiyDUfj2DvCnmSA4K6YVxr14/Bnk/j4lrUs8huh3yCG7hINCiZUrpvHoBj54Iz8Ne4s Pif+ogODHRrnI/wff+Mm7vFH Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2020 02:08:43 -0700 IronPort-SDR: AzRB4wD0RM9kRImFb2G/Q2n5Gxub/1w2H6cpUMLIC5QCc4ujFL1IbG9VjjD5+vVhE69ghKQFaj EGBpbcI+U3njkAWOaNSuFxvLcyGfkYNR5Uiie7sxyIOKlu91HmowhxRpu1bWY5X4Xw+Bxj9NMa ZbnE4FZlV6DegizS/z7m8U3ZTKNPPzG61fwPivxSFTe1SwNUUWSYLOfeA0ScprDr9t720T5e8U /mdBMXLcZbEDx0tmeaUkEuhIBzxgjZ1fzs5zkizXavTPU3fHRY5+YtBl/ijnrcIwj9ZMwAvSKa MNw= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Mar 2020 02:16:44 -0700 From: Damien Le Moal To: linux-riscv@lists.infradead.org, Palmer Dabbelt Subject: [PATCH v3 5/9] riscv: Select required drivers for Kendryte SOC Date: Fri, 13 Mar 2020 18:16:35 +0900 Message-Id: <20200313091639.87862-6-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200313091639.87862-1-damien.lemoal@wdc.com> References: <20200313091639.87862-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-20200313_021646_872768_2D9DC61C X-CRM114-Status: UNSURE ( 7.97 ) 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 [68.232.141.245 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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 Fri Mar 13 09:16: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: 11436423 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 E09C6921 for ; Fri, 13 Mar 2020 09:17:13 +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 BED752073E for ; Fri, 13 Mar 2020 09:17:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="f8BvipkS"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="qN1dflMA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BED752073E 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=on3rPF2BVYRG/gcxHVhrTiZo7EeVSjvjyAfkzT76XIY=; b=f8BvipkSuVRwzh 8StZNPDDpiYUKGYWU6qSb7pJlmC6tbFS9VMhtPxp4mg7nTlKpig+nKgm3IZYEXlVElXCyq62UJRuQ wfsojEBFAPtClfKD8VwsWvEuVODr70eyO7Wyc2NfFesAL4eTRM3+CTa9f+ctKio2dLM4k0f4Lwqv9 +7Icduu70Ckt2eLMfOM4rNk/FGpHnGWBUJ2GjVwXq8v7ce0VUm3w8hvjSmsq2IqXiC95JvHwrUVuP ObvICl3MxT8GcUK85m6YfyzOcz3c8/kOc2MPwf5lo++PoLsMFm54VvFpC1kq04KNSeGTBTJydGqKW tfqyk1OQwd79EbfxTeRg==; 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 1jCgRJ-0006jA-TL; Fri, 13 Mar 2020 09:17:09 +0000 Received: from esa1.hgst.iphmx.com ([68.232.141.245]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jCgQx-0006Ig-Al for linux-riscv@lists.infradead.org; Fri, 13 Mar 2020 09:16:49 +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=1584091007; x=1615627007; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5CrK5+ZfXVJL1wLMJJcmnHdl1+bKwxD6BBEHreYiYC4=; b=qN1dflMAyKIMO81qaE8ueW5wPOQpNwhfZGyVzG+z9GkBTz4h17duUvlr FV891yGFWL5QKg8f4DCDTTyOkBmvinPyQ09tp4L+fVXhTnlLtEpr4Fd2z 9Gb5Qd7m2Bh6Fk73C15uVHru4wIAfobD83COTSeJLI4WAvFRQVsiTtftz kCRjT31sNwijVfW0xvdXIsH3VW4QTG7h83912bvMaIGE+FTnMCsWxdQMp WEBIrWqa8ENsDiViaINOfnH/KiDfcXMvjyHrt2ytsCCAIXJMARg9hVOIn x2HwFFitndbiKqTB/uGPrBYrMuzRHCzxXcmz9guoGZ3tXULT0fH4zSQmI w==; IronPort-SDR: LmxOIX834PKkDg4G7wMX87aLGTTj0zOqtzIrlj5L/yYSmm1RzKf8pFcD6jERdKx+mmmuNoxk+k VFQzqVeY7OG/usvXkLfRfzwt2F6tDaJCSHPEfHmjT1V7/1mq6T3qh5DMZOQBMBqytjZnGdGZ8f /0tzZzf6f6LNxsk3xBLwmVN7b/MM3SvkjK2Ts02DNMiIhrt2dRvdrt+O26jzBPguhaVEHbkrfy 25rekhFCjuwo5QQv1Sjr1HFpTkJ7v25prrZco2NAlJvg6qVMjoK3OKpkeemBzARH6oqXqjO2zW yZU= X-IronPort-AV: E=Sophos;i="5.70,548,1574092800"; d="scan'208";a="240669784" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 13 Mar 2020 17:16:46 +0800 IronPort-SDR: m9WOOb8baQjDpuusFfK4C0y1VPg3vpco06R8VdZRp8XWRw5LxtiGNVluWdngVPY/pXWPEkZ3Sk CGlknsgzt8CRN6DgspiAaLvFo7Nk9ZeLpxZZ/WPtKdeCPcNB8SbCl1pPvQyTIUbEsqbtkUIixl bkeY3jsh49udSvSBzvqkJK/2bacMRf9a16hgPPmbq5FhsnB1eXdLkad5Yo0pjrrfqfrd2UO+GV AtafEDCtI75O3vo56J1nD6C0IWU0D+y0428b8r0WYOzT71KbyczuKucrf/3X6pRIpbHdxg8J1e 4IfQVURigqQkqM170gNUBrMj Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2020 02:08:44 -0700 IronPort-SDR: HxmBf+d8sN3JhzuNT0pkPLDe4kVjS2I2kfMRPPZ/tuzMGlOcmwpU0jxjgUAiwHtkkRRsCbVVC+ DyhufyPZxT7WJ8n1nC4JOmMQ8E/7jvZLOrqH1skX+4WQ91W448DQcz+EfX8Hw8o57aQBvIuRWZ 8PpOOuxtw5EO7GPjevGcRYtMNIpVAswqLn8VXjOrKXcYWoEIK/K3iVjFjWSq4eTzm+qvkN4qhj 7ppr9cMciev3mUaBcEcvpgAdv4xyy3AJ9MYm8L7GzWdTzRPdASvqM8JvWO13LZHOZ+N8c1+uUR N0A= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Mar 2020 02:16:45 -0700 From: Damien Le Moal To: linux-riscv@lists.infradead.org, Palmer Dabbelt Subject: [PATCH v3 6/9] riscv: Add Kendryte K210 device tree Date: Fri, 13 Mar 2020 18:16:36 +0900 Message-Id: <20200313091639.87862-7-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200313091639.87862-1-damien.lemoal@wdc.com> References: <20200313091639.87862-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-20200313_021647_415785_E5187C0B X-CRM114-Status: GOOD ( 15.46 ) 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 [68.232.141.245 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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 Fri Mar 13 09:16: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: 11436421 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 3DC731392 for ; Fri, 13 Mar 2020 09:17: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 1BD882073E for ; Fri, 13 Mar 2020 09:17: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="kRG15wCD"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="f2H7cMw0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1BD882073E 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=kRG15wCDpPZbCq w6bp17iNuqPn66zQp60iodxgervLV5gTI7DUMUYnrPtLmw8tX9myUq3tR+C4iRQcCps1uueTK2p63 zvBxqYhOIJIfLksO/Bn7ZhogAEtJhl7aCwXzIcKOyzOdfKmutlcg+s4/Mhn96/9C9zgbMQGLEy0ON vA5sv8jyvfoSCEJdGShS3qK+9kKanZjOK5Kvn7qu+NKf2vlLJZvp/LwFbId7G9Meoi2f7ZPn2edDt iX9bbjqMyL7C8VME4L2bVgMaYmeOaFltfXYM/9oPMPc6A60S294AtO3FqfZrnSszArNTMTOwfNfPW GoJZ3OPUCJj0n/siLUKA==; 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 1jCgRH-0006fc-Mu; Fri, 13 Mar 2020 09:17:07 +0000 Received: from esa1.hgst.iphmx.com ([68.232.141.245]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jCgQy-0006IT-Ee for linux-riscv@lists.infradead.org; Fri, 13 Mar 2020 09:16:49 +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=1584091008; x=1615627008; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Pl1TKwoc4AJIuIZudJ75PGAeBGt3OPtarJZ5vuLVVGw=; b=f2H7cMw0vzt0zxE9jOLCVJ7O4L4Mdu9dJvtBJ9eS0tKo76UXmN5q/tm8 OoUvm3s0CcJi7JAlSY5wr3+uxcAt6wTffzoN8+IisMGgeVSV1lBCKJBRo /4QbHvAs0WU07Jq0e8WRPUML6J9Nfh+btuX+RFfk+n/hDAS+1t/bSdVil cAaDjMN1v/Zma+E3D/TWOkfVEJKeAll1xknDI/M6hD9dFpxIhTuyhrjr+ MD8Jqn66sUqbmPw8TZB+FfQaZbgvpf63BNP2EmsdOAPzniqAMvK2C9JKv y/0RI2Um+kKRBkAJ8+X7Vvk3XzVMYDzZq8uCIYVgtRvtAJ9lHyRvGp+rW Q==; IronPort-SDR: u8KWedeSQGrfKJtiVyljrCSKbv0o7h5IVX18D1/Cl6ND1u2qgwHdnAe05tVHdGKYr5e7qfcOIU e7cMWV+BXT1552VyaD+wExEYONTzUMzKbz52Z14uvgDrC77huR9xkudyD1ViSzCrvDF/t77fdF No7g9L+8WYtcuMiP+gFZBSBwzCg/bKgi5WKFLGIkVRIKR4xiKyFPy49YXFyZvVelsRNnzH2ocI SkJGF3MljC4+j6Wgjf2K7TaYW/qSU/MkvwIISLhM2W4+j3O64MJdJJJrRducUF9OEjEKQ4L4rB XEM= X-IronPort-AV: E=Sophos;i="5.70,548,1574092800"; d="scan'208";a="240669788" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 13 Mar 2020 17:16:47 +0800 IronPort-SDR: COfmSoWnZrEzMtR8SNfmEu8rR4/BU1R6uG+frCCa1fcOZQBX6ThIq6e2F4Nk9XAR7+0AKAyHZA ksrDd1pV8XMsS6yB5tZwqlQRxHxvePu12SEZUBcpOD+Yg2ovdxe0bglDpqJpVvGKc1+H9jX86B Y6mDDNwsmH1lJ7qhBX8iEjjsZwfhw2dr7SgN+U706AwRpAYNYjanj69LffFP1kpygjpVDU8sK8 aCjvwQJnMQ7JWnT5h6ko/VuIi/Ln5JNFSk8aLAcX1G+xInCxvNa8t9mVDbMVO7OA0zGrN8ADTf YIgnWPEiihsWDXoMPfNpY+5q Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2020 02:08:45 -0700 IronPort-SDR: 3qOQTXvr5qjqqgfacy/OAu64qmI54jfh9ulJVLOKOIxOokwzSIZvAQloEqSzzwSEJw3n9E0V33 PoXUbgIPbSNg566gIjk35FxtQ/6nq114iwtW8DNGmHB21gtpbPZCNu3zbAEe+ryBR2dz4XhMaf lh1Be4u8xmbSQ/HWAc36t0ZR1g6xnWcImma+cWk6TUhod9D/59zUv5RnqG3ArJ8qARbPh5Yj1L QUrpb8jjOa7r6h5WG8jtgGMnSeHqa76guMMvm7jQyrOgLSOWdIpdDX5WJNtgtyt0YpUBik6S1v uFg= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Mar 2020 02:16:46 -0700 From: Damien Le Moal To: linux-riscv@lists.infradead.org, Palmer Dabbelt Subject: [PATCH v3 7/9] riscv: Kendryte K210 default config Date: Fri, 13 Mar 2020 18:16:37 +0900 Message-Id: <20200313091639.87862-8-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200313091639.87862-1-damien.lemoal@wdc.com> References: <20200313091639.87862-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-20200313_021648_514575_8598CC38 X-CRM114-Status: UNSURE ( 8.96 ) 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 [68.232.141.245 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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 Fri Mar 13 09:16: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: 11436425 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 300DB921 for ; Fri, 13 Mar 2020 09:17: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 F321F206FA for ; Fri, 13 Mar 2020 09:17:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="PSc4CB5C"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="bsF8LOia" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F321F206FA 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=PSc4CB5CMPcZD1 6BGl2xZPyTP0BGB/ED33MsG04d4crzPzJYDrfSd8C5rGlqdXbqdcYdIIUKL/qchHcFgB1L2tEnmsB ld9UeRgVD/VhilYXTwEn22rwkgfrvNcUwduQhA+a4F0mXYiU98oAcL8dJPFI8BJGOuYhfAw3nqRB5 3uuL9QkmgM0vMpbKBpXkIY2E6NAxzGTgQrq2NjTR+gvjMqleO/GfL5uODuIdM5lgSbeHjEm0xeeXk 7qxAaCJeTWQ2K15Rw1/uci3tjLFI/hLh0MLeqog3pQiKxEWR9QR6B9XxjgES/aIiW0BMyWddxFK0m VUR8zoMEvYvYoqLgjIug==; 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 1jCgRM-0006n1-Iv; Fri, 13 Mar 2020 09:17:12 +0000 Received: from esa1.hgst.iphmx.com ([68.232.141.245]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jCgQz-0006JH-Ae for linux-riscv@lists.infradead.org; Fri, 13 Mar 2020 09:16: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=1584091009; x=1615627009; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YnJDxVTvCfMa7CzXSBcHLammnRkBJq+coceO+e/SqCk=; b=bsF8LOiatJP8UZ/Ji06gT1EOPN0CY2n5PJhik0FLMsPTA1UlZFG61fPX 98aZOpAQSIExCGCERhEz3jaxDAYbWc782p3YOlalyM9HKo1jbOwA2gqSX 5JDnt7sEjlOZ5LmUH+uhQaW/J8hY2fh+EVIqiQl2dDgTI1PGpkvFqj0pq jZqD4Zo/bFknBQFwe5gFlCvzk5QZ9+ks9PmLP0md/ZKsmpnHZ9o0cRuuh dW+w3539iVqxhX8SU/My0Z+0C2t0eLf76P+HJWvRz0pnjYd4BWvrhkP9k w0jk8AVD31yaCJYIlDcChpRHSRzdmwviklLUvRKWySit04u6cRppxpUQH Q==; IronPort-SDR: FZOuB8AwukeX1OHLSz5A+o1NaIgMvmAawZIXamyjc/DcGskWNZ0wXrgkqHNq3Bzu5FdoDDU8nX 3LumMTVevkzCyHE6cht26D8ynysKXAlEDUAep17ceBEwyg8xuUtPdqxLYKMQ/nopqbzceKTRoh KgWYp96Lw1p6hPuJI1v6DXoIq0MPBi4zeSQ0BBVwl2KK2NpvSsHTvVWqDLexlFouAMqxcmbT3T zrZvb7lI7vcNoetA8/DB+SX8ATgwl3pM7Lzsd9+8bbaasRP3DP8ra0EQLDNtsygkz0ARSFO1VO gIg= X-IronPort-AV: E=Sophos;i="5.70,548,1574092800"; d="scan'208";a="240669791" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 13 Mar 2020 17:16:47 +0800 IronPort-SDR: lo+uyjXk7RFlmZnvpVoeM4+8OEJoQ2zsYhtMrwG/8FV8E4vchP/XjpIEvli4FtLx4+yz20ITgj DfOASkAjJlJHiLrjKD3x+cHZyAokMhx0LIJiJw/DapzDtJClzPAwUMeRIm6YhF6JmrJICz3aGm o9PfEnL7iiovM4fgsxwXzD4FjsScRvwbraQeL7pI9Jdh9APDvK/dmg4Uv28b4e8r+nicy7a87E urhvqsKOToYuyXTAuNHRK2HlGckfKeNWm+Qy1kp4+c4/0ID2KDwW1H5E8vQEBYDe35Z4cZ1r4/ QmSPu3vnijEnqlPlwGhqa10e Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2020 02:08:46 -0700 IronPort-SDR: G7hLnSlYTlmn2m5dkPwLg6QrMyTUTi9lI+L2mlHtxdkX/IB+Y2FulkKCCWx5HAWAnclSLGhESP wLicb+p7Ep0S1rHSm1dBpV1HZDalcdqZwWFYyyojGOBdh+u1xDmfzsyjBqc6OKBG3zi/gYxD08 RSrxhTlxXHqgtrZ3mPKpXf7JsI4QRr8IdOoclbOP6ZeIlhDMaMCD12UiZKZ6b0ptq3QG5CPvMK wEjC6vd5OAmqhl1aDyPcRydJSRD6ECQYG7yyIvbtWlCIhXQ7mKtL8K571+LJieJsyBwbTCsHoF zfc= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Mar 2020 02:16:47 -0700 From: Damien Le Moal To: linux-riscv@lists.infradead.org, Palmer Dabbelt Subject: [PATCH v3 8/9] riscv: create a loader.bin boot image for Kendryte SoC Date: Fri, 13 Mar 2020 18:16:38 +0900 Message-Id: <20200313091639.87862-9-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200313091639.87862-1-damien.lemoal@wdc.com> References: <20200313091639.87862-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-20200313_021649_403089_1F73D25D X-CRM114-Status: UNSURE ( 8.98 ) 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 [68.232.141.245 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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 Fri Mar 13 09:16: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: 11436427 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 793461392 for ; Fri, 13 Mar 2020 09:17:20 +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 494BE206FA for ; Fri, 13 Mar 2020 09:17:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="FaXm3rOi"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="SwGWadt/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 494BE206FA 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=8DEulT0TIjpIawIknI5EgFVnadCCpLBAzLndl5Lj9Ts=; b=FaXm3rOi+8zVJo phkrVv4v6tZs+iBjbkVHIWE6AuTsVEH3O8qPglfhRC4HGDcD4H9ZvXliu5CwnkrdyDUZ0up2VR71V Sz7aynySwmIfzcMxftZV3/3Mls/FQM5cdN0XZ/szgCUr+EdRYIn2zHNZKWiWgc3KL82Mo/EB/IlXe exe8N7s720cCcJexZppdWT/41fX0hgPhVHIKxcVYZzUSSDaOhtZSx6RlNHGjz7+xyHUyuxgjRNh2M BMR+xuIL96C2LVSXYL9KArtA10QOmy7mWeRuL14AuUljpg6G5ikpTJoKD39zNmQb8zFf9r6sh0a2A Sn2yTgYnT5LJZkl/mYig==; 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 1jCgRP-0006qS-5H; Fri, 13 Mar 2020 09:17:15 +0000 Received: from esa1.hgst.iphmx.com ([68.232.141.245]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jCgQz-0006Ig-B4 for linux-riscv@lists.infradead.org; Fri, 13 Mar 2020 09:16:50 +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=1584091009; x=1615627009; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CRphVM9azTZ6wdO6A/8eBNh9+TUuoUAsSA+06Emv/Xc=; b=SwGWadt/kSEJNehVUFsW2CMRF5jODo2bbRndoNouPh3bEonP2nQ7OiQz kbA/a6/E3Ng4ffZO7TBJUFWdq+yWsivmt0uIq8QDxBHdN8Ip3A/S8VFam DpozNcRJoxCmAKceMaMmCY3zDzU8JsVInEr6D3uNjNWE3X1/ncDhHs5vL RIYVb/JEXAkF78BcJ75M474KmeC4McXwRHdC51OomokVPXtxdI+UrGRFG ln2hb5ldN6O1Cl9cUdgyVkI2/SOEZshzyN0P3kxw6lp3GiouxOj2YcQwF ATmvyAM7n9F9IOK66NhTfgfY9LLBrsLziW6sJq7Ck7rR+H9YRvD6vWDIf w==; IronPort-SDR: RQEpRwCDwCa1R58ec0CDKM86zxg1odBOBRvP/3eRMq3cI75U3c4fdOvL2+04JYKWiqjCsyvWSc kmN4skdqX3eA8GcI7tmv+hzTE9343HSDLd8Fc5Xu4IPXGFIAHs7g4s4QiRYH8dxFDAs1IzHX6k mNUtBUqw1WY/8EB9orpE5eda/QhbruzvXLT4GXFQn/6rUvYYowhbLXrubVDt7U8AhnvVQ5hVW1 Ei5A57NSlMds51HDVjTjePL7kn2sOZZJlHR/RsveBD8sKxGob6W6a3dGNNCIaIUV0B3ePb02+4 c2g= X-IronPort-AV: E=Sophos;i="5.70,548,1574092800"; d="scan'208";a="240669794" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 13 Mar 2020 17:16:48 +0800 IronPort-SDR: a4KvFwwT4xJoVUvN3j55eGDZel1+oe7GEQb/7V80WEAhD28zlklJk0mQO37cruUwkCBSE9RpjC omOIy85A0SGJR1oQkbHowsAb4N8Yh5y5GliHHBUTE8W4+X9Q2GzwuLX533tpWzqEElHvLm85jn DLNqgW0oeooG1Rft6BHtdc8Qac4wTgvqj5gCdut8mMx/iNpA708TTRqImDsLJWFekbxGIF2Mzh LBdvd4lyUv7j1OOP7npQqV9R5tKYXIHA7nFYdhiGjooJcxpyhB4gjSYvT1q05/qqSONoipgvAx DIeZnWsfp2tcQDYQYwExWTEs Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2020 02:08:47 -0700 IronPort-SDR: T/tljhhoKG26o7/MP/s6G4xk8Zm76Hm7WwF+QJrFqCu4DYJrIj9Bs8fPINxW8itgIZ3zqY9KEY +PW6Y/4IprR4/VWSkc1YuuCv0UI1P7xLNzTX2B/6yRhyY9es0RelQzqyU1IGCFxAV62ATbbCWN nkkEPvnFupb9wqunwITUNbo5SEPb1Ah6wiGp0+fGoafZ9IpEj0zziAfLQTM18rMYmvYE749ABC OBnJikrQmgF1+4oAQaEtO7wdzYd0yLG8MRw2hBd/INj9be7tPV7Jbhz8ELKqG7rece+pLcDi2A ZyI= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Mar 2020 02:16:48 -0700 From: Damien Le Moal To: linux-riscv@lists.infradead.org, Palmer Dabbelt Subject: [PATCH v3 9/9] riscv: Do not initialize PMP on Kendryte SoC Date: Fri, 13 Mar 2020 18:16:39 +0900 Message-Id: <20200313091639.87862-10-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200313091639.87862-1-damien.lemoal@wdc.com> References: <20200313091639.87862-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-20200313_021649_409332_EE38E687 X-CRM114-Status: GOOD ( 10.70 ) 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 [68.232.141.245 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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