Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp773894lqd; Wed, 24 Apr 2024 17:15:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW7FMmPUxG15DVuCS6Oob+pSdusnTOWiVEppdzE5crfoUgpLZtKjeeqdYmdNaooYmkS7KRrm3cAb0VOCvxY+O8Ijlf7ovr9tAkvcLyYOA== X-Google-Smtp-Source: AGHT+IHn3Sw3cL7lEAuklH5o0K6bBNqIeDtm4f4QvoLc6Jjrouxg1ybc2AIqthf0z7ZeV71GoWoX X-Received: by 2002:a17:90a:8d18:b0:2a2:adfc:6203 with SMTP id c24-20020a17090a8d1800b002a2adfc6203mr4765028pjo.8.1714004128654; Wed, 24 Apr 2024 17:15:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714004128; cv=pass; d=google.com; s=arc-20160816; b=dBvCEb6m/O3oDd9txD+8/7v7tFxwPljM/J9Xwu8DXYlqKhUclQ2vM7b5a0TvQTZtBA nShvfUR/0r2Rs+7d08taiamQsOsUyu5aK50H0KWCJGL72vQuoosiURAncjyfyifu+sLV SyEefDYRjQ31A2flrKPFbQJyflPfhjKVSX72kAlhMAxB1DDnkGq2XkvSVd1O60paeDag 0ikdmYB16kytFq7ynDcQVwqeZdtH4YIFFWtwjfFscaMLmvxhIMln0rXXNI+IT5qLDe1w EBzN2aZqMlPq+2DHjDyLzHBlZ2RulZbBWrUUtExnFr+rg9rJikPX7NMx5ZdPtRNbstiZ ebkA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=yW3rWzRu2U3mMza79f2YiFDKKLiYjn35V/dUh+fOfas=; fh=VnT+uWheY36Da2W5fbL53Yx6nMpGwJw9M6S68Twltig=; b=SJ2VKU/78XnfrAnBYKRpmHo5n0VXWHf31d4F3fBd29Jc6nN7mmHQ8XNvikzCSCGutZ R6T5UInXL5OdBfzyF8WAMfUkp1ZtVDlE8uc8IZgN7zhtN8kBVhycnIQn+0vB3JpX3zss gzatNkCrC4fDNmlGFmeCferrvVI9QCYQy8nLgrNfuNz38tAMqcY9vFZTeNbh1ZIgPvNh ajzj/dlb4l5K/JIXFZcQOkwSrrzb/3rvlC0ZnyOvPy8nc7QKb/q2AMtUMHncnhBo+gYX ujngCn9xSB4EX2PN6n4rM60Sn6r6ByOpQFQtpn+aT/rwnVh6OSwgE+XvgXnBQtButCi3 5BHg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=V6WKQAwp; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-157829-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157829-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id mh1-20020a17090b4ac100b002aec7be8162si3503676pjb.22.2024.04.24.17.15.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 17:15:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-157829-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=V6WKQAwp; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-157829-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157829-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id DD81BB2682E for ; Wed, 24 Apr 2024 23:15:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EAA8F16F0DF; Wed, 24 Apr 2024 23:14:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="V6WKQAwp" Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6373F16F0E9 for ; Wed, 24 Apr 2024 23:14:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714000472; cv=none; b=aB9cBLWM3Xikj+1jSD2AFSIfhdK0CryjNUsriwIym/32ysPo+nQPTCKN7/aKH6ZCU74dlFaJ3TdHLSty92sDxn8xq7GoNvV5KQ/C4KHRhDdIctTc4aF6z4u3IhLIwLTlgJOcVnC1Y4Anvgpi/1ETn2bUBaY1ifOnqazydjtxnUo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714000472; c=relaxed/simple; bh=RjqHHh8+OvvgHWX6skeosEzS4N2AwclxB9HYRka+bGI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gpgDIAzYCYLgJjNm6XpDHkjon4c9uj18YrxVqN4brhLn6Vg8WzsxiQGhDG4kJK7qWPH9bigS/HzFv6Gr0D0sEXXn4mxDPRAiuIIo5c+Vdc6RPVebkDkgEoLwkeAK71VWxdkBuHqm1kLOIMPMn+LKB5q0LS2p84/zx6qeJDpq6+4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=V6WKQAwp; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1e65a1370b7so3652945ad.3 for ; Wed, 24 Apr 2024 16:14:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1714000470; x=1714605270; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yW3rWzRu2U3mMza79f2YiFDKKLiYjn35V/dUh+fOfas=; b=V6WKQAwp44pm6l8lFwzXWMuvXTnpqtJVjYEmNEK4PgbJxXevetq0K6Z7r1xYaLSbO+ Lgi06LH3J3wUxwQu9VoFQtcfcmAElwWQSRvESKc6uo9AxKDaY2lxP2i/W3xosn8GIK2K Susknq3PgCubXRfj6MnYmTZRWuUHJ8A6HDVtU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714000470; x=1714605270; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yW3rWzRu2U3mMza79f2YiFDKKLiYjn35V/dUh+fOfas=; b=t6kVyX2Mgnw7z+iBr+nC7EmIb7Hx6stx9qnhNPjemU3DL6bdnyzrYt5IVC8D4RGwVB samajhNHuIlp4uYG6iEWU4COqFi0wmAeNcWY63cNXVEnlrCO5nqauxMxY+Rug7c7xEZg py0e88R6Wkxnreov2KpAWiYOBNDMOGHrbFqWWUYHwtlK4UGlWamcNsnw0sx5UYL3wOI+ YClc1+YGrFN7AVm3vKVl0mZKaNfqRf4n4+L5/cAsIDoTLhyqf7lBaibfUZ5YXcB0u09L RQWJyPVkh798gFX87LtKLYvKkTVVdIm0mMwJM4bPnW2FjUExHu9ccNQCSZjjR7Xa5Q7R gGpA== X-Gm-Message-State: AOJu0Yy9AVEdz3SoRZoAxC391MkONB/jKKrwylNDVtBBYxMClzwK8LhQ WSlcgIa5OEjsKRZBwIur1hKOIjm2DOuRRfLOmgYCqkj/R5sO3sGCaYAFg/cAPbXCwHoBBm8O2/G eun4hk4l2MQ9iCbR+I9sHZqEi/+pxYgu4rNnO/KjUNDu71NuArdDClQj3AWYk13pnFxVGSrO0iC vkbfwrZ9oIbl+6Xv2Dm4zyf7UProrU5aUENuNUZE4K+inh8/2SDhux X-Received: by 2002:a17:903:18d:b0:1e0:b689:950b with SMTP id z13-20020a170903018d00b001e0b689950bmr5683142plg.16.1714000470208; Wed, 24 Apr 2024 16:14:30 -0700 (PDT) Received: from amakhalov-build-vm.eng.vmware.com ([64.186.27.43]) by smtp.gmail.com with ESMTPSA id n17-20020a170903111100b001e520495f51sm12383936plh.124.2024.04.24.16.14.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 16:14:29 -0700 (PDT) From: Alexey Makhalov To: linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, mingo@redhat.com, tglx@linutronix.de Cc: x86@kernel.org, netdev@vger.kernel.org, richardcochran@gmail.com, linux-input@vger.kernel.org, dmitry.torokhov@gmail.com, zackr@vmware.com, linux-graphics-maintainer@vmware.com, pv-drivers@vmware.com, timothym@vmware.com, akaher@vmware.com, dri-devel@lists.freedesktop.org, daniel@ffwll.ch, airlied@gmail.com, tzimmermann@suse.de, mripard@kernel.org, maarten.lankhorst@linux.intel.com, horms@kernel.org, kirill.shutemov@linux.intel.com, Alexey Makhalov , Nadav Amit Subject: [PATCH v9 2/8] x86/vmware: Move common macros to vmware.h Date: Wed, 24 Apr 2024 16:14:07 -0700 Message-Id: <20240424231407.14098-2-alexey.makhalov@broadcom.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20240424231407.14098-1-alexey.makhalov@broadcom.com> References: <20240424231407.14098-1-alexey.makhalov@broadcom.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Move VMware hypercall macros to vmware.h. This is a prerequisite for the introduction of vmware_hypercall API. No functional changes besides exporting vmware_hypercall_mode symbol. Signed-off-by: Alexey Makhalov Reviewed-by: Nadav Amit --- arch/x86/include/asm/vmware.h | 72 +++++++++++++++++++++++++++++------ arch/x86/kernel/cpu/vmware.c | 43 +-------------------- 2 files changed, 62 insertions(+), 53 deletions(-) diff --git a/arch/x86/include/asm/vmware.h b/arch/x86/include/asm/vmware.h index ac9fc51e2b18..de2533337611 100644 --- a/arch/x86/include/asm/vmware.h +++ b/arch/x86/include/asm/vmware.h @@ -8,25 +8,34 @@ /* * The hypercall definitions differ in the low word of the %edx argument - * in the following way: the old port base interface uses the port - * number to distinguish between high- and low bandwidth versions. + * in the following way: the old I/O port based interface uses the port + * number to distinguish between high- and low bandwidth versions, and + * uses IN/OUT instructions to define transfer direction. * * The new vmcall interface instead uses a set of flags to select * bandwidth mode and transfer direction. The flags should be loaded * into %dx by any user and are automatically replaced by the port - * number if the VMWARE_HYPERVISOR_PORT method is used. - * - * In short, new driver code should strictly use the new definition of - * %dx content. + * number if the I/O port method is used. */ -/* Old port-based version */ -#define VMWARE_HYPERVISOR_PORT 0x5658 -#define VMWARE_HYPERVISOR_PORT_HB 0x5659 +#define VMWARE_HYPERVISOR_HB BIT(0) +#define VMWARE_HYPERVISOR_OUT BIT(1) + +#define VMWARE_HYPERVISOR_PORT 0x5658 +#define VMWARE_HYPERVISOR_PORT_HB (VMWARE_HYPERVISOR_PORT | \ + VMWARE_HYPERVISOR_HB) + +#define VMWARE_HYPERVISOR_MAGIC 0x564d5868U + +#define VMWARE_CMD_GETVERSION 10 +#define VMWARE_CMD_GETHZ 45 +#define VMWARE_CMD_GETVCPU_INFO 68 +#define VMWARE_CMD_STEALCLOCK 91 + +#define CPUID_VMWARE_FEATURES_ECX_VMMCALL BIT(0) +#define CPUID_VMWARE_FEATURES_ECX_VMCALL BIT(1) -/* Current vmcall / vmmcall version */ -#define VMWARE_HYPERVISOR_HB BIT(0) -#define VMWARE_HYPERVISOR_OUT BIT(1) +extern u8 vmware_hypercall_mode; /* The low bandwidth call. The low word of edx is presumed clear. */ #define VMWARE_HYPERCALL \ @@ -54,4 +63,43 @@ "rep insb", \ "vmcall", X86_FEATURE_VMCALL, \ "vmmcall", X86_FEATURE_VMW_VMMCALL) + +#define VMWARE_PORT(cmd, eax, ebx, ecx, edx) \ + __asm__("inl (%%dx), %%eax" : \ + "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ + "a"(VMWARE_HYPERVISOR_MAGIC), \ + "c"(VMWARE_CMD_##cmd), \ + "d"(VMWARE_HYPERVISOR_PORT), "b"(UINT_MAX) : \ + "memory") + +#define VMWARE_VMCALL(cmd, eax, ebx, ecx, edx) \ + __asm__("vmcall" : \ + "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ + "a"(VMWARE_HYPERVISOR_MAGIC), \ + "c"(VMWARE_CMD_##cmd), \ + "d"(0), "b"(UINT_MAX) : \ + "memory") + +#define VMWARE_VMMCALL(cmd, eax, ebx, ecx, edx) \ + __asm__("vmmcall" : \ + "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ + "a"(VMWARE_HYPERVISOR_MAGIC), \ + "c"(VMWARE_CMD_##cmd), \ + "d"(0), "b"(UINT_MAX) : \ + "memory") + +#define VMWARE_CMD(cmd, eax, ebx, ecx, edx) do { \ + switch (vmware_hypercall_mode) { \ + case CPUID_VMWARE_FEATURES_ECX_VMCALL: \ + VMWARE_VMCALL(cmd, eax, ebx, ecx, edx); \ + break; \ + case CPUID_VMWARE_FEATURES_ECX_VMMCALL: \ + VMWARE_VMMCALL(cmd, eax, ebx, ecx, edx); \ + break; \ + default: \ + VMWARE_PORT(cmd, eax, ebx, ecx, edx); \ + break; \ + } \ + } while (0) + #endif diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c index f58c8d669bd3..acd9658f7c4b 100644 --- a/arch/x86/kernel/cpu/vmware.c +++ b/arch/x86/kernel/cpu/vmware.c @@ -41,8 +41,6 @@ #define CPUID_VMWARE_INFO_LEAF 0x40000000 #define CPUID_VMWARE_FEATURES_LEAF 0x40000010 -#define CPUID_VMWARE_FEATURES_ECX_VMMCALL BIT(0) -#define CPUID_VMWARE_FEATURES_ECX_VMCALL BIT(1) #define VMWARE_HYPERVISOR_MAGIC 0x564D5868 @@ -58,44 +56,6 @@ #define STEALCLOCK_DISABLED 0 #define STEALCLOCK_ENABLED 1 -#define VMWARE_PORT(cmd, eax, ebx, ecx, edx) \ - __asm__("inl (%%dx), %%eax" : \ - "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ - "a"(VMWARE_HYPERVISOR_MAGIC), \ - "c"(VMWARE_CMD_##cmd), \ - "d"(VMWARE_HYPERVISOR_PORT), "b"(UINT_MAX) : \ - "memory") - -#define VMWARE_VMCALL(cmd, eax, ebx, ecx, edx) \ - __asm__("vmcall" : \ - "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ - "a"(VMWARE_HYPERVISOR_MAGIC), \ - "c"(VMWARE_CMD_##cmd), \ - "d"(0), "b"(UINT_MAX) : \ - "memory") - -#define VMWARE_VMMCALL(cmd, eax, ebx, ecx, edx) \ - __asm__("vmmcall" : \ - "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ - "a"(VMWARE_HYPERVISOR_MAGIC), \ - "c"(VMWARE_CMD_##cmd), \ - "d"(0), "b"(UINT_MAX) : \ - "memory") - -#define VMWARE_CMD(cmd, eax, ebx, ecx, edx) do { \ - switch (vmware_hypercall_mode) { \ - case CPUID_VMWARE_FEATURES_ECX_VMCALL: \ - VMWARE_VMCALL(cmd, eax, ebx, ecx, edx); \ - break; \ - case CPUID_VMWARE_FEATURES_ECX_VMMCALL: \ - VMWARE_VMMCALL(cmd, eax, ebx, ecx, edx); \ - break; \ - default: \ - VMWARE_PORT(cmd, eax, ebx, ecx, edx); \ - break; \ - } \ - } while (0) - struct vmware_steal_time { union { uint64_t clock; /* stolen time counter in units of vtsc */ @@ -109,7 +69,8 @@ struct vmware_steal_time { }; static unsigned long vmware_tsc_khz __ro_after_init; -static u8 vmware_hypercall_mode __ro_after_init; +u8 vmware_hypercall_mode __ro_after_init; +EXPORT_SYMBOL_GPL(vmware_hypercall_mode); static inline int __vmware_platform(void) { -- 2.39.0