Received: by 2002:a17:90a:b81:0:0:0:0 with SMTP id 1csp5002365pjr; Mon, 26 Aug 2019 16:36:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqwFrI2HtY81iIlDRb2axpz9eYS9Iq9Cto3ujhUcU02l7wmLkATwQKr9ZVKIqYpoEFQIl5hv X-Received: by 2002:aa7:85cd:: with SMTP id z13mr23394951pfn.214.1566862615198; Mon, 26 Aug 2019 16:36:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566862615; cv=none; d=google.com; s=arc-20160816; b=Zs8cNbmS+Dzu0hkx7vfp/F42exXHjx9K/RkzsFavnRsk2DbpvpVOTLk+SN/YgNcrjt t1V95+W+go9MSzBY6g9RShx3vlHlS4WWObGhNIJWvW2eJgu/E+IXruHP1TrWY1/HIAx5 rQPCTavr+ioA1+lFtNzkD3QBhuLOieZORFVMqWUlVRb236svP6h9QiQa7ak8jRaStRjF i1HtuSbrz/pzF6y/0t2E0g2XaW05RLitChlTk2eSTG9gvpzgD33zpEj5umWZym1ny10D q38GgLO3UYdEkKd13haREIjriHoUlIJ17ILfJjWXhiXodjV5nlJdhklyv2xaI9q/wGJ5 bM1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :wdcironportexception:ironport-sdr:ironport-sdr:ironport-sdr :dkim-signature; bh=ed3DG8BNl0KAVweIIqwwTi6U7kkq1aKY+1b7dPcjSz8=; b=DQY8qgCcEJ5VBsGg0TIJ7qG9VkSq3tUK5pPYfMpuzQMde+L66qp7tSvyI3nQgUi9rk FQvsQyP8gg0ixPnW7zw7kbG8ojQtiMAepT56VuKEyFC7wKlbF7OhquANk5ELU52beYPO Go5aSoLSkO3Z/IofhA71YasFWY0y+jedNtP3hdJ39RCjYeKy76BbAAYZvFQj2fEBl7sx ytYrIjVwBOjHPxzNGfEtghPlVoyjWQsF1HnuLS68X+2pW2wLPJ+jLlUeWoiIuMAWHNae JSRCv3YhH52Zyt+OHDPSFOl0ABNa+7IdtSvVj05/GTidN0DmrSzO0lCjl6UbB0er+zA9 ezlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b="MLBZ/IPL"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3si11504593plv.19.2019.08.26.16.36.39; Mon, 26 Aug 2019 16:36:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b="MLBZ/IPL"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728236AbfHZXdh (ORCPT + 99 others); Mon, 26 Aug 2019 19:33:37 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:61044 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727797AbfHZXd2 (ORCPT ); Mon, 26 Aug 2019 19:33:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1566862408; x=1598398408; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NOwAjvHbcc50rcpd47uuWkr60xMZSOcYkQr+KzmxZ80=; b=MLBZ/IPL7Gkjb9LGAdLXZ3Ib5JuM2o+BbwUJbr2ls+Fzlw2rfOdzutCz DI0ycc6dljTXfeS1cqt7AOi9RuM3t8LgCPrPLxtPHEd/ba85boUpZ20jL d6NMyj+O9CudG8ygxiY6ji7nuY6AA6coIF0nFq5YwsXWCmNZOcLRBAiEH 0DFronMUaxlFyAq8eV1pM6ihIkB//rv4RJ5EKTdXN1DSkuhUqAX/QWWsR IhEqocukX3TFB+VA0lrbQodtSmzT0r0l8FAQTAAtS5jhIby0NycvQGDIT NIwAt7D7/O/uYyKvYEdYb+3UvNwdq7f866Am+bZg3hwW1iqMYa+YZFBqZ g==; IronPort-SDR: IUgWkJTWG0MkqUZsCYWqjnXEsqwmDX84fh6Cs/poMQ5vC7L1rbryv2CgRzl4YUO1d09yNEfL4w O/XbiyF0hTWw7OcpmQhtQFJNECPVixFxPxSwOt6550iTcx4iWskx9Z003cvs4LhnU2qmt5Mnj2 dgUN8c0H4B021NhW4cFZ5Q4our/2qoT9xAf3i1Tu39U2Tx+ALKaThl1lgyewf84gWJyP3R7/er 0rXUtWX1xLVPp2+IuMh/1xV8sEbHSoz4Is242FTnUhRq5fdBJcJikG6/BxB9ZF+94iGsC4pxIV VJk= X-IronPort-AV: E=Sophos;i="5.64,435,1559491200"; d="scan'208";a="116718028" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 27 Aug 2019 07:33:27 +0800 IronPort-SDR: IeChZIITFe937Q0rew7gIOLNGyg0EbTvq9fOLNYRx6FS7lOlLY7riwlXPTLK+ygdwLxQCSGq9x 7tCNH0xZX+DvcHg9TELGFsmbgm+S8xNyxhi5trC6V6r3Uc3mQoW5EusY1fTNgi4rq2ClqGhIsT mPKg1WC5kzgZ+ukDyTL+iHJewasAJTfGNrdg74pS8HI22j/M31Z+b2qdd66iTMonsSBxe61rBg dLPMALE0TVNSDyv0udX2jXMdoeyV23TupGXZwDlyM2t18tdWVbttg75VXzKM4DV4hBk+BYdWZT Kjc+zrlG3DY/kXfazgW7mdIc Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2019 16:30:39 -0700 IronPort-SDR: URb8pJMR4ETxv6cJze0dd43lyc6gWQ1YGQRs+0YiVLlUBxpzdCKr2LwKae90PTni5TRqxUTGWj t64IroRNYC4XBYZ25n3+7ajzg5mogFRIPhu98SnXStyODOakhjf/LdyzgjPcjSiNzyew1N2ErJ VyQDtBY9tMq75Q8RvvW3XlPzsbZdg4Ys30gxHzSyVEFukSB6gUhT/Dtaz+sGSkvpVL8EbzT740 6x0kWk/UW5UGrarLDnnCU08k2zhv/Y6XK3XLlvL2ShkRllwDg+F02/lpd5X+EHRKIyklmYu8tK umA= WDCIronportException: Internal Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip01.wdc.com with ESMTP; 26 Aug 2019 16:33:28 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Alan Kao , Albert Ou , Alexios Zavras , Anup Patel , Gary Guo , Greg Kroah-Hartman , linux-riscv@lists.infradead.org, Mike Rapoport , Palmer Dabbelt , Paul Walmsley , Thomas Gleixner Subject: [RFC PATCH 2/2] RISC-V: Add basic support for SBI v0.2 Date: Mon, 26 Aug 2019 16:32:56 -0700 Message-Id: <20190826233256.32383-3-atish.patra@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190826233256.32383-1-atish.patra@wdc.com> References: <20190826233256.32383-1-atish.patra@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The SBI v0.2 introduces a base extension which is backward compatible with v0.1. Implement all helper functions and minimum required SBI calls from v0.2 for now. All other base extension function will be added later as per need. Signed-off-by: Atish Patra --- arch/riscv/include/asm/sbi.h | 68 +++++++++++++++++++++++++++++------- arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/sbi.c | 50 ++++++++++++++++++++++++++ arch/riscv/kernel/setup.c | 2 ++ 4 files changed, 108 insertions(+), 13 deletions(-) create mode 100644 arch/riscv/kernel/sbi.c diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 7f5ecaaaa0d7..4a4476956693 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -8,7 +8,6 @@ #include - #define SBI_EXT_LEGACY_SET_TIMER 0x0 #define SBI_EXT_LEGACY_CONSOLE_PUTCHAR 0x1 #define SBI_EXT_LEGACY_CONSOLE_GETCHAR 0x2 @@ -19,28 +18,61 @@ #define SBI_EXT_LEGACY_REMOTE_SFENCE_VMA_ASID 0x7 #define SBI_EXT_LEGACY_SHUTDOWN 0x8 -#define SBI_CALL_LEGACY(which, arg0, arg1, arg2, arg3) ({ \ +#define SBI_EXT_BASE 0x10 + +enum sbi_ext_base_fid { + SBI_EXT_BASE_GET_SPEC_VERSION = 0, + SBI_EXT_BASE_GET_IMP_ID, + SBI_EXT_BASE_GET_IMP_VERSION, + SBI_EXT_BASE_PROBE_EXT, + SBI_EXT_BASE_GET_MVENDORID, + SBI_EXT_BASE_GET_MARCHID, + SBI_EXT_BASE_GET_MIMPID, +}; + +#define SBI_CALL_LEGACY(ext, fid, arg0, arg1, arg2, arg3) ({ \ register uintptr_t a0 asm ("a0") = (uintptr_t)(arg0); \ register uintptr_t a1 asm ("a1") = (uintptr_t)(arg1); \ register uintptr_t a2 asm ("a2") = (uintptr_t)(arg2); \ register uintptr_t a3 asm ("a3") = (uintptr_t)(arg3); \ - register uintptr_t a7 asm ("a7") = (uintptr_t)(which); \ + register uintptr_t a6 asm ("a6") = (uintptr_t)(fid); \ + register uintptr_t a7 asm ("a7") = (uintptr_t)(ext); \ asm volatile ("ecall" \ - : "+r" (a0) \ - : "r" (a1), "r" (a2), "r" (a3), "r" (a7) \ + : "+r" (a0), "+r" (a1) \ + : "r" (a2), "r" (a3), "r" (a6), "r" (a7) \ : "memory"); \ a0; \ }) /* Lazy implementations until SBI is finalized */ -#define SBI_CALL_LEGACY_0(which) SBI_CALL_LEGACY(which, 0, 0, 0, 0) -#define SBI_CALL_LEGACY_1(which, arg0) SBI_CALL_LEGACY(which, arg0, 0, 0, 0) -#define SBI_CALL_LEGACY_2(which, arg0, arg1) \ - SBI_CALL_LEGACY(which, arg0, arg1, 0, 0) -#define SBI_CALL_LEGACY_3(which, arg0, arg1, arg2) \ - SBI_CALL_LEGACY(which, arg0, arg1, arg2, 0) -#define SBI_CALL_LEGACY_4(which, arg0, arg1, arg2, arg3) \ - SBI_CALL_LEGACY(which, arg0, arg1, arg2, arg3) +#define SBI_CALL_LEGACY_0(ext) SBI_CALL_LEGACY(ext, 0, 0, 0, 0, 0) +#define SBI_CALL_LEGACY_1(ext, arg0) SBI_CALL_LEGACY(ext, 0, arg0, 0, 0, 0) +#define SBI_CALL_LEGACY_2(ext, arg0, arg1) \ + SBI_CALL_LEGACY(ext, 0, arg0, arg1, 0, 0) +#define SBI_CALL_LEGACY_3(ext, arg0, arg1, arg2) \ + SBI_CALL_LEGACY(ext, 0, arg0, arg1, arg2, 0) +#define SBI_CALL_LEGACY_4(ext, arg0, arg1, arg2, arg3) \ + SBI_CALL_LEGACY(ext, 0, arg0, arg1, arg2, arg3) + +extern unsigned long sbi_firmware_version; +struct sbiret { + long error; + long value; +}; + +void riscv_sbi_init(void); +struct sbiret riscv_sbi_ecall(int ext, int fid, int arg0, int arg1, + int arg2, int arg3); + +#define SBI_CALL_0(ext, fid) riscv_sbi_ecall(ext, fid, 0, 0, 0, 0) +#define SBI_CALL_1(ext, fid, arg0) riscv_sbi_ecall(ext, fid, arg0, 0, 0, 0) +#define SBI_CALL_2(ext, fid, arg0, arg1) \ + riscv_sbi_ecall(ext, fid, arg0, arg1, 0, 0) +#define SBI_CALL_3(ext, fid, arg0, arg1, arg2) \ + riscv_sbi_ecall(ext, fid, arg0, arg1, arg2, 0) +#define SBI_CALL_4(ext, fid, arg0, arg1, arg2, arg3) \ + riscv_sbi_ecall(ext, fid, arg0, arg1, arg2, arg3) + static inline void sbi_console_putchar(int ch) { @@ -99,4 +131,14 @@ static inline void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, start, size, asid); } +static inline unsigned long riscv_sbi_major_version(void) +{ + return (sbi_firmware_version >> 24) & 0x7f; +} + +static inline unsigned long riscv_sbi_minor_version(void) +{ + return sbi_firmware_version & 0xffffff; +} + #endif diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile index 2420d37d96de..faf862d26924 100644 --- a/arch/riscv/kernel/Makefile +++ b/arch/riscv/kernel/Makefile @@ -17,6 +17,7 @@ obj-y += irq.o obj-y += process.o obj-y += ptrace.o obj-y += reset.o +obj-y += sbi.o obj-y += setup.o obj-y += signal.o obj-y += syscall_table.o diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c new file mode 100644 index 000000000000..457b8cc0e9d9 --- /dev/null +++ b/arch/riscv/kernel/sbi.c @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * SBI initialilization and base extension implementation. + * + * Copyright (c) 2019 Western Digital Corporation or its affiliates. + */ + +#include +#include + +unsigned long sbi_firmware_version; + +struct sbiret riscv_sbi_ecall(int ext, int fid, int arg0, int arg1, + int arg2, int arg3) +{ + struct sbiret ret; + + register uintptr_t a0 asm ("a0") = (uintptr_t)(arg0); + register uintptr_t a1 asm ("a1") = (uintptr_t)(arg1); + register uintptr_t a2 asm ("a2") = (uintptr_t)(arg2); + register uintptr_t a3 asm ("a3") = (uintptr_t)(arg3); + register uintptr_t a6 asm ("a6") = (uintptr_t)(fid); + register uintptr_t a7 asm ("a7") = (uintptr_t)(ext); + asm volatile ("ecall" + : "+r" (a0), "+r" (a1) + : "r" (a2), "r" (a3), "r" (a6), "r" (a7) + : "memory"); + ret.error = a0; + ret.value = a1; + + return ret; +} + +static struct sbiret sbi_get_spec_version(void) +{ + return SBI_CALL_0(SBI_EXT_BASE, SBI_EXT_BASE_GET_SPEC_VERSION); +} + +void riscv_sbi_init(void) +{ + struct sbiret ret; + + /* legacy SBI version*/ + sbi_firmware_version = 0x1; + ret = sbi_get_spec_version(); + if (!ret.error) + sbi_firmware_version = ret.value; + pr_info("SBI version implemented in firmware [%lu:%lu]\n", + riscv_sbi_major_version(), riscv_sbi_minor_version()); +} diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index a990a6cb184f..4c324fd398c8 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -70,6 +71,7 @@ void __init setup_arch(char **cmdline_p) swiotlb_init(1); #endif + riscv_sbi_init(); #ifdef CONFIG_SMP setup_smp(); #endif -- 2.21.0