VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/SUPDRV.h@ 6412

Last change on this file since 6412 was 6340, checked in by vboxsync, 17 years ago

vboxdrv: added support for Linux high-res timers (disabled), added module parameter for forcing async TSC mode, show some more information on module initialization

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.2 KB
Line 
1/* $Revision: 6340 $ */
2/** @file
3 * VirtualBox Support Driver - Internal header.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27#ifndef __SUPDRV_h__
28#define __SUPDRV_h__
29
30
31/*******************************************************************************
32* Header Files *
33*******************************************************************************/
34#include <VBox/cdefs.h>
35#include <VBox/types.h>
36#include <iprt/assert.h>
37#include <iprt/asm.h>
38#include <VBox/sup.h>
39#ifdef USE_NEW_OS_INTERFACE
40# define USE_NEW_OS_INTERFACE_FOR_MM
41# define USE_NEW_OS_INTERFACE_FOR_GIP
42# undef USE_NEW_OS_INTERFACE_FOR_LOW
43#endif
44#if defined(USE_NEW_OS_INTERFACE) || defined(USE_NEW_OS_INTERFACE_FOR_LOW) || defined(USE_NEW_OS_INTERFACE_FOR_MM) || defined(USE_NEW_OS_INTERFACE_FOR_GIP)
45# include <iprt/memobj.h>
46# include <iprt/time.h>
47# include <iprt/timer.h>
48# include <iprt/string.h>
49# include <iprt/err.h>
50#endif
51
52
53#if defined(RT_OS_WINDOWS)
54 __BEGIN_DECLS
55# if (_MSC_VER >= 1400) && !defined(VBOX_WITH_PATCHED_DDK)
56# define _InterlockedExchange _InterlockedExchange_StupidDDKVsCompilerCrap
57# define _InterlockedExchangeAdd _InterlockedExchangeAdd_StupidDDKVsCompilerCrap
58# define _InterlockedCompareExchange _InterlockedCompareExchange_StupidDDKVsCompilerCrap
59# define _InterlockedAddLargeStatistic _InterlockedAddLargeStatistic_StupidDDKVsCompilerCrap
60# include <ntddk.h>
61# undef _InterlockedExchange
62# undef _InterlockedExchangeAdd
63# undef _InterlockedCompareExchange
64# undef _InterlockedAddLargeStatistic
65# else
66# include <ntddk.h>
67# endif
68# include <memory.h>
69# define memcmp(a,b,c) mymemcmp(a,b,c)
70 int VBOXCALL mymemcmp(const void *, const void *, size_t);
71 __END_DECLS
72
73#elif defined(RT_OS_LINUX)
74# include <linux/autoconf.h>
75# include <linux/version.h>
76# if defined(CONFIG_MODVERSIONS) && !defined(MODVERSIONS)
77# define MODVERSIONS
78# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 71)
79# include <linux/modversions.h>
80# endif
81# endif
82# if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 0)
83# undef ALIGN
84# endif
85# ifndef KBUILD_STR
86# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16)
87# define KBUILD_STR(s) s
88# else
89# define KBUILD_STR(s) #s
90# endif
91# endif
92# include <linux/string.h>
93# include <linux/spinlock.h>
94# include <linux/slab.h>
95# include <asm/semaphore.h>
96# include <linux/timer.h>
97
98# if 0
99# include <linux/hrtimer.h>
100# define VBOX_HRTIMER
101# endif
102
103#elif defined(RT_OS_DARWIN)
104# include <libkern/libkern.h>
105# include <iprt/string.h>
106
107#elif defined(RT_OS_OS2)
108
109#elif defined(RT_OS_FREEBSD)
110# include <sys/libkern.h>
111# include <iprt/string.h>
112
113#elif defined(RT_OS_SOLARIS)
114# include <sys/cmn_err.h>
115# include <iprt/string.h>
116
117#else
118# error "unsupported OS."
119#endif
120
121#include "SUPDRVIOC.h"
122
123
124
125/*******************************************************************************
126* Defined Constants And Macros *
127*******************************************************************************/
128/*
129 * Hardcoded cookies.
130 */
131#define BIRD 0x64726962 /* 'bird' */
132#define BIRD_INV 0x62697264 /* 'drib' */
133
134
135/*
136 * Win32
137 */
138#if defined(RT_OS_WINDOWS)
139
140/* debug printf */
141# define OSDBGPRINT(a) DbgPrint a
142
143/** Maximum number of bytes we try to lock down in one go.
144 * This is supposed to have a limit right below 256MB, but this appears
145 * to actually be much lower. The values here have been determined experimentally.
146 */
147#ifdef RT_ARCH_X86
148# define MAX_LOCK_MEM_SIZE (32*1024*1024) /* 32mb */
149#endif
150#ifdef RT_ARCH_AMD64
151# define MAX_LOCK_MEM_SIZE (24*1024*1024) /* 24mb */
152#endif
153
154
155/*
156 * Linux
157 */
158#elif defined(RT_OS_LINUX)
159
160/* check kernel version */
161#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
162# error Unsupported kernel version!
163#endif
164
165__BEGIN_DECLS
166int linux_dprintf(const char *format, ...);
167__END_DECLS
168
169/* debug printf */
170# define OSDBGPRINT(a) printk a
171
172
173/*
174 * Darwin
175 */
176#elif defined(RT_OS_DARWIN)
177
178/* debug printf */
179# define OSDBGPRINT(a) printf a
180
181
182/*
183 * OS/2
184 */
185#elif defined(RT_OS_OS2)
186
187/* No log API in OS/2 only COM port. */
188# define OSDBGPRINT(a) SUPR0Printf a
189
190
191/*
192 * FreeBSD
193 */
194#elif defined(RT_OS_FREEBSD)
195
196/* No log API in OS/2 only COM port. */
197# define OSDBGPRINT(a) printf a
198
199
200/*
201 * Solaris
202 */
203#elif defined(RT_OS_SOLARIS)
204# define OSDBGPRINT(a) SUPR0Printf a
205
206
207#else
208/** @todo other os'es */
209# error "OS interface defines is not done for this OS!"
210#endif
211
212
213/* dprintf */
214#if (defined(DEBUG) && !defined(NO_LOGGING)) || defined(RT_OS_FREEBSD)
215# ifdef LOG_TO_COM
216# include <VBox/log.h>
217# define dprintf(a) RTLogComPrintf a
218# else
219# define dprintf(a) OSDBGPRINT(a)
220# endif
221#else
222# define dprintf(a) do {} while (0)
223#endif
224
225/* dprintf2 - extended logging. */
226#if defined(RT_OS_DARWIN) || defined(RT_OS_OS2) || defined(RT_OS_FREEBSD)
227# define dprintf2 dprintf
228#else
229# define dprintf2(a) do { } while (0)
230#endif
231
232
233/*
234 * Error codes.
235 */
236/** Invalid parameter. */
237#define SUPDRV_ERR_GENERAL_FAILURE (-1)
238/** Invalid parameter. */
239#define SUPDRV_ERR_INVALID_PARAM (-2)
240/** Invalid magic or cookie. */
241#define SUPDRV_ERR_INVALID_MAGIC (-3)
242/** Invalid loader handle. */
243#define SUPDRV_ERR_INVALID_HANDLE (-4)
244/** Failed to lock the address range. */
245#define SUPDRV_ERR_LOCK_FAILED (-5)
246/** Invalid memory pointer. */
247#define SUPDRV_ERR_INVALID_POINTER (-6)
248/** Failed to patch the IDT. */
249#define SUPDRV_ERR_IDT_FAILED (-7)
250/** Memory allocation failed. */
251#define SUPDRV_ERR_NO_MEMORY (-8)
252/** Already loaded. */
253#define SUPDRV_ERR_ALREADY_LOADED (-9)
254/** Permission denied. */
255#define SUPDRV_ERR_PERMISSION_DENIED (-10)
256/** Version mismatch. */
257#define SUPDRV_ERR_VERSION_MISMATCH (-11)
258
259
260
261/*******************************************************************************
262* Structures and Typedefs *
263*******************************************************************************/
264/** Pointer to the device extension. */
265typedef struct SUPDRVDEVEXT *PSUPDRVDEVEXT;
266
267#ifdef RT_OS_LINUX
268# ifdef VBOX_HRTIMER
269typedef struct hrtimer VBOXKTIMER;
270# else
271typedef struct timer_list VBOXKTIMER;
272# endif
273#endif
274
275#ifdef VBOX_WITH_IDT_PATCHING
276
277/**
278 * An IDT Entry.
279 */
280typedef struct SUPDRVIDTE
281{
282 /** Low offset word. */
283 uint32_t u16OffsetLow : 16;
284 /** Segment Selector. */
285 uint32_t u16SegSel : 16;
286#ifdef RT_ARCH_AMD64
287 /** Interrupt Stack Table index. */
288 uint32_t u3IST : 3;
289 /** Reserved, ignored. */
290 uint32_t u5Reserved : 5;
291#else
292 /** Reserved. */
293 uint32_t u5Reserved : 5;
294 /** IDT Type part one (not used for task gate). */
295 uint32_t u3Type1 : 3;
296#endif
297 /** IDT Type part two. */
298 uint32_t u5Type2 : 5;
299 /** Descriptor Privilege level. */
300 uint32_t u2DPL : 2;
301 /** Present flag. */
302 uint32_t u1Present : 1;
303 /** High offset word. */
304 uint32_t u16OffsetHigh : 16;
305#ifdef RT_ARCH_AMD64
306 /** The upper top part of the address. */
307 uint32_t u32OffsetTop;
308 /** Reserved dword for qword (aligning the struct), ignored. */
309 uint32_t u32Reserved;
310#endif
311} SUPDRVIDTE, *PSUPDRVIDTE;
312
313/** The u5Type2 value for an interrupt gate. */
314#define SUPDRV_IDTE_TYPE2_INTERRUPT_GATE 0x0e
315
316
317/**
318 * Patch code.
319 */
320typedef struct SUPDRVPATCH
321{
322#define SUPDRV_PATCH_CODE_SIZE 0x50
323 /** Patch code. */
324 uint8_t auCode[SUPDRV_PATCH_CODE_SIZE];
325 /** Changed IDT entry (for parnoid UnpatchIdt()). */
326 SUPDRVIDTE ChangedIdt;
327 /** Saved IDT entry. */
328 SUPDRVIDTE SavedIdt;
329 /** Pointer to the IDT.
330 * We ASSUME the IDT is not re(al)located after bootup and use this as key
331 * for the patches rather than processor number. This prevents some
332 * stupid nesting stuff from happening in case of processors sharing the
333 * IDT.
334 * We're fucked if the processors have different physical mapping for
335 * the(se) page(s), but we'll find that out soon enough in VBOX_STRICT mode.
336 */
337 void *pvIdt;
338 /** Pointer to the IDT entry. */
339 SUPDRVIDTE volatile *pIdtEntry;
340 /** Usage counter. */
341 uint32_t volatile cUsage;
342 /** The offset into auCode of the VMMR0Entry fixup. */
343 uint16_t offVMMR0EntryFixup;
344 /** The offset into auCode of the stub function. */
345 uint16_t offStub;
346 /** Pointer to the next patch. */
347 struct SUPDRVPATCH * volatile pNext;
348} SUPDRVPATCH, *PSUPDRVPATCH;
349
350/**
351 * Usage record for a patch.
352 */
353typedef struct SUPDRVPATCHUSAGE
354{
355 /** Next in the chain. */
356 struct SUPDRVPATCHUSAGE * volatile pNext;
357 /** The patch this usage applies to. */
358 PSUPDRVPATCH pPatch;
359 /** Usage count. */
360 uint32_t volatile cUsage;
361} SUPDRVPATCHUSAGE, *PSUPDRVPATCHUSAGE;
362
363#endif /* VBOX_WITH_IDT_PATCHING */
364
365
366/**
367 * Memory reference types.
368 */
369typedef enum
370{
371 /** Unused entry */
372 MEMREF_TYPE_UNUSED = 0,
373 /** Locked memory (r3 mapping only). */
374 MEMREF_TYPE_LOCKED,
375 /** Continous memory block (r3 and r0 mapping). */
376 MEMREF_TYPE_CONT,
377 /** Low memory block (r3 and r0 mapping). */
378 MEMREF_TYPE_LOW,
379 /** Memory block (r3 and r0 mapping). */
380 MEMREF_TYPE_MEM,
381 /** Locked memory (r3 mapping only) allocated by the support driver. */
382 MEMREF_TYPE_LOCKED_SUP,
383 /** Blow the type up to 32-bit and mark the end. */
384 MEMREG_TYPE_32BIT_HACK = 0x7fffffff
385} SUPDRVMEMREFTYPE, *PSUPDRVMEMREFTYPE;
386
387
388/**
389 * Structure used for tracking memory a session
390 * references in one way or another.
391 */
392typedef struct SUPDRVMEMREF
393{
394#ifdef USE_NEW_OS_INTERFACE_FOR_MM
395 /** The memory object handle. */
396 RTR0MEMOBJ MemObj;
397 /** The ring-3 mapping memory object handle. */
398 RTR0MEMOBJ MapObjR3;
399 /** Type of memory. */
400 SUPDRVMEMREFTYPE eType;
401
402#else /* !USE_NEW_OS_INTERFACE_FOR_MM */
403 /** Pointer to the R0 mapping of the memory.
404 * Set to NULL if N/A. */
405 void *pvR0;
406 /** Pointer to the R3 mapping of the memory.
407 * Set to NULL if N/A. */
408 RTR3PTR pvR3;
409 /** Size of the locked memory. */
410 unsigned cb;
411 /** Type of memory. */
412 SUPDRVMEMREFTYPE eType;
413
414 /** memory type specific information. */
415 union
416 {
417 struct
418 {
419#if defined(RT_OS_WINDOWS)
420 /** Pointer to memory descriptor list (MDL). */
421 PMDL *papMdl;
422 unsigned cMdls;
423#elif defined(RT_OS_LINUX)
424 struct page **papPages;
425 unsigned cPages;
426#else
427# error "Either no target was defined or we haven't ported the driver to the target yet."
428#endif
429 } locked;
430 struct
431 {
432#if defined(RT_OS_WINDOWS)
433 /** Pointer to memory descriptor list (MDL). */
434 PMDL pMdl;
435#elif defined(RT_OS_LINUX)
436 struct page *paPages;
437 unsigned cPages;
438#else
439# error "Either no target was defined or we haven't ported the driver to the target yet."
440#endif
441 } cont;
442 struct
443 {
444#if defined(RT_OS_WINDOWS)
445 /** Pointer to memory descriptor list (MDL). */
446 PMDL pMdl;
447#elif defined(RT_OS_LINUX)
448 /** Pointer to the array of page pointers. */
449 struct page **papPages;
450 /** Number of pages in papPages. */
451 unsigned cPages;
452#else
453# error "Either no target was defined or we haven't ported the driver to the target yet."
454#endif
455 } mem;
456#if defined(USE_NEW_OS_INTERFACE_FOR_LOW)
457 struct
458 {
459 /** The memory object handle. */
460 RTR0MEMOBJ MemObj;
461 /** The ring-3 mapping memory object handle. */
462 RTR0MEMOBJ MapObjR3;
463 } iprt;
464#endif
465 } u;
466#endif /* !USE_NEW_OS_INTERFACE_FOR_MM */
467} SUPDRVMEMREF, *PSUPDRVMEMREF;
468
469
470/**
471 * Bundle of locked memory ranges.
472 */
473typedef struct SUPDRVBUNDLE
474{
475 /** Pointer to the next bundle. */
476 struct SUPDRVBUNDLE * volatile pNext;
477 /** Referenced memory. */
478 SUPDRVMEMREF aMem[64];
479 /** Number of entries used. */
480 uint32_t volatile cUsed;
481} SUPDRVBUNDLE, *PSUPDRVBUNDLE;
482
483
484/**
485 * Loaded image.
486 */
487typedef struct SUPDRVLDRIMAGE
488{
489 /** Next in chain. */
490 struct SUPDRVLDRIMAGE * volatile pNext;
491 /** Pointer to the image. */
492 void *pvImage;
493 /** Pointer to the optional module initialization callback. */
494 PFNR0MODULEINIT pfnModuleInit;
495 /** Pointer to the optional module termination callback. */
496 PFNR0MODULETERM pfnModuleTerm;
497 /** Size of the image. */
498 uint32_t cbImage;
499 /** The offset of the symbol table. */
500 uint32_t offSymbols;
501 /** The number of entries in the symbol table. */
502 uint32_t cSymbols;
503 /** The offset of the string table. */
504 uint32_t offStrTab;
505 /** Size of the string table. */
506 uint32_t cbStrTab;
507 /** The ldr image state. (IOCtl code of last opration.) */
508 uint32_t uState;
509 /** Usage count. */
510 uint32_t volatile cUsage;
511 /** Image name. */
512 char szName[32];
513} SUPDRVLDRIMAGE, *PSUPDRVLDRIMAGE;
514
515
516/** Image usage record. */
517typedef struct SUPDRVLDRUSAGE
518{
519 /** Next in chain. */
520 struct SUPDRVLDRUSAGE * volatile pNext;
521 /** The image. */
522 PSUPDRVLDRIMAGE pImage;
523 /** Load count. */
524 uint32_t volatile cUsage;
525} SUPDRVLDRUSAGE, *PSUPDRVLDRUSAGE;
526
527
528/**
529 * Registered object.
530 * This takes care of reference counting and tracking data for access checks.
531 */
532typedef struct SUPDRVOBJ
533{
534 /** Magic value (SUPDRVOBJ_MAGIC). */
535 uint32_t u32Magic;
536 /** The object type. */
537 SUPDRVOBJTYPE enmType;
538 /** Pointer to the next in the global list. */
539 struct SUPDRVOBJ * volatile pNext;
540 /** Pointer to the object destructor.
541 * This may be set to NULL if the image containing the destructor get unloaded. */
542 PFNSUPDRVDESTRUCTOR pfnDestructor;
543 /** User argument 1. */
544 void *pvUser1;
545 /** User argument 2. */
546 void *pvUser2;
547 /** The total sum of all per-session usage. */
548 uint32_t volatile cUsage;
549 /** The creator user id. */
550 RTUID CreatorUid;
551 /** The creator group id. */
552 RTGID CreatorGid;
553 /** The creator process id. */
554 RTPROCESS CreatorProcess;
555} SUPDRVOBJ, *PSUPDRVOBJ;
556
557/** Magic number for SUPDRVOBJ::u32Magic. (Dame Agatha Mary Clarissa Christie). */
558#define SUPDRVOBJ_MAGIC 0x18900915
559
560/**
561 * The per-session object usage record.
562 */
563typedef struct SUPDRVUSAGE
564{
565 /** Pointer to the next in the list. */
566 struct SUPDRVUSAGE * volatile pNext;
567 /** Pointer to the object we're recording usage for. */
568 PSUPDRVOBJ pObj;
569 /** The usage count. */
570 uint32_t volatile cUsage;
571} SUPDRVUSAGE, *PSUPDRVUSAGE;
572
573
574/**
575 * Per session data.
576 * This is mainly for memory tracking.
577 */
578typedef struct SUPDRVSESSION
579{
580 /** Pointer to the device extension. */
581 PSUPDRVDEVEXT pDevExt;
582 /** Session Cookie. */
583 uint32_t u32Cookie;
584
585 /** Load usage records. (protected by SUPDRVDEVEXT::mtxLdr) */
586 PSUPDRVLDRUSAGE volatile pLdrUsage;
587#ifdef VBOX_WITH_IDT_PATCHING
588 /** Patch usage records. (protected by SUPDRVDEVEXT::SpinLock) */
589 PSUPDRVPATCHUSAGE volatile pPatchUsage;
590#endif
591 /** The VM associated with the session. */
592 PVM pVM;
593 /** List of generic usage records. (protected by SUPDRVDEVEXT::SpinLock) */
594 PSUPDRVUSAGE volatile pUsage;
595
596 /** Spinlock protecting the bundles and the GIP members. */
597 RTSPINLOCK Spinlock;
598#ifdef USE_NEW_OS_INTERFACE_FOR_GIP
599 /** The ring-3 mapping of the GIP (readonly). */
600 RTR0MEMOBJ GipMapObjR3;
601#else
602 /** The read-only usermode mapping address of the GID.
603 * This is NULL if the GIP hasn't been mapped. */
604 PSUPGLOBALINFOPAGE pGip;
605#endif
606 /** Set if the session is using the GIP. */
607 uint32_t fGipReferenced;
608 /** Bundle of locked memory objects. */
609 SUPDRVBUNDLE Bundle;
610
611 /** The user id of the session. (Set by the OS part.) */
612 RTUID Uid;
613 /** The group id of the session. (Set by the OS part.) */
614 RTGID Gid;
615 /** The process (id) of the session. (Set by the OS part.) */
616 RTPROCESS Process;
617 /** Which process this session is associated with. */
618 RTR0PROCESS R0Process;
619#if defined(RT_OS_OS2)
620 /** The system file number of this session. */
621 uint16_t sfn;
622 uint16_t Alignment; /**< Alignment */
623#endif
624#if defined(RT_OS_DARWIN) || defined(RT_OS_OS2) || defined(RT_OS_SOLARIS)
625 /** Pointer to the next session with the same hash. */
626 PSUPDRVSESSION pNextHash;
627#endif
628} SUPDRVSESSION;
629
630
631/**
632 * Device extension.
633 */
634typedef struct SUPDRVDEVEXT
635{
636 /** Spinlock to serialize the initialization,
637 * usage counting and destruction of the IDT entry override and objects. */
638 RTSPINLOCK Spinlock;
639
640#ifdef VBOX_WITH_IDT_PATCHING
641 /** List of patches. */
642 PSUPDRVPATCH volatile pIdtPatches;
643 /** List of patches Free. */
644 PSUPDRVPATCH volatile pIdtPatchesFree;
645#endif
646
647 /** List of registered objects. Protected by the spinlock. */
648 PSUPDRVOBJ volatile pObjs;
649 /** List of free object usage records. */
650 PSUPDRVUSAGE volatile pUsageFree;
651
652 /** Global cookie. */
653 uint32_t u32Cookie;
654
655 /** The IDT entry number.
656 * Only valid if pIdtPatches is set. */
657 uint8_t volatile u8Idt;
658
659 /** Loader mutex.
660 * This protects pvVMMR0, pvVMMR0Entry, pImages and SUPDRVSESSION::pLdrUsage. */
661 RTSEMFASTMUTEX mtxLdr;
662
663 /** VMM Module 'handle'.
664 * 0 if the code VMM isn't loaded and Idt are nops. */
665 void * volatile pvVMMR0;
666 /** VMMR0EntryInt() pointer. */
667 DECLR0CALLBACKMEMBER(int, pfnVMMR0EntryInt, (PVM pVM, unsigned uOperation, void *pvArg));
668 /** VMMR0EntryFast() pointer. */
669 DECLR0CALLBACKMEMBER(int, pfnVMMR0EntryFast, (PVM pVM, unsigned uOperation));
670 /** VMMR0EntryEx() pointer. */
671 DECLR0CALLBACKMEMBER(int, pfnVMMR0EntryEx, (PVM pVM, unsigned uOperation, PSUPVMMR0REQHDR pReq, uint64_t u64Arg));
672
673 /** Linked list of loaded code. */
674 PSUPDRVLDRIMAGE volatile pLdrImages;
675
676 /** GIP mutex.
677 * Any changes to any of the GIP members requires ownership of this mutex,
678 * except on driver init and termination. */
679 RTSEMFASTMUTEX mtxGip;
680 /** Pointer to the Global Info Page (GIP). */
681 PSUPGLOBALINFOPAGE pGip;
682 /** The physical address of the GIP. */
683 RTHCPHYS HCPhysGip;
684 /** Number of processes using the GIP.
685 * (The updates are suspend while cGipUsers is 0.)*/
686 uint32_t volatile cGipUsers;
687#ifdef USE_NEW_OS_INTERFACE_FOR_GIP
688 /** The ring-0 memory object handle for the GIP page. */
689 RTR0MEMOBJ GipMemObj;
690 /** The GIP timer handle. */
691 PRTTIMER pGipTimer;
692 /** If non-zero we've successfully called RTTimerRequestSystemGranularity(). */
693 uint32_t u32SystemTimerGranularityGrant;
694#endif
695#ifdef RT_OS_WINDOWS
696 /** The GIP timer object. */
697 KTIMER GipTimer;
698 /** The GIP DPC object associated with GipTimer. */
699 KDPC GipDpc;
700 /** The GIP DPC objects for updating per-cpu data. */
701 KDPC aGipCpuDpcs[32];
702 /** Pointer to the MDL for the pGip page. */
703 PMDL pGipMdl;
704 /** GIP timer interval (ms). */
705 ULONG ulGipTimerInterval;
706#endif
707#ifdef RT_OS_LINUX
708 /** The last jiffies. */
709 unsigned long ulLastJiffies;
710 /** The last mono time stamp. */
711 uint64_t volatile u64LastMonotime;
712 /** Set when GIP is suspended to prevent the timers from re-registering themselves). */
713 uint8_t volatile fGIPSuspended;
714# ifdef CONFIG_SMP
715 /** Array of per CPU data for SUPGIPMODE_ASYNC_TSC. */
716 struct LINUXCPU
717 {
718 /** The last mono time stamp. */
719 uint64_t volatile u64LastMonotime;
720 /** The last jiffies. */
721 unsigned long ulLastJiffies;
722 /** The Linux Process ID. */
723 unsigned iSmpProcessorId;
724 /** The per cpu timer. */
725 VBOXKTIMER Timer;
726 } aCPUs[256];
727# endif
728#endif
729} SUPDRVDEVEXT;
730
731
732__BEGIN_DECLS
733
734/*******************************************************************************
735* OS Specific Functions *
736*******************************************************************************/
737void VBOXCALL supdrvOSObjInitCreator(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession);
738bool VBOXCALL supdrvOSObjCanAccess(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession, const char *pszObjName, int *prc);
739#ifndef USE_NEW_OS_INTERFACE_FOR_MM
740int VBOXCALL supdrvOSLockMemOne(PSUPDRVMEMREF pMem, PSUPPAGE paPages);
741void VBOXCALL supdrvOSUnlockMemOne(PSUPDRVMEMREF pMem);
742int VBOXCALL supdrvOSContAllocOne(PSUPDRVMEMREF pMem, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS pHCPhys);
743void VBOXCALL supdrvOSContFreeOne(PSUPDRVMEMREF pMem);
744int VBOXCALL supdrvOSLowAllocOne(PSUPDRVMEMREF pMem, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PSUPPAGE paPages);
745void VBOXCALL supdrvOSLowFreeOne(PSUPDRVMEMREF pMem);
746int VBOXCALL supdrvOSMemAllocOne(PSUPDRVMEMREF pMem, PRTR0PTR ppvR0, PRTR3PTR ppvR3);
747void VBOXCALL supdrvOSMemGetPages(PSUPDRVMEMREF pMem, PSUPPAGE paPages);
748void VBOXCALL supdrvOSMemFreeOne(PSUPDRVMEMREF pMem);
749#endif
750#ifndef USE_NEW_OS_INTERFACE_FOR_GIP
751int VBOXCALL supdrvOSGipMap(PSUPDRVDEVEXT pDevExt, PSUPGLOBALINFOPAGE *ppGip);
752int VBOXCALL supdrvOSGipUnmap(PSUPDRVDEVEXT pDevExt, PSUPGLOBALINFOPAGE pGip);
753void VBOXCALL supdrvOSGipResume(PSUPDRVDEVEXT pDevExt);
754void VBOXCALL supdrvOSGipSuspend(PSUPDRVDEVEXT pDevExt);
755unsigned VBOXCALL supdrvOSGetCPUCount(void);
756bool VBOXCALL supdrvOSGetForcedAsyncTscMode(void);
757#endif
758
759
760/*******************************************************************************
761* Shared Functions *
762*******************************************************************************/
763int VBOXCALL supdrvIOCtl(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPREQHDR pReqHdr);
764int VBOXCALL supdrvIOCtlFast(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
765int VBOXCALL supdrvInitDevExt(PSUPDRVDEVEXT pDevExt);
766void VBOXCALL supdrvDeleteDevExt(PSUPDRVDEVEXT pDevExt);
767int VBOXCALL supdrvCreateSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION *ppSession);
768void VBOXCALL supdrvCloseSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
769void VBOXCALL supdrvCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
770int VBOXCALL supdrvGipInit(PSUPDRVDEVEXT pDevExt, PSUPGLOBALINFOPAGE pGip, RTHCPHYS HCPhys, uint64_t u64NanoTS, unsigned uUpdateHz);
771void VBOXCALL supdrvGipTerm(PSUPGLOBALINFOPAGE pGip);
772void VBOXCALL supdrvGipUpdate(PSUPGLOBALINFOPAGE pGip, uint64_t u64NanoTS);
773void VBOXCALL supdrvGipUpdatePerCpu(PSUPGLOBALINFOPAGE pGip, uint64_t u64NanoTS, unsigned iCpu);
774
775__END_DECLS
776
777#endif
778
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette