ReactOS 0.4.17-dev-806-gffa4164
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 181 of file ar_memio.c.

182{
183 PPCI_ARBITER_INSTANCE PciArbiter;
184 PARBITER_INSTANCE CommonInstance;
186
187 /* Only valid for root FDOs who are being applied the hack for the first time */
188 ASSERT(!FdoExtension->BrokenVideoHackApplied);
190
191 /* Find the I/O arbiter */
193 SecondaryExtension.Next,
194 PciArb_Io);
195 ASSERT(PciArbiter);
196 if (!PciArbiter) return;
197
198 /* Get the Arb instance */
199 CommonInstance = &PciArbiter->CommonInstance;
200
201 /* Free the two lists, enabling full VGA access */
204
205 /* Build the ordering for broken video PCI access */
207 L"Pci",
208 L"BrokenVideo",
209 NULL);
211 if (!NT_SUCCESS(Status))
212 {
213 DPRINT1("ario_ApplyBrokenVideoHack: ordering failed %X\n", Status);
214 }
215
216 /* Now the hack has been applied */
217 FdoExtension->BrokenVideoHackApplied = TRUE;
218}
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:32
@ PciArb_Io
Definition: pci.h:101
@ FdoExtension
Definition: precomp.h:48
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
ARBITER_INSTANCE CommonInstance
Definition: pci.h:413
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 153 of file ar_memio.c.

159{
161 PAGED_CODE();
162
163 UNREFERENCED_PARAMETER(PciInterface);
166
167 /* This one only arbitrates I/O ports */
168 if ((ULONG_PTR)InterfaceData != CmResourceTypePort)
169 {
171 }
172
173 /* Hand out the instance that was built for this bus */
175 PciArb_Io,
177}
#define PAGED_CODE()
NTSTATUS NTAPI PciArbiterConstructor(_In_ PPCI_FDO_EXTENSION FdoExtension, _In_ PCI_SIGNATURE ArbiterType, _Out_ PARBITER_INTERFACE Interface)
Definition: arb_comn.c:48
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
_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 Interface
Definition: wdffdo.h:465
_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 */
135
136 /* The rest of the engine, and the PCI assignment ordering, is generic */
138 FdoExtension->FunctionalDeviceObject,
140 Arbiter->InstanceName,
141 L"Pci",
142 NULL);
143 if (!NT_SUCCESS(Status))
144 {
145 DPRINT1("ario_Initializer: init arbiter returned %X\n", Status);
146 }
147
148 return Status;
149}
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 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:411
WCHAR InstanceName[24]
Definition: pci.h:412
PARB_UNPACK_RESOURCE UnpackResource
Definition: arbiter.h:312
PARB_SCORE_REQUIREMENT ScoreRequirement
Definition: arbiter.h:313
PARB_UNPACK_REQUIREMENT UnpackRequirement
Definition: arbiter.h:310
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 327 of file ar_memio.c.

333{
335 PAGED_CODE();
336
337 UNREFERENCED_PARAMETER(PciInterface);
340
341 /* This one only arbitrates device memory */
342 if ((ULONG_PTR)InterfaceData != CmResourceTypeMemory)
343 {
345 }
346
347 /* Hand out the instance that was built for this bus */
351}
@ PciArb_Memory
Definition: pci.h:102
#define CmResourceTypeMemory
Definition: restypes.h:106

◆ armem_Initializer()

NTSTATUS NTAPI armem_Initializer ( IN PVOID  Instance)

Definition at line 293 of file ar_memio.c.

294{
298 PAGED_CODE();
299
300 /* Start from a clean engine instance */
301 RtlZeroMemory(&Arbiter->CommonInstance, sizeof(Arbiter->CommonInstance));
302 FdoExtension = Arbiter->BusFdoExtension;
303
304 /* Teach the engine how to read and write memory descriptors */
309
310 /* The rest of the engine, and the PCI assignment ordering, is generic */
312 FdoExtension->FunctionalDeviceObject,
314 Arbiter->InstanceName,
315 L"Pci",
316 NULL);
317 if (!NT_SUCCESS(Status))
318 {
319 DPRINT1("armem_Initializer: init arbiter returned %X\n", Status);
320 }
321
322 return Status;
323}
NTSTATUS NTAPI armem_UnpackResource(_In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Resource, _Out_ PULONGLONG Start, _Out_ PULONGLONG Length)
Definition: ar_memio.c:258
INT32 NTAPI armem_ScoreRequirement(_In_ PIO_RESOURCE_DESCRIPTOR Descriptor)
Definition: ar_memio.c:272
NTSTATUS NTAPI armem_PackResource(_In_ PIO_RESOURCE_DESCRIPTOR Descriptor, _In_ ULONGLONG Start, _Out_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Resource)
Definition: ar_memio.c:241
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:222

◆ armem_PackResource()

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

Definition at line 241 of file ar_memio.c.

244{
245 /* Turn the placement the engine settled on back into a memory resource */
247
249 Resource->Flags = Descriptor->Flags;
250 Resource->ShareDisposition = Descriptor->ShareDisposition;
251 Resource->u.Memory.Start.QuadPart = (LONGLONG)Start;
252 Resource->u.Memory.Length = Descriptor->u.Memory.Length;
253 return STATUS_SUCCESS;
254}

Referenced by armem_Initializer().

◆ armem_ScoreRequirement()

INT32 NTAPI armem_ScoreRequirement ( _In_ PIO_RESOURCE_DESCRIPTOR  Descriptor)

Definition at line 272 of file ar_memio.c.

273{
274 ULONGLONG Minimum, Maximum, Length, Alignment;
275
276 /* A requirement this arbiter cannot read is treated as unsatisfiable */
278 &Minimum,
279 &Maximum,
280 &Length,
281 &Alignment)) ||
282 (Maximum < Minimum))
283 {
284 return -1;
285 }
286
287 if ((Maximum - Minimum) >= MAXLONG) return MAXLONG;
288 return (INT32)(Maximum - Minimum + 1);
289}

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 222 of file ar_memio.c.

227{
228 /* This arbiter is only ever handed device memory descriptors */
230
231 /* An alignment of zero would place the range nowhere, so make it one byte */
232 *Minimum = (ULONGLONG)Descriptor->u.Memory.MinimumAddress.QuadPart;
233 *Maximum = (ULONGLONG)Descriptor->u.Memory.MaximumAddress.QuadPart;
234 *Length = Descriptor->u.Memory.Length;
235 *Alignment = Descriptor->u.Memory.Alignment ? Descriptor->u.Memory.Alignment : 1;
236 return STATUS_SUCCESS;
237}

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 258 of file ar_memio.c.

261{
262 /* Read a previously packed memory resource back out */
264
265 *Start = (ULONGLONG)Resource->u.Memory.Start.QuadPart;
266 *Length = Resource->u.Memory.Length;
267 return STATUS_SUCCESS;
268}

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:153
#define PCI_INTERFACE_FDO
Definition: pci.h:58
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:327
NTSTATUS NTAPI armem_Initializer(IN PVOID Instance)
Definition: ar_memio.c:293

Definition at line 18 of file ar_memio.c.