VirtualBox

source: vbox/trunk/src/VBox/Devices/VMMDev/VMMDevTesting.cpp@ 30724

Last change on this file since 30724 was 30724, checked in by vboxsync, 15 years ago

Recommitted r63480 - VMMDev: Adding an optional (disabled by default) testing side to the device to assist simple guest benchmarks and tests. Started on a MMIO and IOPort benchmark (for comparison with network performance numbers).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.6 KB
Line 
1/* $Id: VMMDevTesting.cpp 30724 2010-07-08 08:30:20Z vboxsync $ */
2/** @file
3 * VMMDev - Testing Extensions.
4 */
5
6/*
7 * Copyright (C) 2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. 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
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#define LOG_GROUP LOG_GROUP_DEV_VMM
23#include <VBox/VMMDev.h>
24#include <VBox/log.h>
25#include <VBox/err.h>
26
27#include <iprt/asm.h>
28#include <iprt/assert.h>
29#include <iprt/string.h>
30#include <iprt/time.h>
31
32#include "VMMDevState.h"
33#include "VMMDevTesting.h"
34
35
36#ifndef VBOX_WITHOUT_TESTING_FEATURES
37
38/**
39 * @callback_method_impl{FNIOMMMIOWRITE}
40 */
41PDMBOTHCBDECL(int) vmmdevTestingMmioWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb)
42{
43 switch (GCPhysAddr)
44 {
45 case VMMDEV_TESTING_MMIO_NOP:
46 switch (cb)
47 {
48 case 8:
49 case 4:
50 case 2:
51 case 1:
52 break;
53 default:
54 AssertFailed();
55 return VERR_INTERNAL_ERROR_5;
56 }
57 return VINF_SUCCESS;
58
59 default:
60 break;
61 }
62 return VINF_SUCCESS;
63}
64
65
66/**
67 * @callback_method_impl{FNIOMMMIOREAD}
68 */
69PDMBOTHCBDECL(int) vmmdevTestingMmioRead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb)
70{
71 switch (GCPhysAddr)
72 {
73 case VMMDEV_TESTING_MMIO_NOP:
74 switch (cb)
75 {
76 case 8:
77 *(uint64_t *)pv = VMMDEV_TESTING_NOP_RET | ((uint64_t)VMMDEV_TESTING_NOP_RET << 32);
78 break;
79 case 4:
80 *(uint32_t *)pv = VMMDEV_TESTING_NOP_RET;
81 break;
82 case 2:
83 *(uint16_t *)pv = (uint16_t)VMMDEV_TESTING_NOP_RET;
84 break;
85 case 1:
86 *(uint8_t *)pv = (uint8_t)VMMDEV_TESTING_NOP_RET;
87 break;
88 default:
89 AssertFailed();
90 return VERR_INTERNAL_ERROR_5;
91 }
92 return VINF_SUCCESS;
93
94
95 default:
96 break;
97 }
98
99 return VINF_IOM_MMIO_UNUSED_FF;
100}
101
102
103/**
104 * @callback_method_impl{FNIOMIOPORTOUT}
105 */
106PDMBOTHCBDECL(int) vmmdevTestingIoWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
107{
108 switch (Port)
109 {
110 case VMMDEV_TESTING_IOPORT_NOP:
111 switch (cb)
112 {
113 case 4:
114 case 2:
115 case 1:
116 break;
117 default:
118 AssertFailed();
119 return VERR_INTERNAL_ERROR_2;
120 }
121 return VINF_SUCCESS;
122
123 case VMMDEV_TESTING_IOPORT_TS_LOW:
124 break;
125
126 case VMMDEV_TESTING_IOPORT_TS_HIGH:
127 break;
128
129 default:
130 break;
131 }
132
133 return VERR_IOM_IOPORT_UNUSED;
134}
135
136
137/**
138 * @callback_method_impl{FNIOMIOPORTIN}
139 */
140PDMBOTHCBDECL(int) vmmdevTestingIoRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
141{
142 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState *);
143
144 switch (Port)
145 {
146 case VMMDEV_TESTING_IOPORT_NOP:
147 switch (cb)
148 {
149 case 4:
150 case 2:
151 case 1:
152 break;
153 default:
154 AssertFailed();
155 return VERR_INTERNAL_ERROR_2;
156 }
157 *pu32 = VMMDEV_TESTING_NOP_RET;
158 return VINF_SUCCESS;
159
160 case VMMDEV_TESTING_IOPORT_TS_LOW:
161 if (cb == 4)
162 {
163 uint64_t NowTS = RTTimeNanoTS();
164 *pu32 = (uint32_t)NowTS;
165 pThis->u32TestingHighTimestamp = (uint32_t)(NowTS >> 32);
166 return VINF_SUCCESS;
167 }
168 break;
169
170 case VMMDEV_TESTING_IOPORT_TS_HIGH:
171 if (cb == 4)
172 {
173 *pu32 = pThis->u32TestingHighTimestamp;
174 return VINF_SUCCESS;
175 }
176 break;
177
178 default:
179 break;
180 }
181
182 return VERR_IOM_IOPORT_UNUSED;
183}
184
185
186#ifdef IN_RING3
187
188/**
189 * Initializes the testing part of the VMMDev if enabled.
190 *
191 * @returns VBox status code.
192 * @param pDevIns The VMMDev device instance.
193 */
194int vmmdevTestingInitialize(PPDMDEVINS pDevIns)
195{
196 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState *);
197 if (!pThis->fTestingEnabled)
198 return VINF_SUCCESS;
199
200 /*
201 * Register a chunk of MMIO memory that we'll use for various
202 * tests interfaces.
203 */
204 int rc = PDMDevHlpMMIORegister(pDevIns, VMMDEV_TESTING_MMIO_BASE, VMMDEV_TESTING_MMIO_SIZE, NULL /*pvUser*/,
205 vmmdevTestingMmioWrite,
206 vmmdevTestingMmioRead,
207 NULL /*pfnFill*/,
208 "VMMDev Testing");
209 AssertRCReturn(rc, rc);
210 if (pThis->fRZEnabled)
211 {
212 rc = PDMDevHlpMMIORegisterR0(pDevIns, VMMDEV_TESTING_MMIO_BASE, VMMDEV_TESTING_MMIO_SIZE, NIL_RTR0PTR /*pvUser*/,
213 "vmmdevTestingMmioWrite",
214 "vmmdevTestingMmioRead",
215 NULL /*pszFill*/);
216 AssertRCReturn(rc, rc);
217 rc = PDMDevHlpMMIORegisterRC(pDevIns, VMMDEV_TESTING_MMIO_BASE, VMMDEV_TESTING_MMIO_SIZE, NIL_RTRCPTR /*pvUser*/,
218 "vmmdevTestingMmioWrite",
219 "vmmdevTestingMmioRead",
220 NULL /*pszFill*/);
221 AssertRCReturn(rc, rc);
222 }
223
224
225 /*
226 * Register the I/O ports used for testing.
227 */
228 rc = PDMDevHlpIOPortRegister(pDevIns, VMMDEV_TESTING_IOPORT_BASE, VMMDEV_TESTING_IOPORT_COUNT, NULL,
229 vmmdevTestingIoWrite,
230 vmmdevTestingIoRead,
231 NULL /*pfnOutStr*/,
232 NULL /*pfnInStr*/,
233 "VMMDev Testing");
234 AssertRCReturn(rc, rc);
235 if (pThis->fRZEnabled)
236 {
237 rc = PDMDevHlpIOPortRegisterR0(pDevIns, VMMDEV_TESTING_IOPORT_BASE, VMMDEV_TESTING_IOPORT_COUNT, NIL_RTR0PTR /*pvUser*/,
238 "vmmdevTestingIoWrite",
239 "vmmdevTestingIoRead",
240 NULL /*pszOutStr*/,
241 NULL /*pszInStr*/,
242 "VMMDev Testing");
243 AssertRCReturn(rc, rc);
244 rc = PDMDevHlpIOPortRegisterRC(pDevIns, VMMDEV_TESTING_IOPORT_BASE, VMMDEV_TESTING_IOPORT_COUNT, NIL_RTRCPTR /*pvUser*/,
245 "vmmdevTestingIoWrite",
246 "vmmdevTestingIoRead",
247 NULL /*pszOutStr*/,
248 NULL /*pszInStr*/,
249 "VMMDev Testing");
250 AssertRCReturn(rc, rc);
251 }
252
253 return VINF_SUCCESS;
254}
255
256#endif /* IN_RING3 */
257#endif /* !VBOX_WITHOUT_TESTING_FEATURES */
258
Note: See TracBrowser for help on using the repository browser.

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