virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: "Sinclair Yeh" <syeh@vmware.com>
To: x86@kernel.org
Cc: Sinclair Yeh <syeh@vmware.com>,
	Xavier Deguillard <xdeguillard@vmware.com>,
	gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
	virtualization@lists.linux-foundation.org,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Alok Kataria <akataria@vmware.com>
Subject: [PATCH 1/6] x86: Add VMWare Host Communication Macros
Date: Tue, 19 Jan 2016 13:46:00 -0800	[thread overview]
Message-ID: <1453239965-1466-2-git-send-email-syeh@vmware.com> (raw)
In-Reply-To: <1453239965-1466-1-git-send-email-syeh@vmware.com>

These macros will be used by multiple VMWare modules for handling
host communication.

Signed-off-by: Sinclair Yeh <syeh@vmware.com>
Reviewed-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Alok N Kataria <akataria@vmware.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Alok Kataria <akataria@vmware.com>
Cc: linux-kernel@vger.kernel.org
Cc: virtualization@lists.linux-foundation.org
Cc: Xavier Deguillard <xdeguillard@vmware.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---

v2:
* Keeping only the minimal common platform defines
* added vmware_platform() check function

v3:
* Added new field to handle different hypervisor magic values

v4:
* Make it so that "cmd" is always the first parameter for both
  High-Bandwidh and non-High-Bandwidth version of the macro
* Addressed comments from H. Peter Anvin on the assembly code

v5:
* Separate SI/DI as independent input/output arguments, given
  the latest update to vmw_balloon.c
---
 arch/x86/include/asm/vmware.h | 138 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 138 insertions(+)
 create mode 100644 arch/x86/include/asm/vmware.h

diff --git a/arch/x86/include/asm/vmware.h b/arch/x86/include/asm/vmware.h
new file mode 100644
index 0000000..7d02a2b
--- /dev/null
+++ b/arch/x86/include/asm/vmware.h
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2015, VMware, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, GOOD TITLE or
+ * NON INFRINGEMENT.  See the GNU General Public License for more
+ * details.
+ *
+ * Based on code from vmware.c and vmmouse.c.
+ * Author:
+ *   Sinclair Yeh <syeh@vmware.com>
+ */
+#ifndef _ASM_X86_VMWARE_H
+#define _ASM_X86_VMWARE_H
+
+
+/**
+ * Hypervisor-specific bi-directional communication channel.  Should never
+ * execute on bare metal hardware.  The caller must make sure to check for
+ * supported hypervisor before using these macros.
+ *
+ * The last two parameters are both input and output and must be initialized.
+ *
+ * @cmd: [IN] Message Cmd
+ * @in_ebx: [IN] Message Len, through EBX
+ * @in_si: [IN] Input argument through SI, set to 0 if not used
+ * @in_di: [IN] Input argument through DI, set ot 0 if not used
+ * @port_num: [IN] port number + [channel id]
+ * @magic: [IN] hypervisor magic value
+ * @eax: [OUT] value of EAX register
+ * @ebx: [OUT] e.g. status from an HB message status command
+ * @ecx: [OUT] e.g. status from a non-HB message status command
+ * @edx: [OUT] e.g. channel id
+ * @si:  [OUT]
+ * @di:  [OUT]
+ */
+#define VMW_PORT(cmd, in_ebx, in_si, in_di,	\
+		 port_num, magic,		\
+		 eax, ebx, ecx, edx, si, di)	\
+({						\
+	asm volatile ("inl %%dx, %%eax;" :	\
+		"=a"(eax),			\
+		"=b"(ebx),			\
+		"=c"(ecx),			\
+		"=d"(edx),			\
+		"=S"(si),			\
+		"=D"(di) :			\
+		"a"(magic),			\
+		"b"(in_ebx),			\
+		"c"(cmd),			\
+		"d"(port_num),			\
+		"S"(in_si),			\
+		"D"(in_di) :			\
+		"memory");			\
+})
+
+
+/**
+ * Hypervisor-specific bi-directional communication channel.  Should never
+ * execute on bare metal hardware.  The caller must make sure to check for
+ * supported hypervisor before using these macros.
+ *
+ * The last 3 parameters are both input and output and must be initialized.
+ *
+ * @cmd: [IN] Message Cmd
+ * @in_ecx: [IN] Message Len, through ECX
+ * @in_si: [IN] Input argument through SI, set to 0 if not used
+ * @in_di: [IN] Input argument through DI, set to 0 if not used
+ * @port_num: [IN] port number + [channel id]
+ * @magic: [IN] hypervisor magic value
+ * @eax: [OUT] value of EAX register
+ * @ebx: [OUT] e.g. status from an HB message status command
+ * @ecx: [OUT] e.g. status from a non-HB message status command
+ * @edx: [OUT] e.g. channel id
+ * @si:  [OUT]
+ * @di:  [OUT]
+ * @bp:  [INOUT] set to 0 if not used
+ */
+#define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di,	\
+			port_num, magic,		\
+			eax, ebx, ecx, edx, si, di, bp)	\
+({							\
+	asm volatile ("push %%rbp;"			\
+		"xchgq %6, %%rbp;"			\
+		"rep outsb;"				\
+		"xchgq %%rbp, %6;"			\
+		"pop %%rbp;" :				\
+		"=a"(eax),				\
+		"=b"(ebx),				\
+		"=c"(ecx),				\
+		"=d"(edx),				\
+		"=S"(si),				\
+		"=D"(di),				\
+		"+r"(bp) :				\
+		"a"(magic),				\
+		"b"(cmd),				\
+		"c"(in_ecx),				\
+		"d"(port_num),				\
+		"S"(in_si),				\
+		"D"(in_di) :				\
+		"memory", "cc");			\
+})
+
+
+#define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di,	\
+		       port_num, magic,			\
+		       eax, ebx, ecx, edx, si, di, bp)	\
+({							\
+	asm volatile ("push %%rbp;"			\
+		"xchgq %6, %%rbp;"			\
+		"rep insb;"				\
+		"xchgq %%rbp, %6;"			\
+		"pop %%rbp" :				\
+		"=a"(eax),				\
+		"=b"(ebx),				\
+		"=c"(ecx),				\
+		"=d"(edx),				\
+		"=S"(si),				\
+		"=D"(di),				\
+		"+r"(bp) :				\
+		"a"(magic),				\
+		"b"(cmd),				\
+		"c"(in_ecx),				\
+		"d"(port_num),				\
+		"S"(in_si),				\
+		"D"(in_di) :				\
+		"memory", "cc");			\
+})
+
+
+#endif
+
-- 
1.9.1

  parent reply	other threads:[~2016-01-19 21:46 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1449008047-8252-1-git-send-email-syeh@vmware.com>
2015-12-01 22:18 ` [PATCH 1/6] x86: Add VMWare Host Communication Macros Sinclair Yeh
2015-12-01 22:18   ` [PATCH 2/6] x86: Update vmware.c to use the common VMW_PORT macros Sinclair Yeh
2015-12-01 22:18   ` [PATCH 3/6] Input: Update vmmouse.c " Sinclair Yeh
2015-12-01 22:24     ` Dmitry Torokhov
     [not found]     ` <20151201222414.GH3740@dtor-ws>
2015-12-01 22:32       ` Sinclair Yeh
     [not found]       ` <20151201223255.GA10753@syeh-linux>
2015-12-01 22:45         ` Dmitry Torokhov
     [not found]         ` <CAKdAkRTVJ_DWD6uYhp+qd1uYwe3rPguDFAMXpa5=8CwVuO16NQ@mail.gmail.com>
2015-12-01 22:54           ` Sinclair Yeh
2015-12-01 23:56             ` Dmitry Torokhov
2015-12-02  0:04             ` Greg Kroah-Hartman
2015-12-02  2:21               ` Sinclair Yeh
2015-12-02  7:07               ` [Linux-graphics-maintainer] " Thomas Hellstrom
     [not found]               ` <20151202022106.GA6471@syeh-linux>
2015-12-02 15:31                 ` Greg Kroah-Hartman
2015-12-02 15:57                   ` Sinclair Yeh
2015-12-02 17:26                   ` Dmitry Torokhov
2015-12-02 17:29                     ` [Linux-graphics-maintainer] " Thomas Hellstrom
2015-12-02 18:45                     ` Greg Kroah-Hartman
2015-12-02 18:58                       ` Dmitry Torokhov
2015-12-02 19:02                       ` Sinclair Yeh
2015-12-02  0:01     ` Greg Kroah-Hartman
2015-12-01 22:18   ` [PATCH 4/6] Input: Remove vmmouse port reservation Sinclair Yeh
2015-12-01 22:18   ` [PATCH 6/6] VMware balloon: Update vmw_balloon.c to use the VMW_PORT macro Sinclair Yeh
     [not found]   ` <1449008332-9394-4-git-send-email-syeh@vmware.com>
2015-12-01 22:30     ` [PATCH 4/6] Input: Remove vmmouse port reservation Dmitry Torokhov
2015-12-01 23:04       ` Sinclair Yeh
2015-12-01 23:52         ` Dmitry Torokhov
2015-12-01 22:32   ` [PATCH 1/6] x86: Add VMWare Host Communication Macros Xavier Deguillard
     [not found]   ` <1449008332-9394-6-git-send-email-syeh@vmware.com>
2015-12-01 22:38     ` [PATCH 6/6] VMware balloon: Update vmw_balloon.c to use the VMW_PORT macro Xavier Deguillard
     [not found]     ` <20151201223801.GN24642@xdeguillard-ws.eng.vmware.com>
2015-12-01 23:17       ` Sinclair Yeh
2015-12-01 22:49   ` [PATCH 1/6] x86: Add VMWare Host Communication Macros H. Peter Anvin
     [not found]   ` <565E23E7.5090800@zytor.com>
2015-12-04 22:33     ` Sinclair Yeh
     [not found] ` <1449271183-1746-1-git-send-email-syeh@vmware.com>
2015-12-04 23:19   ` Sinclair Yeh
2015-12-04 23:19   ` [PATCH 2/6] x86: Update vmware.c to use the common VMW_PORT macros Sinclair Yeh
2015-12-04 23:19   ` [PATCH 3/6] Input: Update vmmouse.c " Sinclair Yeh
2015-12-04 23:19   ` [PATCH 4/6] Input: Remove vmmouse port reservation Sinclair Yeh
2015-12-04 23:19   ` [PATCH 6/6] VMware balloon: Update vmw_balloon.c to use the VMW_PORT macro Sinclair Yeh
     [not found]   ` <1453239965-1466-1-git-send-email-syeh@vmware.com>
2016-01-19 21:46     ` Sinclair Yeh [this message]
2016-01-19 21:46     ` [PATCH 2/6] x86: Update vmware.c to use the common VMW_PORT macros Sinclair Yeh
2016-01-19 21:46     ` [PATCH 3/6] Input: Update vmmouse.c " Sinclair Yeh
2016-01-19 21:46     ` [PATCH 4/6] Input: Remove vmmouse port reservation Sinclair Yeh
2016-01-19 21:46     ` [PATCH 6/6] VMware balloon: Update vmw_balloon.c to use the VMW_PORT macro Sinclair Yeh
2016-02-08 19:41       ` Greg KH
2016-03-31 14:39         ` Sinclair Yeh
     [not found]         ` <20160331143953.GA23662@syeh-linux>
2016-03-31 16:30           ` Greg KH
2016-03-31 17:32             ` Sinclair Yeh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1453239965-1466-2-git-send-email-syeh@vmware.com \
    --to=syeh@vmware.com \
    --cc=akataria@vmware.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=x86@kernel.org \
    --cc=xdeguillard@vmware.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).