https://git.reactos.org/?p=reactos.git;a=commitdiff;h=fec440d8b88b334815dc9…
commit fec440d8b88b334815dc9e84f6abc9c15947f66f
Author: Vadim Galyant <vgal(a)rambler.ru>
AuthorDate: Mon Jan 10 06:35:45 2022 +0300
Commit: GitHub <noreply(a)github.com>
CommitDate: Mon Jan 10 06:35:45 2022 +0300
[SDK:DDK][NTOS:PNP] Implement PnP arbiters initialization
---
ntoskrnl/io/pnpmgr/arbiters.c | 514 ++++++++++++++++++++++++++++++++++++++
ntoskrnl/io/pnpmgr/arbs.c | 123 ---------
ntoskrnl/ntos.cmake | 2 +-
sdk/lib/drivers/arbiter/arbiter.c | 386 +++++++++++++++++++++++++++-
sdk/lib/drivers/arbiter/arbiter.h | 76 +++---
5 files changed, 928 insertions(+), 173 deletions(-)
diff --git a/ntoskrnl/io/pnpmgr/arbiters.c b/ntoskrnl/io/pnpmgr/arbiters.c
new file mode 100644
index 00000000000..9a299c08ac6
--- /dev/null
+++ b/ntoskrnl/io/pnpmgr/arbiters.c
@@ -0,0 +1,514 @@
+/*
+ * PROJECT: ReactOS Kernel
+ * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later)
+ * PURPOSE: Root arbiters of the PnP manager
+ * COPYRIGHT: Copyright 2020 Vadim Galyant <vgal(a)rambler.ru>
+ */
+
+/* INCLUDES ******************************************************************/
+
+#include <ntoskrnl.h>
+
+#define NDEBUG
+#include <debug.h>
+
+/* GLOBALS *******************************************************************/
+
+extern ARBITER_INSTANCE IopRootBusNumberArbiter;
+extern ARBITER_INSTANCE IopRootIrqArbiter;
+extern ARBITER_INSTANCE IopRootDmaArbiter;
+extern ARBITER_INSTANCE IopRootMemArbiter;
+extern ARBITER_INSTANCE IopRootPortArbiter;
+
+/* DATA **********************************************************************/
+
+/* FUNCTIONS *****************************************************************/
+
+/* BusNumber arbiter */
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+IopBusNumberUnpackRequirement(
+ _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,
+ _Out_ PUINT64 OutMinimumAddress,
+ _Out_ PUINT64 OutMaximumAddress,
+ _Out_ PUINT32 OutLength,
+ _Out_ PUINT32 OutAlignment)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+IopBusNumberPackResource(
+ _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,
+ _In_ UINT64 Start,
+ _Out_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+IopBusNumberUnpackResource(
+ _In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor,
+ _Out_ PUINT64 Start,
+ _Out_ PUINT32 Length)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+INT32
+NTAPI
+IopBusNumberScoreRequirement(
+ _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return 0;
+}
+
+#define ARB_MAX_BUS_NUMBER 0xFF
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+IopBusNumberInitialize(VOID)
+{
+ NTSTATUS Status;
+
+ PAGED_CODE();
+
+ DPRINT("IopRootBusNumberArbiter %p\n", &IopRootBusNumberArbiter);
+
+ IopRootBusNumberArbiter.UnpackRequirement = IopBusNumberUnpackRequirement;
+ IopRootBusNumberArbiter.PackResource = IopBusNumberPackResource;
+ IopRootBusNumberArbiter.UnpackResource = IopBusNumberUnpackResource;
+ IopRootBusNumberArbiter.ScoreRequirement = IopBusNumberScoreRequirement;
+
+ Status = ArbInitializeArbiterInstance(&IopRootBusNumberArbiter,
+ NULL,
+ CmResourceTypeBusNumber,
+ L"RootBusNumber",
+ L"Root",
+ NULL);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("IopBusNumberInitialize: Status %p\n", Status);
+ ASSERT(FALSE);
+ return Status;
+ }
+
+ Status = RtlAddRange(IopRootBusNumberArbiter.Allocation,
+ (UINT64)(ARB_MAX_BUS_NUMBER + 1),
+ (UINT64)(-1),
+ 0,
+ 0,
+ NULL,
+ NULL);
+
+ return Status;
+}
+
+/* Irq arbiter */
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+IopIrqUnpackRequirement(
+ _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,
+ _Out_ PUINT64 OutMinimumVector,
+ _Out_ PUINT64 OutMaximumVector,
+ _Out_ PUINT32 OutParam1,
+ _Out_ PUINT32 OutParam2)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+IopIrqPackResource(
+ _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,
+ _In_ UINT64 Start,
+ _Out_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+IopIrqUnpackResource(
+ _In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor,
+ _Out_ PUINT64 Start,
+ _Out_ PUINT32 OutLength)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+INT32
+NTAPI
+IopIrqScoreRequirement(
+ _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return 0;
+}
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+IopIrqTranslateOrdering(
+ _Out_ PIO_RESOURCE_DESCRIPTOR OutIoDescriptor,
+ _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+IopIrqInitialize(VOID)
+{
+ NTSTATUS Status;
+
+ PAGED_CODE();
+
+ DPRINT("IopRootIrqArbiter %p\n", &IopRootIrqArbiter);
+
+ IopRootIrqArbiter.UnpackRequirement = IopIrqUnpackRequirement;
+ IopRootIrqArbiter.PackResource = IopIrqPackResource;
+ IopRootIrqArbiter.UnpackResource = IopIrqUnpackResource;
+ IopRootIrqArbiter.ScoreRequirement = IopIrqScoreRequirement;
+
+ Status = ArbInitializeArbiterInstance(&IopRootIrqArbiter,
+ NULL,
+ CmResourceTypeInterrupt,
+ L"RootIRQ",
+ L"Root",
+ IopIrqTranslateOrdering);
+ return Status;
+}
+
+/* Dma arbiter */
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+IopDmaUnpackRequirement(
+ _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,
+ _Out_ PUINT64 OutMinimumChannel,
+ _Out_ PUINT64 OutMaximumChannel,
+ _Out_ PUINT32 OutParam1,
+ _Out_ PUINT32 OutParam2)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+IopDmaPackResource(
+ _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,
+ _In_ UINT64 Start,
+ _Out_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+IopDmaUnpackResource(
+ _In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor,
+ _Out_ PUINT64 Start,
+ _Out_ PUINT32 OutLength)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+INT32
+NTAPI
+IopDmaScoreRequirement(
+ _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return 0;
+}
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+IopDmaOverrideConflict(
+ _In_ PARBITER_INSTANCE Arbiter)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+IopDmaInitialize(VOID)
+{
+ NTSTATUS Status;
+
+ PAGED_CODE();
+
+ DPRINT("IopRootDmaArbiter %p\n", &IopRootDmaArbiter);
+
+ IopRootDmaArbiter.UnpackRequirement = IopDmaUnpackRequirement;
+ IopRootDmaArbiter.PackResource = IopDmaPackResource;
+ IopRootDmaArbiter.UnpackResource = IopDmaUnpackResource;
+ IopRootDmaArbiter.ScoreRequirement = IopDmaScoreRequirement;
+
+ IopRootDmaArbiter.OverrideConflict = IopDmaOverrideConflict;
+
+ Status = ArbInitializeArbiterInstance(&IopRootDmaArbiter,
+ NULL,
+ CmResourceTypeDma,
+ L"RootDMA",
+ L"Root",
+ NULL);
+ return Status;
+}
+
+/* Common for Memory and Port arbiters */
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+IopGenericUnpackRequirement(
+ _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,
+ _Out_ PUINT64 OutMinimumAddress,
+ _Out_ PUINT64 OutMaximumAddress,
+ _Out_ PUINT32 OutLength,
+ _Out_ PUINT32 OutAlignment)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+IopGenericPackResource(
+ _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,
+ _In_ UINT64 Start,
+ _Out_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+IopGenericUnpackResource(
+ _In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor,
+ _Out_ PUINT64 Start,
+ _Out_ PUINT32 OutLength)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+INT32
+NTAPI
+IopGenericScoreRequirement(
+ _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return 0;
+}
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+IopGenericTranslateOrdering(
+ _Out_ PIO_RESOURCE_DESCRIPTOR OutIoDescriptor,
+ _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+/* Memory arbiter */
+
+CODE_SEG("PAGE")
+BOOLEAN
+NTAPI
+IopMemFindSuitableRange(
+ _In_ PARBITER_INSTANCE Arbiter,
+ _In_ PARBITER_ALLOCATION_STATE State)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return FALSE;
+}
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+IopMemInitialize(VOID)
+{
+ NTSTATUS Status;
+
+ PAGED_CODE();
+
+ DPRINT("IopRootMemArbiter %p\n", &IopRootMemArbiter);
+
+ IopRootMemArbiter.UnpackRequirement = IopGenericUnpackRequirement;
+ IopRootMemArbiter.PackResource = IopGenericPackResource;
+ IopRootMemArbiter.UnpackResource = IopGenericUnpackResource;
+ IopRootMemArbiter.ScoreRequirement = IopGenericScoreRequirement;
+
+ IopRootMemArbiter.FindSuitableRange = IopMemFindSuitableRange;
+
+ Status = ArbInitializeArbiterInstance(&IopRootMemArbiter,
+ NULL,
+ CmResourceTypeMemory,
+ L"RootMemory",
+ L"Root",
+ IopGenericTranslateOrdering);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("IopMemInitialize: Status %p\n", Status);
+ ASSERT(FALSE);
+ return Status;
+ }
+
+ Status = RtlAddRange(IopRootMemArbiter.Allocation,
+ 0,
+ (UINT64)(PAGE_SIZE - 1),
+ 0,
+ 0,
+ NULL,
+ NULL);
+
+ return Status;
+}
+
+/* Port arbiter */
+
+CODE_SEG("PAGE")
+BOOLEAN
+NTAPI
+IopPortFindSuitableRange(
+ _In_ PARBITER_INSTANCE Arbiter,
+ _In_ PARBITER_ALLOCATION_STATE State)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return FALSE;
+}
+
+CODE_SEG("PAGE")
+VOID
+NTAPI
+IopPortAddAllocation(
+ _In_ PARBITER_INSTANCE Arbiter,
+ _In_ PARBITER_ALLOCATION_STATE ArbState)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+VOID
+NTAPI
+IopPortBacktrackAllocation(
+ _In_ PARBITER_INSTANCE Arbiter,
+ _Inout_ PARBITER_ALLOCATION_STATE ArbState)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+IopPortInitialize(VOID)
+{
+ NTSTATUS Status;
+
+ PAGED_CODE();
+
+ DPRINT("IopRootPortArbiter %p\n", &IopRootPortArbiter);
+
+ IopRootPortArbiter.UnpackRequirement = IopGenericUnpackRequirement;
+ IopRootPortArbiter.PackResource = IopGenericPackResource;
+ IopRootPortArbiter.UnpackResource = IopGenericUnpackResource;
+ IopRootPortArbiter.ScoreRequirement = IopGenericScoreRequirement;
+
+ IopRootPortArbiter.FindSuitableRange = IopPortFindSuitableRange;
+ IopRootPortArbiter.AddAllocation = IopPortAddAllocation;
+ IopRootPortArbiter.BacktrackAllocation = IopPortBacktrackAllocation;
+
+ Status = ArbInitializeArbiterInstance(&IopRootPortArbiter,
+ NULL,
+ CmResourceTypePort,
+ L"RootPort",
+ L"Root",
+ IopGenericTranslateOrdering);
+ return Status;
+}
diff --git a/ntoskrnl/io/pnpmgr/arbs.c b/ntoskrnl/io/pnpmgr/arbs.c
deleted file mode 100644
index 09bab2ad735..00000000000
--- a/ntoskrnl/io/pnpmgr/arbs.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * PROJECT: ReactOS Kernel
- * COPYRIGHT: GPL-2.0+ (
https://spdx.org/licenses/GPL-2.0+)
- * FILE: ntoskrnl/io/pnpmgr/arbs.c
- * PURPOSE: Root arbiters of the PnP manager
- * PROGRAMMERS: Copyright 2020 Vadim Galyant <vgal(a)rambler.ru>
- */
-
-/* INCLUDES ******************************************************************/
-
-#include <ntoskrnl.h>
-
-#define NDEBUG
-#include <debug.h>
-
-/* GLOBALS *******************************************************************/
-
-extern ARBITER_INSTANCE IopRootBusNumberArbiter;
-extern ARBITER_INSTANCE IopRootIrqArbiter;
-extern ARBITER_INSTANCE IopRootDmaArbiter;
-extern ARBITER_INSTANCE IopRootMemArbiter;
-extern ARBITER_INSTANCE IopRootPortArbiter;
-
-/* DATA **********************************************************************/
-
-/* FUNCTIONS *****************************************************************/
-
-/* BusNumber arbiter */
-
-NTSTATUS
-NTAPI
-IopBusNumberInitialize(VOID)
-{
- NTSTATUS Status;
-
- DPRINT("IopRootBusNumberArbiter %p\n", &IopRootBusNumberArbiter);
-
- Status = ArbInitializeArbiterInstance(&IopRootBusNumberArbiter,
- NULL,
- CmResourceTypeBusNumber,
- L"RootBusNumber",
- L"Root",
- NULL);
- return Status;
-}
-
-/* Irq arbiter */
-
-NTSTATUS
-NTAPI
-IopIrqInitialize(VOID)
-{
- NTSTATUS Status;
-
- DPRINT("IopRootIrqArbiter %p\n", &IopRootIrqArbiter);
-
- Status = ArbInitializeArbiterInstance(&IopRootIrqArbiter,
- NULL,
- CmResourceTypeInterrupt,
- L"RootIRQ",
- L"Root",
- NULL);
- return Status;
-}
-
-/* Dma arbiter */
-
-NTSTATUS
-NTAPI
-IopDmaInitialize(VOID)
-{
- NTSTATUS Status;
-
- DPRINT("IopRootDmaArbiter %p\n", &IopRootDmaArbiter);
-
- Status = ArbInitializeArbiterInstance(&IopRootDmaArbiter,
- NULL,
- CmResourceTypeDma,
- L"RootDMA",
- L"Root",
- NULL);
- return Status;
-}
-
-/* Memory arbiter */
-
-NTSTATUS
-NTAPI
-IopMemInitialize(VOID)
-{
- NTSTATUS Status;
-
- DPRINT("IopRootMemArbiter %p\n", &IopRootMemArbiter);
-
- Status = ArbInitializeArbiterInstance(&IopRootMemArbiter,
- NULL,
- CmResourceTypeMemory,
- L"RootMemory",
- L"Root",
- NULL);
- return Status;
-}
-
-/* Port arbiter */
-
-NTSTATUS
-NTAPI
-IopPortInitialize(VOID)
-{
- NTSTATUS Status;
-
- DPRINT("IopRootPortArbiter %p\n", &IopRootPortArbiter);
-
- Status = ArbInitializeArbiterInstance(&IopRootPortArbiter,
- NULL,
- CmResourceTypePort,
- L"RootPort",
- L"Root",
- NULL);
- return Status;
-}
-
-/* EOF */
diff --git a/ntoskrnl/ntos.cmake b/ntoskrnl/ntos.cmake
index d4bfd5f08a3..89802e07c41 100644
--- a/ntoskrnl/ntos.cmake
+++ b/ntoskrnl/ntos.cmake
@@ -151,7 +151,7 @@ list(APPEND SOURCE
${REACTOS_SOURCE_DIR}/ntoskrnl/io/iomgr/symlink.c
${REACTOS_SOURCE_DIR}/ntoskrnl/io/iomgr/util.c
${REACTOS_SOURCE_DIR}/ntoskrnl/io/iomgr/volume.c
- ${REACTOS_SOURCE_DIR}/ntoskrnl/io/pnpmgr/arbs.c
+ ${REACTOS_SOURCE_DIR}/ntoskrnl/io/pnpmgr/arbiters.c
${REACTOS_SOURCE_DIR}/ntoskrnl/io/pnpmgr/devaction.c
${REACTOS_SOURCE_DIR}/ntoskrnl/io/pnpmgr/devnode.c
${REACTOS_SOURCE_DIR}/ntoskrnl/io/pnpmgr/plugplay.c
diff --git a/sdk/lib/drivers/arbiter/arbiter.c b/sdk/lib/drivers/arbiter/arbiter.c
index 9d7d5561de4..e4e1c719ac7 100644
--- a/sdk/lib/drivers/arbiter/arbiter.c
+++ b/sdk/lib/drivers/arbiter/arbiter.c
@@ -1,16 +1,14 @@
/*
- * PROJECT: ReactOS Kernel
- * COPYRIGHT: GPL-2.0+ (
https://spdx.org/licenses/GPL-2.0+)
- * FILE: lib/drivers/arbiter/arbiter.c
- * PURPOSE: Hardware Resources Arbiter Library
- * PROGRAMMERS: Copyright 2020 Vadim Galyant <vgal(a)rambler.ru>
+ * PROJECT: ReactOS Kernel&Driver SDK
+ * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later)
+ * PURPOSE: Hardware Resources Arbiter Library
+ * COPYRIGHT: Copyright 2020 Vadim Galyant <vgal(a)rambler.ru>
*/
/* INCLUDES *******************************************************************/
#include <ntifs.h>
-#include <ndk/rtltypes.h>
-
+#include <ndk/rtlfuncs.h>
#include "arbiter.h"
#define NDEBUG
@@ -22,6 +20,263 @@
/* FUNCTIONS ******************************************************************/
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+ArbTestAllocation(
+ _In_ PARBITER_INSTANCE Arbiter,
+ _In_ PLIST_ENTRY ArbitrationList)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+ArbRetestAllocation(
+ _In_ PARBITER_INSTANCE Arbiter,
+ _In_ PLIST_ENTRY ArbitrationList)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+ArbCommitAllocation(
+ _In_ PARBITER_INSTANCE Arbiter)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+ArbRollbackAllocation(
+ _In_ PARBITER_INSTANCE Arbiter)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+/* FIXME: the prototype is not correct yet. */
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+ArbAddReserved(
+ _In_ PARBITER_INSTANCE Arbiter)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+ArbPreprocessEntry(
+ _In_ PARBITER_INSTANCE Arbiter,
+ _Inout_ PARBITER_ALLOCATION_STATE ArbState)
+{
+ PAGED_CODE();
+
+ return STATUS_SUCCESS;
+}
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+ArbAllocateEntry(
+ _In_ PARBITER_INSTANCE Arbiter,
+ _Inout_ PARBITER_ALLOCATION_STATE ArbState)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+BOOLEAN
+NTAPI
+ArbGetNextAllocationRange(
+ _In_ PARBITER_INSTANCE Arbiter,
+ _Inout_ PARBITER_ALLOCATION_STATE ArbState)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return FALSE;
+}
+
+CODE_SEG("PAGE")
+BOOLEAN
+NTAPI
+ArbFindSuitableRange(
+ _In_ PARBITER_INSTANCE Arbiter,
+ _Inout_ PARBITER_ALLOCATION_STATE ArbState)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return FALSE;
+}
+
+CODE_SEG("PAGE")
+VOID
+NTAPI
+ArbAddAllocation(
+ _In_ PARBITER_INSTANCE Arbiter,
+ _Inout_ PARBITER_ALLOCATION_STATE ArbState)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+VOID
+NTAPI
+ArbBacktrackAllocation(
+ _In_ PARBITER_INSTANCE Arbiter,
+ _Inout_ PARBITER_ALLOCATION_STATE ArbState)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+}
+
+/* FIXME: the prototype is not correct yet. */
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+ArbOverrideConflict(
+ _In_ PARBITER_INSTANCE Arbiter)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+ArbBootAllocation(
+ _In_ PARBITER_INSTANCE Arbiter,
+ _In_ PLIST_ENTRY ArbitrationList)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+/* FIXME: the prototype is not correct yet. */
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+ArbQueryConflict(
+ _In_ PARBITER_INSTANCE Arbiter)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+/* FIXME: the prototype is not correct yet. */
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+ArbStartArbiter(
+ _In_ PARBITER_INSTANCE Arbiter)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+ArbAddOrdering(
+ _Out_ PARBITER_ORDERING_LIST OrderList,
+ _In_ UINT64 MinimumAddress,
+ _In_ UINT64 MaximumAddress)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+ArbPruneOrdering(
+ _Out_ PARBITER_ORDERING_LIST OrderingList,
+ _In_ UINT64 MinimumAddress,
+ _In_ UINT64 MaximumAddress)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+ArbInitializeOrderingList(
+ _Out_ PARBITER_ORDERING_LIST OrderList)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+VOID
+NTAPI
+ArbFreeOrderingList(
+ _Out_ PARBITER_ORDERING_LIST OrderList)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+}
+
+CODE_SEG("PAGE")
+NTSTATUS
+NTAPI
+ArbBuildAssignmentOrdering(
+ _Inout_ PARBITER_INSTANCE ArbInstance,
+ _In_ PCWSTR OrderName,
+ _In_ PCWSTR ReservedOrderName,
+ _In_ PARB_TRANSLATE_ORDERING TranslateOrderingFunction)
+{
+ PAGED_CODE();
+
+ UNIMPLEMENTED;
+ return STATUS_SUCCESS;
+}
+
+CODE_SEG("PAGE")
NTSTATUS
NTAPI
ArbInitializeArbiterInstance(
@@ -34,11 +289,118 @@ ArbInitializeArbiterInstance(
{
NTSTATUS Status;
- DPRINT("ArbInitializeArbiterInstance: Initializing %S Arbiter\n",
ArbiterName);
- UNIMPLEMENTED;
+ PAGED_CODE();
+
+ DPRINT("ArbInitializeArbiterInstance: '%S'\n", ArbiterName);
+
+ ASSERT(Arbiter->UnpackRequirement != NULL);
+ ASSERT(Arbiter->PackResource != NULL);
+ ASSERT(Arbiter->UnpackResource != NULL);
+ ASSERT(Arbiter->MutexEvent == NULL);
+ ASSERT(Arbiter->Allocation == NULL);
+ ASSERT(Arbiter->PossibleAllocation == NULL);
+ ASSERT(Arbiter->AllocationStack == NULL);
+
+ Arbiter->Signature = ARBITER_SIGNATURE;
+ Arbiter->BusDeviceObject = BusDeviceObject;
+
+ Arbiter->MutexEvent = ExAllocatePoolWithTag(NonPagedPool, sizeof(KEVENT),
TAG_ARBITER);
+ if (!Arbiter->MutexEvent)
+ {
+ DPRINT1("ArbInitializeArbiterInstance:
STATUS_INSUFFICIENT_RESOURCES\n");
+ return STATUS_INSUFFICIENT_RESOURCES;
+ }
+
+ KeInitializeEvent(Arbiter->MutexEvent, SynchronizationEvent, TRUE);
+
+ Arbiter->AllocationStack = ExAllocatePoolWithTag(PagedPool, PAGE_SIZE,
TAG_ARB_ALLOCATION);
+ if (!Arbiter->AllocationStack)
+ {
+ DPRINT1("ArbInitializeArbiterInstance:
STATUS_INSUFFICIENT_RESOURCES\n");
+ ExFreePoolWithTag(Arbiter->MutexEvent, TAG_ARBITER);
+ return STATUS_INSUFFICIENT_RESOURCES;
+ }
+
+ Arbiter->AllocationStackMaxSize = PAGE_SIZE;
+
+ Arbiter->Allocation = ExAllocatePoolWithTag(PagedPool, sizeof(RTL_RANGE_LIST),
TAG_ARB_RANGE);
+ if (!Arbiter->Allocation)
+ {
+ DPRINT1("ArbInitializeArbiterInstance:
STATUS_INSUFFICIENT_RESOURCES\n");
+ ExFreePoolWithTag(Arbiter->AllocationStack, TAG_ARB_ALLOCATION);
+ ExFreePoolWithTag(Arbiter->MutexEvent, TAG_ARBITER);
+ return STATUS_INSUFFICIENT_RESOURCES;
+ }
+
+ Arbiter->PossibleAllocation = ExAllocatePoolWithTag(PagedPool,
sizeof(RTL_RANGE_LIST), TAG_ARB_RANGE);
+ if (!Arbiter->PossibleAllocation)
+ {
+ DPRINT1("ArbInitializeArbiterInstance:
STATUS_INSUFFICIENT_RESOURCES\n");
+ ExFreePoolWithTag(Arbiter->Allocation, TAG_ARB_RANGE);
+ ExFreePoolWithTag(Arbiter->AllocationStack, TAG_ARB_ALLOCATION);
+ ExFreePoolWithTag(Arbiter->MutexEvent, TAG_ARBITER);
+ return STATUS_INSUFFICIENT_RESOURCES;
+ }
+
+ RtlInitializeRangeList(Arbiter->Allocation);
+ RtlInitializeRangeList(Arbiter->PossibleAllocation);
+
+ Arbiter->Name = ArbiterName;
+ Arbiter->ResourceType = ResourceType;
+ Arbiter->TransactionInProgress = FALSE;
+
+ if (!Arbiter->TestAllocation)
+ Arbiter->TestAllocation = ArbTestAllocation;
+
+ if (!Arbiter->RetestAllocation)
+ Arbiter->RetestAllocation = ArbRetestAllocation;
+
+ if (!Arbiter->CommitAllocation)
+ Arbiter->CommitAllocation = ArbCommitAllocation;
+
+ if (!Arbiter->RollbackAllocation)
+ Arbiter->RollbackAllocation = ArbRollbackAllocation;
+
+ if (!Arbiter->AddReserved)
+ Arbiter->AddReserved = ArbAddReserved;
+
+ if (!Arbiter->PreprocessEntry)
+ Arbiter->PreprocessEntry = ArbPreprocessEntry;
+
+ if (!Arbiter->AllocateEntry)
+ Arbiter->AllocateEntry = ArbAllocateEntry;
+
+ if (!Arbiter->GetNextAllocationRange)
+ Arbiter->GetNextAllocationRange = ArbGetNextAllocationRange;
+
+ if (!Arbiter->FindSuitableRange)
+ Arbiter->FindSuitableRange = ArbFindSuitableRange;
+
+ if (!Arbiter->AddAllocation)
+ Arbiter->AddAllocation = ArbAddAllocation;
+
+ if (!Arbiter->BacktrackAllocation)
+ Arbiter->BacktrackAllocation = ArbBacktrackAllocation;
+
+ if (!Arbiter->OverrideConflict)
+ Arbiter->OverrideConflict = ArbOverrideConflict;
+
+ if (!Arbiter->BootAllocation)
+ Arbiter->BootAllocation = ArbBootAllocation;
+
+ if (!Arbiter->QueryConflict)
+ Arbiter->QueryConflict = ArbQueryConflict;
+
+ if (!Arbiter->StartArbiter)
+ Arbiter->StartArbiter = ArbStartArbiter;
+
+ Status = ArbBuildAssignmentOrdering(Arbiter, OrderName, OrderName,
TranslateOrderingFunction);
+ if (NT_SUCCESS(Status))
+ {
+ return STATUS_SUCCESS;
+ }
+
+ DPRINT1("ArbInitializeArbiterInstance: Status %X\n", Status);
- Status = STATUS_SUCCESS;
return Status;
}
-
-/* EOF */
diff --git a/sdk/lib/drivers/arbiter/arbiter.h b/sdk/lib/drivers/arbiter/arbiter.h
index 6b8be2fb207..98e81711671 100644
--- a/sdk/lib/drivers/arbiter/arbiter.h
+++ b/sdk/lib/drivers/arbiter/arbiter.h
@@ -1,50 +1,53 @@
/*
- * PROJECT: ReactOS Kernel
- * COPYRIGHT: GPL-2.0+ (
https://spdx.org/licenses/GPL-2.0+)
- * FILE: lib/drivers/arbiter/arbiter.h
- * PURPOSE: Hardware Resources Arbiter Library
- * PROGRAMMERS: Copyright 2020 Vadim Galyant <vgal(a)rambler.ru>
+ * PROJECT: ReactOS Kernel&Driver SDK
+ * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later)
+ * PURPOSE: Hardware Resources Arbiter Library
+ * COPYRIGHT: Copyright 2020 Vadim Galyant <vgal(a)rambler.ru>
*/
-#ifndef _ARBITER_H
-#define _ARBITER_H
+#pragma once
+
+#define ARBITER_SIGNATURE 'sbrA'
+#define TAG_ARBITER 'MbrA'
+#define TAG_ARB_ALLOCATION 'AbrA'
+#define TAG_ARB_RANGE 'RbrA'
typedef struct _ARBITER_ORDERING
{
- ULONGLONG Start;
- ULONGLONG End;
+ UINT64 Start;
+ UINT64 End;
} ARBITER_ORDERING, *PARBITER_ORDERING;
typedef struct _ARBITER_ORDERING_LIST
{
- USHORT Count;
- USHORT Maximum;
+ UINT16 Count;
+ UINT16 Maximum;
PARBITER_ORDERING Orderings;
} ARBITER_ORDERING_LIST, *PARBITER_ORDERING_LIST;
typedef struct _ARBITER_ALTERNATIVE
{
- ULONGLONG Minimum;
- ULONGLONG Maximum;
- ULONG Length;
- ULONG Alignment;
- LONG Priority;
- ULONG Flags;
+ UINT64 Minimum;
+ UINT64 Maximum;
+ UINT32 Length;
+ UINT32 Alignment;
+ INT32 Priority;
+ UINT32 Flags;
PIO_RESOURCE_DESCRIPTOR Descriptor;
- ULONG Reserved[3];
+ UINT32 Reserved[3];
} ARBITER_ALTERNATIVE, *PARBITER_ALTERNATIVE;
typedef struct _ARBITER_ALLOCATION_STATE
{
- ULONGLONG Start;
- ULONGLONG End;
- ULONGLONG CurrentMinimum;
- ULONGLONG CurrentMaximum;
+ UINT64 Start;
+ UINT64 End;
+ UINT64 CurrentMinimum;
+ UINT64 CurrentMaximum;
PARBITER_LIST_ENTRY Entry;
PARBITER_ALTERNATIVE CurrentAlternative;
- ULONG AlternativeCount;
+ UINT32 AlternativeCount;
PARBITER_ALTERNATIVE Alternatives;
- USHORT Flags;
+ UINT16 Flags;
UCHAR RangeAttributes;
UCHAR RangeAvailableAttributes;
ULONG_PTR WorkSpace;
@@ -55,27 +58,27 @@ typedef struct _ARBITER_INSTANCE *PARBITER_INSTANCE;
typedef NTSTATUS
(NTAPI * PARB_UNPACK_REQUIREMENT)(
_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,
- _Out_ PULONGLONG OutMinimumAddress,
- _Out_ PULONGLONG OutMaximumAddress,
- _Out_ PULONG OutLength,
- _Out_ PULONG OutAlignment
+ _Out_ PUINT64 OutMinimumAddress,
+ _Out_ PUINT64 OutMaximumAddress,
+ _Out_ PUINT32 OutLength,
+ _Out_ PUINT32 OutAlignment
);
typedef NTSTATUS
(NTAPI * PARB_PACK_RESOURCE)(
_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,
- _In_ ULONGLONG Start,
+ _In_ UINT64 Start,
_Out_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor
);
typedef NTSTATUS
(NTAPI * PARB_UNPACK_RESOURCE)(
_In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor,
- _Out_ PULONGLONG Start,
- _Out_ PULONG OutLength
+ _Out_ PUINT64 Start,
+ _Out_ PUINT32 OutLength
);
-typedef LONG
+typedef INT32
(NTAPI * PARB_SCORE_REQUIREMENT)(
_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor
);
@@ -176,7 +179,7 @@ typedef NTSTATUS
typedef struct _ARBITER_INSTANCE
{
- ULONG Signature;
+ UINT32 Signature;
PKEVENT MutexEvent;
PCWSTR Name;
CM_RESOURCE_TYPE ResourceType;
@@ -184,9 +187,9 @@ typedef struct _ARBITER_INSTANCE
PRTL_RANGE_LIST PossibleAllocation;
ARBITER_ORDERING_LIST OrderingList;
ARBITER_ORDERING_LIST ReservedList;
- LONG ReferenceCount;
+ INT32 ReferenceCount;
PARBITER_INTERFACE Interface;
- ULONG AllocationStackMaxSize;
+ UINT32 AllocationStackMaxSize;
PARBITER_ALLOCATION_STATE AllocationStack;
PARB_UNPACK_REQUIREMENT UnpackRequirement;
PARB_PACK_RESOURCE PackResource;
@@ -221,6 +224,7 @@ typedef NTSTATUS
_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor
);
+CODE_SEG("PAGE")
NTSTATUS
NTAPI
ArbInitializeArbiterInstance(
@@ -231,5 +235,3 @@ ArbInitializeArbiterInstance(
_In_ PCWSTR OrderName,
_In_ PARB_TRANSLATE_ORDERING TranslateOrderingFunction
);
-
-#endif /* _ARBITER_H */