ReactOS  0.4.15-dev-4869-g35a816a
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 
23 CODE_SEG("PAGE")
25 NTAPI
27  _In_ PARBITER_INSTANCE Arbiter,
28  _In_ PLIST_ENTRY ArbitrationList)
29 {
30  PAGED_CODE();
31 
34 }
35 
36 CODE_SEG("PAGE")
38 NTAPI
40  _In_ PARBITER_INSTANCE Arbiter,
41  _In_ PLIST_ENTRY ArbitrationList)
42 {
43  PAGED_CODE();
44 
47 }
48 
49 CODE_SEG("PAGE")
51 NTAPI
53  _In_ PARBITER_INSTANCE Arbiter)
54 {
55  PAGED_CODE();
56 
59 }
60 
61 CODE_SEG("PAGE")
63 NTAPI
65  _In_ PARBITER_INSTANCE Arbiter)
66 {
67  PAGED_CODE();
68 
71 }
72 
73 /* FIXME: the prototype is not correct yet. */
74 CODE_SEG("PAGE")
76 NTAPI
78  _In_ PARBITER_INSTANCE Arbiter)
79 {
80  PAGED_CODE();
81 
84 }
85 
86 CODE_SEG("PAGE")
88 NTAPI
90  _In_ PARBITER_INSTANCE Arbiter,
92 {
93  PAGED_CODE();
94 
95  return STATUS_SUCCESS;
96 }
97 
98 CODE_SEG("PAGE")
100 NTAPI
102  _In_ PARBITER_INSTANCE Arbiter,
104 {
105  PAGED_CODE();
106 
108  return STATUS_NOT_IMPLEMENTED;
109 }
110 
111 CODE_SEG("PAGE")
112 BOOLEAN
113 NTAPI
115  _In_ PARBITER_INSTANCE Arbiter,
117 {
118  PAGED_CODE();
119 
121  return FALSE;
122 }
123 
124 CODE_SEG("PAGE")
125 BOOLEAN
126 NTAPI
128  _In_ PARBITER_INSTANCE Arbiter,
130 {
131  PAGED_CODE();
132 
134  return FALSE;
135 }
136 
137 CODE_SEG("PAGE")
138 VOID
139 NTAPI
141  _In_ PARBITER_INSTANCE Arbiter,
143 {
144  PAGED_CODE();
145 
147 }
148 
149 CODE_SEG("PAGE")
150 VOID
151 NTAPI
153  _In_ PARBITER_INSTANCE Arbiter,
155 {
156  PAGED_CODE();
157 
159 }
160 
161 /* FIXME: the prototype is not correct yet. */
162 CODE_SEG("PAGE")
163 NTSTATUS
164 NTAPI
166  _In_ PARBITER_INSTANCE Arbiter)
167 {
168  PAGED_CODE();
169 
171  return STATUS_NOT_IMPLEMENTED;
172 }
173 
174 CODE_SEG("PAGE")
175 NTSTATUS
176 NTAPI
178  _In_ PARBITER_INSTANCE Arbiter,
179  _In_ PLIST_ENTRY ArbitrationList)
180 {
181  PAGED_CODE();
182 
184  return STATUS_NOT_IMPLEMENTED;
185 }
186 
187 /* FIXME: the prototype is not correct yet. */
188 CODE_SEG("PAGE")
189 NTSTATUS
190 NTAPI
192  _In_ PARBITER_INSTANCE Arbiter)
193 {
194  PAGED_CODE();
195 
197  return STATUS_NOT_IMPLEMENTED;
198 }
199 
200 /* FIXME: the prototype is not correct yet. */
201 CODE_SEG("PAGE")
202 NTSTATUS
203 NTAPI
205  _In_ PARBITER_INSTANCE Arbiter)
206 {
207  PAGED_CODE();
208 
210  return STATUS_NOT_IMPLEMENTED;
211 }
212 
213 CODE_SEG("PAGE")
214 NTSTATUS
215 NTAPI
217  _Out_ PARBITER_ORDERING_LIST OrderList,
218  _In_ UINT64 MinimumAddress,
219  _In_ UINT64 MaximumAddress)
220 {
221  PAGED_CODE();
222 
224  return STATUS_NOT_IMPLEMENTED;
225 }
226 
227 CODE_SEG("PAGE")
228 NTSTATUS
229 NTAPI
231  _Out_ PARBITER_ORDERING_LIST OrderingList,
232  _In_ UINT64 MinimumAddress,
233  _In_ UINT64 MaximumAddress)
234 {
235  PAGED_CODE();
236 
238  return STATUS_NOT_IMPLEMENTED;
239 }
240 
241 CODE_SEG("PAGE")
242 NTSTATUS
243 NTAPI
245  _Out_ PARBITER_ORDERING_LIST OrderList)
246 {
247  PAGED_CODE();
248 
250  return STATUS_NOT_IMPLEMENTED;
251 }
252 
253 CODE_SEG("PAGE")
254 VOID
255 NTAPI
257  _Out_ PARBITER_ORDERING_LIST OrderList)
258 {
259  PAGED_CODE();
260 
262 }
263 
264 CODE_SEG("PAGE")
265 NTSTATUS
266 NTAPI
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 
279 CODE_SEG("PAGE")
280 NTSTATUS
281 NTAPI
283  _Inout_ PARBITER_INSTANCE Arbiter,
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 }
NTSTATUS NTAPI ArbInitializeOrderingList(_Out_ PARBITER_ORDERING_LIST OrderList)
Definition: arbiter.c:244
const uint16_t * PCWSTR
Definition: typedefs.h:57
NTSTATUS NTAPI ArbPruneOrdering(_Out_ PARBITER_ORDERING_LIST OrderingList, _In_ UINT64 MinimumAddress, _In_ UINT64 MaximumAddress)
Definition: arbiter.c:230
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
BOOLEAN NTAPI ArbGetNextAllocationRange(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
Definition: arbiter.c:114
#define _Inout_
Definition: ms_sal.h:378
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
#define _Out_
Definition: ms_sal.h:345
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI ArbAllocateEntry(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
Definition: arbiter.c:101
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
NTSTATUS NTAPI ArbStartArbiter(_In_ PARBITER_INSTANCE Arbiter)
Definition: arbiter.c:204
return STATUS_NOT_IMPLEMENTED
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
#define _In_
Definition: ms_sal.h:308
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
NTSTATUS NTAPI ArbCommitAllocation(_In_ PARBITER_INSTANCE Arbiter)
Definition: arbiter.c:52
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID NTAPI ArbAddAllocation(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
Definition: arbiter.c:140
VOID NTAPI ArbBacktrackAllocation(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
Definition: arbiter.c:152
NTSTATUS NTAPI ArbBootAllocation(_In_ PARBITER_INSTANCE Arbiter, _In_ PLIST_ENTRY ArbitrationList)
Definition: arbiter.c:177
NTSTATUS NTAPI ArbQueryConflict(_In_ PARBITER_INSTANCE Arbiter)
Definition: arbiter.c:191
NTSTATUS NTAPI ArbRetestAllocation(_In_ PARBITER_INSTANCE Arbiter, _In_ PLIST_ENTRY ArbitrationList)
Definition: arbiter.c:39
#define TAG_ARB_ALLOCATION
Definition: arbiter.h:12
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
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
#define PAGE_SIZE
Definition: env_spec_w32.h:49
Definition: typedefs.h:119
NTSTATUS NTAPI ArbAddReserved(_In_ PARBITER_INSTANCE Arbiter)
Definition: arbiter.c:77
#define TAG_ARB_RANGE
Definition: arbiter.h:13
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define NULL
Definition: types.h:112
NTSTATUS NTAPI ArbPreprocessEntry(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
Definition: arbiter.c:89
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI ArbOverrideConflict(_In_ PARBITER_INSTANCE Arbiter)
Definition: arbiter.c:165
#define UNIMPLEMENTED
Definition: debug.h:115
#define STATUS_SUCCESS
Definition: shellext.h:65
unsigned long long UINT64
#define DPRINT
Definition: sndvol32.h:71
NTSYSAPI VOID NTAPI RtlInitializeRangeList(_Out_ PRTL_RANGE_LIST RangeList)
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
static CODE_SEG("PAGE")
Definition: isapnp.c:1482
VOID NTAPI ArbFreeOrderingList(_Out_ PARBITER_ORDERING_LIST OrderList)
Definition: arbiter.c:256
BOOLEAN NTAPI ArbFindSuitableRange(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
Definition: arbiter.c:127
#define PAGED_CODE()