Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1947305ybn; Thu, 26 Sep 2019 04:47:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqw9GvNucCmV4BTUPpxSQpnCEFW17qD6s5jS0FxMMvOVNNy9h6kxpX6wKRPh/Ht9Nd/SeQia X-Received: by 2002:a05:6402:128c:: with SMTP id w12mr3074953edv.158.1569498432795; Thu, 26 Sep 2019 04:47:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569498432; cv=none; d=google.com; s=arc-20160816; b=w/p43U4pyY6iniulouL4QN33D93uWrUGHxMxz8M9PXcrbRIDYUj/PDFuwemkWEliZ7 2ZME3HHAi2+vACdswU3H8TZg+ABll05vTvPt6BjymTlgvpy518alFrb2Hglr6qRtElDs J6UFccaobmFH73f3rR1O1+1NCyRVrltOm8HcssaqpEScOEzhGdjIZO2MwjZeZiWrfpSV i4KexiVWtm92ndI+z6j6FatCR9K8g9sG8e2Ff2ZBJUmd3z6R1GZsIO0A3ib7W5f8YTIB Oq12hHrQHhSLMt2QRiErVMdlJaZ+1jBGTEuzlksn1UIe36PiClTSzixg7w0RPyG1JOPg Pt5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=s2lc6uSXIc0lC9bDA29+fnlBJoA0AhQajGNVBvHvsOk=; b=BRi8ddDEa5S7gjWupwbGnMXcR0Vzo/Q4DTJmxkUcHkNchpot++4O6HeLiI9QJlrXa9 I3rzp5mnTo/4XACfOcjSsObolQFvUl11V73iYq0FW/wmtOwwEm6yUslyb6lRkISnZQSe t7rHopB44mxLobF62G9H1zZ2y0cSebsHfy+/tRfg4wXRK9q2KcxvGooBNAszkDbpGbyN jDuKBvpOGEb4yyYMvJsZhY08upI5P16DXdROGRwdUDeHWRBGghkbEzkzsBQVnCn52xAZ 9EXWzYTj6rEsJrp65pZ1z5OwcQ0y0AiFAFSkXRWdP7nOEPIFA3qZKswG27U58Y/M/dYv A0cg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g19si829553ejj.120.2019.09.26.04.46.48; Thu, 26 Sep 2019 04:47:12 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726605AbfIZLmk (ORCPT + 99 others); Thu, 26 Sep 2019 07:42:40 -0400 Received: from foss.arm.com ([217.140.110.172]:47122 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726463AbfIZLmj (ORCPT ); Thu, 26 Sep 2019 07:42:39 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8954F142F; Thu, 26 Sep 2019 04:42:38 -0700 (PDT) Received: from entos-d05.shanghai.arm.com (entos-d05.shanghai.arm.com [10.169.40.35]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id EE0D73F67D; Thu, 26 Sep 2019 04:42:33 -0700 (PDT) From: Jianyong Wu To: netdev@vger.kernel.org, yangbo.lu@nxp.com, john.stultz@linaro.org, tglx@linutronix.de, pbonzini@redhat.com, sean.j.christopherson@intel.com, maz@kernel.org, richardcochran@gmail.com, Mark.Rutland@arm.com, Will.Deacon@arm.com, suzuki.poulose@arm.com Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, Steve.Capper@arm.com, Kaly.Xin@arm.com, justin.he@arm.com, jianyong.wu@arm.com, nd@arm.com Subject: [RFC PATCH v4 3/5] psci: Add hvc call service for ptp_kvm. Date: Thu, 26 Sep 2019 19:42:10 +0800 Message-Id: <20190926114212.5322-4-jianyong.wu@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190926114212.5322-1-jianyong.wu@arm.com> References: <20190926114212.5322-1-jianyong.wu@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch is the base of ptp_kvm for arm64. ptp_kvm modules will call hvc to get this service. The service offers real time and counter cycle of host for guest. Signed-off-by: Jianyong Wu --- include/linux/arm-smccc.h | 12 ++++++++++++ virt/kvm/arm/psci.c | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h index a6e4d3e3d10a..bc0cdad10f35 100644 --- a/include/linux/arm-smccc.h +++ b/include/linux/arm-smccc.h @@ -94,6 +94,7 @@ /* KVM "vendor specific" services */ #define ARM_SMCCC_KVM_FUNC_FEATURES 0 +#define ARM_SMCCC_KVM_PTP 1 #define ARM_SMCCC_KVM_FUNC_FEATURES_2 127 #define ARM_SMCCC_KVM_NUM_FUNCS 128 @@ -103,6 +104,17 @@ ARM_SMCCC_OWNER_VENDOR_HYP, \ ARM_SMCCC_KVM_FUNC_FEATURES) +/* + * This ID used for virtual ptp kvm clock and it will pass second value + * and nanosecond value of host real time and system counter by vcpu + * register to guest. + */ +#define ARM_SMCCC_VENDOR_HYP_KVM_PTP_FUNC_ID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + ARM_SMCCC_OWNER_VENDOR_HYP, \ + ARM_SMCCC_KVM_PTP) + #ifndef __ASSEMBLY__ #include diff --git a/virt/kvm/arm/psci.c b/virt/kvm/arm/psci.c index 0debf49bf259..3f30fc42a5ca 100644 --- a/virt/kvm/arm/psci.c +++ b/virt/kvm/arm/psci.c @@ -392,6 +392,8 @@ int kvm_hvc_call_handler(struct kvm_vcpu *vcpu) u32 func_id = smccc_get_function(vcpu); u32 val[4] = {}; u32 option; + u64 cycles; + struct system_time_snapshot systime_snapshot; val[0] = SMCCC_RET_NOT_SUPPORTED; @@ -431,6 +433,22 @@ int kvm_hvc_call_handler(struct kvm_vcpu *vcpu) case ARM_SMCCC_VENDOR_HYP_KVM_FEATURES_FUNC_ID: val[0] = BIT(ARM_SMCCC_KVM_FUNC_FEATURES); break; + /* + * This will used for virtual ptp kvm clock. three + * values will be passed back. + * reg0 stores high 32-bit host ktime; + * reg1 stores low 32-bit host ktime; + * reg2 stores high 32-bit difference of host cycles and cntvoff; + * reg3 stores low 32-bit difference of host cycles and cntvoff. + */ + case ARM_SMCCC_VENDOR_HYP_KVM_PTP_FUNC_ID: + ktime_get_snapshot(&systime_snapshot); + val[0] = systime_snapshot.real >> 32; + val[1] = systime_snapshot.real << 32 >> 32; + cycles = systime_snapshot.cycles - vcpu_vtimer(vcpu)->cntvoff; + val[2] = cycles >> 32; + val[3] = cycles << 32 >> 32; + break; default: return kvm_psci_call(vcpu); } -- 2.17.1