VirtualBox

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

Last change on this file since 63910 was 63910, checked in by vboxsync, 8 years ago

DevPlayground.cpp: Use the macros.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.0 KB
Line 
1/* $Id: DevPlayground.cpp 63910 2016-09-20 10:14:30Z 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.virtualbox.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) devPlaygroundMap(PPCIDEVICE pPciDev, int iRegion, RTGCPHYS GCPhysAddress, RTGCPHYS cb, PCIADDRESSSPACE enmType)
83{
84 NOREF(enmType);
85 int rc;
86
87 switch (iRegion)
88 {
89 case 0:
90 rc = PDMDevHlpMMIORegister(pPciDev->pDevIns, GCPhysAddress, cb, NULL,
91 IOMMMIO_FLAGS_READ_PASSTHRU | IOMMMIO_FLAGS_WRITE_PASSTHRU,
92 devPlaygroundMMIOWrite, devPlaygroundMMIORead, "PG-BAR0");
93 break;
94 case 2:
95 rc = PDMDevHlpMMIORegister(pPciDev->pDevIns, GCPhysAddress, cb, NULL,
96 IOMMMIO_FLAGS_READ_PASSTHRU | IOMMMIO_FLAGS_WRITE_PASSTHRU,
97 devPlaygroundMMIOWrite, devPlaygroundMMIORead, "PG-BAR2");
98 break;
99 default:
100 /* We should never get here */
101 AssertMsgFailed(("Invalid PCI region param in map callback"));
102 rc = VERR_INTERNAL_ERROR;
103 }
104 return rc;
105
106}
107
108
109/**
110 * @interface_method_impl{PDMDEVREG,pfnDestruct}
111 */
112static DECLCALLBACK(int) devPlaygroundDestruct(PPDMDEVINS pDevIns)
113{
114 /*
115 * Check the versions here as well since the destructor is *always* called.
116 */
117 PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns);
118
119 return VINF_SUCCESS;
120}
121
122
123/**
124 * @interface_method_impl{PDMDEVREG,pfnConstruct}
125 */
126static DECLCALLBACK(int) devPlaygroundConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
127{
128 RT_NOREF(iInstance, pCfg);
129
130 /*
131 * Check that the device instance and device helper structures are compatible.
132 */
133 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
134
135 /*
136 * Initialize the instance data so that the destructor won't mess up.
137 */
138 PVBOXPLAYGROUNDDEVICE pThis = PDMINS_2_DATA(pDevIns, PVBOXPLAYGROUNDDEVICE);
139 PCIDevSetVendorId(&pThis->PciDev, 0x80ee);
140 PCIDevSetDeviceId(&pThis->PciDev, 0xde4e);
141 PCIDevSetClassBase(&pThis->PciDev, 0x07); /* communications device */
142 PCIDevSetClassSub(&pThis->PciDev, 0x80); /* other communications device */
143
144 /*
145 * Validate and read the configuration.
146 */
147 PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "Whatever1|Whatever2", "");
148
149 /*
150 * PCI device setup.
151 */
152 int rc = PDMDevHlpPCIRegister(pDevIns, &pThis->PciDev);
153 if (RT_FAILURE(rc))
154 return rc;
155 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 0, 8*_1G64,
156 (PCIADDRESSSPACE)(PCI_ADDRESS_SPACE_MEM | PCI_ADDRESS_SPACE_BAR64),
157 devPlaygroundMap);
158 if (RT_FAILURE(rc))
159 return rc;
160 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 2, 8*_1G64,
161 (PCIADDRESSSPACE)(PCI_ADDRESS_SPACE_MEM | PCI_ADDRESS_SPACE_BAR64),
162 devPlaygroundMap);
163 if (RT_FAILURE(rc))
164 return rc;
165
166 return VINF_SUCCESS;
167}
168
169RT_C_DECLS_BEGIN
170extern const PDMDEVREG g_DevicePlayground;
171RT_C_DECLS_END
172
173/**
174 * The device registration structure.
175 */
176const PDMDEVREG g_DevicePlayground =
177{
178 /* u32Version */
179 PDM_DEVREG_VERSION,
180 /* szName */
181 "playground",
182 /* szRCMod */
183 "",
184 /* szR0Mod */
185 "",
186 /* pszDescription */
187 "VBox Playground Device.",
188 /* fFlags */
189 PDM_DEVREG_FLAGS_DEFAULT_BITS,
190 /* fClass */
191 PDM_DEVREG_CLASS_MISC,
192 /* cMaxInstances */
193 1,
194 /* cbInstance */
195 sizeof(VBOXPLAYGROUNDDEVICE),
196 /* pfnConstruct */
197 devPlaygroundConstruct,
198 /* pfnDestruct */
199 devPlaygroundDestruct,
200 /* pfnRelocate */
201 NULL,
202 /* pfnMemSetup */
203 NULL,
204 /* pfnPowerOn */
205 NULL,
206 /* pfnReset */
207 NULL,
208 /* pfnSuspend */
209 NULL,
210 /* pfnResume */
211 NULL,
212 /* pfnAttach */
213 NULL,
214 /* pfnDetach */
215 NULL,
216 /* pfnQueryInterface */
217 NULL,
218 /* pfnInitComplete */
219 NULL,
220 /* pfnPowerOff */
221 NULL,
222 /* pfnSoftReset */
223 NULL,
224 /* u32VersionEnd */
225 PDM_DEVREG_VERSION
226};
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