1 | /* $Id: PCIDeviceAttachmentImpl.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * PCI attachment information implmentation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2020 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 | #define LOG_GROUP LOG_GROUP_MAIN_PCIDEVICEATTACHMENT
|
---|
19 | #include "PCIDeviceAttachmentImpl.h"
|
---|
20 | #include "AutoCaller.h"
|
---|
21 | #include "Global.h"
|
---|
22 | #include "LoggingNew.h"
|
---|
23 |
|
---|
24 | #include <VBox/settings.h>
|
---|
25 |
|
---|
26 | struct PCIDeviceAttachment::Data
|
---|
27 | {
|
---|
28 | Data(const Utf8Str &aDevName,
|
---|
29 | LONG aHostAddress,
|
---|
30 | LONG aGuestAddress,
|
---|
31 | BOOL afPhysical) :
|
---|
32 | DevName(aDevName),
|
---|
33 | HostAddress(aHostAddress),
|
---|
34 | GuestAddress(aGuestAddress),
|
---|
35 | fPhysical(afPhysical)
|
---|
36 | {
|
---|
37 | }
|
---|
38 |
|
---|
39 | Utf8Str DevName;
|
---|
40 | LONG HostAddress;
|
---|
41 | LONG GuestAddress;
|
---|
42 | BOOL fPhysical;
|
---|
43 | };
|
---|
44 |
|
---|
45 | // constructor / destructor
|
---|
46 | /////////////////////////////////////////////////////////////////////////////
|
---|
47 | DEFINE_EMPTY_CTOR_DTOR(PCIDeviceAttachment)
|
---|
48 |
|
---|
49 | HRESULT PCIDeviceAttachment::FinalConstruct()
|
---|
50 | {
|
---|
51 | LogFlowThisFunc(("\n"));
|
---|
52 | return BaseFinalConstruct();
|
---|
53 | }
|
---|
54 |
|
---|
55 | void PCIDeviceAttachment::FinalRelease()
|
---|
56 | {
|
---|
57 | LogFlowThisFunc(("\n"));
|
---|
58 | uninit();
|
---|
59 | BaseFinalRelease();
|
---|
60 | }
|
---|
61 |
|
---|
62 | // public initializer/uninitializer for internal purposes only
|
---|
63 | /////////////////////////////////////////////////////////////////////////////
|
---|
64 | HRESULT PCIDeviceAttachment::init(IMachine *aParent,
|
---|
65 | const Utf8Str &aDevName,
|
---|
66 | LONG aHostAddress,
|
---|
67 | LONG aGuestAddress,
|
---|
68 | BOOL fPhysical)
|
---|
69 | {
|
---|
70 | NOREF(aParent);
|
---|
71 |
|
---|
72 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
73 | AutoInitSpan autoInitSpan(this);
|
---|
74 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
75 |
|
---|
76 | m = new Data(aDevName, aHostAddress, aGuestAddress, fPhysical);
|
---|
77 |
|
---|
78 | /* Confirm a successful initialization */
|
---|
79 | autoInitSpan.setSucceeded();
|
---|
80 |
|
---|
81 | return S_OK;
|
---|
82 | }
|
---|
83 |
|
---|
84 | HRESULT PCIDeviceAttachment::initCopy(IMachine *aParent, PCIDeviceAttachment *aThat)
|
---|
85 | {
|
---|
86 | LogFlowThisFunc(("aParent=%p, aThat=%p\n", aParent, aThat));
|
---|
87 |
|
---|
88 | ComAssertRet(aParent && aThat, E_INVALIDARG);
|
---|
89 |
|
---|
90 | return init(aParent, aThat->m->DevName, aThat->m->HostAddress, aThat->m->GuestAddress, aThat->m->fPhysical);
|
---|
91 | }
|
---|
92 |
|
---|
93 | HRESULT PCIDeviceAttachment::i_loadSettings(IMachine *aParent,
|
---|
94 | const settings::HostPCIDeviceAttachment &hpda)
|
---|
95 | {
|
---|
96 | return init(aParent, hpda.strDeviceName, hpda.uHostAddress, hpda.uGuestAddress, TRUE);
|
---|
97 | }
|
---|
98 |
|
---|
99 |
|
---|
100 | HRESULT PCIDeviceAttachment::i_saveSettings(settings::HostPCIDeviceAttachment &data)
|
---|
101 | {
|
---|
102 | Assert(m);
|
---|
103 | data.uHostAddress = m->HostAddress;
|
---|
104 | data.uGuestAddress = m->GuestAddress;
|
---|
105 | data.strDeviceName = m->DevName;
|
---|
106 |
|
---|
107 | return S_OK;
|
---|
108 | }
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Uninitializes the instance.
|
---|
112 | * Called from FinalRelease().
|
---|
113 | */
|
---|
114 | void PCIDeviceAttachment::uninit()
|
---|
115 | {
|
---|
116 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
117 | AutoUninitSpan autoUninitSpan(this);
|
---|
118 | if (autoUninitSpan.uninitDone())
|
---|
119 | return;
|
---|
120 |
|
---|
121 | delete m;
|
---|
122 | m = NULL;
|
---|
123 | }
|
---|
124 |
|
---|
125 | // IPCIDeviceAttachment properties
|
---|
126 | /////////////////////////////////////////////////////////////////////////////
|
---|
127 | HRESULT PCIDeviceAttachment::getName(com::Utf8Str &aName)
|
---|
128 | {
|
---|
129 | aName = m->DevName;
|
---|
130 | return S_OK;
|
---|
131 | }
|
---|
132 |
|
---|
133 | HRESULT PCIDeviceAttachment::getIsPhysicalDevice(BOOL *aIsPhysicalDevice)
|
---|
134 | {
|
---|
135 | *aIsPhysicalDevice = m->fPhysical;
|
---|
136 | return S_OK;
|
---|
137 | }
|
---|
138 |
|
---|
139 | HRESULT PCIDeviceAttachment::getHostAddress(LONG *aHostAddress)
|
---|
140 | {
|
---|
141 | *aHostAddress = m->HostAddress;
|
---|
142 | return S_OK;
|
---|
143 | }
|
---|
144 | HRESULT PCIDeviceAttachment::getGuestAddress(LONG *aGuestAddress)
|
---|
145 | {
|
---|
146 | *aGuestAddress = m->GuestAddress;
|
---|
147 | return S_OK;
|
---|
148 | }
|
---|