From nobody Mon Feb 9 10:30:02 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1579724681; cv=none; d=zohomail.com; s=zohoarc; b=cZQLE7pkCcjMLuUB9WxWUbEN7lHwCqvTDVl+VJ0KbpJMQX3xvLRKVU0YkSPiAbWCD615SVctHj1KTEUaErVg9y6/wbBrPg3My7y1dcEgcJnc5+hjuV3O7uccz+DSM/wN1XLJ1J6APqnvlfA6j153WgOJm2mdArhYfR/3WSutdzU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579724681; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=F8pwDcX3NUQPCqUCFZDGZlO8uNUP/20S/WCnPhA/TSg=; b=OrxmHPAd4ggfre9AI5YmKRBeYzZCki6rEaZwjcNYZu9fSFDSoVvJxE5RAYhd/9CuzewAZjZS+DP289K2LpnZtkUtthMyq/iLhcyYnNDQxKcdc8QF+jc795Wh7lLAcWDGDJsSva2GYv+3rqReVMb+ZEJGKlabOuCBEZ3dodaLez4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1579724681963230.85730448799416; Wed, 22 Jan 2020 12:24:41 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuMXj-0006GK-Qw; Wed, 22 Jan 2020 20:24:03 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuMXi-0006G6-Va for xen-devel@lists.xenproject.org; Wed, 22 Jan 2020 20:24:02 +0000 Received: from mail-wr1-x441.google.com (unknown [2a00:1450:4864:20::441]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 19d23cd6-3d55-11ea-aecd-bc764e2007e4; Wed, 22 Jan 2020 20:23:50 +0000 (UTC) Received: by mail-wr1-x441.google.com with SMTP id c14so492018wrn.7 for ; Wed, 22 Jan 2020 12:23:50 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id r6sm60267992wrq.92.2020.01.22.12.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 12:23:48 -0800 (PST) X-Inumbo-ID: 19d23cd6-3d55-11ea-aecd-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Wshk7kIRKYuRU8xqobkC9+OQZAACVFBRhKVgA/3wfFw=; b=J5O9J+CgE4hZYtJENBevnbiBydhRlnUT3xMQPNmYXrqZ+y9OM+j6+WjMqD/68GV4Du n2f+vd5inClc2vv7xFhjaww3Bdb/nKK5cXBWCjSuZZIjAqmtvHq9cuCFFL1V1Irzi7e2 qZHKOOTwa0XbwN2JrdVdyLfjsYJh2FPONDyapiEmSO3UdKZGhngkqaPkrlllMV7/WTig Gk+Lt07h4X8hoCxkta7qtA6PefbhtHM1V8AEzBnXYjr682zwVguPxsWYOaxRJNDhclEW wJbt5TFc39x2Xx1ZbgvTI567nBE/l1PE3qp6gCY+hXDRGJCvaEAJcybIy+nKOSwPpilk qhZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Wshk7kIRKYuRU8xqobkC9+OQZAACVFBRhKVgA/3wfFw=; b=ctZ2eGeaLKIoHhqmek9KwtZ3WWhxvyDrvVrrp7E1CAiDyad0jHtBtoIMoNWgCPMihm aBaW4wnDn8BoKSWDJMOGpeqb8bkkiZuRpewXZp7PyTANJnpNzdcSi+yLufMAbSY6J9i5 5LRALpGF7mF5LU+iOSR3Pd+IUslyelhKZUe+21r2Bx8p+BcgkQXU8rlNvURaLoxIMjuK zN6ONsXhFsBK0hidU9Tf1PqCLAaddROLj4zQhgFA+Gie6foWWSrSABYlmskMeZbZiPxS ALcyBSvUqWPAPju6gHbzbB/M4GAGmdDISA6buUso3vkR/OK1Mv4LBM4W+k1DBn9mJRDi RnNg== X-Gm-Message-State: APjAAAVwKQjFy1lEH3g82U385SJhUw8k2Q8wZvP2yoW/uvcp9TvCWDsj qYULjpvKC0L2hMeRom3lHQ2zjlOfURX2AA== X-Google-Smtp-Source: APXvYqycE4F2unuKVNHoENJxRXm3fAuztRCfAPQgiw8xoMEXya576SqK4vk4adWIBQHERmRGHw6DPw== X-Received: by 2002:adf:ed83:: with SMTP id c3mr12699225wro.51.1579724629260; Wed, 22 Jan 2020 12:23:49 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 22 Jan 2020 20:23:39 +0000 Message-Id: <20200122202343.5703-4-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200122202343.5703-1-liuwe@microsoft.com> References: <20200122202343.5703-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 3/7] x86/hyperv: provide Hyper-V hypercall functions X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Paul Durrant , Andrew Cooper , Michael Kelley , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) These functions will be used later to make hypercalls to Hyper-V. Signed-off-by: Wei Liu --- v4: 1. Adjust code due to previous patch has changed 2. Address comments --- xen/include/asm-x86/guest/hyperv-hcall.h | 98 ++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 xen/include/asm-x86/guest/hyperv-hcall.h diff --git a/xen/include/asm-x86/guest/hyperv-hcall.h b/xen/include/asm-x86= /guest/hyperv-hcall.h new file mode 100644 index 0000000000..509e57f481 --- /dev/null +++ b/xen/include/asm-x86/guest/hyperv-hcall.h @@ -0,0 +1,98 @@ +/*************************************************************************= ***** + * asm-x86/guest/hyperv-hcall.h + * + * This program is free software; you can redistribute it and/or + * modify it under the terms and conditions of the GNU General Public + * License, version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; If not, see . + * + * Copyright (c) 2019 Microsoft. + */ + +#ifndef __X86_HYPERV_HCALL_H__ +#define __X86_HYPERV_HCALL_H__ + +#include +#include + +#include +#include +#include +#include + +static inline uint64_t hv_do_hypercall(uint64_t control, paddr_t input_add= r, + paddr_t output_addr) +{ + uint64_t status; + register unsigned long r8 asm("r8") =3D output_addr; + + asm volatile ("INDIRECT_CALL %P[hcall_page]" + : "=3Da" (status), "+c" (control), + "+d" (input_addr) ASM_CALL_CONSTRAINT + : "r" (r8), + [hcall_page] "p" (fix_x_to_virt(FIX_X_HYPERV_HCALL)) + : "memory"); + + return status; +} + +static inline uint64_t hv_do_fast_hypercall(uint16_t code, + uint64_t input1, uint64_t inpu= t2) +{ + uint64_t status; + uint64_t control =3D code | HV_HYPERCALL_FAST_BIT; + register unsigned long r8 asm("r8") =3D input2; + + asm volatile ("INDIRECT_CALL %P[hcall_page]" + : "=3Da" (status), "+c" (control), + "+d" (input1) ASM_CALL_CONSTRAINT + : "r" (r8), + [hcall_page] "p" (fix_x_to_virt(FIX_X_HYPERV_HCALL)) + :); + + return status; +} + +static inline uint64_t hv_do_rep_hypercall(uint16_t code, uint16_t rep_cou= nt, + uint16_t varhead_size, + paddr_t input, paddr_t output) +{ + uint64_t control =3D code; + uint64_t status; + uint16_t rep_comp; + + control |=3D (uint64_t)varhead_size << HV_HYPERCALL_VARHEAD_OFFSET; + control |=3D (uint64_t)rep_count << HV_HYPERCALL_REP_COMP_OFFSET; + + do { + status =3D hv_do_hypercall(control, input, output); + if ( (status & HV_HYPERCALL_RESULT_MASK) !=3D HV_STATUS_SUCCESS ) + break; + + rep_comp =3D MASK_EXTR(status, HV_HYPERCALL_REP_COMP_MASK); + + control &=3D ~HV_HYPERCALL_REP_START_MASK; + control |=3D MASK_INSR(rep_comp, HV_HYPERCALL_REP_COMP_MASK); + } while ( rep_comp < rep_count ); + + return status; +} + +#endif /* __X86_HYPERV_HCALL_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel