1 | /* $Id: VBoxSampleDevice.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Sample Device.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009 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/pdmdev.h>
|
---|
24 | #include <VBox/version.h>
|
---|
25 | #include <VBox/err.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 | */
|
---|
37 | typedef struct VBOXSAMPLEDEVICE
|
---|
38 | {
|
---|
39 | uint32_t Whatever;
|
---|
40 | } VBOXSAMPLEDEVICE;
|
---|
41 | typedef VBOXSAMPLEDEVICE *PVBOXSAMPLEDEVICE;
|
---|
42 |
|
---|
43 |
|
---|
44 |
|
---|
45 |
|
---|
46 | FNPDMDEVCONSTRUCT pfnConstruct;
|
---|
47 | /** Destruct instance - optional. */
|
---|
48 | FNPDMDEVDESTRUCT pfnDestruct;
|
---|
49 |
|
---|
50 | static DECLCALLBACK(int) devSampleDestruct(PPDMDEVINS pDevIns)
|
---|
51 | {
|
---|
52 | /*
|
---|
53 | * Check the versions here as well since the destructor is *always* called.
|
---|
54 | */
|
---|
55 | AssertMsgReturn(pDevIns->u32Version == PDM_DEVINS_VERSION, ("%#x, expected %#x\n", pDevIns->u32Version, PDM_DEVINS_VERSION), VERR_VERSION_MISMATCH);
|
---|
56 | AssertMsgReturn(pDevIns->pHlpR3->u32Version == PDM_DEVHLPR3_VERSION, ("%#x, expected %#x\n", pDevIns->pHlpR3->u32Version, PDM_DEVHLPR3_VERSION), VERR_VERSION_MISMATCH);
|
---|
57 |
|
---|
58 | return VINF_SUCCESS;
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
62 | static DECLCALLBACK(int) devSampleConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
|
---|
63 | {
|
---|
64 | /*
|
---|
65 | * Check that the device instance and device helper structures are compatible.
|
---|
66 | */
|
---|
67 | AssertLogRelMsgReturn(pDevIns->u32Version == PDM_DEVINS_VERSION, ("%#x, expected %#x\n", pDevIns->u32Version, PDM_DEVINS_VERSION), VERR_VERSION_MISMATCH);
|
---|
68 | AssertLogRelMsgReturn(pDevIns->pHlpR3->u32Version == PDM_DEVHLPR3_VERSION, ("%#x, expected %#x\n", pDevIns->pHlpR3->u32Version, PDM_DEVHLPR3_VERSION), VERR_VERSION_MISMATCH);
|
---|
69 |
|
---|
70 | /*
|
---|
71 | * Initialize the instance data so that the destructure won't mess up.
|
---|
72 | */
|
---|
73 | PVBOXSAMPLEDEVICE pThis = PDMINS_2_DATA(pDevIns, PVBOXSAMPLEDEVICE);
|
---|
74 | pThis->Whatever = 0;
|
---|
75 |
|
---|
76 | /*
|
---|
77 | * Validate and read the configuration.
|
---|
78 | */
|
---|
79 | if (!CFGMR3AreValuesValid(pCfg,
|
---|
80 | "Whatever1\0"
|
---|
81 | "Whatever2\0"))
|
---|
82 | return VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
|
---|
83 |
|
---|
84 |
|
---|
85 | return VINF_SUCCESS;
|
---|
86 | }
|
---|
87 |
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * The device registration structure.
|
---|
91 | */
|
---|
92 | static const PDMDEVREG g_DeviceSample =
|
---|
93 | {
|
---|
94 | /* u32Version */
|
---|
95 | PDM_DEVREG_VERSION,
|
---|
96 | /* szName */
|
---|
97 | "sample",
|
---|
98 | /* szRCMod */
|
---|
99 | "",
|
---|
100 | /* szR0Mod */
|
---|
101 | "",
|
---|
102 | /* pszDescription */
|
---|
103 | "VBox Sample Device.",
|
---|
104 | /* fFlags */
|
---|
105 | PDM_DEVREG_FLAGS_DEFAULT_BITS,
|
---|
106 | /* fClass */
|
---|
107 | PDM_DEVREG_CLASS_MISC,
|
---|
108 | /* cMaxInstances */
|
---|
109 | 1,
|
---|
110 | /* cbInstance */
|
---|
111 | sizeof(VBOXSAMPLEDEVICE),
|
---|
112 | /* pfnConstruct */
|
---|
113 | devSampleConstruct,
|
---|
114 | /* pfnDestruct */
|
---|
115 | devSampleDestruct,
|
---|
116 | /* pfnRelocate */
|
---|
117 | NULL,
|
---|
118 | /* pfnIOCtl */
|
---|
119 | NULL,
|
---|
120 | /* pfnPowerOn */
|
---|
121 | NULL,
|
---|
122 | /* pfnReset */
|
---|
123 | NULL,
|
---|
124 | /* pfnSuspend */
|
---|
125 | NULL,
|
---|
126 | /* pfnResume */
|
---|
127 | NULL,
|
---|
128 | /* pfnAttach */
|
---|
129 | NULL,
|
---|
130 | /* pfnDetach */
|
---|
131 | NULL,
|
---|
132 | /* pfnQueryInterface */
|
---|
133 | NULL,
|
---|
134 | /* pfnInitComplete */
|
---|
135 | NULL,
|
---|
136 | /* pfnPowerOff */
|
---|
137 | NULL,
|
---|
138 | /* pfnSoftReset */
|
---|
139 | NULL,
|
---|
140 | /* u32VersionEnd */
|
---|
141 | PDM_DEVREG_VERSION
|
---|
142 | };
|
---|
143 |
|
---|
144 |
|
---|
145 | /**
|
---|
146 | * Register builtin devices.
|
---|
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 |
|
---|