1 | /* $Id: BusAssignmentManager.h 34331 2010-11-24 16:24:17Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | *
|
---|
5 | * VirtualBox bus slots assignment manager
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2010 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.alldomusa.eu.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 | #ifndef __BusAssignmentManager_h
|
---|
20 | #define __BusAssignmentManager_h
|
---|
21 |
|
---|
22 | #include "VBox/types.h"
|
---|
23 | #include "VirtualBoxBase.h"
|
---|
24 |
|
---|
25 | struct PciBusAddress
|
---|
26 | {
|
---|
27 | int iBus;
|
---|
28 | int iDevice;
|
---|
29 | int iFn;
|
---|
30 |
|
---|
31 | PciBusAddress()
|
---|
32 | {
|
---|
33 | clear();
|
---|
34 | }
|
---|
35 |
|
---|
36 | PciBusAddress(int bus, int device, int fn)
|
---|
37 | : iBus(bus), iDevice(device), iFn(fn)
|
---|
38 | {
|
---|
39 | }
|
---|
40 |
|
---|
41 | PciBusAddress& clear()
|
---|
42 | {
|
---|
43 | iBus = iDevice = iFn = -1;
|
---|
44 | return *this;
|
---|
45 | }
|
---|
46 |
|
---|
47 | bool operator<(const PciBusAddress &a) const
|
---|
48 | {
|
---|
49 | if (iBus < a.iBus)
|
---|
50 | return true;
|
---|
51 |
|
---|
52 | if (iBus > a.iBus)
|
---|
53 | return false;
|
---|
54 |
|
---|
55 | if (iDevice < a.iDevice)
|
---|
56 | return true;
|
---|
57 |
|
---|
58 | if (iDevice > a.iDevice)
|
---|
59 | return false;
|
---|
60 |
|
---|
61 | if (iFn < a.iFn)
|
---|
62 | return true;
|
---|
63 |
|
---|
64 | if (iFn > a.iFn)
|
---|
65 | return false;
|
---|
66 |
|
---|
67 | return false;
|
---|
68 | }
|
---|
69 |
|
---|
70 | bool operator==(const PciBusAddress &a) const
|
---|
71 | {
|
---|
72 | return (iBus == a.iBus)
|
---|
73 | && (iDevice == a.iDevice)
|
---|
74 | && (iFn == a.iFn);
|
---|
75 | }
|
---|
76 |
|
---|
77 | bool operator!=(const PciBusAddress &a) const
|
---|
78 | {
|
---|
79 | return (iBus != a.iBus)
|
---|
80 | || (iDevice != a.iDevice)
|
---|
81 | || (iFn != a.iFn);
|
---|
82 | }
|
---|
83 |
|
---|
84 | bool valid() const
|
---|
85 | {
|
---|
86 | return (iBus != -1) && (iDevice != -1) && (iFn != -1);
|
---|
87 | }
|
---|
88 |
|
---|
89 | LONG asLong() const
|
---|
90 | {
|
---|
91 | Assert(valid());
|
---|
92 | return (iBus << 8) | (iDevice << 3) | iFn;
|
---|
93 | }
|
---|
94 |
|
---|
95 | void fromLong(LONG value)
|
---|
96 | {
|
---|
97 | iBus = (value >> 8) & 0xff;
|
---|
98 | iDevice = (value & 0xff) >> 3;
|
---|
99 | iFn = (value & 7);
|
---|
100 | }
|
---|
101 | };
|
---|
102 |
|
---|
103 | class BusAssignmentManager
|
---|
104 | {
|
---|
105 | private:
|
---|
106 | struct State;
|
---|
107 | State* pState;
|
---|
108 |
|
---|
109 | BusAssignmentManager();
|
---|
110 | virtual ~BusAssignmentManager();
|
---|
111 |
|
---|
112 | public:
|
---|
113 | static BusAssignmentManager* createInstance(ChipsetType_T chipsetType);
|
---|
114 | virtual void AddRef();
|
---|
115 | virtual void Release();
|
---|
116 |
|
---|
117 | virtual HRESULT assignPciDevice(const char* pszDevName, PCFGMNODE pCfg, PciBusAddress& Address, bool fAddressRequired = false);
|
---|
118 | virtual HRESULT assignPciDevice(const char* pszDevName, PCFGMNODE pCfg)
|
---|
119 | {
|
---|
120 | PciBusAddress Address;
|
---|
121 | return assignPciDevice(pszDevName, pCfg, Address, false);
|
---|
122 | }
|
---|
123 | virtual bool findPciAddress(const char* pszDevName, int iInstance, PciBusAddress& Address);
|
---|
124 | virtual bool hasPciDevice(const char* pszDevName, int iInstance)
|
---|
125 | {
|
---|
126 | PciBusAddress Address;
|
---|
127 | return findPciAddress(pszDevName, iInstance, Address);
|
---|
128 | }
|
---|
129 | virtual void listAttachedPciDevices(ComSafeArrayOut(IPciDeviceAttachment*, aAttached));
|
---|
130 | };
|
---|
131 |
|
---|
132 | #endif // __BusAssignmentManager_h
|
---|