1 | /* $Id: IOMInline.h 37425 2011-06-12 19:33:00Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IOM - Inlined functions.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2011 Oracle Corporation
|
---|
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 |
|
---|
18 | #ifndef ___IOMInline_h
|
---|
19 | #define ___IOMInline_h
|
---|
20 |
|
---|
21 | /** @addtogroup grp_iom_int Internals
|
---|
22 | * @internal
|
---|
23 | * @{
|
---|
24 | */
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Gets the I/O port range for the specified I/O port in the current context.
|
---|
28 | *
|
---|
29 | * @returns Pointer to I/O port range.
|
---|
30 | * @returns NULL if no port registered.
|
---|
31 | *
|
---|
32 | * @param pVM The VM handle.
|
---|
33 | * @param Port The I/O port lookup.
|
---|
34 | */
|
---|
35 | DECLINLINE(CTX_SUFF(PIOMIOPORTRANGE)) iomIOPortGetRange(PVM pVM, RTIOPORT Port)
|
---|
36 | {
|
---|
37 | #ifdef IN_RING3
|
---|
38 | if (PDMCritSectIsInitialized(&pVM->iom.s.EmtLock))
|
---|
39 | #endif
|
---|
40 | Assert(PDMCritSectIsOwner(&pVM->iom.s.EmtLock));
|
---|
41 | return (CTX_SUFF(PIOMIOPORTRANGE))RTAvlroIOPortRangeGet(&pVM->iom.s.CTX_SUFF(pTrees)->CTX_SUFF(IOPortTree), Port);
|
---|
42 | }
|
---|
43 |
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Gets the I/O port range for the specified I/O port in the HC.
|
---|
47 | *
|
---|
48 | * @returns Pointer to I/O port range.
|
---|
49 | * @returns NULL if no port registered.
|
---|
50 | *
|
---|
51 | * @param pVM The VM handle.
|
---|
52 | * @param Port The I/O port to lookup.
|
---|
53 | */
|
---|
54 | DECLINLINE(PIOMIOPORTRANGER3) iomIOPortGetRangeR3(PVM pVM, RTIOPORT Port)
|
---|
55 | {
|
---|
56 | #ifdef IN_RING3
|
---|
57 | if (PDMCritSectIsInitialized(&pVM->iom.s.EmtLock)) /** @todo Move the call into the assertion since the compiler cannot optimize it away in non-strict builds. */
|
---|
58 | #endif
|
---|
59 | Assert(PDMCritSectIsOwner(&pVM->iom.s.EmtLock));
|
---|
60 | return (PIOMIOPORTRANGER3)RTAvlroIOPortRangeGet(&pVM->iom.s.CTX_SUFF(pTrees)->IOPortTreeR3, Port);
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * Gets the MMIO range for the specified physical address in the current context.
|
---|
66 | *
|
---|
67 | * @returns Pointer to MMIO range.
|
---|
68 | * @returns NULL if address not in a MMIO range.
|
---|
69 | *
|
---|
70 | * @param pVM The VM handle.
|
---|
71 | * @param GCPhys Physical address to lookup.
|
---|
72 | */
|
---|
73 | DECLINLINE(PIOMMMIORANGE) iomMMIOGetRange(PVM pVM, RTGCPHYS GCPhys)
|
---|
74 | {
|
---|
75 | #ifdef IN_RING3
|
---|
76 | if (PDMCritSectIsInitialized(&pVM->iom.s.EmtLock))
|
---|
77 | #endif
|
---|
78 | Assert(PDMCritSectIsOwner(&pVM->iom.s.EmtLock));
|
---|
79 | PIOMMMIORANGE pRange = pVM->iom.s.CTX_SUFF(pMMIORangeLast);
|
---|
80 | if ( !pRange
|
---|
81 | || GCPhys - pRange->GCPhys >= pRange->cb)
|
---|
82 | pVM->iom.s.CTX_SUFF(pMMIORangeLast) = pRange
|
---|
83 | = (PIOMMMIORANGE)RTAvlroGCPhysRangeGet(&pVM->iom.s.CTX_SUFF(pTrees)->MMIOTree, GCPhys);
|
---|
84 | return pRange;
|
---|
85 | }
|
---|
86 |
|
---|
87 |
|
---|
88 | #ifdef VBOX_STRICT
|
---|
89 | /**
|
---|
90 | * Gets the MMIO range for the specified physical address in the current context.
|
---|
91 | *
|
---|
92 | * @returns Pointer to MMIO range.
|
---|
93 | * @returns NULL if address not in a MMIO range.
|
---|
94 | *
|
---|
95 | * @param pVM The VM handle.
|
---|
96 | * @param GCPhys Physical address to lookup.
|
---|
97 | */
|
---|
98 | DECLINLINE(PIOMMMIORANGE) iomMMIOGetRangeUnsafe(PVM pVM, RTGCPHYS GCPhys)
|
---|
99 | {
|
---|
100 | PIOMMMIORANGE pRange = pVM->iom.s.CTX_SUFF(pMMIORangeLast);
|
---|
101 | if ( !pRange
|
---|
102 | || GCPhys - pRange->GCPhys >= pRange->cb)
|
---|
103 | pVM->iom.s.CTX_SUFF(pMMIORangeLast) = pRange
|
---|
104 | = (PIOMMMIORANGE)RTAvlroGCPhysRangeGet(&pVM->iom.s.CTX_SUFF(pTrees)->MMIOTree, GCPhys);
|
---|
105 | return pRange;
|
---|
106 | }
|
---|
107 | #endif /* VBOX_STRICT */
|
---|
108 |
|
---|
109 |
|
---|
110 | #ifdef VBOX_WITH_STATISTICS
|
---|
111 | /**
|
---|
112 | * Gets the MMIO statistics record.
|
---|
113 | *
|
---|
114 | * In ring-3 this will lazily create missing records, while in GC/R0 the caller has to
|
---|
115 | * return the appropriate status to defer the operation to ring-3.
|
---|
116 | *
|
---|
117 | * @returns Pointer to MMIO stats.
|
---|
118 | * @returns NULL if not found (R0/GC), or out of memory (R3).
|
---|
119 | *
|
---|
120 | * @param pVM The VM handle.
|
---|
121 | * @param GCPhys Physical address to lookup.
|
---|
122 | * @param pRange The MMIO range.
|
---|
123 | */
|
---|
124 | DECLINLINE(PIOMMMIOSTATS) iomMMIOGetStats(PVM pVM, RTGCPHYS GCPhys, PIOMMMIORANGE pRange)
|
---|
125 | {
|
---|
126 | Assert(PDMCritSectIsOwner(&pVM->iom.s.EmtLock));
|
---|
127 | /* For large ranges, we'll put everything on the first byte. */
|
---|
128 | if (pRange->cb > PAGE_SIZE)
|
---|
129 | GCPhys = pRange->GCPhys;
|
---|
130 |
|
---|
131 | PIOMMMIOSTATS pStats = pVM->iom.s.CTX_SUFF(pMMIOStatsLast);
|
---|
132 | if ( !pStats
|
---|
133 | || pStats->Core.Key != GCPhys)
|
---|
134 | {
|
---|
135 | pStats = (PIOMMMIOSTATS)RTAvloGCPhysGet(&pVM->iom.s.CTX_SUFF(pTrees)->MMIOStatTree, GCPhys);
|
---|
136 | # ifdef IN_RING3
|
---|
137 | if (!pStats)
|
---|
138 | pStats = iomR3MMIOStatsCreate(pVM, GCPhys, pRange->pszDesc);
|
---|
139 | # endif
|
---|
140 | }
|
---|
141 | return pStats;
|
---|
142 | }
|
---|
143 | #endif /* VBOX_WITH_STATISTICS */
|
---|
144 |
|
---|
145 |
|
---|
146 | /** @} */
|
---|
147 |
|
---|
148 | #endif
|
---|
149 |
|
---|