Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp5133262rwb; Mon, 31 Jul 2023 19:20:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlHSWMZzpgwQrRBM498l8r9jbtE+u8yELw92oWC80hBiMf6bVjjt2nDxLktK0GY3YwUrQAU7 X-Received: by 2002:a05:620a:4549:b0:76c:b7f0:2b97 with SMTP id u9-20020a05620a454900b0076cb7f02b97mr3903804qkp.71.1690856438970; Mon, 31 Jul 2023 19:20:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690856438; cv=none; d=google.com; s=arc-20160816; b=Moolu/lOS6MNlE5oaKS7m/OwBAmoedc/vjxzW6fdk3sniTS16uiBbzpsfrK7rjU3sm DhznOyYNp91JiGshO+AT5be3zQramgW0+Xpr6MDaKs3RO6NGRoqReVDbbSTGAXngq5e8 dRdXTeKXVP51zT6K9P73EFrtJ7c+8tDbzUOkIQjk4c0ajIcwM1CVKXM6qJVSt1kwRHDc z9KUhFE4o2s1BEfc7Hf3/zro9koMetWfvwmejKjA2yaxBHypFzDcSv++VSQM1BCiBO3e e5Jbr3dilYZzwZC6eLYtExQc/NAiuLN8AF/c1K1PC7xokk49yDJppWoPiIOche0H29sy U0gQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=+bklc/Cf2hycZlJSSx3KO+PLJr+gczvHk0dds8ggwHU=; fh=78XkdsmXgGpMLEUd4018w1oFMTvg8nay2829+Tm9pTc=; b=sI8pJ9H962Jp0x2z759c8n0eezgUS1vhtbHxZWCg34vAy2zlKYyZ0KlFKFiucckT/7 0t+2rLyi2KzszG0cOZQcIedWoIzlTJZD08tYs6VXkdgU+CU9uPc0CK5c0Zj94rSTYoFM jBiRNL2Aqw8KSaN+sIRw/M0md/gEpcQ3qyo6HycMUOeVnGb/RpxQfbJcBxkshIHhnAkt LmVohCR3G0cqVIQrdQlyQCLAiglsY0UDBiyJ1nSmhiCRMeMrrX1h8zelNwTfx3wfY8bG CL9WvYk5Xgbas8bmlv8qyP05PjQwMEGUYKqhnXIya/q40XVJyqWzY+34jRHfYcbY5usr b3hg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d1-20020a056a0024c100b00686dd813934si8343292pfv.82.2023.07.31.19.20.26; Mon, 31 Jul 2023 19:20:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231769AbjHACCQ (ORCPT + 99 others); Mon, 31 Jul 2023 22:02:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230017AbjHACCL (ORCPT ); Mon, 31 Jul 2023 22:02:11 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4A4EC116; Mon, 31 Jul 2023 19:02:09 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8BxpPCfZ8hkIMgNAA--.32699S3; Tue, 01 Aug 2023 10:02:07 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxHCOeZ8hkPHJDAA--.25753S3; Tue, 01 Aug 2023 10:02:07 +0800 (CST) From: Tianrui Zhao To: Shuah Khan , Paolo Bonzini , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Vishal Annapurve , Huacai Chen , WANG Xuerui , loongarch@lists.linux.dev, Peter Xu , Vipin Sharma , maobibo@loongson.cn, zhaotianrui@loongson.cn Subject: [PATCH v1 1/4] selftests: kvm: Add kvm selftests header files for LoongArch Date: Tue, 1 Aug 2023 10:02:03 +0800 Message-Id: <20230801020206.1957986-2-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230801020206.1957986-1-zhaotianrui@loongson.cn> References: <20230801020206.1957986-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8BxHCOeZ8hkPHJDAA--.25753S3 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add kvm selftests header files for LoongArch, including processor.h, sysreg.h, and kvm_util_base.h. Those mainly contain LoongArch CSR register defines and page table information. Based-on: <20230720062813.4126751-1-zhaotianrui@loongson.cn> Signed-off-by: Tianrui Zhao --- .../selftests/kvm/include/kvm_util_base.h | 5 ++ .../kvm/include/loongarch/processor.h | 28 ++++++ .../selftests/kvm/include/loongarch/sysreg.h | 89 +++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 tools/testing/selftests/kvm/include/loongarch/processor.h create mode 100644 tools/testing/selftests/kvm/include/loongarch/sysreg.h diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index 07732a157ccd..8747127e0bab 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -197,6 +197,11 @@ extern enum vm_guest_mode vm_mode_default; #define MIN_PAGE_SHIFT 12U #define ptes_per_page(page_size) ((page_size) / 8) +#elif defined(__loongarch__) +#define VM_MODE_DEFAULT VM_MODE_P36V47_16K +#define MIN_PAGE_SHIFT 14U +#define ptes_per_page(page_size) ((page_size) / 8) + #endif #define MIN_PAGE_SIZE (1U << MIN_PAGE_SHIFT) diff --git a/tools/testing/selftests/kvm/include/loongarch/processor.h b/tools/testing/selftests/kvm/include/loongarch/processor.h new file mode 100644 index 000000000000..d67796af51a0 --- /dev/null +++ b/tools/testing/selftests/kvm/include/loongarch/processor.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * LoongArch processor specific defines + */ +#ifndef SELFTEST_KVM_PROCESSOR_H +#define SELFTEST_KVM_PROCESSOR_H + +#include +#define _PAGE_VALID_SHIFT 0 +#define _PAGE_DIRTY_SHIFT 1 +#define _PAGE_PLV_SHIFT 2 /* 2~3, two bits */ +#define _CACHE_SHIFT 4 /* 4~5, two bits */ +#define _PAGE_PRESENT_SHIFT 7 +#define _PAGE_WRITE_SHIFT 8 + +#define PLV_KERN 0 +#define PLV_USER 3 +#define PLV_MASK 0x3 + +#define _PAGE_VALID (0x1UL << _PAGE_VALID_SHIFT) +#define _PAGE_PRESENT (0x1UL << _PAGE_PRESENT_SHIFT) +#define _PAGE_WRITE (0x1UL << _PAGE_WRITE_SHIFT) +#define _PAGE_DIRTY (0x1UL << _PAGE_DIRTY_SHIFT) +#define _PAGE_USER (PLV_USER << _PAGE_PLV_SHIFT) +#define __READABLE (_PAGE_VALID) +#define __WRITEABLE (_PAGE_DIRTY | _PAGE_WRITE) +#define _CACHE_CC (0x1UL << _CACHE_SHIFT) /* Coherent Cached */ +#endif diff --git a/tools/testing/selftests/kvm/include/loongarch/sysreg.h b/tools/testing/selftests/kvm/include/loongarch/sysreg.h new file mode 100644 index 000000000000..04f53674c9d8 --- /dev/null +++ b/tools/testing/selftests/kvm/include/loongarch/sysreg.h @@ -0,0 +1,89 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef SELFTEST_KVM_SYSREG_H +#define SELFTEST_KVM_SYSREG_H + +/* + * note that this declaration raises a checkpatch warning, but + * no good way to avoid it. + */ +#define zero $r0 +#define ra $r1 +#define tp $r2 +#define sp $r3 +#define a0 $r4 +#define a1 $r5 +#define a2 $r6 +#define a3 $r7 +#define a4 $r8 +#define a5 $r9 +#define a6 $r10 +#define a7 $r11 +#define t0 $r12 +#define t1 $r13 +#define t2 $r14 +#define t3 $r15 +#define t4 $r16 +#define t5 $r17 +#define t6 $r18 +#define t7 $r19 +#define t8 $r20 +#define u0 $r21 +#define fp $r22 +#define s0 $r23 +#define s1 $r24 +#define s2 $r25 +#define s3 $r26 +#define s4 $r27 +#define s5 $r28 +#define s6 $r29 +#define s7 $r30 +#define s8 $r31 + +#define PS_4K 0x0000000c +#define PS_8K 0x0000000d +#define PS_16K 0x0000000e +#define PS_DEFAULT_SIZE PS_16K + +/* Basic CSR registers */ +#define LOONGARCH_CSR_CRMD 0x0 /* Current mode info */ +#define CSR_CRMD_PG_SHIFT 4 +#define CSR_CRMD_PG (0x1UL << CSR_CRMD_PG_SHIFT) +#define CSR_CRMD_IE_SHIFT 2 +#define CSR_CRMD_IE (0x1UL << CSR_CRMD_IE_SHIFT) +#define CSR_CRMD_PLV_SHIFT 0 +#define CSR_CRMD_PLV_WIDTH 2 +#define CSR_CRMD_PLV (0x3UL << CSR_CRMD_PLV_SHIFT) +#define PLV_MASK 0x3 + +#define LOONGARCH_CSR_PRMD 0x1 +#define LOONGARCH_CSR_EUEN 0x2 +#define LOONGARCH_CSR_ECFG 0x4 +#define LOONGARCH_CSR_EENTRY 0xc +#define LOONGARCH_CSR_TLBIDX 0x10 /* TLB Index, EHINV, PageSize, NP */ +#define CSR_TLBIDX_PS_SHIFT 24 +#define CSR_TLBIDX_PS_WIDTH 6 +#define CSR_TLBIDX_PS (0x3fUL << CSR_TLBIDX_PS_SHIFT) +#define CSR_TLBIDX_SIZEM 0x3f000000 +#define CSR_TLBIDX_SIZE CSR_TLBIDX_PS_SHIFT + +#define LOONGARCH_CSR_ASID 0x18 /* ASID */ +/* Page table base address when VA[VALEN-1] = 0 */ +#define LOONGARCH_CSR_PGDL 0x19 +/* Page table base address when VA[VALEN-1] = 1 */ +#define LOONGARCH_CSR_PGDH 0x1a +/* Page table base */ +#define LOONGARCH_CSR_PGD 0x1b +#define LOONGARCH_CSR_PWCTL0 0x1c +#define LOONGARCH_CSR_PWCTL1 0x1d +#define LOONGARCH_CSR_STLBPGSIZE 0x1e +#define LOONGARCH_CSR_CPUID 0x20 +#define LOONGARCH_CSR_TMID 0x40 +#define LOONGARCH_CSR_TCFG 0x41 +#define LOONGARCH_CSR_TLBRENTRY 0x88 /* TLB refill exception entry */ +/* KSave for TLB refill exception */ +#define LOONGARCH_CSR_TLBRSAVE 0x8b +#define LOONGARCH_CSR_TLBREHI 0x8e +#define CSR_TLBREHI_PS_SHIFT 0 +#define CSR_TLBREHI_PS (0x3fUL << CSR_TLBREHI_PS_SHIFT) + +#endif /* SELFTEST_KVM_SYSREG_H */ -- 2.39.1