17
17
*********************************************************/
22
22
* This file defines helper functions for VMCI host _and_ guest
23
23
* kernel code. It must work for Windows, Mac OS, vmkernel, Linux and
24
24
* Solaris kernels, i.e. using defines where necessary.
27
27
#ifndef _VMCI_KERNEL_IF_H_
28
28
#define _VMCI_KERNEL_IF_H_
30
30
#if !defined(linux) && !defined(_WIN32) && !defined(__APPLE__) && \
31
31
!defined(VMKERNEL) && !defined(SOLARIS)
32
#error "Platform not supported."
32
# error "Platform not supported."
35
35
#if defined(_WIN32)
39
39
#if defined(linux) && !defined(VMKERNEL)
40
# include "driver-config.h"
41
# include "compat_cred.h"
42
# include "compat_module.h"
43
# include "compat_semaphore.h"
44
# include "compat_spinlock.h"
40
45
# include "compat_version.h"
41
# include "compat_wait.h"
42
# include "compat_spinlock.h"
43
# include "compat_semaphore.h"
46
# include <linux/wait.h>
47
50
# include <IOKit/IOLib.h>
48
#include <mach/task.h>
49
#include <mach/semaphore.h>
51
# include <mach/task.h>
52
# include <mach/semaphore.h>
53
# include <sys/kauth.h>
54
#include "semaphore_ext.h"
58
# include "semaphore_ext.h"
64
# include <sys/kmem.h>
58
65
# include <sys/mutex.h>
59
66
# include <sys/poll.h>
60
67
# include <sys/semaphore.h>
61
# include <sys/kmem.h>
68
# include <sys/sunddi.h>
69
# include <sys/types.h>
64
72
#include "vm_basic_types.h"
65
73
#include "vmci_defs.h"
67
#if defined(__APPLE__)
68
78
# include "dbllnklst.h"
76
86
/* Platform specific type definitions. */
78
88
#if defined(VMKERNEL)
89
# define VMCI_EXPORT_SYMBOL(_SYMBOL) VMK_MODULE_EXPORT_SYMBOL(_SYMBOL);
91
# define VMCI_EXPORT_SYMBOL(_symbol) EXPORT_SYMBOL(_symbol);
92
#elif defined(__APPLE__)
93
# define VMCI_EXPORT_SYMBOL(_symbol) __attribute__((visibility("default")))
95
# define VMCI_EXPORT_SYMBOL(_symbol)
79
99
typedef SP_SpinLock VMCILock;
80
100
typedef SP_IRQL VMCILockFlags;
81
101
typedef Semaphore VMCIEvent;
82
102
typedef Semaphore VMCIMutex;
83
103
typedef World_ID VMCIHostVmID;
104
typedef uint32 VMCIHostUser;
84
105
#elif defined(linux)
85
106
typedef spinlock_t VMCILock;
86
107
typedef unsigned long VMCILockFlags;
87
108
typedef wait_queue_head_t VMCIEvent;
88
109
typedef struct semaphore VMCIMutex;
89
110
typedef PPN *VMCIPpnList; /* List of PPNs in produce/consume queue. */
111
typedef uid_t VMCIHostUser;
90
112
#elif defined(__APPLE__)
91
113
typedef IOLock *VMCILock;
92
114
typedef unsigned long VMCILockFlags;
98
120
typedef IOLock *VMCIMutex;
99
121
typedef void *VMCIPpnList; /* Actually a pointer to the C++ Object IOMemoryDescriptor */
122
typedef uid_t VMCIHostUser;
100
123
#elif defined(_WIN32)
101
124
typedef KSPIN_LOCK VMCILock;
102
125
typedef KIRQL VMCILockFlags;
103
126
typedef KEVENT VMCIEvent;
104
127
typedef FAST_MUTEX VMCIMutex;
105
128
typedef PMDL VMCIPpnList; /* MDL to map the produce/consume queue. */
129
typedef PSID VMCIHostUser;
106
130
#elif defined(SOLARIS)
107
131
typedef kmutex_t VMCILock;
108
132
typedef unsigned long VMCILockFlags;
109
133
typedef ksema_t VMCIEvent;
110
134
typedef kmutex_t VMCIMutex;
111
135
typedef PPN *VMCIPpnList; /* List of PPNs in produce/consume queue. */
136
typedef uid_t VMCIHostUser;
112
137
#endif // VMKERNEL
114
139
/* Callback needed for correctly waiting on events. */
197
222
#elif defined(__APPLE__)
198
223
struct Socket *socket; /* vmci Socket object on Mac OS. */
199
224
#elif defined(_WIN32)
200
KEVENT *callEvent; /* Ptr to userlevel event used when signalling
225
KEVENT *callEvent; /* Ptr to userlevel event used when signalling
201
226
* new pending guestcalls in kernel.
203
228
#elif defined(SOLARIS)
204
229
struct pollhead pollhead; /* Per datagram handle pollhead structure to
205
* be treated as a black-box. None of its
230
* be treated as a black-box. None of its
206
231
* fields should be referenced.
237
* Guest device port I/O.
241
typedef unsigned short int VMCIIoPort;
242
typedef int VMCIIoHandle;
243
#elif defined(_WIN32)
244
typedef PUCHAR VMCIIoPort;
245
typedef int VMCIIoHandle;
246
#elif defined(SOLARIS)
247
typedef uint8_t * VMCIIoPort;
248
typedef ddi_acc_handle_t VMCIIoHandle;
249
#elif defined(__APPLE__)
250
typedef unsigned short int VMCIIoPort;
251
typedef void *VMCIIoHandle;
254
void VMCI_ReadPortBytes(VMCIIoHandle handle, VMCIIoPort port, uint8 *buffer,
255
size_t bufferLength);
212
258
void VMCI_InitLock(VMCILock *lock, char *name, VMCILockRank rank);
213
259
void VMCI_CleanupLock(VMCILock *lock);
235
281
void VMCIHost_SignalBitmap(VMCIHost *hostContext);
286
* On Windows, Driver Verifier will panic() if we leak memory when we are
287
* unloaded. It dumps the leaked blocks for us along with callsites, which
288
* it handily tracks, but if we embed ExAllocate() inside a function, then
289
* the callsite is useless. So make this a macro on this platform only.
291
# define VMCI_AllocKernelMem(_sz, _f) \
292
ExAllocatePoolWithTag((((_f) & VMCI_MEMORY_NONPAGED) ? \
293
NonPagedPool : PagedPool), \
238
296
void *VMCI_AllocKernelMem(size_t size, int flags);
239
298
void VMCI_FreeKernelMem(void *ptr, size_t size);
240
VMCIBuffer VMCI_AllocBuffer(size_t size, int flags);
241
void *VMCI_MapBuffer(VMCIBuffer buf);
242
void VMCI_ReleaseBuffer(void *ptr);
243
void VMCI_FreeBuffer(VMCIBuffer buf, size_t size);
245
int VMCI_CopyToUser(VA64 dst, const void *src, size_t len, int mode);
247
300
int VMCI_CopyToUser(VA64 dst, const void *src, size_t len);
249
* Don't need the following for guests, hence no Solaris code for this
252
301
Bool VMCIWellKnownID_AllowMap(VMCIId wellKnownID,
253
302
VMCIPrivilegeFlags privFlags);
304
int VMCIHost_CompareUser(VMCIHostUser *user1, VMCIHostUser *user2);
256
306
void VMCI_CreateEvent(VMCIEvent *event);
257
307
void VMCI_DestroyEvent(VMCIEvent *event);
258
308
void VMCI_SignalEvent(VMCIEvent *event);
259
void VMCI_WaitOnEvent(VMCIEvent *event, VMCIEventReleaseCB releaseCB,
309
void VMCI_WaitOnEvent(VMCIEvent *event, VMCIEventReleaseCB releaseCB,
260
310
void *clientData);
261
311
#if (defined(__APPLE__) || defined(__linux__) || defined(_WIN32)) && !defined(VMKERNEL)
262
312
Bool VMCI_WaitOnEventInterruptible(VMCIEvent *event,
337
376
struct VMCIQueue *produceQ,
338
377
struct VMCIQueue *detachQ,
339
378
const uint64 produceQSize);
382
void VMCI_InitQueueMutex(struct VMCIQueue *produceQ,
383
struct VMCIQueue *consumeQ);
384
void VMCI_AcquireQueueMutex(struct VMCIQueue *queue);
385
void VMCI_ReleaseQueueMutex(struct VMCIQueue *queue);
386
Bool VMCI_EnqueueToDevNull(struct VMCIQueue *queue);
387
int VMCI_ConvertToLocalQueue(struct VMCIQueue *queueInfo,
388
struct VMCIQueue *otherQueueInfo,
389
uint64 size, Bool keepContent,
391
void VMCI_RevertToNonLocalQueue(struct VMCIQueue *queueInfo,
392
void *nonLocalQueue, uint64 size);
393
void VMCI_FreeQueueBuffer(void *queue, uint64 size);
394
Bool VMCI_CanCreate(void);
341
# define VMCIHost_InitQueueMutex(_pq, _cq)
342
# define VMCIHost_AcquireQueueMutex(_q)
343
# define VMCIHost_ReleaseQueueMutex(_q)
344
# define VMCIHost_EnqueueToDevNull(_q) FALSE
346
#endif // !VMX86_TOOLS
396
# define VMCI_InitQueueMutex(_pq, _cq)
397
# define VMCI_AcquireQueueMutex(_q)
398
# define VMCI_ReleaseQueueMutex(_q)
399
# define VMCI_EnqueueToDevNull(_q) FALSE
400
# define VMCI_ConvertToLocalQueue(_pq, _cq, _s, _oq, _kc) VMCI_ERROR_UNAVAILABLE
401
# define VMCI_RevertToNonLocalQueue(_q, _nlq, _s)
402
# define VMCI_FreeQueueBuffer(_q, _s)
403
# define VMCI_CanCreate() TRUE
405
Bool VMCI_GuestPersonalityActive(void);
406
Bool VMCI_HostPersonalityActive(void);
409
#if defined(VMKERNEL)
410
typedef List_Links VMCIListItem;
411
typedef List_Links VMCIList;
413
# define VMCIList_Init(_l) List_Init(_l)
414
# define VMCIList_InitEntry(_e) List_InitElement(_e)
415
# define VMCIList_Empty(_l) List_IsEmpty(_l)
416
# define VMCIList_Insert(_e, _l) List_Insert(_e, LIST_ATREAR(_l))
417
# define VMCIList_Remove(_e, _l) List_Remove(_e)
418
# define VMCIList_Scan(_cur, _l) LIST_FORALL(_l, _cur)
419
# define VMCIList_ScanSafe(_cur, _next, _l) LIST_FORALL_SAFE(_l, _cur, _next)
420
# define VMCIList_Entry(_elem, _type, _field) List_Entry(_elem, _type, _field)
421
# define VMCIList_First(_l) (VMCIList_Empty(_l)?NULL:List_First(_l))
423
typedef DblLnkLst_Links VMCIListItem;
424
typedef DblLnkLst_Links VMCIList;
426
# define VMCIList_Init(_l) DblLnkLst_Init(_l)
427
# define VMCIList_InitEntry(_e) DblLnkLst_Init(_e)
428
# define VMCIList_Empty(_l) (!DblLnkLst_IsLinked(_l))
429
# define VMCIList_Insert(_e, _l) DblLnkLst_LinkLast(_l, _e)
430
# define VMCIList_Remove(_e, _l) DblLnkLst_Unlink1(_e)
431
# define VMCIList_Scan(_cur, _l) DblLnkLst_ForEach(_cur, _l)
432
# define VMCIList_ScanSafe(_cur, _next, _l) DblLnkLst_ForEachSafe(_cur, _next, _l)
433
# define VMCIList_Entry(_elem, _type, _field) DblLnkLst_Container(_elem, _type, _field)
434
# define VMCIList_First(_l) (VMCIList_Empty(_l)?NULL:(_l)->next)
349
437
#endif // _VMCI_KERNEL_IF_H_