VirtualBox

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

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

PDM,Devices: Changed PDM_DEVREG_FLAGS_MSI_X into a registration field giving the max MSI-X vector count config for the device (typically VBOX_MSIX_MAX_ENTRIES). bugref:9218

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.4 KB
Line 
1/* $Id: VBoxSampleDevice.cpp 80704 2019-09-10 15:19:39Z 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 /* .cMaxMsixVectors = */ 0,
103 /* .pszDescription = */ "VBox Sample Device.",
104#if defined(IN_RING3)
105 /* .pszRCMod = */ "",
106 /* .pszR0Mod = */ "",
107 /* .pfnConstruct = */ devSampleConstruct,
108 /* .pfnDestruct = */ devSampleDestruct,
109 /* .pfnRelocate = */ NULL,
110 /* .pfnMemSetup = */ NULL,
111 /* .pfnPowerOn = */ NULL,
112 /* .pfnReset = */ NULL,
113 /* .pfnSuspend = */ NULL,
114 /* .pfnResume = */ NULL,
115 /* .pfnAttach = */ NULL,
116 /* .pfnDetach = */ NULL,
117 /* .pfnQueryInterface = */ NULL,
118 /* .pfnInitComplete = */ NULL,
119 /* .pfnPowerOff = */ NULL,
120 /* .pfnSoftReset = */ NULL,
121 /* .pfnReserved0 = */ NULL,
122 /* .pfnReserved1 = */ NULL,
123 /* .pfnReserved2 = */ NULL,
124 /* .pfnReserved3 = */ NULL,
125 /* .pfnReserved4 = */ NULL,
126 /* .pfnReserved5 = */ NULL,
127 /* .pfnReserved6 = */ NULL,
128 /* .pfnReserved7 = */ NULL,
129#elif defined(IN_RING0)
130 /* .pfnEarlyConstruct = */ NULL,
131 /* .pfnConstruct = */ NULL,
132 /* .pfnDestruct = */ NULL,
133 /* .pfnFinalDestruct = */ NULL,
134 /* .pfnRequest = */ NULL,
135 /* .pfnReserved0 = */ NULL,
136 /* .pfnReserved1 = */ NULL,
137 /* .pfnReserved2 = */ NULL,
138 /* .pfnReserved3 = */ NULL,
139 /* .pfnReserved4 = */ NULL,
140 /* .pfnReserved5 = */ NULL,
141 /* .pfnReserved6 = */ NULL,
142 /* .pfnReserved7 = */ NULL,
143#elif defined(IN_RC)
144 /* .pfnConstruct = */ NULL,
145 /* .pfnReserved0 = */ NULL,
146 /* .pfnReserved1 = */ NULL,
147 /* .pfnReserved2 = */ NULL,
148 /* .pfnReserved3 = */ NULL,
149 /* .pfnReserved4 = */ NULL,
150 /* .pfnReserved5 = */ NULL,
151 /* .pfnReserved6 = */ NULL,
152 /* .pfnReserved7 = */ NULL,
153#else
154# error "Not in IN_RING3, IN_RING0 or IN_RC!"
155#endif
156 /* .u32VersionEnd = */ PDM_DEVREG_VERSION
157};
158
159
160/**
161 * Register devices provided by the plugin.
162 *
163 * @returns VBox status code.
164 * @param pCallbacks Pointer to the callback table.
165 * @param u32Version VBox version number.
166 */
167extern "C" DECLEXPORT(int) VBoxDevicesRegister(PPDMDEVREGCB pCallbacks, uint32_t u32Version)
168{
169 LogFlow(("VBoxSampleDevice::VBoxDevicesRegister: u32Version=%#x pCallbacks->u32Version=%#x\n", u32Version, pCallbacks->u32Version));
170
171 AssertLogRelMsgReturn(u32Version >= VBOX_VERSION,
172 ("VirtualBox version %#x, expected %#x or higher\n", u32Version, VBOX_VERSION),
173 VERR_VERSION_MISMATCH);
174 AssertLogRelMsgReturn(pCallbacks->u32Version == PDM_DEVREG_CB_VERSION,
175 ("callback version %#x, expected %#x\n", pCallbacks->u32Version, PDM_DEVREG_CB_VERSION),
176 VERR_VERSION_MISMATCH);
177
178 return pCallbacks->pfnRegister(pCallbacks, &g_DeviceSample);
179}
180
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