VirtualBox

source: vbox/trunk/src/VBox/Devices/Samples/VBoxSampleDevice.cpp@ 80703

Last change on this file since 80703 was 80703, checked in by vboxsync, 5 years ago

PDM,Devices: Redefined uReserved1 to cMaxPciDevices in the PDMDEVREG structures and added PDM_DEVREG_FLAGS_MSI_X for indicating possible need for MSI-X. bugref:9218

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
1/* $Id: VBoxSampleDevice.cpp 80703 2019-09-10 14:50:27Z vboxsync $ */
2/** @file
3 * VBox Sample Device.
4 */
5
6/*
7 * Copyright (C) 2009-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. 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_MISC
23#include <VBox/vmm/pdmdev.h>
24#include <VBox/version.h>
25#include <iprt/errcore.h>
26#include <VBox/log.h>
27
28#include <iprt/assert.h>
29
30
31/*********************************************************************************************************************************
32* Structures and Typedefs *
33*********************************************************************************************************************************/
34/**
35 * Device Instance Data.
36 */
37typedef struct VBOXSAMPLEDEVICE
38{
39 uint32_t Whatever;
40} VBOXSAMPLEDEVICE;
41typedef VBOXSAMPLEDEVICE *PVBOXSAMPLEDEVICE;
42
43
44
45static DECLCALLBACK(int) devSampleDestruct(PPDMDEVINS pDevIns)
46{
47 /*
48 * Check the versions here as well since the destructor is *always* called.
49 */
50 PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns);
51
52 return VINF_SUCCESS;
53}
54
55
56static DECLCALLBACK(int) devSampleConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
57{
58
59 /*
60 * Check that the device instance and device helper structures are compatible.
61 */
62 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
63 NOREF(pCfg);
64
65 /*
66 * Initialize the instance data so that the destructor won't mess up.
67 */
68 PVBOXSAMPLEDEVICE pThis = PDMINS_2_DATA(pDevIns, PVBOXSAMPLEDEVICE);
69 pThis->Whatever = 0;
70
71 /*
72 * Validate and read the configuration.
73 */
74 PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "Whatever1|Whatever2", "");
75
76 /*
77 * Use the instance number if necessary (not for this device, which in
78 * g_DeviceSample below declares a maximum instance count of 1).
79 */
80 NOREF(iInstance);
81
82 return VINF_SUCCESS;
83}
84
85
86/**
87 * The device registration structure.
88 */
89static const PDMDEVREG g_DeviceSample =
90{
91 /* .u32Version = */ PDM_DEVREG_VERSION,
92 /* .uReserved0 = */ 0,
93 /* .szName = */ "sample",
94 /* .fFlags = */ PDM_DEVREG_FLAGS_DEFAULT_BITS,
95 /* .fClass = */ PDM_DEVREG_CLASS_MISC,
96 /* .cMaxInstances = */ 1,
97 /* .uSharedVersion = */ 42,
98 /* .cbInstanceShared = */ sizeof(VBOXSAMPLEDEVICE),
99 /* .cbInstanceCC = */ 0,
100 /* .cbInstanceRC = */ 0,
101 /* .cMaxPciDevices = */ 0,
102 /* .pszDescription = */ "VBox Sample Device.",
103#if defined(IN_RING3)
104 /* .pszRCMod = */ "",
105 /* .pszR0Mod = */ "",
106 /* .pfnConstruct = */ devSampleConstruct,
107 /* .pfnDestruct = */ devSampleDestruct,
108 /* .pfnRelocate = */ NULL,
109 /* .pfnMemSetup = */ NULL,
110 /* .pfnPowerOn = */ NULL,
111 /* .pfnReset = */ NULL,
112 /* .pfnSuspend = */ NULL,
113 /* .pfnResume = */ NULL,
114 /* .pfnAttach = */ NULL,
115 /* .pfnDetach = */ NULL,
116 /* .pfnQueryInterface = */ NULL,
117 /* .pfnInitComplete = */ NULL,
118 /* .pfnPowerOff = */ NULL,
119 /* .pfnSoftReset = */ NULL,
120 /* .pfnReserved0 = */ NULL,
121 /* .pfnReserved1 = */ NULL,
122 /* .pfnReserved2 = */ NULL,
123 /* .pfnReserved3 = */ NULL,
124 /* .pfnReserved4 = */ NULL,
125 /* .pfnReserved5 = */ NULL,
126 /* .pfnReserved6 = */ NULL,
127 /* .pfnReserved7 = */ NULL,
128#elif defined(IN_RING0)
129 /* .pfnEarlyConstruct = */ NULL,
130 /* .pfnConstruct = */ NULL,
131 /* .pfnDestruct = */ NULL,
132 /* .pfnFinalDestruct = */ NULL,
133 /* .pfnRequest = */ NULL,
134 /* .pfnReserved0 = */ NULL,
135 /* .pfnReserved1 = */ NULL,
136 /* .pfnReserved2 = */ NULL,
137 /* .pfnReserved3 = */ NULL,
138 /* .pfnReserved4 = */ NULL,
139 /* .pfnReserved5 = */ NULL,
140 /* .pfnReserved6 = */ NULL,
141 /* .pfnReserved7 = */ NULL,
142#elif defined(IN_RC)
143 /* .pfnConstruct = */ NULL,
144 /* .pfnReserved0 = */ NULL,
145 /* .pfnReserved1 = */ NULL,
146 /* .pfnReserved2 = */ NULL,
147 /* .pfnReserved3 = */ NULL,
148 /* .pfnReserved4 = */ NULL,
149 /* .pfnReserved5 = */ NULL,
150 /* .pfnReserved6 = */ NULL,
151 /* .pfnReserved7 = */ NULL,
152#else
153# error "Not in IN_RING3, IN_RING0 or IN_RC!"
154#endif
155 /* .u32VersionEnd = */ PDM_DEVREG_VERSION
156};
157
158
159/**
160 * Register devices provided by the plugin.
161 *
162 * @returns VBox status code.
163 * @param pCallbacks Pointer to the callback table.
164 * @param u32Version VBox version number.
165 */
166extern "C" DECLEXPORT(int) VBoxDevicesRegister(PPDMDEVREGCB pCallbacks, uint32_t u32Version)
167{
168 LogFlow(("VBoxSampleDevice::VBoxDevicesRegister: u32Version=%#x pCallbacks->u32Version=%#x\n", u32Version, pCallbacks->u32Version));
169
170 AssertLogRelMsgReturn(u32Version >= VBOX_VERSION,
171 ("VirtualBox version %#x, expected %#x or higher\n", u32Version, VBOX_VERSION),
172 VERR_VERSION_MISMATCH);
173 AssertLogRelMsgReturn(pCallbacks->u32Version == PDM_DEVREG_CB_VERSION,
174 ("callback version %#x, expected %#x\n", pCallbacks->u32Version, PDM_DEVREG_CB_VERSION),
175 VERR_VERSION_MISMATCH);
176
177 return pCallbacks->pfnRegister(pCallbacks, &g_DeviceSample);
178}
179
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