1 | /* $Id: PCIDeviceAttachmentImpl.cpp 69500 2017-10-28 15:14:05Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | *
|
---|
5 | * PCI attachment information implmentation.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2010-2017 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #include "PCIDeviceAttachmentImpl.h"
|
---|
21 | #include "AutoCaller.h"
|
---|
22 | #include "Global.h"
|
---|
23 | #include "Logging.h"
|
---|
24 |
|
---|
25 | #include <VBox/settings.h>
|
---|
26 |
|
---|
27 | struct PCIDeviceAttachment::Data
|
---|
28 | {
|
---|
29 | Data(const Utf8Str &aDevName,
|
---|
30 | LONG aHostAddress,
|
---|
31 | LONG aGuestAddress,
|
---|
32 | BOOL afPhysical) :
|
---|
33 | DevName(aDevName),
|
---|
34 | HostAddress(aHostAddress),
|
---|
35 | GuestAddress(aGuestAddress),
|
---|
36 | fPhysical(afPhysical)
|
---|
37 | {
|
---|
38 | }
|
---|
39 |
|
---|
40 | Utf8Str DevName;
|
---|
41 | LONG HostAddress;
|
---|
42 | LONG GuestAddress;
|
---|
43 | BOOL fPhysical;
|
---|
44 | };
|
---|
45 |
|
---|
46 | // constructor / destructor
|
---|
47 | /////////////////////////////////////////////////////////////////////////////
|
---|
48 | DEFINE_EMPTY_CTOR_DTOR(PCIDeviceAttachment)
|
---|
49 |
|
---|
50 | HRESULT PCIDeviceAttachment::FinalConstruct()
|
---|
51 | {
|
---|
52 | LogFlowThisFunc(("\n"));
|
---|
53 | return BaseFinalConstruct();
|
---|
54 | }
|
---|
55 |
|
---|
56 | void PCIDeviceAttachment::FinalRelease()
|
---|
57 | {
|
---|
58 | LogFlowThisFunc(("\n"));
|
---|
59 | uninit();
|
---|
60 | BaseFinalRelease();
|
---|
61 | }
|
---|
62 |
|
---|
63 | // public initializer/uninitializer for internal purposes only
|
---|
64 | /////////////////////////////////////////////////////////////////////////////
|
---|
65 | HRESULT PCIDeviceAttachment::init(IMachine *aParent,
|
---|
66 | const Utf8Str &aDevName,
|
---|
67 | LONG aHostAddress,
|
---|
68 | LONG aGuestAddress,
|
---|
69 | BOOL fPhysical)
|
---|
70 | {
|
---|
71 | NOREF(aParent);
|
---|
72 |
|
---|
73 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
74 | AutoInitSpan autoInitSpan(this);
|
---|
75 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
76 |
|
---|
77 | m = new Data(aDevName, aHostAddress, aGuestAddress, fPhysical);
|
---|
78 |
|
---|
79 | /* Confirm a successful initialization */
|
---|
80 | autoInitSpan.setSucceeded();
|
---|
81 |
|
---|
82 | return S_OK;
|
---|
83 | }
|
---|
84 |
|
---|
85 | HRESULT PCIDeviceAttachment::initCopy(IMachine *aParent, PCIDeviceAttachment *aThat)
|
---|
86 | {
|
---|
87 | LogFlowThisFunc(("aParent=%p, aThat=%p\n", aParent, aThat));
|
---|
88 |
|
---|
89 | ComAssertRet(aParent && aThat, E_INVALIDARG);
|
---|
90 |
|
---|
91 | return init(aParent, aThat->m->DevName, aThat->m->HostAddress, aThat->m->GuestAddress, aThat->m->fPhysical);
|
---|
92 | }
|
---|
93 |
|
---|
94 | HRESULT PCIDeviceAttachment::i_loadSettings(IMachine *aParent,
|
---|
95 | const settings::HostPCIDeviceAttachment &hpda)
|
---|
96 | {
|
---|
97 | return init(aParent, hpda.strDeviceName, hpda.uHostAddress, hpda.uGuestAddress, TRUE);
|
---|
98 | }
|
---|
99 |
|
---|
100 |
|
---|
101 | HRESULT PCIDeviceAttachment::i_saveSettings(settings::HostPCIDeviceAttachment &data)
|
---|
102 | {
|
---|
103 | Assert(m);
|
---|
104 | data.uHostAddress = m->HostAddress;
|
---|
105 | data.uGuestAddress = m->GuestAddress;
|
---|
106 | data.strDeviceName = m->DevName;
|
---|
107 |
|
---|
108 | return S_OK;
|
---|
109 | }
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * Uninitializes the instance.
|
---|
113 | * Called from FinalRelease().
|
---|
114 | */
|
---|
115 | void PCIDeviceAttachment::uninit()
|
---|
116 | {
|
---|
117 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
118 | AutoUninitSpan autoUninitSpan(this);
|
---|
119 | if (autoUninitSpan.uninitDone())
|
---|
120 | return;
|
---|
121 |
|
---|
122 | delete m;
|
---|
123 | m = NULL;
|
---|
124 | }
|
---|
125 |
|
---|
126 | // IPCIDeviceAttachment properties
|
---|
127 | /////////////////////////////////////////////////////////////////////////////
|
---|
128 | HRESULT PCIDeviceAttachment::getName(com::Utf8Str &aName)
|
---|
129 | {
|
---|
130 | aName = m->DevName;
|
---|
131 | return S_OK;
|
---|
132 | }
|
---|
133 |
|
---|
134 | HRESULT PCIDeviceAttachment::getIsPhysicalDevice(BOOL *aIsPhysicalDevice)
|
---|
135 | {
|
---|
136 | *aIsPhysicalDevice = m->fPhysical;
|
---|
137 | return S_OK;
|
---|
138 | }
|
---|
139 |
|
---|
140 | HRESULT PCIDeviceAttachment::getHostAddress(LONG *aHostAddress)
|
---|
141 | {
|
---|
142 | *aHostAddress = m->HostAddress;
|
---|
143 | return S_OK;
|
---|
144 | }
|
---|
145 | HRESULT PCIDeviceAttachment::getGuestAddress(LONG *aGuestAddress)
|
---|
146 | {
|
---|
147 | *aGuestAddress = m->GuestAddress;
|
---|
148 | return S_OK;
|
---|
149 | }
|
---|