BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / bus_managers / pci / pci.h
blob3a434a3214e6ee6ce6fe1d7709b92cceb05f9fea
1 /*
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.
6 */
7 #ifndef __PCI_H__
8 #define __PCI_H__
10 #include <PCI.h>
12 #ifdef __cplusplus
13 #include <VectorMap.h>
14 #endif
16 #include "pci_controller.h"
18 #if defined(__INTEL__) || defined(__x86_64__)
19 #include "pci_arch_info.h"
20 #endif
22 #define TRACE_PCI
23 #ifndef TRACE_PCI
24 # define TRACE(x)
25 #else
26 # define TRACE(x) dprintf x
27 #endif
29 #ifdef __cplusplus
31 struct PCIDev;
33 struct PCIBus {
34 PCIBus * next;
35 PCIDev * parent;
36 PCIDev * child;
37 uint8 domain;
38 uint8 bus;
41 struct PCIDev {
42 PCIDev * next;
43 PCIBus * parent;
44 PCIBus * child;
45 uint8 domain;
46 uint8 bus;
47 uint8 device;
48 uint8 function;
49 pci_info info;
50 #if defined(__INTEL__) || defined(__x86_64__)
51 pci_arch_info arch_info;
52 #endif
56 struct domain_data {
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
62 int max_bus_devices;
66 class PCI {
67 public:
68 PCI();
69 ~PCI();
71 void InitDomainData();
72 void InitBus();
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,
81 uint32 *value);
82 uint32 ReadConfig(uint8 domain, uint8 bus, uint8 device,
83 uint8 function, uint16 offset, uint8 size);
84 uint32 ReadConfig(PCIDev *device, uint16 offset,
85 uint8 size);
87 status_t WriteConfig(uint8 domain, uint8 bus, uint8 device,
88 uint8 function, uint16 offset, uint8 size,
89 uint32 value);
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,
105 uint8 *offset);
106 status_t FindHTCapability(PCIDev *device,
107 uint16 capID, uint8 *offset = NULL);
109 status_t ResolveVirtualBus(uint8 virtualBus, uint8 *domain,
110 uint8 *bus);
112 PCIDev * FindDevice(uint8 domain, uint8 bus, uint8 device,
113 uint8 function);
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);
123 private:
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,
131 uint8 function);
133 PCIDev * _CreateDevice(PCIBus *parent, uint8 dev,
134 uint8 function);
135 PCIBus * _CreateBus(PCIDev *parent, uint8 domain,
136 uint8 bus);
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,
152 uint8 *flags = 0);
154 domain_data * _GetDomainData(uint8 domain);
156 status_t _CreateVirtualBus(uint8 domain, uint8 bus,
157 uint8 *virtualBus);
159 int _NumFunctions(uint8 domain, uint8 bus,
160 uint8 device);
161 PCIDev * _FindDevice(PCIBus *current, uint8 domain,
162 uint8 bus, uint8 device, uint8 function);
164 private:
165 PCIBus * fRootBus;
167 enum { MAX_PCI_DOMAINS = 8 };
169 domain_data fDomainData[MAX_PCI_DOMAINS];
170 uint8 fDomainCount;
171 bool fBusEnumeration;
173 typedef VectorMap<uint8, uint16> VirtualBusMap;
175 VirtualBusMap fVirtualBusMap;
176 int fNextVirtualBus;
179 extern PCI *gPCI;
181 #endif // __cplusplus
184 #ifdef __cplusplus
185 extern "C" {
186 #endif
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);
200 #ifdef __cplusplus
202 #endif
204 #endif /* __PCI_H__ */