ReactOS 0.4.17-dev-1196-gb6224c3
ar_memio.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS PCI Bus Driver
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: drivers/bus/pci/arb/ar_memiono.c
5 * PURPOSE: Memory and I/O Port Resource Arbitration
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9/* INCLUDES *******************************************************************/
10
11#include <pci.h>
12
13#define NDEBUG
14#include <debug.h>
15
16/* GLOBALS ********************************************************************/
17
19{
20 &GUID_ARBITER_INTERFACE_STANDARD,
21 sizeof(ARBITER_INTERFACE),
22 0,
23 0,
25 0,
29};
30
32{
33 &GUID_ARBITER_INTERFACE_STANDARD,
34 sizeof(ARBITER_INTERFACE),
35 0,
36 0,
38 0,
42};
43
44/* FUNCTIONS ******************************************************************/
45
49 _Out_ PULONGLONG Minimum,
50 _Out_ PULONGLONG Maximum,
53{
54 /* This arbiter is only ever handed I/O port descriptors */
56
57 /* An alignment of zero would place the range nowhere, so make it one byte */
58 *Minimum = (ULONGLONG)Descriptor->u.Port.MinimumAddress.QuadPart;
59 *Maximum = (ULONGLONG)Descriptor->u.Port.MaximumAddress.QuadPart;
60 *Length = Descriptor->u.Port.Length;
61 *Alignment = Descriptor->u.Port.Alignment ? Descriptor->u.Port.Alignment : 1;
62 return STATUS_SUCCESS;
63}
64
70{
71 /* Turn the placement the engine settled on back into an I/O port resource */
73
75 Resource->Flags = Descriptor->Flags;
76 Resource->ShareDisposition = Descriptor->ShareDisposition;
77 Resource->u.Port.Start.QuadPart = (LONGLONG)Start;
78 Resource->u.Port.Length = Descriptor->u.Port.Length;
79 return STATUS_SUCCESS;
80}
81
87{
88 /* Read a previously packed I/O port resource back out */
90
91 *Start = (ULONGLONG)Resource->u.Port.Start.QuadPart;
92 *Length = Resource->u.Port.Length;
93 return STATUS_SUCCESS;
94}
95
99{
100 ULONGLONG Minimum, Maximum, Length, Alignment;
101
102 /* A requirement this arbiter cannot read is treated as unsatisfiable */
104 &Minimum,
105 &Maximum,
106 &Length,
107 &Alignment)) ||
108 (Maximum < Minimum))
109 {
110 return -1;
111 }
112
113 if ((Maximum - Minimum) >= MAXLONG) return MAXLONG;
114 return (INT32)(Maximum - Minimum + 1);
115}
116
118NTAPI
120{
124 PAGED_CODE();
125
126 /* Start from a clean engine instance */
127 RtlZeroMemory(&Arbiter->CommonInstance, sizeof(Arbiter->CommonInstance));
128 FdoExtension = Arbiter->BusFdoExtension;
129
130 /* Teach the engine how to read and write I/O port descriptors */
138
139 /* The rest of the engine, and the PCI assignment ordering, is generic */
141 FdoExtension->FunctionalDeviceObject,
143 Arbiter->InstanceName,
144 L"Pci",
145 NULL);
146 if (!NT_SUCCESS(Status))
147 {
148 DPRINT1("PCIX - ario_Initializer: init arbiter returned %X\n", Status);
149 }
150
151 return Status;
152}
153
155NTAPI
156ario_Constructor(IN PVOID DeviceExtension,
157 IN PVOID PciInterface,
158 IN PVOID InterfaceData,
160 IN USHORT Size,
162{
164 PAGED_CODE();
165
166 UNREFERENCED_PARAMETER(PciInterface);
169
170 /* This one only arbitrates I/O ports */
171 if ((ULONG_PTR)InterfaceData != CmResourceTypePort)
172 {
174 }
175
176 /* Hand out the instance that was built for this bus */
178 PciArb_Io,
180}
181
182VOID
183NTAPI
185{
186 PPCI_ARBITER_INSTANCE PciArbiter;
187 PARBITER_INSTANCE CommonInstance;
189
190 /* Only valid for root FDOs who are being applied the hack for the first time */
191 ASSERT(!FdoExtension->BrokenVideoHackApplied);
193
194 /* Find the I/O arbiter */
196 SecondaryExtension.Next,
197 PciArb_Io);
198 ASSERT(PciArbiter);
199 if (!PciArbiter) return;
200
201 /* Get the Arb instance */
202 CommonInstance = &PciArbiter->CommonInstance;
203
204 /* Free the two lists, enabling full VGA access */
207
208 /* Build the ordering for broken video PCI access */
210 L"Pci",
211 L"BrokenVideo",
212 NULL);
214 if (!NT_SUCCESS(Status))
215 {
216 DPRINT1("PCIX - ario_ApplyBrokenVideoHack: ordering failed %X\n", Status);
217 }
218
219 /* Now the hack has been applied */
220 FdoExtension->BrokenVideoHackApplied = TRUE;
221}
222
224NTAPI
226 _Out_ PULONGLONG Minimum,
227 _Out_ PULONGLONG Maximum,
230{
231 /* This arbiter is only ever handed device memory descriptors, large ones included */
232 if ((Descriptor->Type != CmResourceTypeMemory) &&
234 {
236 }
237
238 /* An alignment of zero would place the range nowhere, so make it one byte */
240 if (!*Alignment)
241 *Alignment = 1;
242
243 return STATUS_SUCCESS;
244}
245
247NTAPI
251{
252 /* Turn the placement the engine settled on back into a memory resource */
253 if ((Descriptor->Type != CmResourceTypeMemory) &&
255 {
257 }
258
259 /* The flags say how a large length is scaled, so both come across unchanged */
260 Resource->Type = Descriptor->Type;
261 Resource->Flags = Descriptor->Flags;
262 Resource->ShareDisposition = Descriptor->ShareDisposition;
263 Resource->u.Memory.Start.QuadPart = (LONGLONG)Start;
264 Resource->u.Memory.Length = Descriptor->u.Memory.Length;
265 return STATUS_SUCCESS;
266}
267
269NTAPI
273{
274 /* Read a previously packed memory resource back out */
275 if ((Resource->Type != CmResourceTypeMemory) &&
277 {
279 }
280
282 return STATUS_SUCCESS;
283}
284
285INT32
286NTAPI
288{
289 ULONGLONG Minimum, Maximum, Length, Alignment;
290
291 /* A requirement this arbiter cannot read is treated as unsatisfiable */
293 &Minimum,
294 &Maximum,
295 &Length,
296 &Alignment)) ||
297 (Maximum < Minimum))
298 {
299 return -1;
300 }
301
302 if ((Maximum - Minimum) >= MAXLONG) return MAXLONG;
303 return (INT32)(Maximum - Minimum + 1);
304}
305
307NTAPI
309{
313 PAGED_CODE();
314
315 /* Start from a clean engine instance */
316 RtlZeroMemory(&Arbiter->CommonInstance, sizeof(Arbiter->CommonInstance));
317 FdoExtension = Arbiter->BusFdoExtension;
318
319 /* Teach the engine how to read and write memory descriptors */
327
328 /* The rest of the engine, and the PCI assignment ordering, is generic */
330 FdoExtension->FunctionalDeviceObject,
332 Arbiter->InstanceName,
333 L"Pci",
334 NULL);
335 if (!NT_SUCCESS(Status))
336 {
337 DPRINT1("PCIX - armem_Initializer: init arbiter returned %X\n", Status);
338 }
339
340 return Status;
341}
342
344NTAPI
345armem_Constructor(IN PVOID DeviceExtension,
346 IN PVOID PciInterface,
347 IN PVOID InterfaceData,
349 IN USHORT Size,
351{
353 PAGED_CODE();
354
355 UNREFERENCED_PARAMETER(PciInterface);
358
359 /* This one only arbitrates device memory */
360 if ((ULONG_PTR)InterfaceData != CmResourceTypeMemory)
361 {
363 }
364
365 /* Hand out the instance that was built for this bus */
369}
370
371/* EOF */
#define PAGED_CODE()
static _Out_opt_ PULONGLONG Start
PCI_INTERFACE ArbiterInterfaceIo
Definition: ar_memio.c:31
NTSTATUS NTAPI armem_Constructor(IN PVOID DeviceExtension, IN PVOID PciInterface, IN PVOID InterfaceData, IN USHORT Version, IN USHORT Size, IN PINTERFACE Interface)
Definition: ar_memio.c:345
NTSTATUS NTAPI ario_Initializer(IN PVOID Instance)
Definition: ar_memio.c:119
NTSTATUS NTAPI armem_UnpackResource(_In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Resource, _Out_ PULONGLONG Start, _Out_ PULONGLONG Length)
Definition: ar_memio.c:270
VOID NTAPI ario_ApplyBrokenVideoHack(IN PPCI_FDO_EXTENSION FdoExtension)
Definition: ar_memio.c:184
NTSTATUS NTAPI ario_Constructor(IN PVOID DeviceExtension, IN PVOID PciInterface, IN PVOID InterfaceData, IN USHORT Version, IN USHORT Size, IN PINTERFACE Interface)
Definition: ar_memio.c:156
NTSTATUS NTAPI ario_PackResource(_In_ PIO_RESOURCE_DESCRIPTOR Descriptor, _In_ ULONGLONG Start, _Out_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Resource)
Definition: ar_memio.c:67
PCI_INTERFACE ArbiterInterfaceMemory
Definition: ar_memio.c:18
INT32 NTAPI armem_ScoreRequirement(_In_ PIO_RESOURCE_DESCRIPTOR Descriptor)
Definition: ar_memio.c:287
NTSTATUS NTAPI armem_PackResource(_In_ PIO_RESOURCE_DESCRIPTOR Descriptor, _In_ ULONGLONG Start, _Out_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Resource)
Definition: ar_memio.c:248
INT32 NTAPI ario_ScoreRequirement(_In_ PIO_RESOURCE_DESCRIPTOR Descriptor)
Definition: ar_memio.c:98
NTSTATUS NTAPI armem_UnpackRequirement(_In_ PIO_RESOURCE_DESCRIPTOR Descriptor, _Out_ PULONGLONG Minimum, _Out_ PULONGLONG Maximum, _Out_ PULONGLONG Length, _Out_ PULONGLONG Alignment)
Definition: ar_memio.c:225
NTSTATUS NTAPI ario_UnpackRequirement(_In_ PIO_RESOURCE_DESCRIPTOR Descriptor, _Out_ PULONGLONG Minimum, _Out_ PULONGLONG Maximum, _Out_ PULONGLONG Length, _Out_ PULONGLONG Alignment)
Definition: ar_memio.c:48
NTSTATUS NTAPI ario_UnpackResource(_In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Resource, _Out_ PULONGLONG Start, _Out_ PULONGLONG Length)
Definition: ar_memio.c:84
NTSTATUS NTAPI armem_Initializer(IN PVOID Instance)
Definition: ar_memio.c:308
NTSTATUS NTAPI PciArbiter_PreprocessEntry(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE State)
Sets the range attributes of one arbitration entry before the engine looks for a placement for it.
Definition: arb_comn.c:51
BOOLEAN NTAPI PciArbiter_FindSuitableRange(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE State)
Searches for a placement, remembering on the range whether it came from a fixed alternative.
Definition: arb_comn.c:97
NTSTATUS NTAPI PciArbiterConstructor(_In_ PPCI_FDO_EXTENSION FdoExtension, _In_ PCI_SIGNATURE ArbiterType, _Out_ PARBITER_INTERFACE Interface)
Definition: arb_comn.c:200
BOOLEAN NTAPI PciArbiter_OverrideConflict(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE State)
Lets a fixed requirement overlap ranges its own device was given by other fixed requirements.
Definition: arb_comn.c:136
NTSTATUS NTAPI ArbiterLibInitializeInstance(_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:69
NTSTATUS NTAPI ArbiterLibDefaultAssignmentOrdering(_Inout_ PARBITER_INSTANCE Arbiter, _In_ PCWSTR AllocationOrderName, _In_ PCWSTR ReservedResourcesName, _In_opt_ PARB_TRANSLATE_ORDERING TranslateOrderingFunction)
Builds the arbiter's allocation ordering from the registry policy, most-preferred window first.
Definition: ordering.c:571
VOID NTAPI ArbiterLibFreeOrderingList(_Inout_ PARBITER_ORDERING_LIST OrderingList)
Definition: ordering.c:60
ULONGLONG NTAPI RtlIoDecodeMemIoResource(_In_ PIO_RESOURCE_DESCRIPTOR Descriptor, _Out_opt_ PULONGLONG Alignment, _Out_opt_ PULONGLONG MinimumAddress, _Out_opt_ PULONGLONG MaximumAddress)
Definition: memres.c:79
ULONGLONG NTAPI RtlCmDecodeMemIoResource(_In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor, _Out_opt_ PULONGLONG Start)
Definition: memres.c:58
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
_Acquires_exclusive_lock_ Resource _Acquires_shared_lock_ Resource _Inout_ PERESOURCE Resource
Definition: cdprocs.h:843
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define L(x)
Definition: resources.c:13
PPCI_SECONDARY_EXTENSION NTAPI PciFindNextSecondaryExtension(IN PSINGLE_LIST_ENTRY ListHead, IN PCI_SIGNATURE ExtensionType)
Definition: utils.c:584
#define PCI_INTERFACE_FDO
Definition: pci.h:68
#define PCI_IS_ROOT_FDO(x)
Definition: pci.h:42
struct _PCI_FDO_EXTENSION * PPCI_FDO_EXTENSION
@ PciArb_Io
Definition: pci.h:135
@ PciArb_Memory
Definition: pci.h:136
@ FdoExtension
Definition: precomp.h:60
union Alignment_ Alignment
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
__GNU_EXTENSION typedef unsigned __int64 * PULONGLONG
Definition: ntbasedef.h:395
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define STATUS_INVALID_PARAMETER_5
Definition: ntstatus.h:573
unsigned short USHORT
Definition: pedump.c:61
#define CmResourceTypeMemory
Definition: restypes.h:106
#define CmResourceTypePort
Definition: restypes.h:104
#define STATUS_SUCCESS
Definition: shellext.h:65
PPCI_FDO_EXTENSION BusFdoExtension
Definition: pci.h:470
WCHAR InstanceName[24]
Definition: pci.h:471
ARBITER_INSTANCE CommonInstance
Definition: pci.h:472
PARB_UNPACK_RESOURCE UnpackResource
Definition: arbiter.h:312
PARB_OVERRIDE_CONFLICT OverrideConflict
Definition: arbiter.h:329
PARB_SCORE_REQUIREMENT ScoreRequirement
Definition: arbiter.h:313
PARB_UNPACK_REQUIREMENT UnpackRequirement
Definition: arbiter.h:310
ARBITER_ORDERING_LIST ReservedList
Definition: arbiter.h:305
PARB_PREPROCESS_ENTRY PreprocessEntry
Definition: arbiter.h:323
PARB_FIND_SUITABLE_RANGE FindSuitableRange
Definition: arbiter.h:326
ARBITER_ORDERING_LIST OrderingList
Definition: arbiter.h:304
PARB_PACK_RESOURCE PackResource
Definition: arbiter.h:311
int32_t INT32
Definition: typedefs.h:58
int64_t LONGLONG
Definition: typedefs.h:68
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
uint64_t ULONGLONG
Definition: typedefs.h:67
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
_In_ UCXUSBDEVICE _In_ ULONG Interface
Definition: ucxusbdevice.h:428
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define MAXLONG
Definition: umtypes.h:116
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE _In_ USHORT _In_ USHORT Version
Definition: wdffdo.h:469
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_WMI_INSTANCE_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_opt_ WDFWMIINSTANCE * Instance
Definition: wdfwmi.h:481
#define CmResourceTypeMemoryLarge
Definition: cmtypes.h:231
struct _ARBITER_INTERFACE ARBITER_INTERFACE