VirtualBox

source: vbox/trunk/src/VBox/Devices/Samples/DevPlayground.cpp@ 64353

最後變更 在這個檔案從64353是 64353,由 vboxsync 提交於 8 年 前

PDM: Added a pPciDev parameter to PDMDEVHLPR3::pfnMMIOExPreRegister.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 7.9 KB
 
1/* $Id: DevPlayground.cpp 64353 2016-10-21 12:13:14Z vboxsync $ */
2/** @file
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:
10 * VBoxManage setextradata vmname VBoxInternal/PDM/Devices/playground/Path .../obj/VBoxSampleDevice/VBoxSampleDevice
11 * VBoxManage setextradata vmname VBoxInternal/Devices/playground/0/Config/Whatever1 0
12 */
13
14/*
15 * Copyright (C) 2009-2016 Oracle Corporation
16 *
17 * This file is part of VirtualBox Open Source Edition (OSE), as
18 * available from http://www.alldomusa.eu.org. This file is free software;
19 * you can redistribute it and/or modify it under the terms of the GNU
20 * General Public License (GPL) as published by the Free Software
21 * Foundation, in version 2 as it comes in the "COPYING" file of the
22 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
23 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
24 */
25
26
27/*********************************************************************************************************************************
28* Header Files *
29*********************************************************************************************************************************/
30#define LOG_GROUP LOG_GROUP_MISC
31#include <VBox/vmm/pdmdev.h>
32#include <VBox/version.h>
33#include <VBox/err.h>
34#include <VBox/log.h>
35
36#include <iprt/assert.h>
37
38
39/*********************************************************************************************************************************
40* Structures and Typedefs *
41*********************************************************************************************************************************/
42/**
43 * Device Instance Data.
44 */
45typedef struct VBOXPLAYGROUNDDEVICE
46{
47 /** The PCI device. */
48 PCIDEVICE PciDev;
49} VBOXPLAYGROUNDDEVICE;
50typedef VBOXPLAYGROUNDDEVICE *PVBOXPLAYGROUNDDEVICE;
51
52
53/*********************************************************************************************************************************
54* Device Functions *
55*********************************************************************************************************************************/
56
57PDMBOTHCBDECL(int) devPlaygroundMMIORead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb)
58{
59 NOREF(pDevIns);
60 NOREF(pvUser);
61 NOREF(GCPhysAddr);
62 NOREF(pv);
63 NOREF(cb);
64 return VINF_SUCCESS;
65}
66
67
68PDMBOTHCBDECL(int) devPlaygroundMMIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void const *pv, unsigned cb)
69{
70 NOREF(pDevIns);
71 NOREF(pvUser);
72 NOREF(GCPhysAddr);
73 NOREF(pv);
74 NOREF(cb);
75 return VINF_SUCCESS;
76}
77
78
79/**
80 * @callback_method_impl{FNPCIIOREGIONMAP}
81 */
82static DECLCALLBACK(int)
83devPlaygroundMap(PPCIDEVICE pPciDev, int iRegion, RTGCPHYS GCPhysAddress, RTGCPHYS cb, PCIADDRESSSPACE enmType)
84{
85 RT_NOREF(enmType, cb);
86
87 switch (iRegion)
88 {
89 case 0:
90 case 2:
91 Assert(enmType == (PCIADDRESSSPACE)(PCI_ADDRESS_SPACE_MEM | PCI_ADDRESS_SPACE_BAR64));
92 if (GCPhysAddress == NIL_RTGCPHYS)
93 return VINF_SUCCESS; /* We ignore the unmap notification. */
94 return PDMDevHlpMMIOExMap(pPciDev->pDevIns, iRegion, GCPhysAddress);
95
96 default:
97 /* We should never get here */
98 AssertMsgFailedReturn(("Invalid PCI region param in map callback"), VERR_INTERNAL_ERROR);
99 }
100}
101
102
103/**
104 * @interface_method_impl{PDMDEVREG,pfnDestruct}
105 */
106static DECLCALLBACK(int) devPlaygroundDestruct(PPDMDEVINS pDevIns)
107{
108 /*
109 * Check the versions here as well since the destructor is *always* called.
110 */
111 PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns);
112
113 return VINF_SUCCESS;
114}
115
116
117/**
118 * @interface_method_impl{PDMDEVREG,pfnConstruct}
119 */
120static DECLCALLBACK(int) devPlaygroundConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
121{
122 RT_NOREF(iInstance, pCfg);
123
124 /*
125 * Check that the device instance and device helper structures are compatible.
126 */
127 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
128
129 /*
130 * Initialize the instance data so that the destructor won't mess up.
131 */
132 PVBOXPLAYGROUNDDEVICE pThis = PDMINS_2_DATA(pDevIns, PVBOXPLAYGROUNDDEVICE);
133 PCIDevSetVendorId(&pThis->PciDev, 0x80ee);
134 PCIDevSetDeviceId(&pThis->PciDev, 0xde4e);
135 PCIDevSetClassBase(&pThis->PciDev, 0x07); /* communications device */
136 PCIDevSetClassSub(&pThis->PciDev, 0x80); /* other communications device */
137
138 /*
139 * Validate and read the configuration.
140 */
141 PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "Whatever1|Whatever2", "");
142
143 /*
144 * PCI device setup.
145 */
146 int rc = PDMDevHlpPCIRegister(pDevIns, &pThis->PciDev);
147 if (RT_FAILURE(rc))
148 return rc;
149
150 /* First region. */
151 RTGCPHYS const cbFirst = 8*_1G64;
152 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 0, cbFirst,
153 (PCIADDRESSSPACE)(PCI_ADDRESS_SPACE_MEM | PCI_ADDRESS_SPACE_BAR64),
154 devPlaygroundMap);
155 AssertLogRelRCReturn(rc, rc);
156 rc = PDMDevHlpMMIOExPreRegister(pDevIns, &pThis->PciDev, 0, cbFirst,
157 IOMMMIO_FLAGS_READ_PASSTHRU | IOMMMIO_FLAGS_WRITE_PASSTHRU, "PG-BAR0",
158 NULL /*pvUser*/, devPlaygroundMMIOWrite, devPlaygroundMMIORead, NULL /*pfnFill*/,
159 NIL_RTR0PTR /*pvUserR0*/, NULL /*pszWriteR0*/, NULL /*pszReadR0*/, NULL /*pszFillR0*/,
160 NIL_RTRCPTR /*pvUserRC*/, NULL /*pszWriteRC*/, NULL /*pszReadRC*/, NULL /*pszFillRC*/);
161 AssertLogRelRCReturn(rc, rc);
162
163 /* Second region. */
164 RTGCPHYS const cbSecond = 256*_1G64;
165 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 2, cbSecond,
166 (PCIADDRESSSPACE)(PCI_ADDRESS_SPACE_MEM | PCI_ADDRESS_SPACE_BAR64),
167 devPlaygroundMap);
168 AssertLogRelRCReturn(rc, rc);
169 rc = PDMDevHlpMMIOExPreRegister(pDevIns, &pThis->PciDev, 2, cbSecond,
170 IOMMMIO_FLAGS_READ_PASSTHRU | IOMMMIO_FLAGS_WRITE_PASSTHRU, "PG-BAR2",
171 NULL /*pvUser*/, devPlaygroundMMIOWrite, devPlaygroundMMIORead, NULL /*pfnFill*/,
172 NIL_RTR0PTR /*pvUserR0*/, NULL /*pszWriteR0*/, NULL /*pszReadR0*/, NULL /*pszFillR0*/,
173 NIL_RTRCPTR /*pvUserRC*/, NULL /*pszWriteRC*/, NULL /*pszReadRC*/, NULL /*pszFillRC*/);
174 AssertLogRelRCReturn(rc, rc);
175
176 return VINF_SUCCESS;
177}
178
179RT_C_DECLS_BEGIN
180extern const PDMDEVREG g_DevicePlayground;
181RT_C_DECLS_END
182
183/**
184 * The device registration structure.
185 */
186const PDMDEVREG g_DevicePlayground =
187{
188 /* u32Version */
189 PDM_DEVREG_VERSION,
190 /* szName */
191 "playground",
192 /* szRCMod */
193 "",
194 /* szR0Mod */
195 "",
196 /* pszDescription */
197 "VBox Playground Device.",
198 /* fFlags */
199 PDM_DEVREG_FLAGS_DEFAULT_BITS,
200 /* fClass */
201 PDM_DEVREG_CLASS_MISC,
202 /* cMaxInstances */
203 1,
204 /* cbInstance */
205 sizeof(VBOXPLAYGROUNDDEVICE),
206 /* pfnConstruct */
207 devPlaygroundConstruct,
208 /* pfnDestruct */
209 devPlaygroundDestruct,
210 /* pfnRelocate */
211 NULL,
212 /* pfnMemSetup */
213 NULL,
214 /* pfnPowerOn */
215 NULL,
216 /* pfnReset */
217 NULL,
218 /* pfnSuspend */
219 NULL,
220 /* pfnResume */
221 NULL,
222 /* pfnAttach */
223 NULL,
224 /* pfnDetach */
225 NULL,
226 /* pfnQueryInterface */
227 NULL,
228 /* pfnInitComplete */
229 NULL,
230 /* pfnPowerOff */
231 NULL,
232 /* pfnSoftReset */
233 NULL,
234 /* u32VersionEnd */
235 PDM_DEVREG_VERSION
236};
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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