From patchwork Wed Apr 8 16:57:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 11480561 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 04639112C for ; Wed, 8 Apr 2020 16:58:58 +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 CCF3B20730 for ; Wed, 8 Apr 2020 16:58:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="OfV/Vffk"; dkim=pass (2048-bit key) header.d=dabbelt-com.20150623.gappssmtp.com header.i=@dabbelt-com.20150623.gappssmtp.com header.b="xnFP7Ovr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CCF3B20730 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=dabbelt.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:To:From: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date :Subject:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=nE5vctDSuQN5rOCACQ5CjGA7LBmsmXsS0oy2lHDvu38=; b=OfV/Vffk7z7ffLOVz2iqhyEWz TXnQor8DsQxQzPHagAWEFKamp0R71kTXzxi1GflqUdGL/TuHL4qJmeilfXclMlz37MhL+w6Kmj4IM 4ffFL9zJUd3vjfgBW0Il6sB/Qg9ryBUj5rtb9NuPPHcbn2Wgpc2nwPKQAcRfn45+DqTsQy40qJ95C hyX/9oCLbht+hrI8svJjzbmoXPC65Lhnrtg6HPmErCqsHkQRGGADhcMW8mitZ4td64WhQ87g82sKb 8GbGL/hpmu/ygKX2nOZgJfGG1iKKDKFOBD6ESEoGtT8BeU7h3smJcoV37/XRLKj7nLPTJrYEgHlFX XDxbnEN3g==; 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 1jME2P-0003on-NH; Wed, 08 Apr 2020 16:58:53 +0000 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jME2M-0003m8-Fg for linux-riscv@lists.infradead.org; Wed, 08 Apr 2020 16:58:52 +0000 Received: by mail-pj1-x1043.google.com with SMTP id a32so70418pje.5 for ; Wed, 08 Apr 2020 09:58:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20150623.gappssmtp.com; s=20150623; h=subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding:cc:from:to; bh=nE5vctDSuQN5rOCACQ5CjGA7LBmsmXsS0oy2lHDvu38=; b=xnFP7Ovra92iTlA0zgKcCemQUIs33bVKKhwoIosOc0NM+/1xX0Qrm0FDKnsluRpQY1 XExSRZJXhjrNmfTStrnT7xGUktSDgtcXC8HX1O7jOIzRGPIsS8o+JiIeHxdJLglCvzbt Q5hH21b+ggz72gqgFi6H7k33qrL/kXmB1EOdmaCdsd7tSYP4xl80Z30ecoXeDdsEOg+X ec9kZsPgeDcEAA9pEnGDO1w9z5qbCJINxOUMNOgqtdw4yFWi5rCvSv4gK2pdaktNSgog HXT6DkLo4xEA2mp5uK89G3dGATe9urljI4KiSol4wHLL34PWKpvA8NQqSziTKjl4CvD8 q0Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:cc:from:to; bh=nE5vctDSuQN5rOCACQ5CjGA7LBmsmXsS0oy2lHDvu38=; b=RnLSg2MR6TO1wvN3RDJmBXwOMNFO/yTade7ruQd/TIcf6Pi65Vah+ZYkRv1U0e/YS+ eGg8FX/P+wCAozXFpyvIPkLnB7HJc05+Y2vNMiNadTm3hdRAQ4UYSUtCpg+qnR8zXk/f puXscr5//b939H+mU9k9V6laiUmKOX+7s3EitgcH1ehyHofrzms62p+SYeoElh+VbWxL o6sI8tCmM4t6RhMr0nAyqwf1J3em4jykiZiMjimYm5YEzeOjIhuy2TSIGsylpXtYsqT5 8A+LgY64UpwMF1j+LBoVf1IrJsVRIjKP1ooK+2B4BVjnLH+NqxhbMvd9eHJuNphe999B WREQ== X-Gm-Message-State: AGi0PuaoIYFdr1TbQu0zShzua8hY1fR4ihlaGs/+5RpReDG7iR4H1F8M vcu+AgJmxMbup5p7NrTfQ9jS5A== X-Google-Smtp-Source: APiQypLJ11cHDrkmTZL8II1lH+LkjuSV0RRzf8aggogY9osKFdJwzGuBmpFO8wyu9eV27pL9zfM09A== X-Received: by 2002:a17:90a:208f:: with SMTP id f15mr6290845pjg.60.1586365129685; Wed, 08 Apr 2020 09:58:49 -0700 (PDT) Received: from localhost (76-210-143-223.lightspeed.sntcca.sbcglobal.net. [76.210.143.223]) by smtp.gmail.com with ESMTPSA id l22sm80490pjq.15.2020.04.08.09.58.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2020 09:58:49 -0700 (PDT) Subject: [PATCH 1/3] RISC-V: Allow device trees to be built into the kernel Date: Wed, 8 Apr 2020 09:57:39 -0700 Message-Id: <20200408165802.167546-2-palmer@dabbelt.com> X-Mailer: git-send-email 2.26.0.292.g33ef6b2f38-goog In-Reply-To: <20200408165802.167546-1-palmer@dabbelt.com> References: <20200408165802.167546-1-palmer@dabbelt.com> MIME-Version: 1.0 From: Palmer Dabbelt To: linux-riscv@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200408_095850_525674_A496229B X-CRM114-Status: GOOD ( 19.44 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:1043 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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 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: Damien Le Moal , Palmer Dabbelt Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org From: Palmer Dabbelt Some systems don't provide a useful device tree to the kernel on boot. Chasing around bootloaders for these systems is a headache, so instead le't's just keep device tree table in the kernel, keyed by the SOC's unique identifier, that contains the relevant DTB. This is only implemented for M mode right now. While we could implement this via the SBI calls that allow access to these identifiers, we don't have any systems that need this right now. Signed-off-by: Palmer Dabbelt --- arch/riscv/Kconfig | 5 +++++ arch/riscv/include/asm/soc.h | 27 +++++++++++++++++++++++++++ arch/riscv/kernel/Makefile | 3 +++ arch/riscv/kernel/builtin-dtb-table.c | 6 ++++++ arch/riscv/kernel/builtin-dtb.S | 3 +++ arch/riscv/kernel/soc.c | 25 +++++++++++++++++++++++++ arch/riscv/kernel/vmlinux.lds.S | 5 +++++ arch/riscv/mm/init.c | 14 ++++++++++++++ 8 files changed, 88 insertions(+) create mode 100644 arch/riscv/kernel/builtin-dtb-table.c create mode 100644 arch/riscv/kernel/builtin-dtb.S diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index bc713666f00a..7572afc43bd8 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -380,6 +380,11 @@ endchoice endmenu +config BUILTIN_DTB + def_bool y + depends on RISCV_M_MODE + depends on OF + menu "Power management options" source "kernel/power/Kconfig" diff --git a/arch/riscv/include/asm/soc.h b/arch/riscv/include/asm/soc.h index 18bd1253ea18..c232e57bb356 100644 --- a/arch/riscv/include/asm/soc.h +++ b/arch/riscv/include/asm/soc.h @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2020 Western Digital Corporation or its affiliates. + * Copyright (C) 2020 Google, Inc */ #ifndef _ASM_RISCV_SOC_H @@ -22,5 +23,31 @@ void soc_early_init(void); +/* + * Allows Linux to provide a device tree, which is necessary for SOCs that + * don't provide a useful one on their own. + */ +struct soc_builtin_dtb_table_entry { + long vendor_id; + long arch_id; + long imp_id; + void *(*dtb_func)(void); +}; + +#define SOC_BUILTIN_DTB_DECLARE(name, vendor, impl, arch, dtb) \ + static __init __used \ + void *__soc_builtin_dtb_f__##name(void) { return dtb; } \ + \ + static const struct soc_builtin_dtb_table_entry \ + __soc_builtin_dtb__##name __used \ + __section(__soc_builtin_dtb_table) \ + = { \ + .vendor_id = vendor, \ + .arch_id = arch, \ + .imp_id = impl, \ + .dtb_func = __soc_builtin_dtb_f__##name, \ + } + +void *soc_lookup_builtin_dtb(long vendor_id, long arch_id, long imp_id); #endif diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile index 86c83081044f..f40516b6e6c1 100644 --- a/arch/riscv/kernel/Makefile +++ b/arch/riscv/kernel/Makefile @@ -52,4 +52,7 @@ obj-$(CONFIG_SMP) += cpu_ops_sbi.o endif obj-$(CONFIG_HOTPLUG_CPU) += cpu-hotplug.o +obj-$(CONFIG_BUILTIN_DTB) += builtin-dtb.o +obj-$(CONFIG_BUILTIN_DTB) += builtin-dtb-table.o + clean: diff --git a/arch/riscv/kernel/builtin-dtb-table.c b/arch/riscv/kernel/builtin-dtb-table.c new file mode 100644 index 000000000000..7ad6fe93b8a6 --- /dev/null +++ b/arch/riscv/kernel/builtin-dtb-table.c @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Table of built-in device trees + */ + +#include diff --git a/arch/riscv/kernel/builtin-dtb.S b/arch/riscv/kernel/builtin-dtb.S new file mode 100644 index 000000000000..3d459ad86948 --- /dev/null +++ b/arch/riscv/kernel/builtin-dtb.S @@ -0,0 +1,3 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +.section .dtb.init.rodata,"a" diff --git a/arch/riscv/kernel/soc.c b/arch/riscv/kernel/soc.c index c32e7c8e7870..3a05110a2447 100644 --- a/arch/riscv/kernel/soc.c +++ b/arch/riscv/kernel/soc.c @@ -32,3 +32,28 @@ void __init soc_early_init(void) } } } + +static int builtin_dtb_match(long vendor_id, long arch_id, long imp_id, + const struct soc_builtin_dtb_table_entry *entry) +{ + return (entry->vendor_id == vendor_id) + && (entry->arch_id == arch_id) + && (entry->imp_id == imp_id); +} + +extern unsigned long __soc_builtin_dtb_table_start; +extern unsigned long __soc_builtin_dtb_table_end; + +void * __init soc_lookup_builtin_dtb(long vendor_id, long arch_id, long imp_id) +{ + const struct soc_builtin_dtb_table_entry *s; + + for (s = (void *)&__soc_early_init_table_start; + (void *)s < (void *)&__soc_early_init_table_end; s++) { + if (builtin_dtb_match(vendor_id, arch_id, imp_id, s)) { + return s->dtb_func(); + } + } + + return NULL; +} diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S index 0339b6bbe11a..e6f8016b366a 100644 --- a/arch/riscv/kernel/vmlinux.lds.S +++ b/arch/riscv/kernel/vmlinux.lds.S @@ -34,6 +34,11 @@ SECTIONS KEEP(*(__soc_early_init_table)) __soc_early_init_table_end = .; } + __soc_builtin_dtb_table : { + __soc_builtin_dtb_table_start = .; + KEEP(*(__soc_builtin_dtb_table)) + __soc_builtin_dtb_table_end = .; + } /* we have to discard exit text and such at runtime, not link time */ .exit.text : { diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 0c625a5e98db..ad07d931bca8 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -492,7 +493,20 @@ void free_initmem(void) #else asmlinkage void __init setup_vm(uintptr_t dtb_pa) { +#ifdef CONFIG_RISCV_M_MODE + void *builtin_dtb; + long mvendorid, marchid, mimpid; + + __asm__ ("csrr %0, mvendorid" : "=r"(mvendorid)); + __asm__ ("csrr %0, marchid" : "=r"(marchid)); + __asm__ ("csrr %0, mimpid" : "=r"(mimpid)); + + builtin_dtb = soc_lookup_builtin_dtb(mvendorid, marchid, mimpid); + if (builtin_dtb != NULL) + dtb_early_va = builtin_dtb; +#else dtb_early_va = (void *)dtb_pa; +#endif } static inline void setup_vm_final(void) From patchwork Wed Apr 8 16:57:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 11480563 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 4F9CC112C for ; Wed, 8 Apr 2020 16:58:59 +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 2F16F20820 for ; Wed, 8 Apr 2020 16:58:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Fxkbo0/u"; dkim=pass (2048-bit key) header.d=dabbelt-com.20150623.gappssmtp.com header.i=@dabbelt-com.20150623.gappssmtp.com header.b="FnkZUB0I" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2F16F20820 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=dabbelt.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:To:From: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date :Subject:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=D3LzZE0UMVNVcDL+HQwh/ZpkNjkV7N5k0QgoDrqIP8w=; b=Fxkbo0/udqU7nAmnaEHKm1LVK dVuKYOakTbSvJrZDAu1OLQFHshzeGVlTqhgpiG1EoSHSgoxw29tuhsLXp2LRqkHQA7naF8UOgqjER A7XDckKenEWQYJ3Taz+ngPZM0oZ1RRhXty/OAc/04XSRoxejMUrgcvmP2SevdXWChLgjtWkBz/QO5 phrxdKPO98pSp8JiEMvJFsn1aojGNVvJRDr2cdfr34VssM+wa2nIn3rG9JM/xhOy3PpE/cEvcv+YA 4EELao80DNwPP+JKcSYVsjBmSb95UlCQWFq2BiJaYk5+G/b2vhx8LtIA9wVxWcIGDi98A+kAXylxW SAUHAVkeQ==; 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 1jME2R-0003rO-D3; Wed, 08 Apr 2020 16:58:55 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jME2N-0003nM-U9 for linux-riscv@lists.infradead.org; Wed, 08 Apr 2020 16:58:53 +0000 Received: by mail-pf1-x442.google.com with SMTP id v23so3325401pfm.1 for ; Wed, 08 Apr 2020 09:58:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20150623.gappssmtp.com; s=20150623; h=subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding:cc:from:to; bh=D3LzZE0UMVNVcDL+HQwh/ZpkNjkV7N5k0QgoDrqIP8w=; b=FnkZUB0IKieSN8606zUWndwfCzxZ5ulWkgdhwU7zxbhhORY8ClcoOuECMsnvdxtkie quY5NWbZCc2KWJ3nA1PiIFj/Y1xsgqIhHbvuHhFhAkv06y6rtG2K9ySHbgUKr6J4Itjp RaQ8VYAZQmDBcWNJ1ILELQNVPsmS2pVt0RiQwq5CO+/ecCIAZCtGKudMG0s03nTjNQlQ pONyDq4wlGN9AoA1z07KaIWjMYRfs1YoOZmS+7JbPVY8RNgqCZqN+RhzruwMS2oEuRB+ PYm091kD/C911/Dn+S7nBkX84boz+U74lc1440QNcvl9DpSlgf48Gq/JtILlzaHAXs0W Q9Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:cc:from:to; bh=D3LzZE0UMVNVcDL+HQwh/ZpkNjkV7N5k0QgoDrqIP8w=; b=QaMArpd6RrWkQShEWKs/QifEBBCc/Q/iYUPYUOi1vJgmc/EBhL2jikuRk2/l1edYD+ pAy+b0gWvahcpAWU82topPFGsir0nAIrX11k1jHuKYm5icwzcNvn+El8fHQv485MDaVR IyMYklV8jJmPOxzS9Bpsnr9JHn9Mm65Uo/aIXcm1ItxEsnVjVBt/2W0j9jt5YIOEV4Q/ f2CJSFQxLEheV1QWWS0lXRUvBdxg1OsQxQ8ELFPfxaqufaRIOPtYEq4su+s5iaI3CmMe XZxfLHVxfsSHvAmurQm+00MAWZHkeMQm74pAn/XqTkTQqL6VN3LUtfttmx3Fb/ji/70l WMnA== X-Gm-Message-State: AGi0PuZTThYrI7m67wMQpi/+wrKg/Mm95BZOvb28yRSsplN+38SHDdLM hl3vf0vtYGyWz97BKNQCn5pzSw== X-Google-Smtp-Source: APiQypLW1mxyHfs2yhI4Nh0Dv307YcOWD0+Bpcr/KKbG4SWpkGjg7KJbCkRUXMXqHqgaEYptCRehBQ== X-Received: by 2002:a63:5c01:: with SMTP id q1mr7510797pgb.177.1586365130908; Wed, 08 Apr 2020 09:58:50 -0700 (PDT) Received: from localhost (76-210-143-223.lightspeed.sntcca.sbcglobal.net. [76.210.143.223]) by smtp.gmail.com with ESMTPSA id t1sm77803pjf.26.2020.04.08.09.58.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2020 09:58:50 -0700 (PDT) Subject: [PATCH 2/3] RISC-V: K210: Add a built-in device tree Date: Wed, 8 Apr 2020 09:57:40 -0700 Message-Id: <20200408165802.167546-3-palmer@dabbelt.com> X-Mailer: git-send-email 2.26.0.292.g33ef6b2f38-goog In-Reply-To: <20200408165802.167546-1-palmer@dabbelt.com> References: <20200408165802.167546-1-palmer@dabbelt.com> MIME-Version: 1.0 From: Palmer Dabbelt To: linux-riscv@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200408_095851_971174_F61BA4AC X-CRM114-Status: GOOD ( 11.77 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:442 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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 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: Damien Le Moal , Palmer Dabbelt Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org From: Palmer Dabbelt The K210's bootloader doesn't provide a device tree, so we must provide our own. FIXME: I don't actually know the unique IDs on the K210. Signed-off-by: Palmer Dabbelt --- arch/riscv/Kconfig.socs | 13 ++++++++++++- arch/riscv/boot/dts/kendryte/Makefile | 2 +- arch/riscv/kernel/builtin-dtb-table.c | 5 +++++ arch/riscv/kernel/builtin-dtb.S | 6 ++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/arch/riscv/Kconfig.socs b/arch/riscv/Kconfig.socs index a843100124ae..49e953f45e1f 100644 --- a/arch/riscv/Kconfig.socs +++ b/arch/riscv/Kconfig.socs @@ -37,11 +37,22 @@ 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 + select SOC_KENDRYTE_K210_DTB_BUILTIN help This enables support for Kendryte K210 SoC platform hardware. +config SOC_KENDRYTE_K210_DTB + def_bool y + depends on OF + +config SOC_KENDRYTE_K210_DTB_BUILTIN + bool "Builtin device tree for the Kendryte K210" + depends on BUILTIN_DTB + select SOC_KENDRYTE_K210_DTB + help + Builds a device tree for the Kendryte K210 into the Linux image. + endmenu diff --git a/arch/riscv/boot/dts/kendryte/Makefile b/arch/riscv/boot/dts/kendryte/Makefile index 815444e69e89..01d7eb15673f 100644 --- a/arch/riscv/boot/dts/kendryte/Makefile +++ b/arch/riscv/boot/dts/kendryte/Makefile @@ -1,2 +1,2 @@ # SPDX-License-Identifier: GPL-2.0 -dtb-$(CONFIG_SOC_KENDRYTE) += k210.dtb +dtb-$(CONFIG_SOC_KENDRYTE_K210_DTB) += k210.dtb diff --git a/arch/riscv/kernel/builtin-dtb-table.c b/arch/riscv/kernel/builtin-dtb-table.c index 7ad6fe93b8a6..203174ba6f22 100644 --- a/arch/riscv/kernel/builtin-dtb-table.c +++ b/arch/riscv/kernel/builtin-dtb-table.c @@ -4,3 +4,8 @@ */ #include + +#ifdef CONFIG_SOC_KENDRYTE_K210_DTB_BUILTIN +extern void *kendryte_k210_dtb; +SOC_BUILTIN_DTB_DECLARE(kendryte_k210, 0x0, 0x0, 0x0, kendryte_k210_dtb); +#endif diff --git a/arch/riscv/kernel/builtin-dtb.S b/arch/riscv/kernel/builtin-dtb.S index 3d459ad86948..b0fd5ca231d7 100644 --- a/arch/riscv/kernel/builtin-dtb.S +++ b/arch/riscv/kernel/builtin-dtb.S @@ -1,3 +1,9 @@ /* SPDX-License-Identifier: GPL-2.0 */ .section .dtb.init.rodata,"a" + +#ifdef CONFIG_SOC_KENDRYTE_K210_DTB_BUILTIN +.global kendryte_k210_dtb +kendryte_k210_dtb: + .incbin "arch/riscv/boot/dts/kendryte/k210.dtb" +#endif From patchwork Wed Apr 8 16:57:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 11480565 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 28BED17D4 for ; Wed, 8 Apr 2020 16:59:01 +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 066D720820 for ; Wed, 8 Apr 2020 16:59: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="AP7sH+OB"; dkim=pass (2048-bit key) header.d=dabbelt-com.20150623.gappssmtp.com header.i=@dabbelt-com.20150623.gappssmtp.com header.b="1x0cUsLP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 066D720820 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=dabbelt.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:To:From: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date :Subject:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=/mofz8FjwFxWbzOgw5tTHBwe33Bm8nY/vb2rVIqiwFs=; b=AP7sH+OBYT215tNV9GRytVf2H USH5N0OiOYG3OqnrXU0oFag7UPTVAVXDE//aoyMJCwrdGIyRFntA/f9aC5q6cd9nI8XyP7nOMVkLJ lJ4NiIk6AwWOHPuVJ02ktmMhTn+EGCOtOdXKuG7huunAijk287r/mz08EremB5Kcmnu4n6Yu59Gsa RrDeQxD6kGHhJDVJ4GTMTMBBLH9ZmeOSqiUKwAobxhkiuErWcnolnuuPxptThLjjtvdQVGO2bDkWr T0TIAYdzbfsoUDE8CCV2RILPPmfmozW04mC77sqWNp5ydap5L/t8F1/8mZwO39Txamkl6EnimVJp1 M4ZMES/yg==; 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 1jME2T-0003tt-15; Wed, 08 Apr 2020 16:58:57 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jME2P-0003om-MH for linux-riscv@lists.infradead.org; Wed, 08 Apr 2020 16:58:55 +0000 Received: by mail-pf1-x442.google.com with SMTP id k15so2674488pfh.6 for ; Wed, 08 Apr 2020 09:58:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20150623.gappssmtp.com; s=20150623; h=subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding:cc:from:to; bh=/mofz8FjwFxWbzOgw5tTHBwe33Bm8nY/vb2rVIqiwFs=; b=1x0cUsLPTIt1BfHy7xhedGKagzrrcLA2h88HutNelHxEM+IlJJfi8Co+VzADUxO6/E JFXw5hkbDbsAvjUf6Kkx5JhhQLpnccXvysrfgSL5ImfSLtgwwQ1G+eyOYSbo1rWsf2ci I8TwsFjlVABCz5SRn4+pvPgxR65U9uQ1iNZtsYzBHF3gU7gjj91BKAdf3ipARVcq61Z6 0xWmZ5ROSD7KC3/l1VQK+QK8ILtoJs0SKaPUEURIWyX4kcfm1B9S8MfjHlnBXHcVWluy Z8LK8WBHey3p5g5hLAmi6NzxoAgwU4wLajjwrLnQ8Ii0WU0hRMatfuvWhn1Mk4c1yxm/ g9Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:cc:from:to; bh=/mofz8FjwFxWbzOgw5tTHBwe33Bm8nY/vb2rVIqiwFs=; b=cnOWECOapAvwFM1M7vkZQdz5cmRpD7z7GRCYL1s6UWqOcdO2e88Ugex68TWP5glIsM 9MzbrZyrwkVEjdR9GQkS5Q5JldrNWr4Q2brZStZKaLEgdYZnRyUbjA0DxslezFB3J0NO ZlOUDk+YvC+fRPNIzwNAWTmWvcgkFeccCpe+14Tr7Fbevyv0H60b8iz82qU07W/4IpD0 2r/5Ch9+41/4n90IT/41rac1EYKYpBZGDL5DASXIj3Kv+YgkJicitf6cBeXWULqLf8yk xkO+QRBqdjILwYTZ29MVuLapIr8SHayY31kdFKO5/Wz2nEScw2/I7ZobXOXC6EO8g/4X If8w== X-Gm-Message-State: AGi0PuYoddIT1U/KwQNjSpE+rW3VTEpu2Mq7Oh4zEs/dvydK230kVFdv 2rg4MSXVwYy2oU/jbWmZU57DCQ== X-Google-Smtp-Source: APiQypLnauC8w+MVe+D19F4ziPpqCL7apqbY2oP/2WI1/9pLg4OSc/wmSEluSerATeSvPQdRn/xJTA== X-Received: by 2002:a62:1b51:: with SMTP id b78mr8369209pfb.23.1586365132924; Wed, 08 Apr 2020 09:58:52 -0700 (PDT) Received: from localhost (76-210-143-223.lightspeed.sntcca.sbcglobal.net. [76.210.143.223]) by smtp.gmail.com with ESMTPSA id z66sm16766215pfz.30.2020.04.08.09.58.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2020 09:58:52 -0700 (PDT) Subject: [PATCH 3/3] RISC-V: Skip setting up PMPs on traps Date: Wed, 8 Apr 2020 09:57:41 -0700 Message-Id: <20200408165802.167546-4-palmer@dabbelt.com> X-Mailer: git-send-email 2.26.0.292.g33ef6b2f38-goog In-Reply-To: <20200408165802.167546-1-palmer@dabbelt.com> References: <20200408165802.167546-1-palmer@dabbelt.com> MIME-Version: 1.0 From: Palmer Dabbelt To: linux-riscv@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200408_095853_729555_4170E523 X-CRM114-Status: GOOD ( 12.76 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:442 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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 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: Damien Le Moal , Palmer Dabbelt Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org From: Palmer Dabbelt The RISC-V ISA manual says that PMPs are WARL, but it appears the K210 doesn't implement them and instead traps on the unsupported accesses. This patch handles those traps by just skipping the PMP initialization entirely, under the theory that machines that trap on PMP accesses must allow memory accesses as otherwise they're pretty useless. Signed-off-by: Palmer Dabbelt Tested-by: Damien Le Moal Reviewed-by: Damien Le Moal --- arch/riscv/kernel/head.S | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index 98a406474e7d..7ed1b22950fd 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -161,11 +161,20 @@ ENTRY(_start_kernel) /* Reset all registers except ra, a0, a1 */ call reset_regs - /* Setup a PMP to permit access to all of memory. */ + /* + * Setup a PMP to permit access to all of memory. Some machines may + * not implement PMPs, so we set up a quick trap handler to just skip + * touching the PMPs on any trap. + */ + la a0, pmp_done + csrw CSR_TVEC, a0 + li a0, -1 csrw CSR_PMPADDR0, a0 li a0, (PMP_A_NAPOT | PMP_R | PMP_W | PMP_X) csrw CSR_PMPCFG0, a0 +.align 2 +pmp_done: /* * The hartid in a0 is expected later on, and we have no firmware