ReactOS 0.4.17-dev-806-gffa4164
arb_comn.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS PCI Bus Driver
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: drivers/bus/pci/arb/arb_comn.c
5 * PURPOSE: Common Arbitration Code
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9/* INCLUDES *******************************************************************/
10
11#include <pci.h>
12
13#define NDEBUG
14#include <debug.h>
15
16/* GLOBALS ********************************************************************/
17
19{
20 "I/O Port",
21 "Memory",
22 "Interrupt",
23 "Bus Number"
24};
25
26/* FUNCTIONS ******************************************************************/
27
28VOID
31{
33
35}
36
37VOID
40{
42
44}
45
49 _In_ PCI_SIGNATURE ArbiterType,
51{
53 PAGED_CODE();
54
55 if (!FdoExtension->ArbitersInitialized) return STATUS_NOT_SUPPORTED;
56
57 /* Find the instance this bus built for the requested resource type */
59 SecondaryExtension.Next,
60 ArbiterType);
61 if (!Arbiter)
62 {
63 DPRINT1("PCI - FDO ext 0x%p has no %s arbiter to hand out.\n",
65 PciArbiterNames[ArbiterType - PciArb_Io]);
67 }
68
69 Interface->Size = sizeof(ARBITER_INTERFACE);
71 Interface->Context = &Arbiter->CommonInstance;
72 Interface->InterfaceReference = PciArbiter_Reference;
73 Interface->InterfaceDereference = PciArbiter_Dereference;
74 Interface->ArbiterHandler = ArbiterLibHandler;
75 Interface->Flags = 0;
76 return STATUS_SUCCESS;
77}
78
79VOID
82{
83 PAGED_CODE();
84
85 ArbiterLibDeleteInstance(&Arbiter->CommonInstance);
86}
87
91{
92 PPCI_INTERFACE CurrentInterface, *Interfaces;
94 PPCI_ARBITER_INSTANCE ArbiterInterface;
96 PCI_SIGNATURE ArbiterType;
98
99 /* A bus that ends up needing no arbiter at all is not a failure */
101
102 /* Loop all the arbiters */
103 for (ArbiterType = PciArb_Io; ArbiterType <= PciArb_BusNumber; ArbiterType++)
104 {
105 /* Check if this is the extension for the Root PCI Bus */
107 {
108 /* Get the PDO extension */
109 PdoExtension = FdoExtension->PhysicalDeviceObject->DeviceExtension;
111
112 /* Skip this bus if it does subtractive decode */
113 if (PdoExtension->Dependent.type1.SubtractiveDecode)
114 {
115 DPRINT1("PCI Not creating arbiters for subtractive bus %u\n",
116 PdoExtension->Dependent.type1.SubtractiveDecode);
117 continue;
118 }
119 }
120
121 /* Query all the registered arbiter interfaces */
122 Interfaces = PciInterfaces;
123 while (*Interfaces)
124 {
125 /* Find the one that matches the arbiter currently being setup */
126 CurrentInterface = *Interfaces;
127 if (CurrentInterface->Signature == ArbiterType) break;
128 Interfaces++;
129 }
130
131 /* Check if the required arbiter was not found in the list */
132 if (!*Interfaces)
133 {
134 /* Skip this arbiter and try the next one */
135 DPRINT1("PCI - FDO ext 0x%p no %s arbiter.\n",
137 PciArbiterNames[ArbiterType - PciArb_Io]);
138 continue;
139 }
140
141 /* An arbiter was found, allocate an instance for it */
143 ArbiterInterface = ExAllocatePoolWithTag(PagedPool,
144 sizeof(PCI_ARBITER_INSTANCE),
146 if (!ArbiterInterface) break;
147
148 /* Setup the instance */
149 ArbiterInterface->BusFdoExtension = FdoExtension;
150 ArbiterInterface->Interface = CurrentInterface;
151 _swprintf(ArbiterInterface->InstanceName,
152 L"PCI %S (b=%02x)",
153 PciArbiterNames[ArbiterType - PciArb_Io],
154 FdoExtension->BaseBus);
155
156 /* Call the interface initializer for it */
157 Status = CurrentInterface->Initializer(ArbiterInterface);
158 if (!NT_SUCCESS(Status)) break;
159
160 /* Link it with this FDO */
161 PcipLinkSecondaryExtension(&FdoExtension->SecondaryExtension,
162 &FdoExtension->SecondaryExtLock,
163 &ArbiterInterface->Header,
164 ArbiterType,
166
167 /* This arbiter is now initialized, move to the next one */
168 DPRINT1("PCI - FDO ext 0x%p %S arbiter initialized (context 0x%p).\n",
170 L"ARBITER HEADER MISSING", //ArbiterInterface->CommonInstance.Name,
171 ArbiterInterface);
173 }
174
175 /* Return to caller */
176 return Status;
177}
178
180NTAPI
183{
186 PCI_SIGNATURE ArbiterType;
188
189 /* Arbiters should not already be initialized */
190 if (DeviceExtension->ArbitersInitialized)
191 {
192 /* Duplicated start request, fail initialization */
193 DPRINT1("PCI Warning hot start FDOx %p, resource ranges not checked.\n", DeviceExtension);
195 }
196
197 /* Check for non-root FDO */
198 if (!PCI_IS_ROOT_FDO(DeviceExtension))
199 {
200 /* Grab the PDO */
201 PdoExtension = (PPCI_PDO_EXTENSION)DeviceExtension->PhysicalDeviceObject->DeviceExtension;
203
204 /* Check if this is a subtractive bus */
205 if (PdoExtension->Dependent.type1.SubtractiveDecode)
206 {
207 /* There is nothing to do regarding arbitration of resources */
208 DPRINT1("PCI Skipping arbiter initialization for subtractive bridge FDOX %p\n", DeviceExtension);
209 return STATUS_SUCCESS;
210 }
211 }
212
213 /* Loop the arbiters that hand out the ranges a bus decodes */
214 for (ArbiterType = PciArb_Io; ArbiterType <= PciArb_Memory; ArbiterType++)
215 {
216 /* Find an arbiter of this type */
217 Instance = (PVOID)PciFindNextSecondaryExtension(DeviceExtension->
218 SecondaryExtension.Next,
219 ArbiterType);
220 if (Instance)
221 {
222 /*
223 * Hand it the resources this bus was started with. They describe
224 * the windows the bus actually decodes, which is what bounds the
225 * addresses it may hand out to the devices behind it.
226 */
227 Status = Instance->CommonInstance.StartArbiter(&Instance->CommonInstance,
228 Resources);
229 if (!NT_SUCCESS(Status))
230 {
231 DPRINT1("PCI - FDO ext 0x%p %s arbiter failed to start: %X\n",
232 DeviceExtension,
233 PciArbiterNames[ArbiterType - PciArb_Io],
234 Status);
235 return Status;
236 }
237 }
238 else
239 {
240 /* The arbiter was not found, this is an error! */
241 DPRINT1("PCI - FDO ext 0x%p %s arbiter (REQUIRED) is missing.\n",
242 DeviceExtension,
243 PciArbiterNames[ArbiterType - PciArb_Io]);
244 }
245 }
246
247 /* Arbiters are now initialized */
248 DeviceExtension->ArbitersInitialized = TRUE;
249 return STATUS_SUCCESS;
250}
251
252/* EOF */
#define PAGED_CODE()
NTSTATUS NTAPI PciInitializeArbiterRanges(IN PPCI_FDO_EXTENSION DeviceExtension, IN PCM_RESOURCE_LIST Resources)
Definition: arb_comn.c:181
VOID NTAPI PciArbiter_Reference(_In_ PVOID Context)
Definition: arb_comn.c:30
PCHAR PciArbiterNames[]
Definition: arb_comn.c:18
VOID NTAPI PciArbiter_Dereference(_In_ PVOID Context)
Definition: arb_comn.c:39
NTSTATUS NTAPI PciInitializeArbiters(IN PPCI_FDO_EXTENSION FdoExtension)
Definition: arb_comn.c:90
NTSTATUS NTAPI PciArbiterConstructor(_In_ PPCI_FDO_EXTENSION FdoExtension, _In_ PCI_SIGNATURE ArbiterType, _Out_ PARBITER_INTERFACE Interface)
Definition: arb_comn.c:48
VOID NTAPI PciArbiterDestructor(IN PPCI_ARBITER_INSTANCE Arbiter)
Definition: arb_comn.c:81
VOID NTAPI ArbiterLibDeleteInstance(_In_ PARBITER_INSTANCE Arbiter)
Definition: arbiter.c:22
NTSTATUS NTAPI ArbiterLibHandler(_In_ PVOID Context, _In_ ARBITER_ACTION Action, _Inout_ PARBITER_PARAMETERS Parameters)
The single ARBITER_ACTION dispatcher every exported ARBITER_INTERFACE points its ArbiterHandler at; C...
Definition: handler.c:164
struct _ARBITER_INSTANCE * PARBITER_INSTANCE
Definition: arbiter.h:110
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define L(x)
Definition: resources.c:13
#define ARBITER_INTERFACE_VERSION
Definition: pci.h:77
PPCI_SECONDARY_EXTENSION NTAPI PciFindNextSecondaryExtension(IN PSINGLE_LIST_ENTRY ListHead, IN PCI_SIGNATURE ExtensionType)
Definition: utils.c:584
enum _PCI_SIGNATURE PCI_SIGNATURE
struct _PCI_PDO_EXTENSION * PPCI_PDO_EXTENSION
VOID NTAPI PcipLinkSecondaryExtension(IN PSINGLE_LIST_ENTRY List, IN PVOID Lock, IN PPCI_SECONDARY_EXTENSION SecondaryExtension, IN PCI_SIGNATURE ExtensionType, IN PVOID Destructor)
Definition: utils.c:459
#define PCI_IS_ROOT_FDO(x)
Definition: pci.h:32
#define PCI_POOL_TAG
Definition: pci.h:27
#define ASSERT_FDO(x)
Definition: pci.h:37
#define ASSERT_PDO(x)
Definition: pci.h:38
@ PciArb_BusNumber
Definition: pci.h:104
@ PciArb_Io
Definition: pci.h:101
@ PciArb_Memory
Definition: pci.h:102
@ PdoExtension
Definition: precomp.h:49
@ FdoExtension
Definition: precomp.h:48
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
Status
Definition: gdiplustypes.h:24
PPCI_INTERFACE PciInterfaces[]
Definition: intrface.c:18
#define _swprintf(buf, format,...)
Definition: sprintf.c:56
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define STATUS_SUCCESS
Definition: shellext.h:65
_In_ PVOID Context
Definition: storport.h:2269
PPCI_FDO_EXTENSION BusFdoExtension
Definition: pci.h:411
PCI_SECONDARY_EXTENSION Header
Definition: pci.h:409
WCHAR InstanceName[24]
Definition: pci.h:412
ARBITER_INSTANCE CommonInstance
Definition: pci.h:413
PPCI_INTERFACE Interface
Definition: pci.h:410
ULONG ReferenceCount
Definition: arbiter.h:306
PCI_SIGNATURE Signature
Definition: pci.h:389
PCI_INTERFACE_INITIALIZER Initializer
Definition: pci.h:391
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
#define IN
Definition: typedefs.h:39
int32_t * PLONG
Definition: typedefs.h:58
char * PCHAR
Definition: typedefs.h:51
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE Interface
Definition: wdffdo.h:465
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_WMI_INSTANCE_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_opt_ WDFWMIINSTANCE * Instance
Definition: wdfwmi.h:481
struct _ARBITER_INTERFACE ARBITER_INTERFACE