Changeset 63884 in vbox
- Timestamp:
- Sep 19, 2016 12:21:00 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 110748
- Location:
- trunk/src/VBox/Devices/Samples
- Files:
-
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Samples/DevPlayground.cpp
r63881 r63884 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Sample Device. 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 4 12 */ 5 13 … … 35 43 * Device Instance Data. 36 44 */ 37 typedef struct VBOXSAMPLEDEVICE 38 { 39 uint32_t Whatever; 40 } VBOXSAMPLEDEVICE; 41 typedef VBOXSAMPLEDEVICE *PVBOXSAMPLEDEVICE; 42 43 44 45 static DECLCALLBACK(int) devSampleDestruct(PPDMDEVINS pDevIns) 45 typedef struct VBOXPLAYGROUNDDEVICE 46 { 47 /** The PCI device. */ 48 PCIDEVICE PciDev; 49 } VBOXPLAYGROUNDDEVICE; 50 typedef VBOXPLAYGROUNDDEVICE *PVBOXPLAYGROUNDDEVICE; 51 52 53 /********************************************************************************************************************************* 54 * Device Functions * 55 *********************************************************************************************************************************/ 56 /** 57 * @interface_method_impl{PDMDEVREG,pfnDestruct} 58 */ 59 static DECLCALLBACK(int) devPlaygroundDestruct(PPDMDEVINS pDevIns) 46 60 { 47 61 /* … … 55 69 56 70 57 static DECLCALLBACK(int) devSampleConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg) 58 { 71 PDMBOTHCBDECL(int) devPlaygroundMMIORead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb) 72 { 73 NOREF(pDevIns); 74 NOREF(pvUser); 75 NOREF(GCPhysAddr); 76 NOREF(pv); 77 NOREF(cb); 78 return VINF_SUCCESS; 79 } 80 81 82 PDMBOTHCBDECL(int) devPlaygroundMMIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void const *pv, unsigned cb) 83 { 84 NOREF(pDevIns); 85 NOREF(pvUser); 86 NOREF(GCPhysAddr); 87 NOREF(pv); 88 NOREF(cb); 89 return VINF_SUCCESS; 90 } 91 92 93 /** 94 * @callback_method_impl{FNPCIIOREGIONMAP} 95 */ 96 static DECLCALLBACK(int) devPlaygroundMap(PPCIDEVICE pPciDev, int iRegion, RTGCPHYS GCPhysAddress, RTGCPHYS cb, PCIADDRESSSPACE enmType) 97 { 98 NOREF(enmType); 99 int rc; 100 101 switch (iRegion) 102 { 103 case 0: 104 rc = PDMDevHlpMMIORegister(pPciDev->pDevIns, GCPhysAddress, cb, NULL, 105 IOMMMIO_FLAGS_READ_PASSTHRU | IOMMMIO_FLAGS_WRITE_PASSTHRU, 106 devPlaygroundMMIOWrite, devPlaygroundMMIORead, "PG-BAR0"); 107 break; 108 case 2: 109 rc = PDMDevHlpMMIORegister(pPciDev->pDevIns, GCPhysAddress, cb, NULL, 110 IOMMMIO_FLAGS_READ_PASSTHRU | IOMMMIO_FLAGS_WRITE_PASSTHRU, 111 devPlaygroundMMIOWrite, devPlaygroundMMIORead, "PG-BAR2"); 112 break; 113 default: 114 /* We should never get here */ 115 AssertMsgFailed(("Invalid PCI region param in map callback")); 116 rc = VERR_INTERNAL_ERROR; 117 } 118 return rc; 119 120 } 121 122 123 /** 124 * @interface_method_impl{PDMDEVREG,pfnConstruct} 125 */ 126 static DECLCALLBACK(int) devPlaygroundConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg) 127 { 128 NOREF(iInstance); 129 59 130 /* 60 131 * Check that the device instance and device helper structures are compatible. … … 66 137 * Initialize the instance data so that the destructor won't mess up. 67 138 */ 68 PVBOXSAMPLEDEVICE pThis = PDMINS_2_DATA(pDevIns, PVBOXSAMPLEDEVICE); 69 pThis->Whatever = 0; 139 PVBOXPLAYGROUNDDEVICE pThis = PDMINS_2_DATA(pDevIns, PVBOXPLAYGROUNDDEVICE); 140 PCIDevSetVendorId(&pThis->PciDev, 0x80ee); 141 PCIDevSetDeviceId(&pThis->PciDev, 0xde4e); 142 PCIDevSetClassBase(&pThis->PciDev, 0x07); /* communications device */ 143 PCIDevSetClassSub(&pThis->PciDev, 0x80); /* other communications device */ 70 144 71 145 /* … … 78 152 79 153 /* 80 * Use the instance number if necessary (not for this device, which in 81 * g_DeviceSample below declares a maximum instance count of 1). 82 */ 83 NOREF(iInstance); 84 85 return VINF_SUCCESS; 86 } 87 154 * PCI device setup. 155 */ 156 int rc = PDMDevHlpPCIRegister(pDevIns, &pThis->PciDev); 157 if (RT_FAILURE(rc)) 158 return rc; 159 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 0, 8*_1G64, 160 (PCIADDRESSSPACE)(PCI_ADDRESS_SPACE_MEM | PCI_ADDRESS_SPACE_BAR64), 161 devPlaygroundMap); 162 if (RT_FAILURE(rc)) 163 return rc; 164 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 2, 8*_1G64, 165 (PCIADDRESSSPACE)(PCI_ADDRESS_SPACE_MEM | PCI_ADDRESS_SPACE_BAR64), 166 devPlaygroundMap); 167 if (RT_FAILURE(rc)) 168 return rc; 169 170 return VINF_SUCCESS; 171 } 172 173 RT_C_DECLS_BEGIN 174 extern const PDMDEVREG g_DevicePlayground; 175 RT_C_DECLS_END 88 176 89 177 /** 90 178 * The device registration structure. 91 179 */ 92 static const PDMDEVREG g_DeviceSample=180 const PDMDEVREG g_DevicePlayground = 93 181 { 94 182 /* u32Version */ 95 183 PDM_DEVREG_VERSION, 96 184 /* szName */ 97 " sample",185 "playground", 98 186 /* szRCMod */ 99 187 "", … … 101 189 "", 102 190 /* pszDescription */ 103 "VBox SampleDevice.",191 "VBox Playground Device.", 104 192 /* fFlags */ 105 193 PDM_DEVREG_FLAGS_DEFAULT_BITS, … … 109 197 1, 110 198 /* cbInstance */ 111 sizeof(VBOX SAMPLEDEVICE),199 sizeof(VBOXPLAYGROUNDDEVICE), 112 200 /* pfnConstruct */ 113 dev SampleConstruct,201 devPlaygroundConstruct, 114 202 /* pfnDestruct */ 115 dev SampleDestruct,203 devPlaygroundDestruct, 116 204 /* pfnRelocate */ 117 205 NULL, … … 141 229 PDM_DEVREG_VERSION 142 230 }; 143 144 145 /**146 * Register devices provided by the plugin.147 *148 * @returns VBox status code.149 * @param pCallbacks Pointer to the callback table.150 * @param u32Version VBox version number.151 */152 extern "C" DECLEXPORT(int) VBoxDevicesRegister(PPDMDEVREGCB pCallbacks, uint32_t u32Version)153 {154 LogFlow(("VBoxSampleDevice::VBoxDevicesRegister: u32Version=%#x pCallbacks->u32Version=%#x\n", u32Version, pCallbacks->u32Version));155 156 AssertLogRelMsgReturn(pCallbacks->u32Version == PDM_DEVREG_CB_VERSION,157 ("%#x, expected %#x\n", pCallbacks->u32Version, PDM_DEVREG_CB_VERSION),158 VERR_VERSION_MISMATCH);159 160 return pCallbacks->pfnRegister(pCallbacks, &g_DeviceSample);161 }162 -
trunk/src/VBox/Devices/Samples/Makefile.kmk
r62508 r63884 27 27 VBoxSampleDevice_INSTTYPE = none 28 28 VBoxSampleDevice_SOURCES = \ 29 VBoxSampleDevice.cpp 29 VBoxSampleDevice.cpp \ 30 DevPlayground.cpp 30 31 VBoxSampleDevice_LIBS = \ 31 32 $(LIB_RUNTIME) \ -
trunk/src/VBox/Devices/Samples/VBoxSampleDevice.cpp
r63878 r63884 158 158 VERR_VERSION_MISMATCH); 159 159 160 return pCallbacks->pfnRegister(pCallbacks, &g_DeviceSample); 160 /* Two devices in this module. */ 161 extern const PDMDEVREG g_DevicePlayground; 162 int rc = pCallbacks->pfnRegister(pCallbacks, &g_DeviceSample); 163 if (RT_SUCCESS(rc)) 164 rc = pCallbacks->pfnRegister(pCallbacks, &g_DevicePlayground); 165 return rc; 161 166 } 162 167
Note:
See TracChangeset
for help on using the changeset viewer.