ReactOS 0.4.15-dev-5667-ged97270
arbiter.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Kernel&Driver SDK
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Hardware Resources Arbiter Library
5 * COPYRIGHT: Copyright 2020 Vadim Galyant <vgal@rambler.ru>
6 */
7
8/* INCLUDES *******************************************************************/
9
10#include <ntifs.h>
11#include <ndk/rtlfuncs.h>
12#include "arbiter.h"
13
14#define NDEBUG
15#include <debug.h>
16
17/* GLOBALS ********************************************************************/
18
19/* DATA **********************************************************************/
20
21/* FUNCTIONS ******************************************************************/
22
23CODE_SEG("PAGE")
27 _In_ PARBITER_INSTANCE Arbiter,
28 _In_ PLIST_ENTRY ArbitrationList)
29{
30 PAGED_CODE();
31
34}
35
36CODE_SEG("PAGE")
40 _In_ PARBITER_INSTANCE Arbiter,
41 _In_ PLIST_ENTRY ArbitrationList)
42{
43 PAGED_CODE();
44
47}
48
49CODE_SEG("PAGE")
53 _In_ PARBITER_INSTANCE Arbiter)
54{
55 PAGED_CODE();
56
59}
60
61CODE_SEG("PAGE")
65 _In_ PARBITER_INSTANCE Arbiter)
66{
67 PAGED_CODE();
68
71}
72
73/* FIXME: the prototype is not correct yet. */
74CODE_SEG("PAGE")
78 _In_ PARBITER_INSTANCE Arbiter)
79{
80 PAGED_CODE();
81
84}
85
86CODE_SEG("PAGE")
90 _In_ PARBITER_INSTANCE Arbiter,
92{
93 PAGED_CODE();
94
95 return STATUS_SUCCESS;
96}
97
98CODE_SEG("PAGE")
100NTAPI
102 _In_ PARBITER_INSTANCE Arbiter,
104{
105 PAGED_CODE();
106
109}
110
111CODE_SEG("PAGE")
113NTAPI
115 _In_ PARBITER_INSTANCE Arbiter,
117{
118 PAGED_CODE();
119
121 return FALSE;
122}
123
124CODE_SEG("PAGE")
126NTAPI
128 _In_ PARBITER_INSTANCE Arbiter,
130{
131 PAGED_CODE();
132
134 return FALSE;
135}
136
137CODE_SEG("PAGE")
138VOID
139NTAPI
141 _In_ PARBITER_INSTANCE Arbiter,
143{
144 PAGED_CODE();
145
147}
148
149CODE_SEG("PAGE")
150VOID
151NTAPI
153 _In_ PARBITER_INSTANCE Arbiter,
155{
156 PAGED_CODE();
157
159}
160
161/* FIXME: the prototype is not correct yet. */
162CODE_SEG("PAGE")
164NTAPI
166 _In_ PARBITER_INSTANCE Arbiter)
167{
168 PAGED_CODE();
169
172}
173
174CODE_SEG("PAGE")
176NTAPI
178 _In_ PARBITER_INSTANCE Arbiter,
179 _In_ PLIST_ENTRY ArbitrationList)
180{
181 PAGED_CODE();
182
185}
186
187/* FIXME: the prototype is not correct yet. */
188CODE_SEG("PAGE")
190NTAPI
192 _In_ PARBITER_INSTANCE Arbiter)
193{
194 PAGED_CODE();
195
198}
199
200/* FIXME: the prototype is not correct yet. */
201CODE_SEG("PAGE")
203NTAPI
205 _In_ PARBITER_INSTANCE Arbiter)
206{
207 PAGED_CODE();
208
211}
212
213CODE_SEG("PAGE")
215NTAPI
218 _In_ UINT64 MinimumAddress,
219 _In_ UINT64 MaximumAddress)
220{
221 PAGED_CODE();
222
225}
226
227CODE_SEG("PAGE")
229NTAPI
231 _Out_ PARBITER_ORDERING_LIST OrderingList,
232 _In_ UINT64 MinimumAddress,
233 _In_ UINT64 MaximumAddress)
234{
235 PAGED_CODE();
236
239}
240
241CODE_SEG("PAGE")
243NTAPI
246{
247 PAGED_CODE();
248
251}
252
253CODE_SEG("PAGE")
254VOID
255NTAPI
258{
259 PAGED_CODE();
260
262}
263
264CODE_SEG("PAGE")
266NTAPI
268 _Inout_ PARBITER_INSTANCE ArbInstance,
269 _In_ PCWSTR OrderName,
270 _In_ PCWSTR ReservedOrderName,
271 _In_ PARB_TRANSLATE_ORDERING TranslateOrderingFunction)
272{
273 PAGED_CODE();
274
276 return STATUS_SUCCESS;
277}
278
279CODE_SEG("PAGE")
281NTAPI
284 _In_ PDEVICE_OBJECT BusDeviceObject,
285 _In_ CM_RESOURCE_TYPE ResourceType,
286 _In_ PCWSTR ArbiterName,
287 _In_ PCWSTR OrderName,
288 _In_ PARB_TRANSLATE_ORDERING TranslateOrderingFunction)
289{
291
292 PAGED_CODE();
293
294 DPRINT("ArbInitializeArbiterInstance: '%S'\n", ArbiterName);
295
296 ASSERT(Arbiter->UnpackRequirement != NULL);
297 ASSERT(Arbiter->PackResource != NULL);
298 ASSERT(Arbiter->UnpackResource != NULL);
299 ASSERT(Arbiter->MutexEvent == NULL);
300 ASSERT(Arbiter->Allocation == NULL);
301 ASSERT(Arbiter->PossibleAllocation == NULL);
302 ASSERT(Arbiter->AllocationStack == NULL);
303
304 Arbiter->Signature = ARBITER_SIGNATURE;
305 Arbiter->BusDeviceObject = BusDeviceObject;
306
307 Arbiter->MutexEvent = ExAllocatePoolWithTag(NonPagedPool, sizeof(KEVENT), TAG_ARBITER);
308 if (!Arbiter->MutexEvent)
309 {
310 DPRINT1("ArbInitializeArbiterInstance: STATUS_INSUFFICIENT_RESOURCES\n");
312 }
313
314 KeInitializeEvent(Arbiter->MutexEvent, SynchronizationEvent, TRUE);
315
316 Arbiter->AllocationStack = ExAllocatePoolWithTag(PagedPool, PAGE_SIZE, TAG_ARB_ALLOCATION);
317 if (!Arbiter->AllocationStack)
318 {
319 DPRINT1("ArbInitializeArbiterInstance: STATUS_INSUFFICIENT_RESOURCES\n");
320 ExFreePoolWithTag(Arbiter->MutexEvent, TAG_ARBITER);
322 }
323
324 Arbiter->AllocationStackMaxSize = PAGE_SIZE;
325
326 Arbiter->Allocation = ExAllocatePoolWithTag(PagedPool, sizeof(RTL_RANGE_LIST), TAG_ARB_RANGE);
327 if (!Arbiter->Allocation)
328 {
329 DPRINT1("ArbInitializeArbiterInstance: STATUS_INSUFFICIENT_RESOURCES\n");
330 ExFreePoolWithTag(Arbiter->AllocationStack, TAG_ARB_ALLOCATION);
331 ExFreePoolWithTag(Arbiter->MutexEvent, TAG_ARBITER);
333 }
334
335 Arbiter->PossibleAllocation = ExAllocatePoolWithTag(PagedPool, sizeof(RTL_RANGE_LIST), TAG_ARB_RANGE);
336 if (!Arbiter->PossibleAllocation)
337 {
338 DPRINT1("ArbInitializeArbiterInstance: STATUS_INSUFFICIENT_RESOURCES\n");
339 ExFreePoolWithTag(Arbiter->Allocation, TAG_ARB_RANGE);
340 ExFreePoolWithTag(Arbiter->AllocationStack, TAG_ARB_ALLOCATION);
341 ExFreePoolWithTag(Arbiter->MutexEvent, TAG_ARBITER);
343 }
344
345 RtlInitializeRangeList(Arbiter->Allocation);
346 RtlInitializeRangeList(Arbiter->PossibleAllocation);
347
348 Arbiter->Name = ArbiterName;
349 Arbiter->ResourceType = ResourceType;
350 Arbiter->TransactionInProgress = FALSE;
351
352 if (!Arbiter->TestAllocation)
353 Arbiter->TestAllocation = ArbTestAllocation;
354
355 if (!Arbiter->RetestAllocation)
356 Arbiter->RetestAllocation = ArbRetestAllocation;
357
358 if (!Arbiter->CommitAllocation)
359 Arbiter->CommitAllocation = ArbCommitAllocation;
360
361 if (!Arbiter->RollbackAllocation)
362 Arbiter->RollbackAllocation = ArbRollbackAllocation;
363
364 if (!Arbiter->AddReserved)
365 Arbiter->AddReserved = ArbAddReserved;
366
367 if (!Arbiter->PreprocessEntry)
368 Arbiter->PreprocessEntry = ArbPreprocessEntry;
369
370 if (!Arbiter->AllocateEntry)
371 Arbiter->AllocateEntry = ArbAllocateEntry;
372
373 if (!Arbiter->GetNextAllocationRange)
374 Arbiter->GetNextAllocationRange = ArbGetNextAllocationRange;
375
376 if (!Arbiter->FindSuitableRange)
377 Arbiter->FindSuitableRange = ArbFindSuitableRange;
378
379 if (!Arbiter->AddAllocation)
380 Arbiter->AddAllocation = ArbAddAllocation;
381
382 if (!Arbiter->BacktrackAllocation)
383 Arbiter->BacktrackAllocation = ArbBacktrackAllocation;
384
385 if (!Arbiter->OverrideConflict)
386 Arbiter->OverrideConflict = ArbOverrideConflict;
387
388 if (!Arbiter->BootAllocation)
389 Arbiter->BootAllocation = ArbBootAllocation;
390
391 if (!Arbiter->QueryConflict)
392 Arbiter->QueryConflict = ArbQueryConflict;
393
394 if (!Arbiter->StartArbiter)
395 Arbiter->StartArbiter = ArbStartArbiter;
396
397 Status = ArbBuildAssignmentOrdering(Arbiter, OrderName, OrderName, TranslateOrderingFunction);
398 if (NT_SUCCESS(Status))
399 {
400 return STATUS_SUCCESS;
401 }
402
403 DPRINT1("ArbInitializeArbiterInstance: Status %X\n", Status);
404
405 return Status;
406}
#define PAGED_CODE()
unsigned char BOOLEAN
unsigned long long UINT64
NTSTATUS NTAPI ArbOverrideConflict(_In_ PARBITER_INSTANCE Arbiter)
Definition: arbiter.c:165
NTSTATUS NTAPI ArbPruneOrdering(_Out_ PARBITER_ORDERING_LIST OrderingList, _In_ UINT64 MinimumAddress, _In_ UINT64 MaximumAddress)
Definition: arbiter.c:230
BOOLEAN NTAPI ArbGetNextAllocationRange(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
Definition: arbiter.c:114
VOID NTAPI ArbAddAllocation(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
Definition: arbiter.c:140
NTSTATUS NTAPI ArbRetestAllocation(_In_ PARBITER_INSTANCE Arbiter, _In_ PLIST_ENTRY ArbitrationList)
Definition: arbiter.c:39
NTSTATUS NTAPI ArbAddReserved(_In_ PARBITER_INSTANCE Arbiter)
Definition: arbiter.c:77
NTSTATUS NTAPI ArbStartArbiter(_In_ PARBITER_INSTANCE Arbiter)
Definition: arbiter.c:204
BOOLEAN NTAPI ArbFindSuitableRange(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
Definition: arbiter.c:127
NTSTATUS NTAPI ArbCommitAllocation(_In_ PARBITER_INSTANCE Arbiter)
Definition: arbiter.c:52
NTSTATUS NTAPI ArbPreprocessEntry(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
Definition: arbiter.c:89
NTSTATUS NTAPI ArbInitializeOrderingList(_Out_ PARBITER_ORDERING_LIST OrderList)
Definition: arbiter.c:244
VOID NTAPI ArbBacktrackAllocation(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
Definition: arbiter.c:152
NTSTATUS NTAPI ArbQueryConflict(_In_ PARBITER_INSTANCE Arbiter)
Definition: arbiter.c:191
NTSTATUS NTAPI ArbAllocateEntry(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
Definition: arbiter.c:101
NTSTATUS NTAPI ArbBuildAssignmentOrdering(_Inout_ PARBITER_INSTANCE ArbInstance, _In_ PCWSTR OrderName, _In_ PCWSTR ReservedOrderName, _In_ PARB_TRANSLATE_ORDERING TranslateOrderingFunction)
Definition: arbiter.c:267
NTSTATUS NTAPI ArbAddOrdering(_Out_ PARBITER_ORDERING_LIST OrderList, _In_ UINT64 MinimumAddress, _In_ UINT64 MaximumAddress)
Definition: arbiter.c:216
NTSTATUS NTAPI ArbBootAllocation(_In_ PARBITER_INSTANCE Arbiter, _In_ PLIST_ENTRY ArbitrationList)
Definition: arbiter.c:177
NTSTATUS NTAPI ArbInitializeArbiterInstance(_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: arbiter.c:282
VOID NTAPI ArbFreeOrderingList(_Out_ PARBITER_ORDERING_LIST OrderList)
Definition: arbiter.c:256
NTSTATUS NTAPI ArbTestAllocation(_In_ PARBITER_INSTANCE Arbiter, _In_ PLIST_ENTRY ArbitrationList)
Definition: arbiter.c:26
NTSTATUS NTAPI ArbRollbackAllocation(_In_ PARBITER_INSTANCE Arbiter)
Definition: arbiter.c:64
#define TAG_ARB_ALLOCATION
Definition: arbiter.h:12
NTSTATUS(NTAPI * PARB_TRANSLATE_ORDERING)(_Out_ PIO_RESOURCE_DESCRIPTOR OutIoDescriptor, _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor)
Definition: arbiter.h:222
#define ARBITER_SIGNATURE
Definition: arbiter.h:10
#define TAG_ARBITER
Definition: arbiter.h:11
#define TAG_ARB_RANGE
Definition: arbiter.h:13
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define UNIMPLEMENTED
Definition: debug.h:115
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#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:25
static CODE_SEG("PAGE")
Definition: isapnp.c:1482
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define _Inout_
Definition: ms_sal.h:378
#define _Out_
Definition: ms_sal.h:345
#define _In_
Definition: ms_sal.h:308
NTSYSAPI VOID NTAPI RtlInitializeRangeList(_Out_ PRTL_RANGE_LIST RangeList)
@ SynchronizationEvent
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
Definition: typedefs.h:120
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define NTAPI
Definition: typedefs.h:36
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158