ReactOS 0.4.17-dev-804-g023d8af
arbiter.c File Reference
#include <ntifs.h>
#include <ndk/rtlfuncs.h>
#include "arbiter.h"
#include <debug.h>
Include dependency graph for arbiter.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define ARBITER_SIG   'sbrA'
 

Functions

NTSTATUS NTAPI ArbiterLibBootAllocation (_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_BOOT_ALLOCATION_PARAMETERS Parameters)
 
NTSTATUS NTAPI ArbiterLibAddReserved (_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ADD_RESERVED_PARAMETERS Parameters)
 
NTSTATUS NTAPI ArbiterLibQueryConflict (_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_QUERY_CONFLICT_PARAMETERS Parameters)
 
NTSTATUS NTAPI ArbiterLibInitializeRangeList (_In_ PARBITER_INSTANCE Arbiter, _In_ ULONG ResourceCount, _In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Resources, _Inout_ PRTL_RANGE_LIST RangeList)
 
NTSTATUS NTAPI ArbiterLibStartArbiter (_In_ PARBITER_INSTANCE Arbiter, _In_ PCM_RESOURCE_LIST StartResources)
 
NTSTATUS NTAPI ArbiterLibPreprocessEntry (_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
 
NTSTATUS NTAPI ArbiterLibAllocateEntry (_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
 
NTSTATUS NTAPI ArbiterLibSortArbitrationList (_Inout_ PLIST_ENTRY ArbitrationList)
 
VOID NTAPI ArbiterLibConfirmAllocation (_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
 
BOOLEAN NTAPI ArbiterLibOverrideConflict (_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
 
NTSTATUS NTAPI ArbiterLibHandler (_In_ PVOID Context, _In_ ARBITER_ACTION Action, _Inout_ PARBITER_PARAMETERS Parameters)
 
VOID NTAPI ArbiterLibDeleteInstance (_In_ PARBITER_INSTANCE Arbiter)
 
NTSTATUS NTAPI ArbiterLibInitializeInstance (_Inout_ PARBITER_INSTANCE Arbiter, _In_ PDEVICE_OBJECT BusDeviceObject, _In_ CM_RESOURCE_TYPE ResourceType, _In_ PCWSTR ArbiterName, _In_ PCWSTR OrderName, _In_ PARB_TRANSLATE_ORDERING TranslateOrderingFunction)
 

Macro Definition Documentation

◆ ARBITER_SIG

#define ARBITER_SIG   'sbrA'

Definition at line 17 of file arbiter.c.

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file arbiter.c.

Function Documentation

◆ ArbiterLibAddReserved()

NTSTATUS NTAPI ArbiterLibAddReserved ( _In_ PARBITER_INSTANCE  Arbiter,
_Inout_ PARBITER_ADD_RESERVED_PARAMETERS  Parameters 
)

Definition at line 42 of file arbiter.c.

51{
52 PAGED_CODE();
53
56}
#define PAGED_CODE()
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42

Referenced by ArbiterLibInitializeInstance().

◆ ArbiterLibAllocateEntry()

NTSTATUS NTAPI ArbiterLibAllocateEntry ( _In_ PARBITER_INSTANCE  Arbiter,
_Inout_ PARBITER_ALLOCATION_STATE  ArbState 
)

Definition at line 126 of file arbiter.c.

129{
130 PAGED_CODE();
131
134}

Referenced by ArbiterLibInitializeInstance().

◆ ArbiterLibBootAllocation()

NTSTATUS NTAPI ArbiterLibBootAllocation ( _In_ PARBITER_INSTANCE  Arbiter,
_Inout_ PARBITER_BOOT_ALLOCATION_PARAMETERS  Parameters 
)

Definition at line 23 of file arbiter.c.

31{
32 PAGED_CODE();
33
36}

Referenced by ArbiterLibInitializeInstance().

◆ ArbiterLibConfirmAllocation()

VOID NTAPI ArbiterLibConfirmAllocation ( _In_ PARBITER_INSTANCE  Arbiter,
_Inout_ PARBITER_ALLOCATION_STATE  ArbState 
)

Definition at line 151 of file arbiter.c.

154{
155 PAGED_CODE();
156
158}

◆ ArbiterLibDeleteInstance()

VOID NTAPI ArbiterLibDeleteInstance ( _In_ PARBITER_INSTANCE  Arbiter)

Definition at line 190 of file arbiter.c.

192{
193 PAGED_CODE();
194
195 if (Arbiter->PossibleAllocation)
196 {
197 RtlFreeRangeList(Arbiter->PossibleAllocation);
198 ExFreePoolWithTag(Arbiter->PossibleAllocation, TAG_ARBITER);
199 Arbiter->PossibleAllocation = NULL;
200 }
201
202 if (Arbiter->Allocation)
203 {
204 RtlFreeRangeList(Arbiter->Allocation);
205 ExFreePoolWithTag(Arbiter->Allocation, TAG_ARBITER);
206 Arbiter->Allocation = NULL;
207 }
208
209 if (Arbiter->AllocationStack)
210 {
211 ExFreePoolWithTag(Arbiter->AllocationStack, TAG_ARBITER);
212 Arbiter->AllocationStack = NULL;
213 Arbiter->AllocationStackMaxSize = 0;
214 }
215
216 ArbiterLibFreeOrderingList(&Arbiter->OrderingList);
217 ArbiterLibFreeOrderingList(&Arbiter->ReservedList);
218
219#if (NTDDI_VERSION >= NTDDI_VISTA)
220 if (Arbiter->TransactionEvent)
221 {
222 ExFreePoolWithTag(Arbiter->TransactionEvent, TAG_ARBITER);
223 Arbiter->TransactionEvent = NULL;
224 }
225#endif
226
227 if (Arbiter->MutexEvent)
228 {
229 ExFreePoolWithTag(Arbiter->MutexEvent, TAG_ARBITER);
230 Arbiter->MutexEvent = NULL;
231 }
232}
#define TAG_ARBITER
Definition: arbiter.h:10
VOID NTAPI ArbiterLibFreeOrderingList(_Inout_ PARBITER_ORDERING_LIST OrderingList)
Definition: ordering.c:52
#define NULL
Definition: types.h:112
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
NTSYSAPI VOID NTAPI RtlFreeRangeList(_In_ PRTL_RANGE_LIST RangeList)

Referenced by ArbiterLibInitializeInstance(), and PciArbiterDestructor().

◆ ArbiterLibHandler()

NTSTATUS NTAPI ArbiterLibHandler ( _In_ PVOID  Context,
_In_ ARBITER_ACTION  Action,
_Inout_ PARBITER_PARAMETERS  Parameters 
)

Definition at line 176 of file arbiter.c.

180{
181 PAGED_CODE();
182
185}

Referenced by PciArbiterConstructor().

◆ ArbiterLibInitializeInstance()

NTSTATUS NTAPI ArbiterLibInitializeInstance ( _Inout_ PARBITER_INSTANCE  Arbiter,
_In_ PDEVICE_OBJECT  BusDeviceObject,
_In_ CM_RESOURCE_TYPE  ResourceType,
_In_ PCWSTR  ArbiterName,
_In_ PCWSTR  OrderName,
_In_ PARB_TRANSLATE_ORDERING  TranslateOrderingFunction 
)

Definition at line 237 of file arbiter.c.

244{
246
247 PAGED_CODE();
248
249 DPRINT("ArbiterLibInitializeInstance: '%S'\n", ArbiterName);
250
251 ASSERT(Arbiter->UnpackRequirement != NULL);
252 ASSERT(Arbiter->PackResource != NULL);
253 ASSERT(Arbiter->UnpackResource != NULL);
254 ASSERT(Arbiter->MutexEvent == NULL);
255 ASSERT(Arbiter->Allocation == NULL);
256 ASSERT(Arbiter->PossibleAllocation == NULL);
257 ASSERT(Arbiter->AllocationStack == NULL);
258
259 Arbiter->Signature = ARBITER_SIG;
260 Arbiter->BusDeviceObject = BusDeviceObject;
261 Arbiter->Name = ArbiterName;
262 Arbiter->ResourceType = ResourceType;
263 Arbiter->TransactionInProgress = FALSE;
264#if (NTDDI_VERSION >= NTDDI_VISTA)
265 Arbiter->OrderingName = OrderName;
266#endif
267
268 /* The per-instance lock: a signaled synchronization event used as a mutex. */
269 Arbiter->MutexEvent = ExAllocatePoolWithTag(NonPagedPool, sizeof(KEVENT), TAG_ARBITER);
270 if (!Arbiter->MutexEvent)
271 {
273 goto Failure;
274 }
275 KeInitializeEvent(Arbiter->MutexEvent, SynchronizationEvent, TRUE);
276
277#if (NTDDI_VERSION >= NTDDI_VISTA)
278 /* Vista+: a notification event exposing whether a Test is outstanding. */
279 Arbiter->TransactionEvent = ExAllocatePoolWithTag(NonPagedPool, sizeof(KEVENT), TAG_ARBITER);
280 if (!Arbiter->TransactionEvent)
281 {
283 goto Failure;
284 }
285 KeInitializeEvent(Arbiter->TransactionEvent, NotificationEvent, TRUE);
286#endif
287
288 Arbiter->AllocationStack = ExAllocatePoolWithTag(PagedPool, PAGE_SIZE, TAG_ARBITER);
289 if (!Arbiter->AllocationStack)
290 {
292 goto Failure;
293 }
294 Arbiter->AllocationStackMaxSize = PAGE_SIZE;
295 Arbiter->Allocation = ExAllocatePoolWithTag(PagedPool, sizeof(RTL_RANGE_LIST), TAG_ARBITER);
296 if (!Arbiter->Allocation)
297 {
299 goto Failure;
300 }
301 RtlInitializeRangeList(Arbiter->Allocation);
302
303 Arbiter->PossibleAllocation = ExAllocatePoolWithTag(PagedPool, sizeof(RTL_RANGE_LIST), TAG_ARBITER);
304 if (!Arbiter->PossibleAllocation)
305 {
307 goto Failure;
308 }
309 RtlInitializeRangeList(Arbiter->PossibleAllocation);
310
311 if (!Arbiter->TestAllocation)
312 Arbiter->TestAllocation = ArbiterLibTestAllocation;
313 if (!Arbiter->RetestAllocation)
314 Arbiter->RetestAllocation = ArbiterLibRetestAllocation;
315 if (!Arbiter->CommitAllocation)
316 Arbiter->CommitAllocation = ArbiterLibCommitAllocation;
317 if (!Arbiter->RollbackAllocation)
318 Arbiter->RollbackAllocation = ArbiterLibRollbackAllocation;
319 if (!Arbiter->BootAllocation)
320 Arbiter->BootAllocation = ArbiterLibBootAllocation;
321 if (!Arbiter->AddReserved)
322 Arbiter->AddReserved = ArbiterLibAddReserved;
323 if (!Arbiter->QueryConflict)
324 Arbiter->QueryConflict = ArbiterLibQueryConflict;
325 if (!Arbiter->StartArbiter)
326 Arbiter->StartArbiter = ArbiterLibStartArbiter;
327 if (!Arbiter->PreprocessEntry)
328 Arbiter->PreprocessEntry = ArbiterLibPreprocessEntry;
329 if (!Arbiter->AllocateEntry)
330 Arbiter->AllocateEntry = ArbiterLibAllocateEntry;
331 if (!Arbiter->GetNextAllocationRange)
332 Arbiter->GetNextAllocationRange = ArbiterLibGetNextAllocationRange;
333 if (!Arbiter->FindSuitableRange)
334 Arbiter->FindSuitableRange = ArbiterLibFindSuitableRange;
335 if (!Arbiter->AddAllocation)
336 Arbiter->AddAllocation = ArbiterLibAddAllocation;
337 if (!Arbiter->BacktrackAllocation)
338 Arbiter->BacktrackAllocation = ArbiterLibBacktrackAllocation;
339 if (!Arbiter->OverrideConflict)
340 Arbiter->OverrideConflict = ArbiterLibOverrideConflict;
341#if (NTDDI_VERSION >= NTDDI_VISTA)
342 if (!Arbiter->InitializeRangeList)
343 Arbiter->InitializeRangeList = ArbiterLibInitializeRangeList;
344#endif
345
346 Status = ArbiterLibDefaultAssignmentOrdering(Arbiter, OrderName, OrderName, TranslateOrderingFunction);
347 if (!NT_SUCCESS(Status))
348 {
349 DPRINT1("ArbiterLibInitializeInstance: ArbiterLibDefaultAssignmentOrdering failed, Status %X\n", Status);
350 goto Failure;
351 }
352
353 return STATUS_SUCCESS;
354
355Failure:
356 DPRINT1("ArbiterLibInitializeInstance: '%S' failed, Status %X\n", ArbiterName, Status);
358 return Status;
359}
NTSTATUS NTAPI ArbiterLibBootAllocation(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_BOOT_ALLOCATION_PARAMETERS Parameters)
Definition: arbiter.c:23
NTSTATUS NTAPI ArbiterLibInitializeRangeList(_In_ PARBITER_INSTANCE Arbiter, _In_ ULONG ResourceCount, _In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Resources, _Inout_ PRTL_RANGE_LIST RangeList)
Definition: arbiter.c:84
NTSTATUS NTAPI ArbiterLibAllocateEntry(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
Definition: arbiter.c:126
NTSTATUS NTAPI ArbiterLibAddReserved(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ADD_RESERVED_PARAMETERS Parameters)
Definition: arbiter.c:42
VOID NTAPI ArbiterLibDeleteInstance(_In_ PARBITER_INSTANCE Arbiter)
Definition: arbiter.c:190
NTSTATUS NTAPI ArbiterLibPreprocessEntry(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
Definition: arbiter.c:113
NTSTATUS NTAPI ArbiterLibStartArbiter(_In_ PARBITER_INSTANCE Arbiter, _In_ PCM_RESOURCE_LIST StartResources)
Definition: arbiter.c:100
BOOLEAN NTAPI ArbiterLibOverrideConflict(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
Definition: arbiter.c:163
#define ARBITER_SIG
Definition: arbiter.c:17
NTSTATUS NTAPI ArbiterLibQueryConflict(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_QUERY_CONFLICT_PARAMETERS Parameters)
Definition: arbiter.c:62
BOOLEAN NTAPI ArbiterLibGetNextAllocationRange(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
Moves the working window to the next candidate range, walking the entry's alternatives in priority or...
Definition: range.c:379
NTSTATUS NTAPI ArbiterLibRetestAllocation(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_RETEST_ALLOCATION_PARAMETERS Parameters)
The RetestAllocation action: deterministically re-establishes the placements a previous test chose,...
Definition: transaction.c:469
NTSTATUS NTAPI ArbiterLibTestAllocation(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_TEST_ALLOCATION_PARAMETERS Parameters)
The TestAllocation action: tentatively places every entry of the arbitration list,...
Definition: transaction.c:433
VOID NTAPI ArbiterLibBacktrackAllocation(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
Undoes the last AddAllocation performed for this entry.
Definition: range.c:656
BOOLEAN NTAPI ArbiterLibFindSuitableRange(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
Finds a free range of the current candidate window in the arbiter's tentative allocation list.
Definition: range.c:520
NTSTATUS NTAPI ArbiterLibCommitAllocation(_In_ PARBITER_INSTANCE Arbiter)
The CommitAllocation action: the tentative PossibleAllocation becomes the committed Allocation,...
Definition: transaction.c:501
NTSTATUS NTAPI ArbiterLibRollbackAllocation(_In_ PARBITER_INSTANCE Arbiter)
The RollbackAllocation action: discards the tentative allocation; the committed one is untouched.
Definition: transaction.c:529
NTSTATUS NTAPI ArbiterLibDefaultAssignmentOrdering(_Inout_ PARBITER_INSTANCE Arbiter, _In_ PCWSTR AllocationOrderName, _In_ PCWSTR ReservedResourcesName, _In_opt_ PARB_TRANSLATE_ORDERING TranslateOrderingFunction)
Definition: ordering.c:328
VOID NTAPI ArbiterLibAddAllocation(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
Records the chosen placement in the arbiter's tentative allocation list, owned by the requesting devi...
Definition: range.c:618
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define NonPagedPool
Definition: env_spec_w32.h:307
#define PagedPool
Definition: env_spec_w32.h:308
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
NTSYSAPI VOID NTAPI RtlInitializeRangeList(_Out_ PRTL_RANGE_LIST RangeList)
@ NotificationEvent
@ SynchronizationEvent
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158

Referenced by arbusno_Initializer(), ario_Initializer(), armem_Initializer(), IopArbBusNumberInitialize(), IopArbDmaInitialize(), IopArbIrqInitialize(), IopArbMemInitialize(), and IopArbPortInitialize().

◆ ArbiterLibInitializeRangeList()

NTSTATUS NTAPI ArbiterLibInitializeRangeList ( _In_ PARBITER_INSTANCE  Arbiter,
_In_ ULONG  ResourceCount,
_In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR  Resources,
_Inout_ PRTL_RANGE_LIST  RangeList 
)

Definition at line 84 of file arbiter.c.

89{
90 PAGED_CODE();
91
94}

Referenced by ArbiterLibInitializeInstance().

◆ ArbiterLibOverrideConflict()

BOOLEAN NTAPI ArbiterLibOverrideConflict ( _In_ PARBITER_INSTANCE  Arbiter,
_Inout_ PARBITER_ALLOCATION_STATE  ArbState 
)

Definition at line 163 of file arbiter.c.

166{
167 PAGED_CODE();
168
170 return FALSE;
171}

Referenced by ArbiterLibInitializeInstance().

◆ ArbiterLibPreprocessEntry()

NTSTATUS NTAPI ArbiterLibPreprocessEntry ( _In_ PARBITER_INSTANCE  Arbiter,
_Inout_ PARBITER_ALLOCATION_STATE  ArbState 
)

Definition at line 113 of file arbiter.c.

116{
117 PAGED_CODE();
118
120 return STATUS_SUCCESS;
121}

Referenced by ArbiterLibInitializeInstance().

◆ ArbiterLibQueryConflict()

NTSTATUS NTAPI ArbiterLibQueryConflict ( _In_ PARBITER_INSTANCE  Arbiter,
_Inout_ PARBITER_QUERY_CONFLICT_PARAMETERS  Parameters 
)

Definition at line 62 of file arbiter.c.

73{
74 PAGED_CODE();
75
78}

Referenced by ArbiterLibInitializeInstance().

◆ ArbiterLibSortArbitrationList()

NTSTATUS NTAPI ArbiterLibSortArbitrationList ( _Inout_ PLIST_ENTRY  ArbitrationList)

Definition at line 139 of file arbiter.c.

141{
142 PAGED_CODE();
143
146}

Referenced by ArbpTestAllocation().

◆ ArbiterLibStartArbiter()

NTSTATUS NTAPI ArbiterLibStartArbiter ( _In_ PARBITER_INSTANCE  Arbiter,
_In_ PCM_RESOURCE_LIST  StartResources 
)

Definition at line 100 of file arbiter.c.

103{
104 PAGED_CODE();
105
108}

Referenced by ArbiterLibInitializeInstance().