[22985] | 1 | /* $Id: DevPlayground.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[63884] | 3 | * DevPlayground - Device for making PDM/PCI/... experiments.
|
---|
| 4 | *
|
---|
| 5 | * This device uses big PCI BAR64 resources, which needs the ICH9 chipset.
|
---|
| 6 | * The device works without any PCI config (because the default setup with the
|
---|
| 7 | * ICH9 chipset doesn't have anything at bus=0, device=0, function=0.
|
---|
| 8 | *
|
---|
| 9 | * To enable this device for a particular VM:
|
---|
[69067] | 10 | * VBoxManage setextradata vmname VBoxInternal/PDM/Devices/playground/Path .../obj/VBoxPlaygroundDevice/VBoxPlaygroundDevice
|
---|
[63884] | 11 | * VBoxManage setextradata vmname VBoxInternal/Devices/playground/0/Config/Whatever1 0
|
---|
[22985] | 12 | */
|
---|
| 13 |
|
---|
| 14 | /*
|
---|
[98103] | 15 | * Copyright (C) 2009-2023 Oracle and/or its affiliates.
|
---|
[22985] | 16 | *
|
---|
[96407] | 17 | * This file is part of VirtualBox base platform packages, as
|
---|
| 18 | * available from https://www.virtualbox.org.
|
---|
| 19 | *
|
---|
| 20 | * This program is free software; you can redistribute it and/or
|
---|
| 21 | * modify it under the terms of the GNU General Public License
|
---|
| 22 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 23 | * License.
|
---|
| 24 | *
|
---|
| 25 | * This program is distributed in the hope that it will be useful, but
|
---|
| 26 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 28 | * General Public License for more details.
|
---|
| 29 | *
|
---|
| 30 | * You should have received a copy of the GNU General Public License
|
---|
| 31 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 32 | *
|
---|
| 33 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[22985] | 34 | */
|
---|
| 35 |
|
---|
| 36 |
|
---|
[57358] | 37 | /*********************************************************************************************************************************
|
---|
| 38 | * Header Files *
|
---|
| 39 | *********************************************************************************************************************************/
|
---|
[22985] | 40 | #define LOG_GROUP LOG_GROUP_MISC
|
---|
[35346] | 41 | #include <VBox/vmm/pdmdev.h>
|
---|
[22985] | 42 | #include <VBox/version.h>
|
---|
| 43 | #include <VBox/err.h>
|
---|
| 44 | #include <VBox/log.h>
|
---|
| 45 |
|
---|
[69067] | 46 | #include <VBox/com/assert.h>
|
---|
| 47 | #include <VBox/com/defs.h>
|
---|
| 48 | #include <VBox/com/string.h>
|
---|
| 49 | #include <VBox/com/Guid.h>
|
---|
| 50 | #include <VBox/com/VirtualBox.h>
|
---|
| 51 |
|
---|
[22985] | 52 | #include <iprt/assert.h>
|
---|
| 53 |
|
---|
| 54 |
|
---|
[57358] | 55 | /*********************************************************************************************************************************
|
---|
| 56 | * Structures and Typedefs *
|
---|
| 57 | *********************************************************************************************************************************/
|
---|
[22985] | 58 | /**
|
---|
[64373] | 59 | * Playground device per function (sub-device) data.
|
---|
[22985] | 60 | */
|
---|
[64373] | 61 | typedef struct VBOXPLAYGROUNDDEVICEFUNCTION
|
---|
| 62 | {
|
---|
| 63 | /** The function number. */
|
---|
[81616] | 64 | uint8_t iFun;
|
---|
[64373] | 65 | /** Device function name. */
|
---|
[81616] | 66 | char szName[31];
|
---|
| 67 | /** MMIO region \#0 name. */
|
---|
| 68 | char szMmio0[32];
|
---|
| 69 | /** MMIO region \#2 name. */
|
---|
| 70 | char szMmio2[32];
|
---|
| 71 | /** The MMIO region \#0 handle. */
|
---|
| 72 | IOMMMIOHANDLE hMmio0;
|
---|
| 73 | /** The MMIO region \#2 handle. */
|
---|
| 74 | IOMMMIOHANDLE hMmio2;
|
---|
[87307] | 75 | /** Backing storage. */
|
---|
| 76 | uint8_t abBacking[4096];
|
---|
[64373] | 77 | } VBOXPLAYGROUNDDEVICEFUNCTION;
|
---|
| 78 | /** Pointer to a PCI function of the playground device. */
|
---|
| 79 | typedef VBOXPLAYGROUNDDEVICEFUNCTION *PVBOXPLAYGROUNDDEVICEFUNCTION;
|
---|
| 80 |
|
---|
| 81 | /**
|
---|
| 82 | * Playground device instance data.
|
---|
| 83 | */
|
---|
[63884] | 84 | typedef struct VBOXPLAYGROUNDDEVICE
|
---|
[22985] | 85 | {
|
---|
[64373] | 86 | /** PCI device functions. */
|
---|
| 87 | VBOXPLAYGROUNDDEVICEFUNCTION aPciFuns[8];
|
---|
[63884] | 88 | } VBOXPLAYGROUNDDEVICE;
|
---|
[64373] | 89 | /** Pointer to the instance data of a playground device instance. */
|
---|
[63884] | 90 | typedef VBOXPLAYGROUNDDEVICE *PVBOXPLAYGROUNDDEVICE;
|
---|
[22985] | 91 |
|
---|
| 92 |
|
---|
[69067] | 93 | #define PLAYGROUND_SSM_VERSION 3
|
---|
| 94 |
|
---|
| 95 |
|
---|
[63884] | 96 | /*********************************************************************************************************************************
|
---|
| 97 | * Device Functions *
|
---|
| 98 | *********************************************************************************************************************************/
|
---|
[22985] | 99 |
|
---|
[87307] | 100 | /**
|
---|
| 101 | * @callback_method_impl{FNIOMMMIONEWREAD}
|
---|
| 102 | */
|
---|
[81616] | 103 | static DECLCALLBACK(VBOXSTRICTRC) devPlaygroundMMIORead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void *pv, unsigned cb)
|
---|
[22985] | 104 | {
|
---|
[87307] | 105 | PVBOXPLAYGROUNDDEVICEFUNCTION pFun = (PVBOXPLAYGROUNDDEVICEFUNCTION)pvUser;
|
---|
[63884] | 106 | NOREF(pDevIns);
|
---|
[87307] | 107 |
|
---|
| 108 | #ifdef LOG_ENABLED
|
---|
| 109 | unsigned const cbLog = cb;
|
---|
| 110 | RTGCPHYS offLog = off;
|
---|
| 111 | #endif
|
---|
| 112 | uint8_t *pbDst = (uint8_t *)pv;
|
---|
| 113 | while (cb-- > 0)
|
---|
| 114 | {
|
---|
| 115 | *pbDst = pFun->abBacking[off % RT_ELEMENTS(pFun->abBacking)];
|
---|
| 116 | pbDst++;
|
---|
| 117 | off++;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | Log(("DevPlayGr/[%u]: READ off=%RGv cb=%u: %.*Rhxs\n", pFun->iFun, offLog, cbLog, cbLog, pv));
|
---|
[63884] | 121 | return VINF_SUCCESS;
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 |
|
---|
[87307] | 125 | /**
|
---|
| 126 | * @callback_method_impl{FNIOMMMIONEWWRITE}
|
---|
| 127 | */
|
---|
[81616] | 128 | static DECLCALLBACK(VBOXSTRICTRC) devPlaygroundMMIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void const *pv, unsigned cb)
|
---|
[63884] | 129 | {
|
---|
[87307] | 130 | PVBOXPLAYGROUNDDEVICEFUNCTION pFun = (PVBOXPLAYGROUNDDEVICEFUNCTION)pvUser;
|
---|
[63884] | 131 | NOREF(pDevIns);
|
---|
[87307] | 132 | Log(("DevPlayGr/[%u]: WRITE off=%RGv cb=%u: %.*Rhxs\n", pFun->iFun, off, cb, cb, pv));
|
---|
| 133 |
|
---|
| 134 | uint8_t const *pbSrc = (uint8_t const *)pv;
|
---|
| 135 | while (cb-- > 0)
|
---|
| 136 | {
|
---|
| 137 | pFun->abBacking[off % RT_ELEMENTS(pFun->abBacking)] = *pbSrc;
|
---|
| 138 | pbSrc++;
|
---|
| 139 | off++;
|
---|
| 140 | }
|
---|
| 141 |
|
---|
[63884] | 142 | return VINF_SUCCESS;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 |
|
---|
| 146 | /**
|
---|
[69067] | 147 | * @callback_method_impl{FNSSMDEVSAVEEXEC}
|
---|
[63910] | 148 | */
|
---|
[69067] | 149 | static DECLCALLBACK(int) devPlaygroundSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
|
---|
[63910] | 150 | {
|
---|
[81591] | 151 | PVBOXPLAYGROUNDDEVICE pThis = PDMDEVINS_2_DATA(pDevIns, PVBOXPLAYGROUNDDEVICE);
|
---|
[81616] | 152 | PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
|
---|
[63910] | 153 |
|
---|
[69067] | 154 | /* dummy (real devices would need to save their state here) */
|
---|
| 155 | RT_NOREF(pThis);
|
---|
| 156 |
|
---|
| 157 | /* Demo of some API stuff - very unusual, think twice if there's no better
|
---|
| 158 | * solution which doesn't need API interaction. */
|
---|
[81616] | 159 | #if 0
|
---|
| 160 | try
|
---|
[69067] | 161 | {
|
---|
[81616] | 162 | HRESULT hrc = S_OK;
|
---|
| 163 | com::Bstr bstrSnapName;
|
---|
| 164 | com::Guid uuid(COM_IIDOF(ISnapshot));
|
---|
| 165 | ISnapshot *pSnap = (ISnapshot *)PDMDevHlpQueryGenericUserObject(pDevIns, uuid.raw());
|
---|
| 166 | if (pSnap)
|
---|
| 167 | {
|
---|
| 168 | hrc = pSnap->COMGETTER(Name)(bstrSnapName.asOutParam());
|
---|
| 169 | AssertComRCReturn(hrc, VERR_INVALID_STATE);
|
---|
| 170 | }
|
---|
| 171 | com::Utf8Str strSnapName(bstrSnapName);
|
---|
| 172 | pHlp->pfnSSMPutStrZ(pSSM, strSnapName.c_str());
|
---|
| 173 | LogRel(("Playground: saving state of snapshot '%s', hrc=%Rhrc\n", strSnapName.c_str(), hrc));
|
---|
[69067] | 174 | }
|
---|
[81616] | 175 | catch (...)
|
---|
| 176 | {
|
---|
| 177 | AssertLogRelFailed();
|
---|
| 178 | return VERR_UNEXPECTED_EXCEPTION;
|
---|
| 179 | }
|
---|
| 180 | #else
|
---|
[87307] | 181 | pHlp->pfnSSMPutStrZ(pSSM, "playground");
|
---|
[81616] | 182 | #endif
|
---|
[69067] | 183 |
|
---|
[63910] | 184 | return VINF_SUCCESS;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
[81616] | 187 |
|
---|
[69067] | 188 | /**
|
---|
| 189 | * @callback_method_impl{FNSSMDEVLOADEXEC}
|
---|
| 190 | */
|
---|
| 191 | static DECLCALLBACK(int) devPlaygroundLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
|
---|
| 192 | {
|
---|
[81591] | 193 | PVBOXPLAYGROUNDDEVICE pThis = PDMDEVINS_2_DATA(pDevIns, PVBOXPLAYGROUNDDEVICE);
|
---|
[81616] | 194 | PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
|
---|
[63910] | 195 |
|
---|
[69067] | 196 | if (uVersion > PLAYGROUND_SSM_VERSION)
|
---|
| 197 | return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
|
---|
| 198 | Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
|
---|
| 199 |
|
---|
| 200 | /* dummy (real devices would need to load their state here) */
|
---|
| 201 | RT_NOREF(pThis);
|
---|
| 202 |
|
---|
| 203 | /* Reading the stuff written to saved state, just a demo. */
|
---|
| 204 | char szSnapName[256];
|
---|
[81616] | 205 | int rc = pHlp->pfnSSMGetStrZ(pSSM, szSnapName, sizeof(szSnapName));
|
---|
[69067] | 206 | AssertRCReturn(rc, rc);
|
---|
| 207 | LogRel(("Playground: loading state of snapshot '%s'\n", szSnapName));
|
---|
| 208 |
|
---|
| 209 | return VINF_SUCCESS;
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 |
|
---|
[63910] | 213 | /**
|
---|
[81616] | 214 | * @interface_method_impl{PDMDEVREG,pfnDestruct}
|
---|
| 215 | */
|
---|
| 216 | static DECLCALLBACK(int) devPlaygroundDestruct(PPDMDEVINS pDevIns)
|
---|
| 217 | {
|
---|
| 218 | /*
|
---|
| 219 | * Check the versions here as well since the destructor is *always* called.
|
---|
| 220 | * THIS IS ALWAYS THE FIRST STATEMENT IN A DESTRUCTOR!
|
---|
| 221 | */
|
---|
| 222 | PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns);
|
---|
| 223 |
|
---|
| 224 | return VINF_SUCCESS;
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 |
|
---|
| 228 | /**
|
---|
[63884] | 229 | * @interface_method_impl{PDMDEVREG,pfnConstruct}
|
---|
| 230 | */
|
---|
| 231 | static DECLCALLBACK(int) devPlaygroundConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
|
---|
| 232 | {
|
---|
[22985] | 233 | /*
|
---|
| 234 | * Check that the device instance and device helper structures are compatible.
|
---|
[81616] | 235 | * THIS IS ALWAYS THE FIRST STATEMENT IN A CONSTRUCTOR!
|
---|
[22985] | 236 | */
|
---|
[81616] | 237 | PDMDEV_CHECK_VERSIONS_RETURN(pDevIns); /* This must come first. */
|
---|
| 238 | Assert(iInstance == 0); RT_NOREF(iInstance);
|
---|
[22985] | 239 |
|
---|
| 240 | /*
|
---|
[63878] | 241 | * Initialize the instance data so that the destructor won't mess up.
|
---|
[22985] | 242 | */
|
---|
[81591] | 243 | PVBOXPLAYGROUNDDEVICE pThis = PDMDEVINS_2_DATA(pDevIns, PVBOXPLAYGROUNDDEVICE);
|
---|
[22985] | 244 |
|
---|
| 245 | /*
|
---|
| 246 | * Validate and read the configuration.
|
---|
| 247 | */
|
---|
[77828] | 248 | PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "Whatever1|NumFunctions|BigBAR0MB|BigBAR0GB|BigBAR2MB|BigBAR2GB", "");
|
---|
[22985] | 249 |
|
---|
[81616] | 250 | PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
|
---|
| 251 |
|
---|
[77828] | 252 | uint8_t uNumFunctions;
|
---|
[81031] | 253 | AssertCompile(RT_ELEMENTS(pThis->aPciFuns) <= RT_ELEMENTS(pDevIns->apPciDevs));
|
---|
[81616] | 254 | int rc = pHlp->pfnCFGMQueryU8Def(pCfg, "NumFunctions", &uNumFunctions, RT_ELEMENTS(pThis->aPciFuns));
|
---|
[77828] | 255 | if (RT_FAILURE(rc))
|
---|
| 256 | return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to query integer value \"NumFunctions\""));
|
---|
| 257 | if ((uNumFunctions < 1) || (uNumFunctions > RT_ELEMENTS(pThis->aPciFuns)))
|
---|
| 258 | return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Invalid \"NumFunctions\" value (must be between 1 and 8)"));
|
---|
| 259 |
|
---|
| 260 | RTGCPHYS cbFirstBAR;
|
---|
| 261 | uint16_t uBigBAR0GB;
|
---|
[81616] | 262 | rc = pHlp->pfnCFGMQueryU16Def(pCfg, "BigBAR0GB", &uBigBAR0GB, 0); /* Default to nothing. */
|
---|
[77828] | 263 | if (RT_FAILURE(rc))
|
---|
| 264 | return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to query integer value \"BigBAR0GB\""));
|
---|
| 265 | if (uBigBAR0GB > 512)
|
---|
| 266 | return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Invalid \"BigBAR0GB\" value (must be 512 or less)"));
|
---|
| 267 |
|
---|
| 268 | if (uBigBAR0GB)
|
---|
| 269 | cbFirstBAR = uBigBAR0GB * _1G64;
|
---|
| 270 | else
|
---|
| 271 | {
|
---|
| 272 | uint16_t uBigBAR0MB;
|
---|
[81616] | 273 | rc = pHlp->pfnCFGMQueryU16Def(pCfg, "BigBAR0MB", &uBigBAR0MB, 8); /* 8 MB default. */
|
---|
[77828] | 274 | if (RT_FAILURE(rc))
|
---|
| 275 | return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to query integer value \"BigBAR0MB\""));
|
---|
| 276 | if (uBigBAR0MB < 1 || uBigBAR0MB > 4095)
|
---|
| 277 | return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Invalid \"BigBAR0MB\" value (must be between 1 and 4095)"));
|
---|
| 278 | cbFirstBAR = uBigBAR0MB * _1M;
|
---|
| 279 | }
|
---|
| 280 |
|
---|
| 281 | RTGCPHYS cbSecondBAR;
|
---|
| 282 | uint16_t uBigBAR2GB;
|
---|
[81616] | 283 | rc = pHlp->pfnCFGMQueryU16Def(pCfg, "BigBAR2GB", &uBigBAR2GB, 0); /* Default to nothing. */
|
---|
[77828] | 284 | if (RT_FAILURE(rc))
|
---|
| 285 | return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to query integer value \"BigBAR2GB\""));
|
---|
| 286 | if (uBigBAR2GB > 512)
|
---|
| 287 | return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Invalid \"BigBAR2GB\" value (must be 512 or less)"));
|
---|
| 288 |
|
---|
| 289 | if (uBigBAR2GB)
|
---|
| 290 | cbSecondBAR = uBigBAR2GB * _1G64;
|
---|
| 291 | else
|
---|
| 292 | {
|
---|
| 293 | uint16_t uBigBAR2MB;
|
---|
[81616] | 294 | rc = pHlp->pfnCFGMQueryU16Def(pCfg, "BigBAR2MB", &uBigBAR2MB, 16); /* 16 MB default. */
|
---|
[77828] | 295 | if (RT_FAILURE(rc))
|
---|
| 296 | return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to query integer value \"BigBAR2MB\""));
|
---|
| 297 | if (uBigBAR2MB < 1 || uBigBAR2MB > 4095)
|
---|
| 298 | return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Invalid \"BigBAR2MB\" value (must be between 1 and 4095)"));
|
---|
| 299 | cbSecondBAR = uBigBAR2MB * _1M;
|
---|
| 300 | }
|
---|
| 301 |
|
---|
| 302 |
|
---|
[63878] | 303 | /*
|
---|
[63884] | 304 | * PCI device setup.
|
---|
[63878] | 305 | */
|
---|
[64373] | 306 | uint32_t iPciDevNo = PDMPCIDEVREG_DEV_NO_FIRST_UNUSED;
|
---|
[77828] | 307 | for (uint32_t iPciFun = 0; iPciFun < uNumFunctions; iPciFun++)
|
---|
[64373] | 308 | {
|
---|
[81031] | 309 | PPDMPCIDEV pPciDev = pDevIns->apPciDevs[iPciFun];
|
---|
| 310 | PVBOXPLAYGROUNDDEVICEFUNCTION pFun = &pThis->aPciFuns[iPciFun];
|
---|
| 311 | RTStrPrintf(pFun->szName, sizeof(pFun->szName), "playground%u", iPciFun);
|
---|
[64373] | 312 | pFun->iFun = iPciFun;
|
---|
[64329] | 313 |
|
---|
[81031] | 314 | PDMPCIDEV_ASSERT_VALID(pDevIns, pPciDev);
|
---|
[64860] | 315 |
|
---|
[81031] | 316 | PDMPciDevSetVendorId(pPciDev, 0x80ee);
|
---|
| 317 | PDMPciDevSetDeviceId(pPciDev, 0xde4e);
|
---|
| 318 | PDMPciDevSetClassBase(pPciDev, 0x07); /* communications device */
|
---|
| 319 | PDMPciDevSetClassSub(pPciDev, 0x80); /* other communications device */
|
---|
| 320 | if (iPciFun == 0) /* only for the primary function */
|
---|
| 321 | PDMPciDevSetHeaderType(pPciDev, 0x80); /* normal, multifunction device */
|
---|
| 322 |
|
---|
| 323 | rc = PDMDevHlpPCIRegisterEx(pDevIns, pPciDev, 0 /*fFlags*/, iPciDevNo, iPciFun, pThis->aPciFuns[iPciFun].szName);
|
---|
[64373] | 324 | AssertLogRelRCReturn(rc, rc);
|
---|
[64115] | 325 |
|
---|
[64373] | 326 | /* First region. */
|
---|
[77828] | 327 | RTGCPHYS const cbFirst = iPciFun == 0 ? cbFirstBAR : iPciFun * _4K;
|
---|
[81616] | 328 | RTStrPrintf(pFun->szMmio0, sizeof(pFun->szMmio0), "PG-F%d-BAR0", iPciFun);
|
---|
| 329 | rc = PDMDevHlpMmioCreate(pDevIns, cbFirst, pPciDev, 0 /*iPciRegion*/,
|
---|
[87307] | 330 | devPlaygroundMMIOWrite, devPlaygroundMMIORead, pFun,
|
---|
[81616] | 331 | IOMMMIO_FLAGS_READ_PASSTHRU | IOMMMIO_FLAGS_WRITE_PASSTHRU, pFun->szMmio0, &pFun->hMmio0);
|
---|
[64373] | 332 | AssertLogRelRCReturn(rc, rc);
|
---|
[81616] | 333 |
|
---|
| 334 | rc = PDMDevHlpPCIIORegionRegisterMmioEx(pDevIns, pPciDev, 0, cbFirst,
|
---|
| 335 | (PCIADDRESSSPACE)( PCI_ADDRESS_SPACE_MEM | PCI_ADDRESS_SPACE_BAR64
|
---|
| 336 | | (iPciFun == 0 ? PCI_ADDRESS_SPACE_MEM_PREFETCH : 0)),
|
---|
| 337 | pFun->hMmio0, NULL);
|
---|
[64373] | 338 | AssertLogRelRCReturn(rc, rc);
|
---|
[22985] | 339 |
|
---|
[64373] | 340 | /* Second region. */
|
---|
[77828] | 341 | RTGCPHYS const cbSecond = iPciFun == 0 ? cbSecondBAR : iPciFun * _32K;
|
---|
[81616] | 342 | RTStrPrintf(pFun->szMmio2, sizeof(pFun->szMmio2), "PG-F%d-BAR2", iPciFun);
|
---|
| 343 | rc = PDMDevHlpMmioCreate(pDevIns, cbSecond, pPciDev, 2 << 16 /*iPciRegion*/,
|
---|
[87307] | 344 | devPlaygroundMMIOWrite, devPlaygroundMMIORead, pFun,
|
---|
[81616] | 345 | IOMMMIO_FLAGS_READ_PASSTHRU | IOMMMIO_FLAGS_WRITE_PASSTHRU, pFun->szMmio2, &pFun->hMmio2);
|
---|
[64373] | 346 | AssertLogRelRCReturn(rc, rc);
|
---|
[81616] | 347 |
|
---|
| 348 | rc = PDMDevHlpPCIIORegionRegisterMmioEx(pDevIns, pPciDev, 2, cbSecond,
|
---|
| 349 | (PCIADDRESSSPACE)( PCI_ADDRESS_SPACE_MEM | PCI_ADDRESS_SPACE_BAR64
|
---|
| 350 | | (iPciFun == 0 ? PCI_ADDRESS_SPACE_MEM_PREFETCH : 0)),
|
---|
| 351 | pFun->hMmio2, NULL);
|
---|
[64373] | 352 | AssertLogRelRCReturn(rc, rc);
|
---|
| 353 |
|
---|
| 354 | /* Subsequent function should use the same major as the previous one. */
|
---|
| 355 | iPciDevNo = PDMPCIDEVREG_DEV_NO_SAME_AS_PREV;
|
---|
| 356 | }
|
---|
| 357 |
|
---|
[69067] | 358 | /*
|
---|
| 359 | * Save state handling.
|
---|
| 360 | */
|
---|
| 361 | rc = PDMDevHlpSSMRegister(pDevIns, PLAYGROUND_SSM_VERSION, sizeof(*pThis), devPlaygroundSaveExec, devPlaygroundLoadExec);
|
---|
| 362 | if (RT_FAILURE(rc))
|
---|
| 363 | return rc;
|
---|
| 364 |
|
---|
[22985] | 365 | return VINF_SUCCESS;
|
---|
| 366 | }
|
---|
| 367 |
|
---|
| 368 |
|
---|
| 369 | /**
|
---|
| 370 | * The device registration structure.
|
---|
| 371 | */
|
---|
[69067] | 372 | static const PDMDEVREG g_DevicePlayground =
|
---|
[22985] | 373 | {
|
---|
[80531] | 374 | /* .u32Version = */ PDM_DEVREG_VERSION,
|
---|
| 375 | /* .uReserved0 = */ 0,
|
---|
| 376 | /* .szName = */ "playground",
|
---|
[81616] | 377 | /* .fFlags = */ PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_NEW_STYLE,
|
---|
[80531] | 378 | /* .fClass = */ PDM_DEVREG_CLASS_MISC,
|
---|
| 379 | /* .cMaxInstances = */ 1,
|
---|
| 380 | /* .uSharedVersion = */ 42,
|
---|
| 381 | /* .cbInstanceShared = */ sizeof(VBOXPLAYGROUNDDEVICE),
|
---|
| 382 | /* .cbInstanceCC = */ 0,
|
---|
| 383 | /* .cbInstanceRC = */ 0,
|
---|
[81031] | 384 | /* .cMaxPciDevices = */ 8,
|
---|
[80704] | 385 | /* .cMaxMsixVectors = */ 0,
|
---|
[80531] | 386 | /* .pszDescription = */ "VBox Playground Device.",
|
---|
| 387 | #if defined(IN_RING3)
|
---|
| 388 | /* .pszRCMod = */ "",
|
---|
| 389 | /* .pszR0Mod = */ "",
|
---|
| 390 | /* .pfnConstruct = */ devPlaygroundConstruct,
|
---|
| 391 | /* .pfnDestruct = */ devPlaygroundDestruct,
|
---|
| 392 | /* .pfnRelocate = */ NULL,
|
---|
| 393 | /* .pfnMemSetup = */ NULL,
|
---|
| 394 | /* .pfnPowerOn = */ NULL,
|
---|
| 395 | /* .pfnReset = */ NULL,
|
---|
| 396 | /* .pfnSuspend = */ NULL,
|
---|
| 397 | /* .pfnResume = */ NULL,
|
---|
| 398 | /* .pfnAttach = */ NULL,
|
---|
| 399 | /* .pfnDetach = */ NULL,
|
---|
| 400 | /* .pfnQueryInterface = */ NULL,
|
---|
| 401 | /* .pfnInitComplete = */ NULL,
|
---|
| 402 | /* .pfnPowerOff = */ NULL,
|
---|
| 403 | /* .pfnSoftReset = */ NULL,
|
---|
| 404 | /* .pfnReserved0 = */ NULL,
|
---|
| 405 | /* .pfnReserved1 = */ NULL,
|
---|
| 406 | /* .pfnReserved2 = */ NULL,
|
---|
| 407 | /* .pfnReserved3 = */ NULL,
|
---|
| 408 | /* .pfnReserved4 = */ NULL,
|
---|
| 409 | /* .pfnReserved5 = */ NULL,
|
---|
| 410 | /* .pfnReserved6 = */ NULL,
|
---|
| 411 | /* .pfnReserved7 = */ NULL,
|
---|
| 412 | #elif defined(IN_RING0)
|
---|
| 413 | /* .pfnEarlyConstruct = */ NULL,
|
---|
| 414 | /* .pfnConstruct = */ NULL,
|
---|
| 415 | /* .pfnDestruct = */ NULL,
|
---|
| 416 | /* .pfnFinalDestruct = */ NULL,
|
---|
| 417 | /* .pfnRequest = */ NULL,
|
---|
| 418 | /* .pfnReserved0 = */ NULL,
|
---|
| 419 | /* .pfnReserved1 = */ NULL,
|
---|
| 420 | /* .pfnReserved2 = */ NULL,
|
---|
| 421 | /* .pfnReserved3 = */ NULL,
|
---|
| 422 | /* .pfnReserved4 = */ NULL,
|
---|
| 423 | /* .pfnReserved5 = */ NULL,
|
---|
| 424 | /* .pfnReserved6 = */ NULL,
|
---|
| 425 | /* .pfnReserved7 = */ NULL,
|
---|
| 426 | #elif defined(IN_RC)
|
---|
| 427 | /* .pfnConstruct = */ NULL,
|
---|
| 428 | /* .pfnReserved0 = */ NULL,
|
---|
| 429 | /* .pfnReserved1 = */ NULL,
|
---|
| 430 | /* .pfnReserved2 = */ NULL,
|
---|
| 431 | /* .pfnReserved3 = */ NULL,
|
---|
| 432 | /* .pfnReserved4 = */ NULL,
|
---|
| 433 | /* .pfnReserved5 = */ NULL,
|
---|
| 434 | /* .pfnReserved6 = */ NULL,
|
---|
| 435 | /* .pfnReserved7 = */ NULL,
|
---|
| 436 | #else
|
---|
| 437 | # error "Not in IN_RING3, IN_RING0 or IN_RC!"
|
---|
| 438 | #endif
|
---|
| 439 | /* .u32VersionEnd = */ PDM_DEVREG_VERSION
|
---|
[22985] | 440 | };
|
---|
[69067] | 441 |
|
---|
| 442 |
|
---|
| 443 | /**
|
---|
| 444 | * Register devices provided by the plugin.
|
---|
| 445 | *
|
---|
| 446 | * @returns VBox status code.
|
---|
| 447 | * @param pCallbacks Pointer to the callback table.
|
---|
| 448 | * @param u32Version VBox version number.
|
---|
| 449 | */
|
---|
| 450 | extern "C" DECLEXPORT(int) VBoxDevicesRegister(PPDMDEVREGCB pCallbacks, uint32_t u32Version)
|
---|
| 451 | {
|
---|
| 452 | LogFlow(("VBoxPlaygroundDevice::VBoxDevicesRegister: u32Version=%#x pCallbacks->u32Version=%#x\n", u32Version, pCallbacks->u32Version));
|
---|
| 453 |
|
---|
| 454 | AssertLogRelMsgReturn(u32Version >= VBOX_VERSION,
|
---|
| 455 | ("VirtualBox version %#x, expected %#x or higher\n", u32Version, VBOX_VERSION),
|
---|
| 456 | VERR_VERSION_MISMATCH);
|
---|
| 457 | AssertLogRelMsgReturn(pCallbacks->u32Version == PDM_DEVREG_CB_VERSION,
|
---|
| 458 | ("callback version %#x, expected %#x\n", pCallbacks->u32Version, PDM_DEVREG_CB_VERSION),
|
---|
| 459 | VERR_VERSION_MISMATCH);
|
---|
| 460 |
|
---|
| 461 | return pCallbacks->pfnRegister(pCallbacks, &g_DevicePlayground);
|
---|
| 462 | }
|
---|
| 463 |
|
---|