1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Root arbiters of the PnP manager
5 * COPYRIGHT: Copyright 2020 Vadim Galyant <vgal@rambler.ru>
6 */
7
8 /* INCLUDES ******************************************************************/
9
10 #include <ntoskrnl.h>
11
12 #define NDEBUG
13 #include <debug.h>
14
15 /* GLOBALS *******************************************************************/
16
17 extern ARBITER_INSTANCE IopRootBusNumberArbiter;
18 extern ARBITER_INSTANCE IopRootIrqArbiter;
19 extern ARBITER_INSTANCE IopRootDmaArbiter;
20 extern ARBITER_INSTANCE IopRootMemArbiter;
21 extern ARBITER_INSTANCE IopRootPortArbiter;
22
23 /* DATA **********************************************************************/
24
25 /* FUNCTIONS *****************************************************************/
26
27 /* BusNumber arbiter */
28
29 CODE_SEG("PAGE")
30 NTSTATUS
31 NTAPI
IopBusNumberUnpackRequirement(_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,_Out_ PUINT64 OutMinimumAddress,_Out_ PUINT64 OutMaximumAddress,_Out_ PUINT32 OutLength,_Out_ PUINT32 OutAlignment)32 IopBusNumberUnpackRequirement(
33 _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,
34 _Out_ PUINT64 OutMinimumAddress,
35 _Out_ PUINT64 OutMaximumAddress,
36 _Out_ PUINT32 OutLength,
37 _Out_ PUINT32 OutAlignment)
38 {
39 PAGED_CODE();
40
41 UNIMPLEMENTED;
42 return STATUS_NOT_IMPLEMENTED;
43 }
44
45 CODE_SEG("PAGE")
46 NTSTATUS
47 NTAPI
IopBusNumberPackResource(_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,_In_ UINT64 Start,_Out_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor)48 IopBusNumberPackResource(
49 _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,
50 _In_ UINT64 Start,
51 _Out_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor)
52 {
53 PAGED_CODE();
54
55 UNIMPLEMENTED;
56 return STATUS_NOT_IMPLEMENTED;
57 }
58
59 CODE_SEG("PAGE")
60 NTSTATUS
61 NTAPI
IopBusNumberUnpackResource(_In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor,_Out_ PUINT64 Start,_Out_ PUINT32 Length)62 IopBusNumberUnpackResource(
63 _In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor,
64 _Out_ PUINT64 Start,
65 _Out_ PUINT32 Length)
66 {
67 PAGED_CODE();
68
69 UNIMPLEMENTED;
70 return STATUS_NOT_IMPLEMENTED;
71 }
72
73 CODE_SEG("PAGE")
74 INT32
75 NTAPI
IopBusNumberScoreRequirement(_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor)76 IopBusNumberScoreRequirement(
77 _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor)
78 {
79 PAGED_CODE();
80
81 UNIMPLEMENTED;
82 return 0;
83 }
84
85 #define ARB_MAX_BUS_NUMBER 0xFF
86
87 CODE_SEG("PAGE")
88 NTSTATUS
89 NTAPI
IopBusNumberInitialize(VOID)90 IopBusNumberInitialize(VOID)
91 {
92 NTSTATUS Status;
93
94 PAGED_CODE();
95
96 DPRINT("IopRootBusNumberArbiter %p\n", &IopRootBusNumberArbiter);
97
98 IopRootBusNumberArbiter.UnpackRequirement = IopBusNumberUnpackRequirement;
99 IopRootBusNumberArbiter.PackResource = IopBusNumberPackResource;
100 IopRootBusNumberArbiter.UnpackResource = IopBusNumberUnpackResource;
101 IopRootBusNumberArbiter.ScoreRequirement = IopBusNumberScoreRequirement;
102
103 Status = ArbInitializeArbiterInstance(&IopRootBusNumberArbiter,
104 NULL,
105 CmResourceTypeBusNumber,
106 L"RootBusNumber",
107 L"Root",
108 NULL);
109 if (!NT_SUCCESS(Status))
110 {
111 DPRINT1("IopBusNumberInitialize: Status %p\n", Status);
112 ASSERT(FALSE);
113 return Status;
114 }
115
116 Status = RtlAddRange(IopRootBusNumberArbiter.Allocation,
117 (UINT64)(ARB_MAX_BUS_NUMBER + 1),
118 (UINT64)(-1),
119 0,
120 0,
121 NULL,
122 NULL);
123
124 return Status;
125 }
126
127 /* Irq arbiter */
128
129 CODE_SEG("PAGE")
130 NTSTATUS
131 NTAPI
IopIrqUnpackRequirement(_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,_Out_ PUINT64 OutMinimumVector,_Out_ PUINT64 OutMaximumVector,_Out_ PUINT32 OutParam1,_Out_ PUINT32 OutParam2)132 IopIrqUnpackRequirement(
133 _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,
134 _Out_ PUINT64 OutMinimumVector,
135 _Out_ PUINT64 OutMaximumVector,
136 _Out_ PUINT32 OutParam1,
137 _Out_ PUINT32 OutParam2)
138 {
139 PAGED_CODE();
140
141 UNIMPLEMENTED;
142 return STATUS_NOT_IMPLEMENTED;
143 }
144
145 CODE_SEG("PAGE")
146 NTSTATUS
147 NTAPI
IopIrqPackResource(_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,_In_ UINT64 Start,_Out_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor)148 IopIrqPackResource(
149 _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,
150 _In_ UINT64 Start,
151 _Out_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor)
152 {
153 PAGED_CODE();
154
155 UNIMPLEMENTED;
156 return STATUS_NOT_IMPLEMENTED;
157 }
158
159 CODE_SEG("PAGE")
160 NTSTATUS
161 NTAPI
IopIrqUnpackResource(_In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor,_Out_ PUINT64 Start,_Out_ PUINT32 OutLength)162 IopIrqUnpackResource(
163 _In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor,
164 _Out_ PUINT64 Start,
165 _Out_ PUINT32 OutLength)
166 {
167 PAGED_CODE();
168
169 UNIMPLEMENTED;
170 return STATUS_NOT_IMPLEMENTED;
171 }
172
173 CODE_SEG("PAGE")
174 INT32
175 NTAPI
IopIrqScoreRequirement(_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor)176 IopIrqScoreRequirement(
177 _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor)
178 {
179 PAGED_CODE();
180
181 UNIMPLEMENTED;
182 return 0;
183 }
184
185 CODE_SEG("PAGE")
186 NTSTATUS
187 NTAPI
IopIrqTranslateOrdering(_Out_ PIO_RESOURCE_DESCRIPTOR OutIoDescriptor,_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor)188 IopIrqTranslateOrdering(
189 _Out_ PIO_RESOURCE_DESCRIPTOR OutIoDescriptor,
190 _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor)
191 {
192 PAGED_CODE();
193
194 UNIMPLEMENTED;
195 return STATUS_NOT_IMPLEMENTED;
196 }
197
198 CODE_SEG("PAGE")
199 NTSTATUS
200 NTAPI
IopIrqInitialize(VOID)201 IopIrqInitialize(VOID)
202 {
203 NTSTATUS Status;
204
205 PAGED_CODE();
206
207 DPRINT("IopRootIrqArbiter %p\n", &IopRootIrqArbiter);
208
209 IopRootIrqArbiter.UnpackRequirement = IopIrqUnpackRequirement;
210 IopRootIrqArbiter.PackResource = IopIrqPackResource;
211 IopRootIrqArbiter.UnpackResource = IopIrqUnpackResource;
212 IopRootIrqArbiter.ScoreRequirement = IopIrqScoreRequirement;
213
214 Status = ArbInitializeArbiterInstance(&IopRootIrqArbiter,
215 NULL,
216 CmResourceTypeInterrupt,
217 L"RootIRQ",
218 L"Root",
219 IopIrqTranslateOrdering);
220 return Status;
221 }
222
223 /* Dma arbiter */
224
225 CODE_SEG("PAGE")
226 NTSTATUS
227 NTAPI
IopDmaUnpackRequirement(_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,_Out_ PUINT64 OutMinimumChannel,_Out_ PUINT64 OutMaximumChannel,_Out_ PUINT32 OutParam1,_Out_ PUINT32 OutParam2)228 IopDmaUnpackRequirement(
229 _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,
230 _Out_ PUINT64 OutMinimumChannel,
231 _Out_ PUINT64 OutMaximumChannel,
232 _Out_ PUINT32 OutParam1,
233 _Out_ PUINT32 OutParam2)
234 {
235 PAGED_CODE();
236
237 UNIMPLEMENTED;
238 return STATUS_NOT_IMPLEMENTED;
239 }
240
241 CODE_SEG("PAGE")
242 NTSTATUS
243 NTAPI
IopDmaPackResource(_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,_In_ UINT64 Start,_Out_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor)244 IopDmaPackResource(
245 _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,
246 _In_ UINT64 Start,
247 _Out_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor)
248 {
249 PAGED_CODE();
250
251 UNIMPLEMENTED;
252 return STATUS_NOT_IMPLEMENTED;
253 }
254
255 CODE_SEG("PAGE")
256 NTSTATUS
257 NTAPI
IopDmaUnpackResource(_In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor,_Out_ PUINT64 Start,_Out_ PUINT32 OutLength)258 IopDmaUnpackResource(
259 _In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor,
260 _Out_ PUINT64 Start,
261 _Out_ PUINT32 OutLength)
262 {
263 PAGED_CODE();
264
265 UNIMPLEMENTED;
266 return STATUS_NOT_IMPLEMENTED;
267 }
268
269 CODE_SEG("PAGE")
270 INT32
271 NTAPI
IopDmaScoreRequirement(_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor)272 IopDmaScoreRequirement(
273 _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor)
274 {
275 PAGED_CODE();
276
277 UNIMPLEMENTED;
278 return 0;
279 }
280
281 CODE_SEG("PAGE")
282 NTSTATUS
283 NTAPI
IopDmaOverrideConflict(_In_ PARBITER_INSTANCE Arbiter)284 IopDmaOverrideConflict(
285 _In_ PARBITER_INSTANCE Arbiter)
286 {
287 PAGED_CODE();
288
289 UNIMPLEMENTED;
290 return STATUS_NOT_IMPLEMENTED;
291 }
292
293 CODE_SEG("PAGE")
294 NTSTATUS
295 NTAPI
IopDmaInitialize(VOID)296 IopDmaInitialize(VOID)
297 {
298 NTSTATUS Status;
299
300 PAGED_CODE();
301
302 DPRINT("IopRootDmaArbiter %p\n", &IopRootDmaArbiter);
303
304 IopRootDmaArbiter.UnpackRequirement = IopDmaUnpackRequirement;
305 IopRootDmaArbiter.PackResource = IopDmaPackResource;
306 IopRootDmaArbiter.UnpackResource = IopDmaUnpackResource;
307 IopRootDmaArbiter.ScoreRequirement = IopDmaScoreRequirement;
308
309 IopRootDmaArbiter.OverrideConflict = IopDmaOverrideConflict;
310
311 Status = ArbInitializeArbiterInstance(&IopRootDmaArbiter,
312 NULL,
313 CmResourceTypeDma,
314 L"RootDMA",
315 L"Root",
316 NULL);
317 return Status;
318 }
319
320 /* Common for Memory and Port arbiters */
321
322 CODE_SEG("PAGE")
323 NTSTATUS
324 NTAPI
IopGenericUnpackRequirement(_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,_Out_ PUINT64 OutMinimumAddress,_Out_ PUINT64 OutMaximumAddress,_Out_ PUINT32 OutLength,_Out_ PUINT32 OutAlignment)325 IopGenericUnpackRequirement(
326 _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,
327 _Out_ PUINT64 OutMinimumAddress,
328 _Out_ PUINT64 OutMaximumAddress,
329 _Out_ PUINT32 OutLength,
330 _Out_ PUINT32 OutAlignment)
331 {
332 PAGED_CODE();
333
334 UNIMPLEMENTED;
335 return STATUS_NOT_IMPLEMENTED;
336 }
337
338 CODE_SEG("PAGE")
339 NTSTATUS
340 NTAPI
IopGenericPackResource(_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,_In_ UINT64 Start,_Out_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor)341 IopGenericPackResource(
342 _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,
343 _In_ UINT64 Start,
344 _Out_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor)
345 {
346 PAGED_CODE();
347
348 UNIMPLEMENTED;
349 return STATUS_NOT_IMPLEMENTED;
350 }
351
352 CODE_SEG("PAGE")
353 NTSTATUS
354 NTAPI
IopGenericUnpackResource(_In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor,_Out_ PUINT64 Start,_Out_ PUINT32 OutLength)355 IopGenericUnpackResource(
356 _In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor,
357 _Out_ PUINT64 Start,
358 _Out_ PUINT32 OutLength)
359 {
360 PAGED_CODE();
361
362 UNIMPLEMENTED;
363 return STATUS_NOT_IMPLEMENTED;
364 }
365
366 CODE_SEG("PAGE")
367 INT32
368 NTAPI
IopGenericScoreRequirement(_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor)369 IopGenericScoreRequirement(
370 _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor)
371 {
372 PAGED_CODE();
373
374 UNIMPLEMENTED;
375 return 0;
376 }
377
378 CODE_SEG("PAGE")
379 NTSTATUS
380 NTAPI
IopGenericTranslateOrdering(_Out_ PIO_RESOURCE_DESCRIPTOR OutIoDescriptor,_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor)381 IopGenericTranslateOrdering(
382 _Out_ PIO_RESOURCE_DESCRIPTOR OutIoDescriptor,
383 _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor)
384 {
385 PAGED_CODE();
386
387 UNIMPLEMENTED;
388 return STATUS_NOT_IMPLEMENTED;
389 }
390
391 /* Memory arbiter */
392
393 CODE_SEG("PAGE")
394 BOOLEAN
395 NTAPI
IopMemFindSuitableRange(_In_ PARBITER_INSTANCE Arbiter,_In_ PARBITER_ALLOCATION_STATE State)396 IopMemFindSuitableRange(
397 _In_ PARBITER_INSTANCE Arbiter,
398 _In_ PARBITER_ALLOCATION_STATE State)
399 {
400 PAGED_CODE();
401
402 UNIMPLEMENTED;
403 return FALSE;
404 }
405
406 CODE_SEG("PAGE")
407 NTSTATUS
408 NTAPI
IopMemInitialize(VOID)409 IopMemInitialize(VOID)
410 {
411 NTSTATUS Status;
412
413 PAGED_CODE();
414
415 DPRINT("IopRootMemArbiter %p\n", &IopRootMemArbiter);
416
417 IopRootMemArbiter.UnpackRequirement = IopGenericUnpackRequirement;
418 IopRootMemArbiter.PackResource = IopGenericPackResource;
419 IopRootMemArbiter.UnpackResource = IopGenericUnpackResource;
420 IopRootMemArbiter.ScoreRequirement = IopGenericScoreRequirement;
421
422 IopRootMemArbiter.FindSuitableRange = IopMemFindSuitableRange;
423
424 Status = ArbInitializeArbiterInstance(&IopRootMemArbiter,
425 NULL,
426 CmResourceTypeMemory,
427 L"RootMemory",
428 L"Root",
429 IopGenericTranslateOrdering);
430 if (!NT_SUCCESS(Status))
431 {
432 DPRINT1("IopMemInitialize: Status %p\n", Status);
433 ASSERT(FALSE);
434 return Status;
435 }
436
437 Status = RtlAddRange(IopRootMemArbiter.Allocation,
438 0,
439 (UINT64)(PAGE_SIZE - 1),
440 0,
441 0,
442 NULL,
443 NULL);
444
445 return Status;
446 }
447
448 /* Port arbiter */
449
450 CODE_SEG("PAGE")
451 BOOLEAN
452 NTAPI
IopPortFindSuitableRange(_In_ PARBITER_INSTANCE Arbiter,_In_ PARBITER_ALLOCATION_STATE State)453 IopPortFindSuitableRange(
454 _In_ PARBITER_INSTANCE Arbiter,
455 _In_ PARBITER_ALLOCATION_STATE State)
456 {
457 PAGED_CODE();
458
459 UNIMPLEMENTED;
460 return FALSE;
461 }
462
463 CODE_SEG("PAGE")
464 VOID
465 NTAPI
IopPortAddAllocation(_In_ PARBITER_INSTANCE Arbiter,_In_ PARBITER_ALLOCATION_STATE ArbState)466 IopPortAddAllocation(
467 _In_ PARBITER_INSTANCE Arbiter,
468 _In_ PARBITER_ALLOCATION_STATE ArbState)
469 {
470 PAGED_CODE();
471
472 UNIMPLEMENTED;
473 }
474
475 CODE_SEG("PAGE")
476 VOID
477 NTAPI
IopPortBacktrackAllocation(_In_ PARBITER_INSTANCE Arbiter,_Inout_ PARBITER_ALLOCATION_STATE ArbState)478 IopPortBacktrackAllocation(
479 _In_ PARBITER_INSTANCE Arbiter,
480 _Inout_ PARBITER_ALLOCATION_STATE ArbState)
481 {
482 PAGED_CODE();
483
484 UNIMPLEMENTED;
485 }
486
487 CODE_SEG("PAGE")
488 NTSTATUS
489 NTAPI
IopPortInitialize(VOID)490 IopPortInitialize(VOID)
491 {
492 NTSTATUS Status;
493
494 PAGED_CODE();
495
496 DPRINT("IopRootPortArbiter %p\n", &IopRootPortArbiter);
497
498 IopRootPortArbiter.UnpackRequirement = IopGenericUnpackRequirement;
499 IopRootPortArbiter.PackResource = IopGenericPackResource;
500 IopRootPortArbiter.UnpackResource = IopGenericUnpackResource;
501 IopRootPortArbiter.ScoreRequirement = IopGenericScoreRequirement;
502
503 IopRootPortArbiter.FindSuitableRange = IopPortFindSuitableRange;
504 IopRootPortArbiter.AddAllocation = IopPortAddAllocation;
505 IopRootPortArbiter.BacktrackAllocation = IopPortBacktrackAllocation;
506
507 Status = ArbInitializeArbiterInstance(&IopRootPortArbiter,
508 NULL,
509 CmResourceTypePort,
510 L"RootPort",
511 L"Root",
512 IopGenericTranslateOrdering);
513 return Status;
514 }
515