1 | /* $Id: BusAssignmentManager.h 33918 2010-11-09 17:11:14Z 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.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 | #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 |
|
---|
90 | class BusAssignmentManager
|
---|
91 | {
|
---|
92 | private:
|
---|
93 | struct State;
|
---|
94 | State* pState;
|
---|
95 |
|
---|
96 | BusAssignmentManager();
|
---|
97 | virtual ~BusAssignmentManager();
|
---|
98 |
|
---|
99 | static BusAssignmentManager* pInstance;
|
---|
100 |
|
---|
101 | public:
|
---|
102 | static BusAssignmentManager* getInstance(ChipsetType_T chipsetType);
|
---|
103 | virtual void AddRef();
|
---|
104 | virtual void Release();
|
---|
105 |
|
---|
106 | virtual HRESULT assignPciDevice(const char* pszDevName, PCFGMNODE pCfg, PciBusAddress& Address, bool fAddressRequired = false);
|
---|
107 | virtual HRESULT assignPciDevice(const char* pszDevName, PCFGMNODE pCfg)
|
---|
108 | {
|
---|
109 | PciBusAddress Address;
|
---|
110 | return assignPciDevice(pszDevName, pCfg, Address, false);
|
---|
111 | }
|
---|
112 | virtual bool findPciAddress(const char* pszDevName, int iInstance, PciBusAddress& Address);
|
---|
113 | virtual bool hasPciDevice(const char* pszDevName, int iInstance)
|
---|
114 | {
|
---|
115 | PciBusAddress Address;
|
---|
116 | return findPciAddress(pszDevName, iInstance, Address);
|
---|
117 | }
|
---|
118 | };
|
---|
119 |
|
---|
120 | #endif // __BusAssignmentManager_h
|
---|