1 | /* $Id: PCIDeviceAttachmentImpl.cpp 93115 2022-01-01 11:31:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * PCI attachment information implmentation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2022 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 | /** @todo r=bird: Inconsistent signed/unsigned crap. */
|
---|
97 | return init(aParent, hpda.strDeviceName, (LONG)hpda.uHostAddress, (LONG)hpda.uGuestAddress, TRUE);
|
---|
98 | }
|
---|
99 |
|
---|
100 |
|
---|
101 | HRESULT PCIDeviceAttachment::i_saveSettings(settings::HostPCIDeviceAttachment &data)
|
---|
102 | {
|
---|
103 | Assert(m);
|
---|
104 | /** @todo r=bird: Inconsistent signed/unsigned crap. */
|
---|
105 | data.uHostAddress = (uint32_t)m->HostAddress;
|
---|
106 | data.uGuestAddress = (uint32_t)m->GuestAddress;
|
---|
107 | data.strDeviceName = m->DevName;
|
---|
108 |
|
---|
109 | return S_OK;
|
---|
110 | }
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * Uninitializes the instance.
|
---|
114 | * Called from FinalRelease().
|
---|
115 | */
|
---|
116 | void PCIDeviceAttachment::uninit()
|
---|
117 | {
|
---|
118 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
119 | AutoUninitSpan autoUninitSpan(this);
|
---|
120 | if (autoUninitSpan.uninitDone())
|
---|
121 | return;
|
---|
122 |
|
---|
123 | delete m;
|
---|
124 | m = NULL;
|
---|
125 | }
|
---|
126 |
|
---|
127 | // IPCIDeviceAttachment properties
|
---|
128 | /////////////////////////////////////////////////////////////////////////////
|
---|
129 | HRESULT PCIDeviceAttachment::getName(com::Utf8Str &aName)
|
---|
130 | {
|
---|
131 | aName = m->DevName;
|
---|
132 | return S_OK;
|
---|
133 | }
|
---|
134 |
|
---|
135 | HRESULT PCIDeviceAttachment::getIsPhysicalDevice(BOOL *aIsPhysicalDevice)
|
---|
136 | {
|
---|
137 | *aIsPhysicalDevice = m->fPhysical;
|
---|
138 | return S_OK;
|
---|
139 | }
|
---|
140 |
|
---|
141 | HRESULT PCIDeviceAttachment::getHostAddress(LONG *aHostAddress)
|
---|
142 | {
|
---|
143 | *aHostAddress = m->HostAddress;
|
---|
144 | return S_OK;
|
---|
145 | }
|
---|
146 | HRESULT PCIDeviceAttachment::getGuestAddress(LONG *aGuestAddress)
|
---|
147 | {
|
---|
148 | *aGuestAddress = m->GuestAddress;
|
---|
149 | return S_OK;
|
---|
150 | }
|
---|