[NTOS][SDK:LIB] Add a Resources Arbiter library, to be used by bus drivers (acpi, pci), kernel and legacy hal (PIC HAL). (#2471)

This commit is contained in:
Vadim Galyant 2020-03-26 18:45:59 +04:00 committed by Hermès Bélusca-Maïto
parent 28e277b65f
commit 374f2b4d98
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
10 changed files with 470 additions and 4 deletions

View file

@ -42,7 +42,7 @@ else()
#add_linker_script(ntoskrnl ${REACTOS_SOURCE_DIR}/sdk/cmake/init-section.lds)
endif()
target_link_libraries(ntoskrnl cportlib csq ${PSEH_LIB} cmlib ntlsalib rtl ${ROSSYM_LIB} libcntpr wdmguid ioevent)
target_link_libraries(ntoskrnl cportlib csq ${PSEH_LIB} arbiter cmlib ntlsalib rtl ${ROSSYM_LIB} libcntpr wdmguid ioevent)
if(STACK_PROTECTOR)
target_link_libraries(ntoskrnl gcc_ssp)

View file

@ -79,6 +79,7 @@
#include "hal.h"
#include "hdl.h"
#include "arch/intrin_i.h"
#include <arbiter.h>
/*
* generic information class probing code

123
ntoskrnl/io/pnpmgr/arbs.c Normal file
View file

@ -0,0 +1,123 @@
/*
* 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@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 */

View file

@ -24,6 +24,18 @@ PUNICODE_STRING PiInitGroupOrderTable;
USHORT PiInitGroupOrderTableCount;
INTERFACE_TYPE PnpDefaultInterfaceType;
ARBITER_INSTANCE IopRootBusNumberArbiter;
ARBITER_INSTANCE IopRootIrqArbiter;
ARBITER_INSTANCE IopRootDmaArbiter;
ARBITER_INSTANCE IopRootMemArbiter;
ARBITER_INSTANCE IopRootPortArbiter;
NTSTATUS NTAPI IopPortInitialize(VOID);
NTSTATUS NTAPI IopMemInitialize(VOID);
NTSTATUS NTAPI IopDmaInitialize(VOID);
NTSTATUS NTAPI IopIrqInitialize(VOID);
NTSTATUS NTAPI IopBusNumberInitialize(VOID);
/* FUNCTIONS ******************************************************************/
INTERFACE_TYPE
@ -38,10 +50,46 @@ NTSTATUS
NTAPI
IopInitializeArbiters(VOID)
{
/* FIXME: TODO */
return STATUS_SUCCESS;
NTSTATUS Status;
Status = IopPortInitialize();
if (!NT_SUCCESS(Status))
{
DPRINT1("IopPortInitialize() return %X\n", Status);
return Status;
}
Status = IopMemInitialize();
if (!NT_SUCCESS(Status))
{
DPRINT1("IopMemInitialize() return %X\n", Status);
return Status;
}
Status = IopDmaInitialize();
if (!NT_SUCCESS(Status))
{
DPRINT1("IopDmaInitialize() return %X\n", Status);
return Status;
}
Status = IopIrqInitialize();
if (!NT_SUCCESS(Status))
{
DPRINT1("IopIrqInitialize() return %X\n", Status);
return Status;
}
Status = IopBusNumberInitialize();
if (!NT_SUCCESS(Status))
{
DPRINT1("IopBusNumberInitialize() return %X\n", Status);
}
return Status;
}
INIT_FUNCTION
NTSTATUS
NTAPI

View file

@ -40,7 +40,7 @@ elseif(RUNTIME_CHECKS)
target_link_libraries(ntkrnlmp runtmchk)
endif()
target_link_libraries(ntkrnlmp cportlib csq ${PSEH_LIB} cmlib ntlsalib rtl ${ROSSYM_LIB} libcntpr wdmguid ioevent)
target_link_libraries(ntkrnlmp cportlib csq ${PSEH_LIB} arbiter cmlib ntlsalib rtl ${ROSSYM_LIB} libcntpr wdmguid ioevent)
add_importlibs(ntkrnlmp hal kdcom bootvid)
add_pch(ntkrnlmp ${REACTOS_SOURCE_DIR}/ntoskrnl/include/ntoskrnl.h NTKRNLMP_SOURCE)
add_dependencies(ntkrnlmp psdk bugcodes asm)

View file

@ -1,6 +1,7 @@
include_directories(
${REACTOS_SOURCE_DIR}
${REACTOS_SOURCE_DIR}/sdk/lib/drivers/arbiter
${REACTOS_SOURCE_DIR}/sdk/lib/cmlib
include
${CMAKE_CURRENT_BINARY_DIR}/include
@ -151,6 +152,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/plugplay.c
${REACTOS_SOURCE_DIR}/ntoskrnl/io/pnpmgr/pnpdma.c
${REACTOS_SOURCE_DIR}/ntoskrnl/io/pnpmgr/pnpinit.c

View file

@ -1,4 +1,5 @@
add_subdirectory(arbiter)
add_subdirectory(chew)
add_subdirectory(copysup)
add_subdirectory(csq)

View file

@ -0,0 +1,10 @@
include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/rtl)
list(APPEND SOURCE
arbiter.c
arbiter.h)
add_library(arbiter ${SOURCE})
add_dependencies(arbiter bugcodes xdk)
add_pch(arbiter arbiter.h SOURCE)

View file

@ -0,0 +1,41 @@
/*
* 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@rambler.ru>
*/
/* INCLUDES *******************************************************************/
#define NDEBUG
#include <debug.h>
#include "arbiter.h"
/* GLOBALS ********************************************************************/
/* DATA **********************************************************************/
/* FUNCTIONS ******************************************************************/
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)
{
NTSTATUS Status;
DPRINT("ArbInitializeArbiterInstance: Initializing %S Arbiter\n", ArbiterName);
UNIMPLEMENTED;
Status = STATUS_SUCCESS;
return Status;
}
/* EOF */

View file

@ -0,0 +1,240 @@
/*
* 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@rambler.ru>
*/
#ifndef _ARBITER_H
#define _ARBITER_H
#ifndef _NTOSKRNL_
#include <ntifs.h>
#include <ndk/rtlfuncs.h>
#endif
typedef struct _ARBITER_ORDERING
{
ULONGLONG Start;
ULONGLONG End;
} ARBITER_ORDERING, *PARBITER_ORDERING;
typedef struct _ARBITER_ORDERING_LIST
{
USHORT Count;
USHORT 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;
PIO_RESOURCE_DESCRIPTOR Descriptor;
ULONG Reserved[3];
} ARBITER_ALTERNATIVE, *PARBITER_ALTERNATIVE;
typedef struct _ARBITER_ALLOCATION_STATE
{
ULONGLONG Start;
ULONGLONG End;
ULONGLONG CurrentMinimum;
ULONGLONG CurrentMaximum;
PARBITER_LIST_ENTRY Entry;
PARBITER_ALTERNATIVE CurrentAlternative;
ULONG AlternativeCount;
PARBITER_ALTERNATIVE Alternatives;
USHORT Flags;
UCHAR RangeAttributes;
UCHAR RangeAvailableAttributes;
ULONG_PTR WorkSpace;
} ARBITER_ALLOCATION_STATE, *PARBITER_ALLOCATION_STATE;
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
);
typedef NTSTATUS
(NTAPI * PARB_PACK_RESOURCE)(
_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor,
_In_ ULONGLONG 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
);
typedef LONG
(NTAPI * PARB_SCORE_REQUIREMENT)(
_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor
);
typedef NTSTATUS
(NTAPI * PARB_TEST_ALLOCATION)(
_In_ PARBITER_INSTANCE Arbiter,
_In_ PLIST_ENTRY ArbitrationList
);
typedef NTSTATUS
(NTAPI * PARB_RETEST_ALLOCATION)(
_In_ PARBITER_INSTANCE Arbiter,
_In_ PLIST_ENTRY ArbitrationList
);
typedef NTSTATUS
(NTAPI * PARB_COMMIT_ALLOCATION)(
_In_ PARBITER_INSTANCE Arbiter
);
typedef NTSTATUS
(NTAPI * PARB_ROLLBACK_ALLOCATION)(
_In_ PARBITER_INSTANCE Arbiter
);
typedef NTSTATUS
(NTAPI * PARB_BOOT_ALLOCATION)(
_In_ PARBITER_INSTANCE Arbiter,
_In_ PLIST_ENTRY ArbitrationList
);
/* Not correct yet, FIXME! */
typedef NTSTATUS
(NTAPI * PARB_QUERY_ARBITRATE)(
_In_ PARBITER_INSTANCE Arbiter
);
/* Not correct yet, FIXME! */
typedef NTSTATUS
(NTAPI * PARB_QUERY_CONFLICT)(
_In_ PARBITER_INSTANCE Arbiter
);
/* Not correct yet, FIXME! */
typedef NTSTATUS
(NTAPI * PARB_ADD_RESERVED)(
_In_ PARBITER_INSTANCE Arbiter
);
/* Not correct yet, FIXME! */
typedef NTSTATUS
(NTAPI * PARB_START_ARBITER)(
_In_ PARBITER_INSTANCE Arbiter
);
typedef NTSTATUS
(NTAPI * PARB_PREPROCESS_ENTRY)(
_In_ PARBITER_INSTANCE Arbiter,
_Inout_ PARBITER_ALLOCATION_STATE ArbState
);
typedef NTSTATUS
(NTAPI * PARB_ALLOCATE_ENTRY)(
_In_ PARBITER_INSTANCE Arbiter,
_Inout_ PARBITER_ALLOCATION_STATE ArbState
);
typedef BOOLEAN
(NTAPI * PARB_GET_NEXT_ALLOCATION_RANGE)(
_In_ PARBITER_INSTANCE Arbiter,
_Inout_ PARBITER_ALLOCATION_STATE ArbState
);
typedef BOOLEAN
(NTAPI * PARB_FIND_SUITABLE_RANGE)(
_In_ PARBITER_INSTANCE Arbiter,
_Inout_ PARBITER_ALLOCATION_STATE ArbState
);
typedef VOID
(NTAPI * PARB_ADD_ALLOCATION)(
_In_ PARBITER_INSTANCE Arbiter,
_Inout_ PARBITER_ALLOCATION_STATE ArbState
);
typedef VOID
(NTAPI * PARB_BACKTRACK_ALLOCATION)(
_In_ PARBITER_INSTANCE Arbiter,
_Inout_ PARBITER_ALLOCATION_STATE ArbState
);
/* Not correct yet, FIXME! */
typedef NTSTATUS
(NTAPI * PARB_OVERRIDE_CONFLICT)(
_In_ PARBITER_INSTANCE Arbiter
);
typedef struct _ARBITER_INSTANCE
{
ULONG Signature;
PKEVENT MutexEvent;
PCWSTR Name;
CM_RESOURCE_TYPE ResourceType;
PRTL_RANGE_LIST Allocation;
PRTL_RANGE_LIST PossibleAllocation;
ARBITER_ORDERING_LIST OrderingList;
ARBITER_ORDERING_LIST ReservedList;
LONG ReferenceCount;
PARBITER_INTERFACE Interface;
ULONG AllocationStackMaxSize;
PARBITER_ALLOCATION_STATE AllocationStack;
PARB_UNPACK_REQUIREMENT UnpackRequirement;
PARB_PACK_RESOURCE PackResource;
PARB_UNPACK_RESOURCE UnpackResource;
PARB_SCORE_REQUIREMENT ScoreRequirement;
PARB_TEST_ALLOCATION TestAllocation;
PARB_RETEST_ALLOCATION RetestAllocation;
PARB_COMMIT_ALLOCATION CommitAllocation;
PARB_ROLLBACK_ALLOCATION RollbackAllocation;
PARB_BOOT_ALLOCATION BootAllocation;
PARB_QUERY_ARBITRATE QueryArbitrate; // Not used yet
PARB_QUERY_CONFLICT QueryConflict; // Not used yet
PARB_ADD_RESERVED AddReserved; // Not used yet
PARB_START_ARBITER StartArbiter; // Not used yet
PARB_PREPROCESS_ENTRY PreprocessEntry;
PARB_ALLOCATE_ENTRY AllocateEntry;
PARB_GET_NEXT_ALLOCATION_RANGE GetNextAllocationRange;
PARB_FIND_SUITABLE_RANGE FindSuitableRange;
PARB_ADD_ALLOCATION AddAllocation;
PARB_BACKTRACK_ALLOCATION BacktrackAllocation;
PARB_OVERRIDE_CONFLICT OverrideConflict; // Not used yet
BOOLEAN TransactionInProgress;
PVOID Extension;
PDEVICE_OBJECT BusDeviceObject;
PVOID ConflictCallbackContext;
PVOID ConflictCallback;
} ARBITER_INSTANCE, *PARBITER_INSTANCE;
typedef NTSTATUS
(NTAPI * PARB_TRANSLATE_ORDERING)(
_Out_ PIO_RESOURCE_DESCRIPTOR OutIoDescriptor,
_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor
);
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
);
#endif /* _ARBITER_H */