From: VMware, Inc <> Date: Tue, 29 Mar 2011 18:49:42 +0000 (-0700) Subject: This is part 12 of a change to support Nested VMs. X-Git-Tag: 2011.03.28-387002~86 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=de839f1bcfe4c3731a151d42a4fb5a3757b1f2d1;p=thirdparty%2Fopen-vm-tools.git This is part 12 of a change to support Nested VMs. This part removes vmciUtil.* and vmciInt.h from the guest driver and uses vmciDriver.* instead. I'm cheating here, by copying some of the old vmciUtil code into vmciDriver. The change after this will unify more of the code. Everything under common/guest is gone with this change. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/modules/linux/shared/vmci_kernel_if.h b/open-vm-tools/modules/linux/shared/vmci_kernel_if.h index eff077aef..a7a64746e 100644 --- a/open-vm-tools/modules/linux/shared/vmci_kernel_if.h +++ b/open-vm-tools/modules/linux/shared/vmci_kernel_if.h @@ -60,14 +60,18 @@ #endif #ifdef SOLARIS +# include +# include # include # include # include -# include +# include +# include #endif #include "vm_basic_types.h" #include "vmci_defs.h" +#include "vmci_infrastructure.h" #if defined(VMKERNEL) # include "list.h" @@ -230,6 +234,39 @@ typedef struct VMCIHost { #endif } VMCIHost; +/* + * Guest device port I/O. + */ + +#if defined(linux) + typedef unsigned short int VMCIIoPort; + typedef int VMCIIoHandle; +#elif defined(_WIN32) + typedef PUCHAR VMCIIoPort; + typedef int VMCIIoHandle; +#elif defined(SOLARIS) + typedef uint8_t * VMCIIoPort; + typedef ddi_acc_handle_t VMCIIoHandle; +#elif defined(__APPLE__) + typedef unsigned short int VMCIIoPort; + typedef void *VMCIIoHandle; +#endif // __APPLE__ + +void VMCI_ReadPortBytes(VMCIIoHandle handle, VMCIIoPort port, uint8 *buffer, + size_t bufferLength); + +/* + * Guest device handle (FsCtx). Not used on VMK, but we use an empty type to + * keep offsetchecker happy. + */ + +typedef struct VMCIGuestDeviceHandle { +#if !defined(VMKERNEL) + void *obj; + VMCIObjType objType; +#endif // VMKERNEL +} VMCIGuestDeviceHandle; + void VMCI_InitLock(VMCILock *lock, char *name, VMCILockRank rank); void VMCI_CleanupLock(VMCILock *lock); diff --git a/open-vm-tools/modules/linux/vmci/stubs.c b/open-vm-tools/modules/linux/vmci/stubs.c deleted file mode 100644 index 304cff5c3..000000000 --- a/open-vm-tools/modules/linux/vmci/stubs.c +++ /dev/null @@ -1,52 +0,0 @@ -/********************************************************* - * Copyright (C) 2011 VMware, Inc. All rights reserved. - * - * 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 version 2 and no 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. 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, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - *********************************************************/ - -/* - * stubs.c - * - * Stubs for host functions still missing from the guest driver. - * - */ - -#ifdef __linux__ -# include "driver-config.h" -#endif - -#include "vmci_kernel_if.h" -#include "vmci_defs.h" -#include "vmciContext.h" -#include "vmciDoorbell.h" - - -/* - *------------------------------------------------------------------------------ - * - * VMCIUnsetNotify -- - * - * Stub. Not called in the guest driver (yet). - * - * Result: - * Always VMCI_ERROR_GENERIC. - * - *------------------------------------------------------------------------------ - */ - -void -VMCIUnsetNotify(VMCIContext *context) -{ -} diff --git a/open-vm-tools/modules/linux/vmci/vmciContext.c b/open-vm-tools/modules/linux/vmci/vmciContext.c index 40f216e9f..e91fbe90a 100644 --- a/open-vm-tools/modules/linux/vmci/vmciContext.c +++ b/open-vm-tools/modules/linux/vmci/vmciContext.c @@ -22,11 +22,6 @@ * Platform independent routines for VMCI calls. */ -#if defined(__linux__) && !defined(VMKERNEL) -# include "driver-config.h" -# include "compat_kernel.h" -# include "compat_module.h" -#endif // __linux__ #include "vmci_kernel_if.h" #include "vm_assert.h" #include "vmci_defs.h" @@ -39,10 +34,7 @@ #include "vmciKernelAPI.h" #include "vmciQueuePair.h" #include "vmciResource.h" -#ifdef VMX86_TOOLS -# include "vmciInt.h" -# include "vmciUtil.h" -#elif defined(VMKERNEL) +#if defined(VMKERNEL) # include "vmciVmkInt.h" # include "vm_libc.h" # include "helper_ext.h" @@ -929,7 +921,7 @@ VMCIContext_DequeueDatagram(VMCIContext *context, // IN *maxSize = dqEntry->dgSize; VMCI_ReleaseLock(&context->lock, flags); VMCI_DEBUG_LOG(4, (LGPFX"Caller's buffer should be at least " - "(size=%"FMTSZ"d bytes).\n", *maxSize)); + "(size=%u bytes).\n", (uint32)*maxSize)); return VMCI_ERROR_NO_MEM; } @@ -1300,20 +1292,19 @@ VMCI_EXPORT_SYMBOL(VMCIContext_GetPrivFlags) VMCIPrivilegeFlags VMCIContext_GetPrivFlags(VMCIId contextID) // IN { -#if defined(VMX86_TOOLS) - return VMCI_NO_PRIVILEGE_FLAGS; -#else // VMX86_TOOLS - VMCIPrivilegeFlags flags; - VMCIContext *context; + if (VMCI_HasHostDevice()) { + VMCIPrivilegeFlags flags; + VMCIContext *context; - context = VMCIContext_Get(contextID); - if (!context) { - return VMCI_LEAST_PRIVILEGE_FLAGS; + context = VMCIContext_Get(contextID); + if (!context) { + return VMCI_LEAST_PRIVILEGE_FLAGS; + } + flags = context->privFlags; + VMCIContext_Release(context); + return flags; } - flags = context->privFlags; - VMCIContext_Release(context); - return flags; -#endif // VMX86_TOOLS + return VMCI_NO_PRIVILEGE_FLAGS; } @@ -2329,35 +2320,34 @@ int VMCI_IsContextOwner(VMCIId contextID, // IN void *hostUser) // IN { -#if defined(VMX86_TOOLS) - return VMCI_ERROR_UNAVAILABLE; -#else // VMX86_TOOLS - VMCIContext *context; - VMCIHostUser *user = (VMCIHostUser *)hostUser; - int retval; + if (VMCI_HasHostDevice()) { + VMCIContext *context; + VMCIHostUser *user = (VMCIHostUser *)hostUser; + int retval; - if (vmkernel) { - return VMCI_ERROR_UNAVAILABLE; - } + if (vmkernel) { + return VMCI_ERROR_UNAVAILABLE; + } - if (!hostUser) { - return VMCI_ERROR_INVALID_ARGS; - } + if (!hostUser) { + return VMCI_ERROR_INVALID_ARGS; + } - context = VMCIContext_Get(contextID); - if (!context) { - return VMCI_ERROR_NOT_FOUND; - } + context = VMCIContext_Get(contextID); + if (!context) { + return VMCI_ERROR_NOT_FOUND; + } - if (context->validUser) { - retval = VMCIHost_CompareUser(user, &context->user); - } else { - retval = VMCI_ERROR_UNAVAILABLE; - } - VMCIContext_Release(context); + if (context->validUser) { + retval = VMCIHost_CompareUser(user, &context->user); + } else { + retval = VMCI_ERROR_UNAVAILABLE; + } + VMCIContext_Release(context); - return retval; -#endif // VMX86_TOOLS + return retval; + } + return VMCI_ERROR_UNAVAILABLE; } diff --git a/open-vm-tools/modules/linux/vmci/vmciDatagram.c b/open-vm-tools/modules/linux/vmci/vmciDatagram.c index 641e4476b..3fbfae9ba 100644 --- a/open-vm-tools/modules/linux/vmci/vmciDatagram.c +++ b/open-vm-tools/modules/linux/vmci/vmciDatagram.c @@ -22,11 +22,6 @@ * This file implements the VMCI Simple Datagram API on the host. */ -#if defined(__linux__) && !defined(VMKERNEL) -# include "driver-config.h" -# include "compat_kernel.h" -# include "compat_module.h" -#endif // __linux__ #include "vmci_kernel_if.h" #include "vm_assert.h" #include "vmci_defs.h" @@ -39,10 +34,7 @@ #include "vmciKernelAPI.h" #include "vmciResource.h" #include "vmciRoute.h" -#ifdef VMX86_TOOLS -# include "vmciInt.h" -# include "vmciUtil.h" -#elif defined(VMKERNEL) +#if defined(VMKERNEL) # include "vmciVmkInt.h" # include "vm_libc.h" # include "helper_ext.h" @@ -828,7 +820,6 @@ VMCIDatagramDispatchAsGuest(VMCIDatagram *dg) #else // VMKERNEL int retval; VMCIResource *resource; - extern int VMCI_SendDatagram(VMCIDatagram *); ASSERT(VMCI_HasGuestDevice()); diff --git a/open-vm-tools/modules/linux/vmci/vmciDoorbell.c b/open-vm-tools/modules/linux/vmci/vmciDoorbell.c index 5f6aacd83..ca4cc4c1f 100644 --- a/open-vm-tools/modules/linux/vmci/vmciDoorbell.c +++ b/open-vm-tools/modules/linux/vmci/vmciDoorbell.c @@ -22,11 +22,6 @@ * This file implements the VMCI doorbell API on the host. */ -#if defined(__linux__) && !defined(VMKERNEL) -# include "driver-config.h" -# include "compat_kernel.h" -# include "compat_module.h" -#endif // __linux__ #include "vmci_kernel_if.h" #include "vm_assert.h" #include "vmci_defs.h" @@ -37,10 +32,7 @@ #include "vmciKernelAPI.h" #include "vmciResource.h" #include "vmciRoute.h" -#ifdef VMX86_TOOLS -# include "vmciInt.h" -# include "vmciUtil.h" -#elif defined(VMKERNEL) +#if defined(VMKERNEL) # include "vmciVmkInt.h" # include "vm_libc.h" # include "helper_ext.h" @@ -127,7 +119,6 @@ static uint32 lastNotifyIdxReleased = PAGE_SIZE; static void VMCIDoorbellFreeCB(void *clientData); static int VMCIDoorbellReleaseCB(void *clientData); static void VMCIDoorbellDelayedDispatchCB(void *data); -extern int VMCI_SendDatagram(VMCIDatagram *); /* @@ -1189,7 +1180,7 @@ VMCI_ScanNotificationBitmap(uint8 *bitmap) VMCI_EXPORT_SYMBOL(VMCIDoorbell_Create) int VMCIDoorbell_Create(VMCIHandle *handle, // IN - uint32 flags, // I + uint32 flags, // IN VMCIPrivilegeFlags privFlags, // IN VMCICallback notifyCB, // IN void *clientData) // IN diff --git a/open-vm-tools/modules/linux/vmci/vmciUtil.c b/open-vm-tools/modules/linux/vmci/vmciDriver.c similarity index 71% rename from open-vm-tools/modules/linux/vmci/vmciUtil.c rename to open-vm-tools/modules/linux/vmci/vmciDriver.c index 2ade9348c..9b9803922 100644 --- a/open-vm-tools/modules/linux/vmci/vmciUtil.c +++ b/open-vm-tools/modules/linux/vmci/vmciDriver.c @@ -17,81 +17,131 @@ *********************************************************/ /* - * vmciUtil.c - * - * Small utility function for allocating kernel memory and copying data. + * vmciDriver.c -- * + * VMCI initialization and ioctl handling. */ -#ifdef __linux__ -# include "driver-config.h" -# define EXPORT_SYMTAB -# include -# include "compat_kernel.h" -# include "compat_slab.h" -# include "compat_interrupt.h" -#endif - #include "vmci_kernel_if.h" #include "vm_assert.h" -#include "vm_atomic.h" #include "vmci_defs.h" -#include "vmci_kernel_if.h" -#include "vmciGuestKernelIf.h" -#include "vmciInt.h" +#include "vmci_infrastructure.h" +#include "vmciCommonInt.h" +#include "vmciContext.h" #include "vmciDatagram.h" -#include "vmciUtil.h" +#include "vmciDoorbell.h" #include "vmciEvent.h" +#include "vmciHashtable.h" #include "vmciKernelAPI.h" +#include "vmciQueuePair.h" +#include "vmciResource.h" +#if defined(VMKERNEL) +# include "vmciVmkInt.h" +# include "vm_libc.h" +# include "helper_ext.h" +# include "vmciDriver.h" +#else +# include "vmciDriver.h" +#endif -#define LGPFX "VMCIUtil: " - -static void VMCIUtilCidUpdate(VMCIId subID, VMCI_EventData *eventData, - void *clientData); +#define LGPFX "VMCI: " -static VMCIId ctxUpdateSubID = VMCI_INVALID_ID; static Atomic_uint32 vmContextID = { VMCI_INVALID_ID }; -static Atomic_uint32 vmciClientCount; + +#if !defined(VMX86_TOOLS) + +static VMCIContext *hostContext; /* - *----------------------------------------------------------------------------- + *---------------------------------------------------------------------- * - * VMCIUtil_Init -- + * VMCI_Init -- * - * Subscribe to context id update event. + * Initializes VMCI. This registers core hypercalls. * * Results: - * None. + * VMCI_SUCCESS if successful, appropriate error code otherwise. * * Side effects: * None. * - *----------------------------------------------------------------------------- + *---------------------------------------------------------------------- */ -void -VMCIUtil_Init(void) +int +VMCI_Init(void) { + int result; + + result = VMCIResource_Init(); + if (result < VMCI_SUCCESS) { + VMCI_WARNING((LGPFX"Failed to initialize VMCIResource (result=%d)", + result)); + goto errorExit; + } + + result = VMCIContext_Init(); + if (result < VMCI_SUCCESS) { + VMCI_WARNING((LGPFX"Failed to initialize VMCIContext (result=%d)", + result)); + goto resourceExit; + } + + result = VMCIDatagram_Init(); + if (result < VMCI_SUCCESS) { + VMCI_WARNING((LGPFX"Failed to initialize VMCIDatagram (result=%d)", + result)); + goto contextExit; + } + /* - * We subscribe to the VMCI_EVENT_CTX_ID_UPDATE here so we can update the - * internal context id when needed. + * In theory, it is unsafe to pass an eventHnd of -1 to platforms which use + * it (VMKernel/Windows/Mac OS at the time of this writing). In practice we + * are fine though, because the event is never used in the case of the host + * context. */ - if (VMCIEvent_Subscribe(VMCI_EVENT_CTX_ID_UPDATE, VMCI_FLAG_EVENT_NONE, - VMCIUtilCidUpdate, NULL, - &ctxUpdateSubID) < VMCI_SUCCESS) { - VMCI_WARNING((LGPFX"Failed to subscribe to event (type=%d).\n", - VMCI_EVENT_CTX_ID_UPDATE)); + result = VMCIContext_InitContext(VMCI_HOST_CONTEXT_ID, + VMCI_DEFAULT_PROC_PRIVILEGE_FLAGS, + -1, VMCI_VERSION, NULL, &hostContext); + if (result < VMCI_SUCCESS) { + VMCI_WARNING((LGPFX"Failed to initialize VMCIContext (result=%d)", + result)); + goto datagramExit; } + + VMCIEvent_Init(); + VMCIDoorbell_Init(); + + result = VMCIQPBroker_Init(); + if (result < VMCI_SUCCESS) { + goto hostContextExit; + } + + VMCI_LOG((LGPFX"Driver initialized.")); + return VMCI_SUCCESS; + + hostContextExit: + VMCIDoorbell_Exit(); + VMCIEvent_Exit(); + VMCIContext_ReleaseContext(hostContext); + datagramExit: + VMCIDatagram_Exit(); + contextExit: + VMCIContext_Exit(); + resourceExit: + VMCIResource_Exit(); + errorExit: + return result; } /* - *----------------------------------------------------------------------------- + *---------------------------------------------------------------------- * - * VMCIUtil_Exit -- + * VMCI_Cleanup -- * - * Cleanup + * Cleanup the VMCI module. * * Results: * None. @@ -99,20 +149,104 @@ VMCIUtil_Init(void) * Side effects: * None. * - *----------------------------------------------------------------------------- + *---------------------------------------------------------------------- */ void -VMCIUtil_Exit(void) +VMCI_Cleanup(void) { - if (VMCIEvent_Unsubscribe(ctxUpdateSubID) < VMCI_SUCCESS) { - VMCI_WARNING((LGPFX"Failed to unsubscribe to event (type=%d) with " - "subscriber (ID=0x%x).\n", VMCI_EVENT_CTX_ID_UPDATE, - ctxUpdateSubID)); + VMCIDoorbell_Exit(); + VMCIEvent_Exit(); + VMCIContext_ReleaseContext(hostContext); + VMCIDatagram_Exit(); + VMCIContext_Exit(); + VMCIResource_Exit(); + VMCIQPBroker_Exit(); +} + + +/* + *---------------------------------------------------------------------- + * + * VMCI_DeviceGet -- + * + * API provided for compatibility with the guest vmci + * API. Indicates the callers intention to use the device until + * it calls VMCI_DeviceRelease(). + * + * Results: + * TRUE. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +VMCI_EXPORT_SYMBOL(VMCI_DeviceGet) +Bool +VMCI_DeviceGet(uint32 *apiVersion) +{ + if (*apiVersion > VMCI_KERNEL_API_VERSION) { + *apiVersion = VMCI_KERNEL_API_VERSION; + return FALSE; } + return TRUE; +} + + +/* + *---------------------------------------------------------------------- + * + * VMCI_DeviceRelease -- + * + * API provided for compatibility with the guest vmci + * API. Indicates that the caller is done using the VMCI device. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +VMCI_EXPORT_SYMBOL(VMCI_DeviceRelease) +void +VMCI_DeviceRelease(void) +{ } +/* + *----------------------------------------------------------------------------- + * + * VMCI_SendDatagram -- + * + * Stub for guest VM to hypervisor call mechanism. + * + * Results: + * Always VMCI_ERROR_GENERIC. + * + * Side effects: + * None. + * + *----------------------------------------------------------------------------- + */ + +int +VMCI_SendDatagram(VMCIDatagram *dg) +{ + return VMCI_ERROR_UNAVAILABLE; +} + +#else // VMX86_TOOLS + +static Atomic_uint32 vmciClientCount; +static VMCIId ctxUpdateSubID = VMCI_INVALID_ID; + + /* *----------------------------------------------------------------------------- * @@ -151,6 +285,64 @@ VMCIUtilCidUpdate(VMCIId subID, // IN: } +/* + *----------------------------------------------------------------------------- + * + * VMCIUtil_Init -- + * + * Subscribe to context id update event. + * + * Results: + * None. + * + * Side effects: + * None. + * + *----------------------------------------------------------------------------- + */ + +void +VMCIUtil_Init(void) +{ + /* + * We subscribe to the VMCI_EVENT_CTX_ID_UPDATE here so we can update the + * internal context id when needed. + */ + if (VMCIEvent_Subscribe(VMCI_EVENT_CTX_ID_UPDATE, VMCI_FLAG_EVENT_NONE, + VMCIUtilCidUpdate, NULL, + &ctxUpdateSubID) < VMCI_SUCCESS) { + VMCI_WARNING((LGPFX"Failed to subscribe to event (type=%d).\n", + VMCI_EVENT_CTX_ID_UPDATE)); + } +} + + +/* + *----------------------------------------------------------------------------- + * + * VMCIUtil_Exit -- + * + * Cleanup + * + * Results: + * None. + * + * Side effects: + * None. + * + *----------------------------------------------------------------------------- + */ + +void +VMCIUtil_Exit(void) +{ + if (VMCIEvent_Unsubscribe(ctxUpdateSubID) < VMCI_SUCCESS) { + VMCI_WARNING((LGPFX"Failed to unsubscribe to event (type=%d) with " + "subscriber (ID=0x%x).\n", VMCI_EVENT_CTX_ID_UPDATE, + ctxUpdateSubID)); + } +} + /* *----------------------------------------------------------------------------- @@ -172,8 +364,8 @@ VMCIUtilCidUpdate(VMCIId subID, // IN: #define VMCI_UTIL_NUM_RESOURCES 1 -Bool -VMCIUtil_CheckHostCapabilities(void) +static Bool +VMCIUtilCheckHostCapabilities(void) { int result; VMCIResourcesQueryMsg *msg; @@ -203,40 +395,6 @@ VMCIUtil_CheckHostCapabilities(void) } -/* - *----------------------------------------------------------------------------- - * - * VMCI_GetContextID -- - * - * Returns the context id. - * - * Results: - * Context id. - * - * Side effects: - * None. - * - *----------------------------------------------------------------------------- - */ - -VMCI_EXPORT_SYMBOL(VMCI_GetContextID) -VMCIId -VMCI_GetContextID(void) -{ - if (Atomic_Read(&vmContextID) == VMCI_INVALID_ID) { - uint32 result; - VMCIDatagram getCidMsg; - getCidMsg.dst = VMCI_MAKE_HANDLE(VMCI_HYPERVISOR_CONTEXT_ID, - VMCI_GET_CONTEXT_ID); - getCidMsg.src = VMCI_ANON_SRC_HANDLE; - getCidMsg.payloadSize = 0; - result = VMCI_SendDatagram(&getCidMsg); - Atomic_Write(&vmContextID, result); - } - return Atomic_Read(&vmContextID); -} - - /* *----------------------------------------------------------------------------- * @@ -261,71 +419,13 @@ VMCI_CheckHostCapabilities(void) { Bool result = VMCIEvent_CheckHostCapabilities(); result &= VMCIDatagram_CheckHostCapabilities(); - result &= VMCIUtil_CheckHostCapabilities(); + result &= VMCIUtilCheckHostCapabilities(); VMCI_LOG((LGPFX"Host capability check: %s\n", result ? "PASSED" : "FAILED")); return result; } -/* - *---------------------------------------------------------------------- - * - * VMCI_Version -- - * - * Returns the version of the VMCI guest driver. - * - * Results: - * Returns a version number. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -VMCI_EXPORT_SYMBOL(VMCI_Version) -uint32 -VMCI_Version() -{ - return VMCI_VERSION_NUMBER; -} - - -/* - *---------------------------------------------------------------------- - * - * VMCI_InInterrupt -- - * - * Determines if we are running in tasklet/dispatch level or above. - * - * Results: - * TRUE if tasklet/dispatch or above, FALSE otherwise. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Bool -VMCI_InInterrupt() -{ -#if defined(_WIN32) - return KeGetCurrentIrql() >= DISPATCH_LEVEL; -#elif defined(__linux__) - return in_interrupt(); -#elif defined(SOLARIS) - return servicing_interrupt(); /* servicing_interrupt is not part of DDI. */ -#elif defined(__APPLE__) - /* - * All interrupt servicing is handled by IOKit functions, by the time the IOService - * interrupt handler is called we're no longer in an interrupt dispatch level. - */ - return false; -#endif // -} - /* *---------------------------------------------------------------------- @@ -561,3 +661,68 @@ VMCI_ReadDatagramsFromPort(VMCIIoHandle ioHandle, // IN } } } + +#endif // VMX86_TOOLS + +/* + *---------------------------------------------------------------------------- + * + * VMCI_GetContextID -- + * + * Returns the current context ID. Note that since this is accessed only + * from code running in the host, this always returns the host context ID. + * + * Results: + * Context ID. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------------- + */ + +VMCI_EXPORT_SYMBOL(VMCI_GetContextID) +VMCIId +VMCI_GetContextID(void) +{ + if (VMCI_HasGuestDevice()) { + if (Atomic_Read(&vmContextID) == VMCI_INVALID_ID) { + uint32 result; + VMCIDatagram getCidMsg; + getCidMsg.dst = VMCI_MAKE_HANDLE(VMCI_HYPERVISOR_CONTEXT_ID, + VMCI_GET_CONTEXT_ID); + getCidMsg.src = VMCI_ANON_SRC_HANDLE; + getCidMsg.payloadSize = 0; + result = VMCI_SendDatagram(&getCidMsg); + Atomic_Write(&vmContextID, result); + } + return Atomic_Read(&vmContextID); + } else if (VMCI_HasHostDevice()) { + return VMCI_HOST_CONTEXT_ID; + } + return VMCI_INVALID_ID; +} + + +/* + *---------------------------------------------------------------------- + * + * VMCI_Version -- + * + * Returns the version of the VMCI driver. + * + * Results: + * Returns a version number. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +VMCI_EXPORT_SYMBOL(VMCI_Version) +uint32 +VMCI_Version() +{ + return VMCI_VERSION; +} diff --git a/open-vm-tools/modules/linux/vmci/vmciDriver.h b/open-vm-tools/modules/linux/vmci/vmciDriver.h index 731258d5a..cf18e9eac 100644 --- a/open-vm-tools/modules/linux/vmci/vmciDriver.h +++ b/open-vm-tools/modules/linux/vmci/vmciDriver.h @@ -43,7 +43,12 @@ #ifdef _WIN32 # include "vmciLog.h" #else // _WIN32 -#ifdef VMKERNEL +#if defined(VMKERNEL) && !defined(VMKERNEL_OFFSET_CHECKER) + /* + * LOGLEVEL_MODULE is defined in another header that gets included into the + * dummy file used by the offsetchecker, which causes it to barf on the + * redefinition. + */ # define LOGLEVEL_MODULE_LEN 0 # define LOGLEVEL_MODULE VMCIVMK # include "log.h" @@ -54,10 +59,10 @@ int i = _level; \ _VMCILOG _args ; \ } while(FALSE) -# else +# else // VMX86_LOG # define VMCI_DEBUG_LOG(_level, _args) -# endif -#else +# endif // VMX86_LOG +#else // VMKERNEL # define VMCI_DEBUG_LEVEL 4 # define VMCI_DEBUG_LOG(_level, _args) \ do { \ @@ -65,13 +70,30 @@ Log _args ; \ } \ } while(FALSE) -#endif +#endif // VMKERNEL #define VMCI_LOG(_args) Log _args #define VMCI_WARNING(_args) Warning _args #endif // _WIN32 + int VMCI_Init(void); void VMCI_Cleanup(void); VMCIId VMCI_GetContextID(void); +int VMCI_SendDatagram(VMCIDatagram *dg); + +#if defined(VMX86_TOOLS) +void VMCIUtil_Init(void); +void VMCIUtil_Exit(void); +Bool VMCI_CheckHostCapabilities(void); +void VMCI_ReadDatagramsFromPort(VMCIIoHandle ioHandle, VMCIIoPort dgInPort, + uint8 *dgInBuffer, size_t dgInBufferSize); +Bool VMCI_DeviceInUse(void); +Bool VMCI_DeviceEnabled(void); +#if defined(_WIN64) +int VMCIDoSendDatagram(unsigned int dgSize, ULONG *dataPort, ULONG *resultPort, + VMCIDatagram *dg); +#endif // _WIN64 +#endif // VMX86_TOOLS + #endif // _VMCI_DRIVER_H_ diff --git a/open-vm-tools/modules/linux/vmci/vmciEvent.c b/open-vm-tools/modules/linux/vmci/vmciEvent.c index 84e195244..3319d1590 100644 --- a/open-vm-tools/modules/linux/vmci/vmciEvent.c +++ b/open-vm-tools/modules/linux/vmci/vmciEvent.c @@ -22,20 +22,12 @@ * VMCI Event code for host and guests. */ -#if defined(__linux__) && !defined(VMKERNEL) -# include "driver-config.h" -# include "compat_kernel.h" -# include "compat_module.h" -#endif // __linux__ #include "vmci_kernel_if.h" #include "vmci_defs.h" #include "vmci_infrastructure.h" #include "vmciEvent.h" #include "vmciKernelAPI.h" -#ifdef VMX86_TOOLS -# include "vmciInt.h" -# include "vmciUtil.h" -#elif defined(VMKERNEL) +#if defined(VMKERNEL) # include "vmciVmkInt.h" # include "vm_libc.h" # include "helper_ext.h" @@ -69,21 +61,19 @@ static int VMCIEventRegisterSubscription(VMCISubscription *sub, void *callbackData); static VMCISubscription *VMCIEventUnregisterSubscription(VMCIId subID); -/* - * In the guest, VMCI events are dispatched from interrupt context, so - * the locks need to be bottom half safe. In the host kernel, this - * isn't so, and regular locks are used instead. - */ -#ifdef VMX86_TOOLS -#define VMCIEventInitLock(_lock, _name) VMCI_InitLock(_lock, _name, VMCI_LOCK_RANK_HIGHER_BH) -#define VMCIEventGrabLock(_lock, _flags) VMCI_GrabLock_BH(_lock, _flags) -#define VMCIEventReleaseLock(_lock, _flags) VMCI_ReleaseLock_BH(_lock, _flags) -#else -#define VMCIEventInitLock(_lock, _name) VMCI_InitLock(_lock, _name, VMCI_LOCK_RANK_HIGHER) -#define VMCIEventGrabLock(_lock, _flags) VMCI_GrabLock(_lock, _flags) -#define VMCIEventReleaseLock(_lock, _flags) VMCI_ReleaseLock(_lock, _flags) -#endif +#if defined(VMKERNEL) + /* VMK doesn't need BH locks, so use lower ranks. */ +# define VMCIEventInitLock(_lock, _name) \ + VMCI_InitLock(_lock, _name, VMCI_LOCK_RANK_HIGHER) +# define VMCIEventGrabLock(_lock, _flags) VMCI_GrabLock(_lock, _flags) +# define VMCIEventReleaseLock(_lock, _flags) VMCI_ReleaseLock(_lock, _flags) +#else // VMKERNEL +# define VMCIEventInitLock(_lock, _name) \ + VMCI_InitLock(_lock, _name, VMCI_LOCK_RANK_HIGHER_BH) +# define VMCIEventGrabLock(_lock, _flags) VMCI_GrabLock_BH(_lock, _flags) +# define VMCIEventReleaseLock(_lock, _flags) VMCI_ReleaseLock_BH(_lock, _flags) +#endif // VMKERNEL static VMCIList subscriberArray[VMCI_EVENT_MAX]; diff --git a/open-vm-tools/modules/linux/vmci/vmciGuestKernelIf.c b/open-vm-tools/modules/linux/vmci/vmciGuestKernelIf.c index f57b0eb80..6b3da469e 100644 --- a/open-vm-tools/modules/linux/vmci/vmciGuestKernelIf.c +++ b/open-vm-tools/modules/linux/vmci/vmciGuestKernelIf.c @@ -35,7 +35,7 @@ #include "compat_version.h" #include "compat_pci.h" #include "vm_basic_types.h" -#include "vmciGuestKernelIf.h" +#include "vmciDriver.h" /* diff --git a/open-vm-tools/modules/linux/vmci/vmciGuestKernelIf.h b/open-vm-tools/modules/linux/vmci/vmciGuestKernelIf.h deleted file mode 100644 index 737008d5c..000000000 --- a/open-vm-tools/modules/linux/vmci/vmciGuestKernelIf.h +++ /dev/null @@ -1,62 +0,0 @@ -/********************************************************* - * Copyright (C) 2007 VMware, Inc. All rights reserved. - * - * 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 version 2 and no 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. 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, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - *********************************************************/ - -/* - * vmciGuestKernelIf.h -- - * - * This file defines OS encapsulation helper functions that are - * needed only in VMCI guest kernel code. It must work for - * windows, solaris and linux kernel, ie. using defines - * where necessary. - */ - -#ifndef _VMCI_GUEST_KERNEL_IF_H_ -#define _VMCI_GUEST_KERNEL_IF_H_ - -#if defined(_WIN32) -#include -#endif - -#ifdef SOLARIS -# include -# include -# include -#endif - -#include "vm_basic_types.h" -#include "vmci_defs.h" - -#if defined(linux) - typedef unsigned short int VMCIIoPort; - typedef int VMCIIoHandle; -#elif defined(_WIN32) - typedef PUCHAR VMCIIoPort; - typedef int VMCIIoHandle; -#elif defined(SOLARIS) - typedef uint8_t * VMCIIoPort; - typedef ddi_acc_handle_t VMCIIoHandle; -#elif defined(__APPLE__) - typedef unsigned short int VMCIIoPort; - typedef void *VMCIIoHandle; -#endif // VMKERNEL - -void VMCI_ReadPortBytes(VMCIIoHandle handle, VMCIIoPort port, uint8 *buffer, - size_t bufferLength); - -#endif // _VMCI_GUEST_KERNEL_IF_H_ - diff --git a/open-vm-tools/modules/linux/vmci/vmciHashtable.c b/open-vm-tools/modules/linux/vmci/vmciHashtable.c index cdea16b8c..46fa43e3a 100644 --- a/open-vm-tools/modules/linux/vmci/vmciHashtable.c +++ b/open-vm-tools/modules/linux/vmci/vmciHashtable.c @@ -24,21 +24,13 @@ * our own implementation. */ -#if defined(__linux__) && !defined(VMKERNEL) -# include "driver-config.h" -# include "compat_kernel.h" -# include "compat_module.h" -#endif // __linux__ #include "vmci_kernel_if.h" #include "vm_assert.h" #include "vmci_defs.h" #include "vmci_infrastructure.h" #include "vmciCommonInt.h" #include "vmciHashtable.h" -#ifdef VMX86_TOOLS -# include "vmciInt.h" -# include "vmciUtil.h" -#elif defined(VMKERNEL) +#if defined(VMKERNEL) # include "vmciVmkInt.h" # include "vm_libc.h" # include "helper_ext.h" diff --git a/open-vm-tools/modules/linux/vmci/vmciInt.h b/open-vm-tools/modules/linux/vmci/vmciInt.h deleted file mode 100644 index ce03fda6e..000000000 --- a/open-vm-tools/modules/linux/vmci/vmciInt.h +++ /dev/null @@ -1,47 +0,0 @@ -/********************************************************* - * Copyright (C) 2006 VMware, Inc. All rights reserved. - * - * 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 version 2 and no 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. 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, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - *********************************************************/ - -#ifndef __VMCI_INT_H__ -#define __VMCI_INT_H__ - -#define INCLUDE_ALLOW_MODULE -#include "includeCheck.h" - -#include "vm_basic_types.h" -#include "vmci_call_defs.h" - -#define DODEBUGLOG(...) printk(KERN_DEBUG __VA_ARGS__) -#define DOLOG(...) printk(KERN_INFO __VA_ARGS__) -#define DOWARNING(...) printk(KERN_WARNING __VA_ARGS__) - -#ifdef VMCI_DEBUG -# define VMCI_DEBUG_LOG(_level, _args) DODEBUGLOG _args -#else -# define VMCI_DEBUG_LOG(_level, _args) -#endif // VMCI_DEBUG -#define VMCI_LOG(_args) DOLOG _args -#define VMCI_WARNING(_args) DOWARNING _args - -/* - * Called by common code, hence the different naming convention. - * XXX Should be in vmci.h. - */ -int VMCI_SendDatagram(VMCIDatagram *dg); -Bool VMCI_DeviceEnabled(void); - -#endif /* __VMCIINT_H__ */ diff --git a/open-vm-tools/modules/linux/vmci/vmciQueuePair.c b/open-vm-tools/modules/linux/vmci/vmciQueuePair.c index 99b6eaed5..1fa4ce352 100644 --- a/open-vm-tools/modules/linux/vmci/vmciQueuePair.c +++ b/open-vm-tools/modules/linux/vmci/vmciQueuePair.c @@ -22,11 +22,6 @@ * VMCI QueuePair API implementation in the host driver. */ -#if defined(__linux__) && !defined(VMKERNEL) -# include "driver-config.h" -# include "compat_kernel.h" -# include "compat_module.h" -#endif // __linux__ #include "vmci_kernel_if.h" #include "vm_assert.h" #include "vmci_defs.h" @@ -41,10 +36,7 @@ #include "vmciQueuePair.h" #include "vmciResource.h" #include "vmciRoute.h" -#ifdef VMX86_TOOLS -# include "vmciInt.h" -# include "vmciUtil.h" -#elif defined(VMKERNEL) +#if defined(VMKERNEL) # include "vmciVmkInt.h" # include "vm_libc.h" # include "helper_ext.h" diff --git a/open-vm-tools/modules/linux/vmci/vmciResource.c b/open-vm-tools/modules/linux/vmci/vmciResource.c index 2034b78cd..6192073cb 100644 --- a/open-vm-tools/modules/linux/vmci/vmciResource.c +++ b/open-vm-tools/modules/linux/vmci/vmciResource.c @@ -22,11 +22,6 @@ * Implementation of the VMCI Resource Access Control API. */ -#if defined(__linux__) && !defined(VMKERNEL) -# include "driver-config.h" -# include "compat_kernel.h" -# include "compat_module.h" -#endif // __linux__ #include "vmci_kernel_if.h" #include "vm_assert.h" #include "vmci_defs.h" @@ -34,10 +29,7 @@ #include "vmciCommonInt.h" #include "vmciHashtable.h" #include "vmciResource.h" -#ifdef VMX86_TOOLS -# include "vmciInt.h" -# include "vmciUtil.h" -#elif defined(VMKERNEL) +#if defined(VMKERNEL) # include "vmciVmkInt.h" # include "vm_libc.h" # include "helper_ext.h" diff --git a/open-vm-tools/modules/linux/vmci/vmciRoute.c b/open-vm-tools/modules/linux/vmci/vmciRoute.c index 112337ee7..84d9c377a 100644 --- a/open-vm-tools/modules/linux/vmci/vmciRoute.c +++ b/open-vm-tools/modules/linux/vmci/vmciRoute.c @@ -22,11 +22,6 @@ * Implementation of VMCI routing rules. */ -#if defined(__linux__) && !defined(VMKERNEL) -# include "driver-config.h" -# include "compat_kernel.h" -# include "compat_module.h" -#endif // __linux__ #include "vmci_kernel_if.h" #include "vm_assert.h" #include "vmci_defs.h" @@ -35,10 +30,7 @@ #include "vmciContext.h" #include "vmciKernelAPI.h" #include "vmciRoute.h" -#ifdef VMX86_TOOLS -# include "vmciInt.h" -# include "vmciUtil.h" -#elif defined(VMKERNEL) +#if defined(VMKERNEL) # include "vmciVmkInt.h" # include "vm_libc.h" # include "helper_ext.h" diff --git a/open-vm-tools/modules/linux/vmci/vmciUtil.h b/open-vm-tools/modules/linux/vmci/vmciUtil.h deleted file mode 100644 index 62dccbfeb..000000000 --- a/open-vm-tools/modules/linux/vmci/vmciUtil.h +++ /dev/null @@ -1,53 +0,0 @@ -/********************************************************* - * Copyright (C) 2006 VMware, Inc. All rights reserved. - * - * 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 version 2 and no 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. 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, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - *********************************************************/ - -/* - * vmciUtil.h -- - * - * Helper functions. - */ - -#ifndef __VMCI_UTIL_H__ -#define __VMCI_UTIL_H__ - -#define INCLUDE_ALLOW_MODULE -#include "includeCheck.h" - -#include "vmciGuestKernelIf.h" -#include "vmci_infrastructure.h" - -#define VMCI_MAJOR_VERSION_NUMBER 1 -#define VMCI_MINOR_VERSION_NUMBER 0 -#define VMCI_VERSION_NUMBER \ - ((VMCI_MAJOR_VERSION_NUMBER << 16) | (VMCI_MINOR_VERSION_NUMBER)) - -typedef struct VMCIGuestDeviceHandle { - void *obj; - VMCIObjType objType; -} VMCIGuestDeviceHandle; - -void VMCIUtil_Init(void); -void VMCIUtil_Exit(void); -Bool VMCIUtil_CheckHostCapabilities(void); -Bool VMCI_CheckHostCapabilities(void); -Bool VMCI_InInterrupt(void); -void VMCI_ReadDatagramsFromPort(VMCIIoHandle ioHandle, VMCIIoPort dgInPort, - uint8 *dgInBuffer, size_t dgInBufferSize); -Bool VMCI_DeviceInUse(void); - -#endif //__VMCI_UTIL_H__ diff --git a/open-vm-tools/modules/linux/vmci/vmci_drv.c b/open-vm-tools/modules/linux/vmci/vmci_drv.c index 9a55afb65..a0e24a1d1 100644 --- a/open-vm-tools/modules/linux/vmci/vmci_drv.c +++ b/open-vm-tools/modules/linux/vmci/vmci_drv.c @@ -48,11 +48,10 @@ #include "vmciContext.h" #include "vmciDatagram.h" #include "vmciDoorbell.h" +#include "vmciDriver.h" #include "vmciEvent.h" -#include "vmciInt.h" #include "vmciQueuePair.h" #include "vmciResource.h" -#include "vmciUtil.h" #define LGPFX "VMCI: " #define VMCI_DEVICE_MINOR_NUM 0 @@ -1025,6 +1024,25 @@ process_bitmap(unsigned long data) } +/* + *------------------------------------------------------------------------------ + * + * VMCIUnsetNotify -- + * + * Stub. Not called in the guest driver (yet). + * + * Result: + * Always VMCI_ERROR_GENERIC. + * + *------------------------------------------------------------------------------ + */ + +void +VMCIUnsetNotify(VMCIContext *context) +{ +} + + module_init(vmci_init); module_exit(vmci_exit); MODULE_DEVICE_TABLE(pci, vmci_ids); diff --git a/open-vm-tools/modules/linux/vmci/vmci_version.h b/open-vm-tools/modules/linux/vmci/vmci_version.h index 0f5aad60f..68fac7e46 100644 --- a/open-vm-tools/modules/linux/vmci/vmci_version.h +++ b/open-vm-tools/modules/linux/vmci/vmci_version.h @@ -25,8 +25,8 @@ #ifndef _VMCI_VERSION_H_ #define _VMCI_VERSION_H_ -#define VMCI_DRIVER_VERSION 9.1.9.0 -#define VMCI_DRIVER_VERSION_COMMAS 9,1,9,0 -#define VMCI_DRIVER_VERSION_STRING "9.1.9.0" +#define VMCI_DRIVER_VERSION 9.1.10.0 +#define VMCI_DRIVER_VERSION_COMMAS 9,1,10,0 +#define VMCI_DRIVER_VERSION_STRING "9.1.10.0" #endif /* _VMCI_VERSION_H_ */