1 /* 2 * PROJECT: ReactOS Kernel 3 * COPYRIGHT: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) 4 * FILE: lib/drivers/arbiter/arbiter.h 5 * PURPOSE: Hardware Resources Arbiter Library 6 * PROGRAMMERS: Copyright 2020 Vadim Galyant <vgal@rambler.ru> 7 */ 8 9 #ifndef _ARBITER_H 10 #define _ARBITER_H 11 12 typedef struct _ARBITER_ORDERING 13 { 14 ULONGLONG Start; 15 ULONGLONG End; 16 } ARBITER_ORDERING, *PARBITER_ORDERING; 17 18 typedef struct _ARBITER_ORDERING_LIST 19 { 20 USHORT Count; 21 USHORT Maximum; 22 PARBITER_ORDERING Orderings; 23 } ARBITER_ORDERING_LIST, *PARBITER_ORDERING_LIST; 24 25 typedef struct _ARBITER_ALTERNATIVE 26 { 27 ULONGLONG Minimum; 28 ULONGLONG Maximum; 29 ULONG Length; 30 ULONG Alignment; 31 LONG Priority; 32 ULONG Flags; 33 PIO_RESOURCE_DESCRIPTOR Descriptor; 34 ULONG Reserved[3]; 35 } ARBITER_ALTERNATIVE, *PARBITER_ALTERNATIVE; 36 37 typedef struct _ARBITER_ALLOCATION_STATE 38 { 39 ULONGLONG Start; 40 ULONGLONG End; 41 ULONGLONG CurrentMinimum; 42 ULONGLONG CurrentMaximum; 43 PARBITER_LIST_ENTRY Entry; 44 PARBITER_ALTERNATIVE CurrentAlternative; 45 ULONG AlternativeCount; 46 PARBITER_ALTERNATIVE Alternatives; 47 USHORT Flags; 48 UCHAR RangeAttributes; 49 UCHAR RangeAvailableAttributes; 50 ULONG_PTR WorkSpace; 51 } ARBITER_ALLOCATION_STATE, *PARBITER_ALLOCATION_STATE; 52 53 typedef struct _ARBITER_INSTANCE *PARBITER_INSTANCE; 54 55 typedef NTSTATUS 56 (NTAPI * PARB_UNPACK_REQUIREMENT)( 57 _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor, 58 _Out_ PULONGLONG OutMinimumAddress, 59 _Out_ PULONGLONG OutMaximumAddress, 60 _Out_ PULONG OutLength, 61 _Out_ PULONG OutAlignment 62 ); 63 64 typedef NTSTATUS 65 (NTAPI * PARB_PACK_RESOURCE)( 66 _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor, 67 _In_ ULONGLONG Start, 68 _Out_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor 69 ); 70 71 typedef NTSTATUS 72 (NTAPI * PARB_UNPACK_RESOURCE)( 73 _In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor, 74 _Out_ PULONGLONG Start, 75 _Out_ PULONG OutLength 76 ); 77 78 typedef LONG 79 (NTAPI * PARB_SCORE_REQUIREMENT)( 80 _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor 81 ); 82 83 typedef NTSTATUS 84 (NTAPI * PARB_TEST_ALLOCATION)( 85 _In_ PARBITER_INSTANCE Arbiter, 86 _In_ PLIST_ENTRY ArbitrationList 87 ); 88 89 typedef NTSTATUS 90 (NTAPI * PARB_RETEST_ALLOCATION)( 91 _In_ PARBITER_INSTANCE Arbiter, 92 _In_ PLIST_ENTRY ArbitrationList 93 ); 94 95 typedef NTSTATUS 96 (NTAPI * PARB_COMMIT_ALLOCATION)( 97 _In_ PARBITER_INSTANCE Arbiter 98 ); 99 100 typedef NTSTATUS 101 (NTAPI * PARB_ROLLBACK_ALLOCATION)( 102 _In_ PARBITER_INSTANCE Arbiter 103 ); 104 105 typedef NTSTATUS 106 (NTAPI * PARB_BOOT_ALLOCATION)( 107 _In_ PARBITER_INSTANCE Arbiter, 108 _In_ PLIST_ENTRY ArbitrationList 109 ); 110 111 /* Not correct yet, FIXME! */ 112 typedef NTSTATUS 113 (NTAPI * PARB_QUERY_ARBITRATE)( 114 _In_ PARBITER_INSTANCE Arbiter 115 ); 116 117 /* Not correct yet, FIXME! */ 118 typedef NTSTATUS 119 (NTAPI * PARB_QUERY_CONFLICT)( 120 _In_ PARBITER_INSTANCE Arbiter 121 ); 122 123 /* Not correct yet, FIXME! */ 124 typedef NTSTATUS 125 (NTAPI * PARB_ADD_RESERVED)( 126 _In_ PARBITER_INSTANCE Arbiter 127 ); 128 129 /* Not correct yet, FIXME! */ 130 typedef NTSTATUS 131 (NTAPI * PARB_START_ARBITER)( 132 _In_ PARBITER_INSTANCE Arbiter 133 ); 134 135 typedef NTSTATUS 136 (NTAPI * PARB_PREPROCESS_ENTRY)( 137 _In_ PARBITER_INSTANCE Arbiter, 138 _Inout_ PARBITER_ALLOCATION_STATE ArbState 139 ); 140 141 typedef NTSTATUS 142 (NTAPI * PARB_ALLOCATE_ENTRY)( 143 _In_ PARBITER_INSTANCE Arbiter, 144 _Inout_ PARBITER_ALLOCATION_STATE ArbState 145 ); 146 147 typedef BOOLEAN 148 (NTAPI * PARB_GET_NEXT_ALLOCATION_RANGE)( 149 _In_ PARBITER_INSTANCE Arbiter, 150 _Inout_ PARBITER_ALLOCATION_STATE ArbState 151 ); 152 153 typedef BOOLEAN 154 (NTAPI * PARB_FIND_SUITABLE_RANGE)( 155 _In_ PARBITER_INSTANCE Arbiter, 156 _Inout_ PARBITER_ALLOCATION_STATE ArbState 157 ); 158 159 typedef VOID 160 (NTAPI * PARB_ADD_ALLOCATION)( 161 _In_ PARBITER_INSTANCE Arbiter, 162 _Inout_ PARBITER_ALLOCATION_STATE ArbState 163 ); 164 165 typedef VOID 166 (NTAPI * PARB_BACKTRACK_ALLOCATION)( 167 _In_ PARBITER_INSTANCE Arbiter, 168 _Inout_ PARBITER_ALLOCATION_STATE ArbState 169 ); 170 171 /* Not correct yet, FIXME! */ 172 typedef NTSTATUS 173 (NTAPI * PARB_OVERRIDE_CONFLICT)( 174 _In_ PARBITER_INSTANCE Arbiter 175 ); 176 177 typedef struct _ARBITER_INSTANCE 178 { 179 ULONG Signature; 180 PKEVENT MutexEvent; 181 PCWSTR Name; 182 CM_RESOURCE_TYPE ResourceType; 183 PRTL_RANGE_LIST Allocation; 184 PRTL_RANGE_LIST PossibleAllocation; 185 ARBITER_ORDERING_LIST OrderingList; 186 ARBITER_ORDERING_LIST ReservedList; 187 LONG ReferenceCount; 188 PARBITER_INTERFACE Interface; 189 ULONG AllocationStackMaxSize; 190 PARBITER_ALLOCATION_STATE AllocationStack; 191 PARB_UNPACK_REQUIREMENT UnpackRequirement; 192 PARB_PACK_RESOURCE PackResource; 193 PARB_UNPACK_RESOURCE UnpackResource; 194 PARB_SCORE_REQUIREMENT ScoreRequirement; 195 PARB_TEST_ALLOCATION TestAllocation; 196 PARB_RETEST_ALLOCATION RetestAllocation; 197 PARB_COMMIT_ALLOCATION CommitAllocation; 198 PARB_ROLLBACK_ALLOCATION RollbackAllocation; 199 PARB_BOOT_ALLOCATION BootAllocation; 200 PARB_QUERY_ARBITRATE QueryArbitrate; // Not used yet 201 PARB_QUERY_CONFLICT QueryConflict; // Not used yet 202 PARB_ADD_RESERVED AddReserved; // Not used yet 203 PARB_START_ARBITER StartArbiter; // Not used yet 204 PARB_PREPROCESS_ENTRY PreprocessEntry; 205 PARB_ALLOCATE_ENTRY AllocateEntry; 206 PARB_GET_NEXT_ALLOCATION_RANGE GetNextAllocationRange; 207 PARB_FIND_SUITABLE_RANGE FindSuitableRange; 208 PARB_ADD_ALLOCATION AddAllocation; 209 PARB_BACKTRACK_ALLOCATION BacktrackAllocation; 210 PARB_OVERRIDE_CONFLICT OverrideConflict; // Not used yet 211 BOOLEAN TransactionInProgress; 212 PVOID Extension; 213 PDEVICE_OBJECT BusDeviceObject; 214 PVOID ConflictCallbackContext; 215 PVOID ConflictCallback; 216 } ARBITER_INSTANCE, *PARBITER_INSTANCE; 217 218 typedef NTSTATUS 219 (NTAPI * PARB_TRANSLATE_ORDERING)( 220 _Out_ PIO_RESOURCE_DESCRIPTOR OutIoDescriptor, 221 _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor 222 ); 223 224 NTSTATUS 225 NTAPI 226 ArbInitializeArbiterInstance( 227 _Inout_ PARBITER_INSTANCE Arbiter, 228 _In_ PDEVICE_OBJECT BusDeviceObject, 229 _In_ CM_RESOURCE_TYPE ResourceType, 230 _In_ PCWSTR ArbiterName, 231 _In_ PCWSTR OrderName, 232 _In_ PARB_TRANSLATE_ORDERING TranslateOrderingFunction 233 ); 234 235 #endif /* _ARBITER_H */ 236