ReactOS 0.4.17-dev-1190-g4c812f4
ar_memio.c File Reference
#include <pci.h>
#include <debug.h>
Include dependency graph for ar_memio.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI ario_UnpackRequirement (_In_ PIO_RESOURCE_DESCRIPTOR Descriptor, _Out_ PULONGLONG Minimum, _Out_ PULONGLONG Maximum, _Out_ PULONGLONG Length, _Out_ PULONGLONG Alignment)
 
NTSTATUS NTAPI ario_PackResource (_In_ PIO_RESOURCE_DESCRIPTOR Descriptor, _In_ ULONGLONG Start, _Out_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Resource)
 
NTSTATUS NTAPI ario_UnpackResource (_In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Resource, _Out_ PULONGLONG Start, _Out_ PULONGLONG Length)
 
INT32 NTAPI ario_ScoreRequirement (_In_ PIO_RESOURCE_DESCRIPTOR Descriptor)
 
NTSTATUS NTAPI ario_Initializer (IN PVOID Instance)
 
NTSTATUS NTAPI ario_Constructor (IN PVOID DeviceExtension, IN PVOID PciInterface, IN PVOID InterfaceData, IN USHORT Version, IN USHORT Size, IN PINTERFACE Interface)
 
VOID NTAPI ario_ApplyBrokenVideoHack (IN PPCI_FDO_EXTENSION FdoExtension)
 
NTSTATUS NTAPI armem_UnpackRequirement (_In_ PIO_RESOURCE_DESCRIPTOR Descriptor, _Out_ PULONGLONG Minimum, _Out_ PULONGLONG Maximum, _Out_ PULONGLONG Length, _Out_ PULONGLONG Alignment)
 
NTSTATUS NTAPI armem_PackResource (_In_ PIO_RESOURCE_DESCRIPTOR Descriptor, _In_ ULONGLONG Start, _Out_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Resource)
 
NTSTATUS NTAPI armem_UnpackResource (_In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Resource, _Out_ PULONGLONG Start, _Out_ PULONGLONG Length)
 
INT32 NTAPI armem_ScoreRequirement (_In_ PIO_RESOURCE_DESCRIPTOR Descriptor)
 
NTSTATUS NTAPI armem_Initializer (IN PVOID Instance)
 
NTSTATUS NTAPI armem_Constructor (IN PVOID DeviceExtension, IN PVOID PciInterface, IN PVOID InterfaceData, IN USHORT Version, IN USHORT Size, IN PINTERFACE Interface)
 

Variables

PCI_INTERFACE ArbiterInterfaceMemory
 
PCI_INTERFACE ArbiterInterfaceIo
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file ar_memio.c.

Function Documentation

◆ ario_ApplyBrokenVideoHack()

VOID NTAPI ario_ApplyBrokenVideoHack ( IN PPCI_FDO_EXTENSION  FdoExtension)

Definition at line 184 of file ar_memio.c.

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}
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
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#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_IS_ROOT_FDO(x)
Definition: pci.h:42
@ PciArb_Io
Definition: pci.h:135
@ FdoExtension
Definition: precomp.h:60
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
ARBITER_INSTANCE CommonInstance
Definition: pci.h:472
ARBITER_ORDERING_LIST ReservedList
Definition: arbiter.h:305
ARBITER_ORDERING_LIST OrderingList
Definition: arbiter.h:304
void * PVOID
Definition: typedefs.h:50

Referenced by PciApplyHacks().

◆ ario_Constructor()

NTSTATUS NTAPI ario_Constructor ( IN PVOID  DeviceExtension,
IN PVOID  PciInterface,
IN PVOID  InterfaceData,
IN USHORT  Version,
IN USHORT  Size,
IN PINTERFACE  Interface 
)

Definition at line 156 of file ar_memio.c.

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}
#define PAGED_CODE()
NTSTATUS NTAPI PciArbiterConstructor(_In_ PPCI_FDO_EXTENSION FdoExtension, _In_ PCI_SIGNATURE ArbiterType, _Out_ PARBITER_INTERFACE Interface)
Definition: arb_comn.c:200
struct _PCI_FDO_EXTENSION * PPCI_FDO_EXTENSION
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
#define STATUS_INVALID_PARAMETER_5
Definition: ntstatus.h:573
#define CmResourceTypePort
Definition: restypes.h:104
uint32_t ULONG_PTR
Definition: typedefs.h:65
_In_ UCXUSBDEVICE _In_ ULONG Interface
Definition: ucxusbdevice.h:428
_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

◆ ario_Initializer()

NTSTATUS NTAPI ario_Initializer ( IN PVOID  Instance)

Definition at line 119 of file ar_memio.c.

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}
NTSTATUS NTAPI ario_PackResource(_In_ PIO_RESOURCE_DESCRIPTOR Descriptor, _In_ ULONGLONG Start, _Out_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Resource)
Definition: ar_memio.c:67
INT32 NTAPI ario_ScoreRequirement(_In_ PIO_RESOURCE_DESCRIPTOR Descriptor)
Definition: ar_memio.c:98
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 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
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
PPCI_FDO_EXTENSION BusFdoExtension
Definition: pci.h:470
WCHAR InstanceName[24]
Definition: pci.h:471
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
PARB_PREPROCESS_ENTRY PreprocessEntry
Definition: arbiter.h:323
PARB_FIND_SUITABLE_RANGE FindSuitableRange
Definition: arbiter.h:326
PARB_PACK_RESOURCE PackResource
Definition: arbiter.h:311
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_WMI_INSTANCE_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_opt_ WDFWMIINSTANCE * Instance
Definition: wdfwmi.h:481

◆ ario_PackResource()

NTSTATUS NTAPI ario_PackResource ( _In_ PIO_RESOURCE_DESCRIPTOR  Descriptor,
_In_ ULONGLONG  Start,
_Out_ PCM_PARTIAL_RESOURCE_DESCRIPTOR  Resource 
)

Definition at line 67 of file ar_memio.c.

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}
static _Out_opt_ PULONGLONG Start
_Acquires_exclusive_lock_ Resource _Acquires_shared_lock_ Resource _Inout_ PERESOURCE Resource
Definition: cdprocs.h:843
#define STATUS_SUCCESS
Definition: shellext.h:65
int64_t LONGLONG
Definition: typedefs.h:68
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342

Referenced by ario_Initializer().

◆ ario_ScoreRequirement()

INT32 NTAPI ario_ScoreRequirement ( _In_ PIO_RESOURCE_DESCRIPTOR  Descriptor)

Definition at line 98 of file ar_memio.c.

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}
union Alignment_ Alignment
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
int32_t INT32
Definition: typedefs.h:58
uint64_t ULONGLONG
Definition: typedefs.h:67
#define MAXLONG
Definition: umtypes.h:116

Referenced by ario_Initializer().

◆ ario_UnpackRequirement()

NTSTATUS NTAPI ario_UnpackRequirement ( _In_ PIO_RESOURCE_DESCRIPTOR  Descriptor,
_Out_ PULONGLONG  Minimum,
_Out_ PULONGLONG  Maximum,
_Out_ PULONGLONG  Length,
_Out_ PULONGLONG  Alignment 
)

Definition at line 48 of file ar_memio.c.

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}

Referenced by ario_Initializer(), and ario_ScoreRequirement().

◆ ario_UnpackResource()

NTSTATUS NTAPI ario_UnpackResource ( _In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR  Resource,
_Out_ PULONGLONG  Start,
_Out_ PULONGLONG  Length 
)

Definition at line 84 of file ar_memio.c.

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}

Referenced by ario_Initializer().

◆ armem_Constructor()

NTSTATUS NTAPI armem_Constructor ( IN PVOID  DeviceExtension,
IN PVOID  PciInterface,
IN PVOID  InterfaceData,
IN USHORT  Version,
IN USHORT  Size,
IN PINTERFACE  Interface 
)

Definition at line 345 of file ar_memio.c.

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}
@ PciArb_Memory
Definition: pci.h:136
#define CmResourceTypeMemory
Definition: restypes.h:106

◆ armem_Initializer()

NTSTATUS NTAPI armem_Initializer ( IN PVOID  Instance)

Definition at line 308 of file ar_memio.c.

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}
NTSTATUS NTAPI armem_UnpackResource(_In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Resource, _Out_ PULONGLONG Start, _Out_ PULONGLONG Length)
Definition: ar_memio.c:270
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
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

◆ armem_PackResource()

NTSTATUS NTAPI armem_PackResource ( _In_ PIO_RESOURCE_DESCRIPTOR  Descriptor,
_In_ ULONGLONG  Start,
_Out_ PCM_PARTIAL_RESOURCE_DESCRIPTOR  Resource 
)

Definition at line 248 of file ar_memio.c.

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}
#define CmResourceTypeMemoryLarge
Definition: cmtypes.h:231

Referenced by armem_Initializer().

◆ armem_ScoreRequirement()

INT32 NTAPI armem_ScoreRequirement ( _In_ PIO_RESOURCE_DESCRIPTOR  Descriptor)

Definition at line 287 of file ar_memio.c.

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}

Referenced by armem_Initializer().

◆ armem_UnpackRequirement()

NTSTATUS NTAPI armem_UnpackRequirement ( _In_ PIO_RESOURCE_DESCRIPTOR  Descriptor,
_Out_ PULONGLONG  Minimum,
_Out_ PULONGLONG  Maximum,
_Out_ PULONGLONG  Length,
_Out_ PULONGLONG  Alignment 
)

Definition at line 225 of file ar_memio.c.

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}
ULONGLONG NTAPI RtlIoDecodeMemIoResource(_In_ PIO_RESOURCE_DESCRIPTOR Descriptor, _Out_opt_ PULONGLONG Alignment, _Out_opt_ PULONGLONG MinimumAddress, _Out_opt_ PULONGLONG MaximumAddress)
Definition: memres.c:79

Referenced by armem_Initializer(), and armem_ScoreRequirement().

◆ armem_UnpackResource()

NTSTATUS NTAPI armem_UnpackResource ( _In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR  Resource,
_Out_ PULONGLONG  Start,
_Out_ PULONGLONG  Length 
)

Definition at line 270 of file ar_memio.c.

273{
274 /* Read a previously packed memory resource back out */
275 if ((Resource->Type != CmResourceTypeMemory) &&
277 {
279 }
280
282 return STATUS_SUCCESS;
283}
ULONGLONG NTAPI RtlCmDecodeMemIoResource(_In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor, _Out_opt_ PULONGLONG Start)
Definition: memres.c:58

Referenced by armem_Initializer().

Variable Documentation

◆ ArbiterInterfaceIo

PCI_INTERFACE ArbiterInterfaceIo
Initial value:
=
{
&GUID_ARBITER_INTERFACE_STANDARD,
0,
0,
0,
}
NTSTATUS NTAPI ario_Initializer(IN PVOID Instance)
Definition: ar_memio.c:119
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
#define PCI_INTERFACE_FDO
Definition: pci.h:68
struct _ARBITER_INTERFACE ARBITER_INTERFACE

Definition at line 31 of file ar_memio.c.

◆ ArbiterInterfaceMemory

PCI_INTERFACE ArbiterInterfaceMemory
Initial value:
=
{
&GUID_ARBITER_INTERFACE_STANDARD,
0,
0,
0,
}
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 armem_Initializer(IN PVOID Instance)
Definition: ar_memio.c:308

Definition at line 18 of file ar_memio.c.