2 * Copyright 2003-2008, Marcus Overhagen. All rights reserved.
3 * Copyright 2005-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
5 * Distributed under the terms of the MIT License.
13 #include <VectorMap.h>
16 #include "pci_controller.h"
18 #if defined(__INTEL__) || defined(__x86_64__)
19 #include "pci_arch_info.h"
26 # define TRACE(x) dprintf x
50 #if defined(__INTEL__) || defined(__x86_64__)
51 pci_arch_info arch_info
;
57 // These two are set in PCI::AddController:
58 pci_controller
* controller
;
59 void * controller_cookie
;
61 // All the rest is set in PCI::InitDomainData
71 void InitDomainData();
74 status_t
AddController(pci_controller
*controller
,
75 void *controller_cookie
);
77 status_t
GetNthInfo(long index
, pci_info
*outInfo
);
79 status_t
ReadConfig(uint8 domain
, uint8 bus
, uint8 device
,
80 uint8 function
, uint16 offset
, uint8 size
,
82 uint32
ReadConfig(uint8 domain
, uint8 bus
, uint8 device
,
83 uint8 function
, uint16 offset
, uint8 size
);
84 uint32
ReadConfig(PCIDev
*device
, uint16 offset
,
87 status_t
WriteConfig(uint8 domain
, uint8 bus
, uint8 device
,
88 uint8 function
, uint16 offset
, uint8 size
,
90 status_t
WriteConfig(PCIDev
*device
, uint16 offset
,
91 uint8 size
, uint32 value
);
93 status_t
FindCapability(uint8 domain
, uint8 bus
,
94 uint8 device
, uint8 function
, uint8 capID
,
95 uint8
*offset
= NULL
);
96 status_t
FindCapability(PCIDev
*device
, uint8 capID
,
97 uint8
*offset
= NULL
);
98 status_t
FindExtendedCapability(uint8 domain
, uint8 bus
,
99 uint8 device
, uint8 function
, uint16 capID
,
100 uint16
*offset
= NULL
);
101 status_t
FindExtendedCapability(PCIDev
*device
,
102 uint16 capID
, uint16
*offset
= NULL
);
103 status_t
FindHTCapability(uint8 domain
, uint8 bus
,
104 uint8 device
, uint8 function
, uint16 capID
,
106 status_t
FindHTCapability(PCIDev
*device
,
107 uint16 capID
, uint8
*offset
= NULL
);
109 status_t
ResolveVirtualBus(uint8 virtualBus
, uint8
*domain
,
112 PCIDev
* FindDevice(uint8 domain
, uint8 bus
, uint8 device
,
115 void ClearDeviceStatus(PCIBus
*bus
, bool dumpStatus
);
117 void RefreshDeviceInfo();
119 status_t
UpdateInterruptLine(uint8 domain
, uint8 bus
,
120 uint8 device
, uint8 function
,
121 uint8 newInterruptLineValue
);
124 void _EnumerateBus(uint8 domain
, uint8 bus
,
125 uint8
*subordinateBus
= NULL
);
127 void _FixupDevices(uint8 domain
, uint8 bus
);
129 void _DiscoverBus(PCIBus
*bus
);
130 void _DiscoverDevice(PCIBus
*bus
, uint8 dev
,
133 PCIDev
* _CreateDevice(PCIBus
*parent
, uint8 dev
,
135 PCIBus
* _CreateBus(PCIDev
*parent
, uint8 domain
,
138 status_t
_GetNthInfo(PCIBus
*bus
, long *currentIndex
,
139 long wantIndex
, pci_info
*outInfo
);
140 void _ReadBasicInfo(PCIDev
*dev
);
141 void _ReadHeaderInfo(PCIDev
*dev
);
143 void _ConfigureBridges(PCIBus
*bus
);
144 void _RefreshDeviceInfo(PCIBus
*bus
);
146 uint32
_BarSize(uint32 bits
, uint32 mask
);
147 size_t _GetBarInfo(PCIDev
*dev
, uint8 offset
,
148 uint32
*address
, uint32
*size
= 0,
149 uint8
*flags
= 0, uint32
*highAddress
= 0);
150 void _GetRomBarInfo(PCIDev
*dev
, uint8 offset
,
151 uint32
*address
, uint32
*size
= 0,
154 domain_data
* _GetDomainData(uint8 domain
);
156 status_t
_CreateVirtualBus(uint8 domain
, uint8 bus
,
159 int _NumFunctions(uint8 domain
, uint8 bus
,
161 PCIDev
* _FindDevice(PCIBus
*current
, uint8 domain
,
162 uint8 bus
, uint8 device
, uint8 function
);
167 enum { MAX_PCI_DOMAINS
= 8 };
169 domain_data fDomainData
[MAX_PCI_DOMAINS
];
171 bool fBusEnumeration
;
173 typedef VectorMap
<uint8
, uint16
> VirtualBusMap
;
175 VirtualBusMap fVirtualBusMap
;
181 #endif // __cplusplus
188 status_t
pci_init(void);
189 void pci_uninit(void);
191 long pci_get_nth_pci_info(long index
, pci_info
*outInfo
);
193 uint32
pci_read_config(uint8 virtualBus
, uint8 device
, uint8 function
,
194 uint16 offset
, uint8 size
);
195 void pci_write_config(uint8 virtualBus
, uint8 device
, uint8 function
,
196 uint16 offset
, uint8 size
, uint32 value
);
198 void __pci_resolve_virtual_bus(uint8 virtualBus
, uint8
*domain
, uint8
*bus
);
204 #endif /* __PCI_H__ */