ReactOS 0.4.17-dev-806-gffa4164
arbport.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for arbport.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define PORT_ALIAS_STRIDE_10_BIT   0x400
 
#define PORT_ALIAS_STRIDE_12_BIT   0x1000
 
#define PORT_MAX_ADDRESS   0xFFFF
 

Functions

ULONGLONG NTAPI RtlIoDecodeMemIoResource (_In_ PIO_RESOURCE_DESCRIPTOR Descriptor, _Out_opt_ PULONGLONG Alignment, _Out_opt_ PULONGLONG MinimumAddress, _Out_opt_ PULONGLONG MaximumAddress)
 
ULONGLONG NTAPI RtlCmDecodeMemIoResource (_In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor, _Out_opt_ PULONGLONG Start)
 
static NTSTATUS IopArbPortTranslateAddress (_In_ UCHAR SourceType, _In_ PHYSICAL_ADDRESS SourceAddress, _Out_ PPHYSICAL_ADDRESS TranslatedAddress, _Out_ PUCHAR TranslatedType)
 Translates one bus-relative address to a system-physical one on the ISA bus, and reports the space it landed in as a CM resource type.
 
static BOOLEAN IopArbPortGetNextAlias (_In_ USHORT DescriptorFlags, _In_ UINT64 LastAlias, _Out_ PUINT64 NextAlias)
 Walks the decode-alias chain of a port range: given the previous alias, or the granted range's start on the first call, produces the next one.
 
static NTSTATUS NTAPI IopArbPortUnpackRequirements (_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor, _Out_ PUINT64 OutMinimumAddress, _Out_ PUINT64 OutMaximumAddress, _Out_ PUINT64 OutLength, _Out_ PUINT64 OutAlignment)
 Extracts the placement window from one I/O port requirement. The UnpackRequirement callback of the Root Port arbiter.
 
static NTSTATUS NTAPI IopArbPortPackResource (_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor, _In_ UINT64 Start, _Out_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor)
 Materialises the arbiter's chosen placement as an assigned CM descriptor. The PackResource callback of the Root Port arbiter.
 
static NTSTATUS NTAPI IopArbPortUnpackResource (_In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor, _Out_ PUINT64 Start, _Out_ PUINT64 OutLength)
 Reads the placement back out of an already-assigned descriptor (a firmware boot configuration, typically) so the arbiter can mark that span occupied. The inverse of IopArbPortPackResource and the UnpackResource callback of the Root Port arbiter.
 
static INT32 NTAPI IopArbPortScoreRequirement (_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor)
 Scores how constrained a requirement is: the number of distinct aligned addresses it could be placed at inside its own window, ignoring what is already allocated. The ScoreRequirement callback of the Root Port arbiter.
 
static NTSTATUS NTAPI IopArbPortTranslateOrdering (_Out_ PIO_RESOURCE_DESCRIPTOR OutIoDescriptor, _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor)
 Translates one registry allocation-ordering window from the bus-relative addresses it is written in into the system-physical space the arbiter allocates in. The TranslateOrdering function of the Root Port arbiter.
 
static BOOLEAN NTAPI IopArbPortFindSuitableRange (_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
 The Root Port arbiter's FindSuitableRange: the engine search, incremented for a device asking to keep the ports the firmware already programmed it into.
 
static VOID NTAPI IopArbPortAddAllocation (_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
 The Root Port arbiter's AddAllocation: records the granted range in the tentative allocation, and behind it every port range a partially-decoding ISA card would shadow.
 
static VOID NTAPI IopArbPortBacktrackAllocation (_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
 The Root Port arbiter's BacktrackAllocation: the exact inverse of IopArbPortAddAllocation.
 
NTSTATUS NTAPI IopArbPortInitialize (VOID)
 Initialize the RootPortArbiter.
 

Variables

ARBITER_INSTANCE IopRootPortArbiter
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file arbport.c.

◆ PORT_ALIAS_STRIDE_10_BIT

#define PORT_ALIAS_STRIDE_10_BIT   0x400

Definition at line 37 of file arbport.c.

◆ PORT_ALIAS_STRIDE_12_BIT

#define PORT_ALIAS_STRIDE_12_BIT   0x1000

Definition at line 38 of file arbport.c.

◆ PORT_MAX_ADDRESS

#define PORT_MAX_ADDRESS   0xFFFF

Definition at line 39 of file arbport.c.

Function Documentation

◆ IopArbPortAddAllocation()

static VOID NTAPI IopArbPortAddAllocation ( _In_ PARBITER_INSTANCE  Arbiter,
_Inout_ PARBITER_ALLOCATION_STATE  ArbState 
)
static

The Root Port arbiter's AddAllocation: records the granted range in the tentative allocation, and behind it every port range a partially-decoding ISA card would shadow.

Parameters
[in]ArbiterThe Root Port arbiter instance.
[in,out]ArbStateThe allocation state carrying the granted Start and End. Alias ranges span the same width, belong to the same device, and are tagged ARBITER_RANGE_PORT_ALIAS.

Definition at line 455 of file arbport.c.

458{
459 PARBITER_ALTERNATIVE Alternative = ArbState->CurrentAlternative;
460 PVOID Owner = ArbState->Entry ? ArbState->Entry->PhysicalDeviceObject : NULL;
463 UINT64 Span;
464
465 PAGED_CODE();
466
467 if (Alternative != NULL && (Alternative->Flags & ARBITER_ALTERNATIVE_FLAG_SHARED))
469
470 RtlAddRange(Arbiter->PossibleAllocation,
471 ArbState->Start,
472 ArbState->End,
473 ArbState->RangeAttributes,
474 Flags,
475 NULL,
476 Owner);
477
478 if (Alternative == NULL)
479 return;
480
481 /* Alias the width actually granted, not the width asked for. */
482 Span = ArbState->End - ArbState->Start;
483
484 Alias = ArbState->Start;
485 while (IopArbPortGetNextAlias(Alternative->Descriptor->Flags, Alias, &Alias))
486 {
487 RtlAddRange(Arbiter->PossibleAllocation,
488 Alias,
489 Alias + Span,
490 ArbState->RangeAttributes | ARBITER_RANGE_PORT_ALIAS,
491 Flags,
492 NULL,
493 Owner);
494 }
495}
#define PAGED_CODE()
COMPILER_DEPENDENT_UINT64 UINT64
Definition: actypes.h:131
#define ARBITER_ALTERNATIVE_FLAG_SHARED
Definition: arbiter.h:31
#define ARBITER_RANGE_PORT_ALIAS
Definition: arbiter.h:55
static BOOLEAN IopArbPortGetNextAlias(_In_ USHORT DescriptorFlags, _In_ UINT64 LastAlias, _Out_ PUINT64 NextAlias)
Walks the decode-alias chain of a port range: given the previous alias, or the granted range's start ...
Definition: arbport.c:134
_In_ D3DDDI_VIDEO_PRESENT_TARGET_ID _In_ ULONG _In_ ULONG Flags
Definition: dispmprt.h:245
#define NULL
Definition: types.h:112
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL _Inout_ PULONG _Out_writes_bytes_to_opt_ SaclSize PACL _Inout_ PULONG _Out_writes_bytes_to_opt_ OwnerSize PSID Owner
Definition: rtlfuncs.h:1629
NTSYSAPI NTSTATUS NTAPI RtlAddRange(_Inout_ PRTL_RANGE_LIST RangeList, _In_ ULONGLONG Start, _In_ ULONGLONG End, _In_ UCHAR Attributes, _In_ ULONG Flags, _In_opt_ PVOID UserData, _In_opt_ PVOID Owner)
#define RTL_RANGE_LIST_ADD_IF_CONFLICT
Definition: rtltypes.h:81
#define RTL_RANGE_LIST_ADD_SHARED
Definition: rtltypes.h:82
PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: arbiter.h:77
uint32_t ULONG
Definition: typedefs.h:59

Referenced by IopArbPortInitialize().

◆ IopArbPortBacktrackAllocation()

static VOID NTAPI IopArbPortBacktrackAllocation ( _In_ PARBITER_INSTANCE  Arbiter,
_Inout_ PARBITER_ALLOCATION_STATE  ArbState 
)
static

The Root Port arbiter's BacktrackAllocation: the exact inverse of IopArbPortAddAllocation.

Parameters
[in]ArbiterThe Root Port arbiter instance.
[in,out]ArbStateThe allocation state whose placement is being withdrawn.
Remarks
The alias chain is regenerated and removed along with the granted range. Leaving the aliases behind would quietly wall off the port space for every placement the engine tries afterwards.

Definition at line 516 of file arbport.c.

519{
520 PARBITER_ALTERNATIVE Alternative = ArbState->CurrentAlternative;
521 PVOID Owner = ArbState->Entry ? ArbState->Entry->PhysicalDeviceObject : NULL;
523 UINT64 Span;
524
525 PAGED_CODE();
526
527 if (Alternative != NULL)
528 {
529 Span = ArbState->End - ArbState->Start;
530
531 Alias = ArbState->Start;
532 while (IopArbPortGetNextAlias(Alternative->Descriptor->Flags, Alias, &Alias))
533 {
534 RtlDeleteRange(Arbiter->PossibleAllocation, Alias, Alias + Span, Owner);
535 }
536 }
537
538 RtlDeleteRange(Arbiter->PossibleAllocation, ArbState->Start, ArbState->End, Owner);
539}
NTSYSAPI NTSTATUS NTAPI RtlDeleteRange(_Inout_ PRTL_RANGE_LIST RangeList, _In_ ULONGLONG Start, _In_ ULONGLONG End, _In_ PVOID Owner)

Referenced by IopArbPortInitialize().

◆ IopArbPortFindSuitableRange()

static BOOLEAN NTAPI IopArbPortFindSuitableRange ( _In_ PARBITER_INSTANCE  Arbiter,
_Inout_ PARBITER_ALLOCATION_STATE  ArbState 
)
static

The Root Port arbiter's FindSuitableRange: the engine search, incremented for a device asking to keep the ports the firmware already programmed it into.

Parameters
[in]ArbiterThe Root Port arbiter instance.
[in,out]ArbStateThe allocation state of the requirement being placed.
Returns
Returns TRUE if a placement was found, FALSE otherwise.
Remarks
A boot configuration is held in the range list as an ARBITER_RANGE_BOOT_ALLOCATED range and so reads as occupied. A request carrying ARBITER_FLAG_BOOT_CONFIG is precisely the one asking for that space back, so those ranges are made available to it. The engine already extends the same courtesy to legacy request sources.

Definition at line 426 of file arbport.c.

429{
430 PAGED_CODE();
431
432 if (ArbState->Entry != NULL && (ArbState->Entry->Flags & ARBITER_FLAG_BOOT_CONFIG))
433 ArbState->RangeAvailableAttributes |= ARBITER_RANGE_BOOT_ALLOCATED;
434
435 return ArbiterLibFindSuitableRange(Arbiter, ArbState);
436}
BOOLEAN NTAPI ArbiterLibFindSuitableRange(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
Finds a free range of the current candidate window in the arbiter's tentative allocation list.
Definition: range.c:717
#define ARBITER_RANGE_BOOT_ALLOCATED
Definition: arbiter.h:53
#define ARBITER_FLAG_BOOT_CONFIG
Definition: iotypes.h:4631

Referenced by IopArbPortInitialize().

◆ IopArbPortGetNextAlias()

static BOOLEAN IopArbPortGetNextAlias ( _In_ USHORT  DescriptorFlags,
_In_ UINT64  LastAlias,
_Out_ PUINT64  NextAlias 
)
static

Walks the decode-alias chain of a port range: given the previous alias, or the granted range's start on the first call, produces the next one.

Parameters
[in]DescriptorFlagsThe requirement's flags. Only 10-bit and 12-bit decode requirements alias; a full 16-bit decoder owns exactly what it asked for.
[in]LastAliasThe previous alias start, or the granted range's start.
[out]NextAliasReceives the next alias start.
Returns
Returns TRUE with the next alias, or FALSE once the card decodes fully or the next alias would leave I/O space.

Definition at line 134 of file arbport.c.

138{
139 UINT64 Next;
140
141 PAGED_CODE();
142
143 if (DescriptorFlags & CM_RESOURCE_PORT_10_BIT_DECODE)
144 Next = LastAlias + PORT_ALIAS_STRIDE_10_BIT;
145 else if (DescriptorFlags & CM_RESOURCE_PORT_12_BIT_DECODE)
146 Next = LastAlias + PORT_ALIAS_STRIDE_12_BIT;
147 else
148 return FALSE;
149
151 return FALSE;
152
153 *NextAlias = Next;
154 return TRUE;
155}
#define PORT_MAX_ADDRESS
Definition: arbport.c:39
#define PORT_ALIAS_STRIDE_10_BIT
Definition: arbport.c:37
#define PORT_ALIAS_STRIDE_12_BIT
Definition: arbport.c:38
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CM_RESOURCE_PORT_12_BIT_DECODE
Definition: cmtypes.h:111
#define CM_RESOURCE_PORT_10_BIT_DECODE
Definition: cmtypes.h:110
STDMETHOD() Next(THIS_ ULONG celt, IAssociationElement *pElement, ULONG *pceltFetched) PURE

Referenced by IopArbPortAddAllocation(), and IopArbPortBacktrackAllocation().

◆ IopArbPortInitialize()

NTSTATUS NTAPI IopArbPortInitialize ( VOID  )

Initialize the RootPortArbiter.

The root port arbiter owns the 16-bit x86 I/O port space and hands out sub-ranges of it. It is the fallback for every device whose ports no closer arbiter claims: root-enumerated and HAL-reported legacy hardware above all, which is also the hardware that partially decodes its address lines and so needs the aliasing this arbiter adds.

Returns
NTSTATUS
Return values
STATUS_SUCCESS
STATUS_UNSUCCESSFUL
STATUS_INSUFFICIENT_RESOURCES

Definition at line 557 of file arbport.c.

558{
560
561 PAGED_CODE();
562
563 IopRootPortArbiter.Name = L"RootPort";
568
569 /* Port-specific placement: boot-config leniency and ISA decode aliasing. */
573
575 NULL,
578 L"Root",
580 if (!NT_SUCCESS(Status))
581 {
582 DPRINT1("IopArbPortInitialize: Failed with %X\n", Status);
583 }
584
585 return Status;
586}
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
static VOID NTAPI IopArbPortAddAllocation(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
The Root Port arbiter's AddAllocation: records the granted range in the tentative allocation,...
Definition: arbport.c:455
static VOID NTAPI IopArbPortBacktrackAllocation(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
The Root Port arbiter's BacktrackAllocation: the exact inverse of IopArbPortAddAllocation.
Definition: arbport.c:516
static NTSTATUS NTAPI IopArbPortPackResource(_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor, _In_ UINT64 Start, _Out_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor)
Materialises the arbiter's chosen placement as an assigned CM descriptor. The PackResource callback o...
Definition: arbport.c:227
static NTSTATUS NTAPI IopArbPortUnpackResource(_In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor, _Out_ PUINT64 Start, _Out_ PUINT64 OutLength)
Reads the placement back out of an already-assigned descriptor (a firmware boot configuration,...
Definition: arbport.c:266
static NTSTATUS NTAPI IopArbPortTranslateOrdering(_Out_ PIO_RESOURCE_DESCRIPTOR OutIoDescriptor, _In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor)
Translates one registry allocation-ordering window from the bus-relative addresses it is written in i...
Definition: arbport.c:358
ARBITER_INSTANCE IopRootPortArbiter
Definition: pnpinit.c:27
static NTSTATUS NTAPI IopArbPortUnpackRequirements(_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor, _Out_ PUINT64 OutMinimumAddress, _Out_ PUINT64 OutMaximumAddress, _Out_ PUINT64 OutLength, _Out_ PUINT64 OutAlignment)
Extracts the placement window from one I/O port requirement. The UnpackRequirement callback of the Ro...
Definition: arbport.c:185
static INT32 NTAPI IopArbPortScoreRequirement(_In_ PIO_RESOURCE_DESCRIPTOR IoDescriptor)
Scores how constrained a requirement is: the number of distinct aligned addresses it could be placed ...
Definition: arbport.c:302
static BOOLEAN NTAPI IopArbPortFindSuitableRange(_In_ PARBITER_INSTANCE Arbiter, _Inout_ PARBITER_ALLOCATION_STATE ArbState)
The Root Port arbiter's FindSuitableRange: the engine search, incremented for a device asking to keep...
Definition: arbport.c:426
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define L(x)
Definition: resources.c:13
Status
Definition: gdiplustypes.h:24
#define CmResourceTypePort
Definition: restypes.h:104
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_FIND_SUITABLE_RANGE FindSuitableRange
Definition: arbiter.h:326
PARB_ADD_ALLOCATION AddAllocation
Definition: arbiter.h:327
PARB_PACK_RESOURCE PackResource
Definition: arbiter.h:311
PARB_BACKTRACK_ALLOCATION BacktrackAllocation
Definition: arbiter.h:328

Referenced by IopInitializeArbiters().

◆ IopArbPortPackResource()

static NTSTATUS NTAPI IopArbPortPackResource ( _In_ PIO_RESOURCE_DESCRIPTOR  IoDescriptor,
_In_ UINT64  Start,
_Out_ PCM_PARTIAL_RESOURCE_DESCRIPTOR  CmDescriptor 
)
static

Materialises the arbiter's chosen placement as an assigned CM descriptor. The PackResource callback of the Root Port arbiter.

Parameters
[in]IoDescriptorThe requirement the placement satisfies. Type, Flags and ShareDisposition come across unchanged, and so does the Length, still in the encoding its Flags describe.
[in]StartThe port address the arbiter settled on.
[out]CmDescriptorReceives the assigned descriptor.
Returns
Returns STATUS_SUCCESS.

Definition at line 227 of file arbport.c.

231{
232 PAGED_CODE();
233
234 CmDescriptor->Type = IoDescriptor->Type;
235 CmDescriptor->Flags = IoDescriptor->Flags;
236 CmDescriptor->ShareDisposition = IoDescriptor->ShareDisposition;
237
238 CmDescriptor->u.Generic.Start.QuadPart = Start;
239 CmDescriptor->u.Generic.Length = IoDescriptor->u.Generic.Length;
240
241 return STATUS_SUCCESS;
242}
static _Out_opt_ PULONGLONG Start
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by IopArbPortInitialize().

◆ IopArbPortScoreRequirement()

static INT32 NTAPI IopArbPortScoreRequirement ( _In_ PIO_RESOURCE_DESCRIPTOR  IoDescriptor)
static

Scores how constrained a requirement is: the number of distinct aligned addresses it could be placed at inside its own window, ignoring what is already allocated. The ScoreRequirement callback of the Root Port arbiter.

Parameters
[in]IoDescriptorThe requirement to score.
Returns
Returns the placement count, saturated to MAXLONG, or -1 for a window that cannot hold the requirement at all - which the engine treats as a bad configuration and fails the arbitration on.
Remarks
The engine places the most constrained device (the lowest score) first, so the devices with real freedom of movement are left to absorb whatever space is still available.

Definition at line 302 of file arbport.c.

304{
306 UINT64 Minimum, Maximum, AlignedMinimum;
307 UINT64 Span, Placements;
308
309 PAGED_CODE();
310
311 Length = RtlIoDecodeMemIoResource(IoDescriptor, &Alignment, &Minimum, &Maximum);
312
313 if (Alignment == 0)
314 Alignment = 1;
315
316 /* Round the window's base up to the first address the device can sit at. */
317 AlignedMinimum = (Minimum + Alignment - 1) & ~(Alignment - 1);
318 if (AlignedMinimum < Minimum || AlignedMinimum > Maximum)
319 return -1;
320
321 /* Count in addresses above the base, so a full-width window cannot overflow. */
322 Span = Maximum - AlignedMinimum;
323
324 if (Length != 0)
325 {
326 if (Length - 1 > Span)
327 return -1;
328
329 Span -= Length - 1;
330 }
331
332 Placements = Span / Alignment + 1;
333 return (INT32)min(Placements, MAXLONG);
334}
ULONGLONG NTAPI RtlIoDecodeMemIoResource(_In_ PIO_RESOURCE_DESCRIPTOR Descriptor, _Out_opt_ PULONGLONG Alignment, _Out_opt_ PULONGLONG MinimumAddress, _Out_opt_ PULONGLONG MaximumAddress)
Definition: memres.c:79
union Alignment_ Alignment
#define min(a, b)
Definition: monoChain.cc:55
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
int32_t INT32
Definition: typedefs.h:58
#define MAXLONG
Definition: umtypes.h:116

Referenced by IopArbPortInitialize().

◆ IopArbPortTranslateAddress()

static NTSTATUS IopArbPortTranslateAddress ( _In_ UCHAR  SourceType,
_In_ PHYSICAL_ADDRESS  SourceAddress,
_Out_ PPHYSICAL_ADDRESS  TranslatedAddress,
_Out_ PUCHAR  TranslatedType 
)
static

Translates one bus-relative address to a system-physical one on the ISA bus, and reports the space it landed in as a CM resource type.

Parameters
[in]SourceTypeThe CM resource type of the address being translated.
[in]SourceAddressThe bus-relative address.
[out]TranslatedAddressReceives the system-physical address.
[out]TranslatedTypeReceives the post-translation resource type. A HAL may map one space onto another (memory-mapped I/O ports being the usual case) so the type is taken from the space the translation actually returned rather than assumed, e.g IOPorts, MMIO, etc.
Returns
Returns STATUS_SUCCESS, STATUS_INVALID_PARAMETER for a resource type that carries no address or for an address space the HAL is not expected to report, or STATUS_UNSUCCESSFUL when the HAL declines the translation.

Definition at line 72 of file arbport.c.

77{
79
80 PAGED_CODE();
81
82 if (SourceType == CmResourceTypePort)
83 AddressSpace = 1; /* I/O port space */
84 else if (SourceType == CmResourceTypeMemory || SourceType == CmResourceTypeMemoryLarge)
85 AddressSpace = 0; /* System memory */
86 else
88
91
92 /* The HAL reports back the space it landed in; only these two are expected. */
93 if (AddressSpace == 1)
94 {
95 *TranslatedType = CmResourceTypePort;
96 }
97 else if (AddressSpace == 0)
98 {
99 *TranslatedType = (SourceType == CmResourceTypeMemoryLarge)
102 }
103 else
104 {
106 }
107
108 return STATUS_SUCCESS;
109}
BOOLEAN NTAPI HalTranslateBusAddress(IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber, IN PHYSICAL_ADDRESS BusAddress, IN OUT PULONG AddressSpace, OUT PPHYSICAL_ADDRESS TranslatedAddress)
Definition: bus.c:140
#define CmResourceTypeMemory
Definition: restypes.h:106
@ Isa
Definition: restypes.h:122
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define CmResourceTypeMemoryLarge
Definition: cmtypes.h:231
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG _Out_ PPHYSICAL_ADDRESS TranslatedAddress
Definition: iofuncs.h:2275
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2274
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS SourceAddress
Definition: iotypes.h:1127

Referenced by IopArbPortTranslateOrdering().

◆ IopArbPortTranslateOrdering()

static NTSTATUS NTAPI IopArbPortTranslateOrdering ( _Out_ PIO_RESOURCE_DESCRIPTOR  OutIoDescriptor,
_In_ PIO_RESOURCE_DESCRIPTOR  IoDescriptor 
)
static

Translates one registry allocation-ordering window from the bus-relative addresses it is written in into the system-physical space the arbiter allocates in. The TranslateOrdering function of the Root Port arbiter.

Parameters
[out]OutIoDescriptorReceives the translated copy. An entry whose endpoints cannot both be translated is marked CmResourceTypeNull for the ordering reader to drop; otherwise it takes the translated type.
[in]IoDescriptorThe ordering window. A descriptor that carries no address passes through untouched.
Returns
Returns STATUS_SUCCESS.

Definition at line 358 of file arbport.c.

361{
362 UCHAR SourceType;
363 UCHAR MinimumType;
365
366 PAGED_CODE();
367
368 *OutIoDescriptor = *IoDescriptor;
369
370 SourceType = IoDescriptor->Type;
371 if (SourceType != CmResourceTypePort &&
372 SourceType != CmResourceTypeMemory &&
373 SourceType != CmResourceTypeMemoryLarge)
374 {
375 return STATUS_SUCCESS;
376 }
377
378 MinimumType = SourceType;
379 MaximumType = SourceType;
380
382 IoDescriptor->u.Generic.MinimumAddress,
383 &OutIoDescriptor->u.Generic.MinimumAddress,
384 &MinimumType)) ||
386 IoDescriptor->u.Generic.MaximumAddress,
387 &OutIoDescriptor->u.Generic.MaximumAddress,
388 &MaximumType)))
389 {
390 OutIoDescriptor->Type = CmResourceTypeNull;
391 }
392 else
393 {
394 OutIoDescriptor->Type = MaximumType;
395 }
396
397 return STATUS_SUCCESS;
398}
static NTSTATUS IopArbPortTranslateAddress(_In_ UCHAR SourceType, _In_ PHYSICAL_ADDRESS SourceAddress, _Out_ PPHYSICAL_ADDRESS TranslatedAddress, _Out_ PUCHAR TranslatedType)
Translates one bus-relative address to a system-physical one on the ISA bus, and reports the space it...
Definition: arbport.c:72
#define CmResourceTypeNull
Definition: restypes.h:103
@ MaximumType
Definition: arc.h:154
unsigned char UCHAR
Definition: typedefs.h:53

Referenced by IopArbPortInitialize().

◆ IopArbPortUnpackRequirements()

static NTSTATUS NTAPI IopArbPortUnpackRequirements ( _In_ PIO_RESOURCE_DESCRIPTOR  IoDescriptor,
_Out_ PUINT64  OutMinimumAddress,
_Out_ PUINT64  OutMaximumAddress,
_Out_ PUINT64  OutLength,
_Out_ PUINT64  OutAlignment 
)
static

Extracts the placement window from one I/O port requirement. The UnpackRequirement callback of the Root Port arbiter.

Parameters
[in]IoDescriptorThe requirement to decode.
[out]OutMinimumAddressReceives the lowest port address the requirement accepts.
[out]OutMaximumAddressReceives the highest port address the requirement accepts.
[out]OutLengthReceives the number of consecutive ports wanted.
[out]OutAlignmentReceives the requirement's alignment; a zero alignment means the device does not care and is normalized to byte alignment, since the placement arithmetic divides by it.
Returns
Returns STATUS_SUCCESS.

Definition at line 185 of file arbport.c.

191{
192 PAGED_CODE();
193
194 *OutLength = RtlIoDecodeMemIoResource(IoDescriptor,
195 OutAlignment,
196 OutMinimumAddress,
197 OutMaximumAddress);
198
199 if (*OutAlignment == 0)
200 *OutAlignment = 1;
201
202 return STATUS_SUCCESS;
203}

Referenced by IopArbPortInitialize().

◆ IopArbPortUnpackResource()

static NTSTATUS NTAPI IopArbPortUnpackResource ( _In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR  CmDescriptor,
_Out_ PUINT64  Start,
_Out_ PUINT64  OutLength 
)
static

Reads the placement back out of an already-assigned descriptor (a firmware boot configuration, typically) so the arbiter can mark that span occupied. The inverse of IopArbPortPackResource and the UnpackResource callback of the Root Port arbiter.

Parameters
[in]CmDescriptorThe assigned descriptor to decode.
[out]StartReceives the assigned port address.
[out]OutLengthReceives the assigned length.
Returns
Returns STATUS_SUCCESS.

Definition at line 266 of file arbport.c.

270{
271 PAGED_CODE();
272
273 *OutLength = RtlCmDecodeMemIoResource(CmDescriptor, Start);
274
275 return STATUS_SUCCESS;
276}
ULONGLONG NTAPI RtlCmDecodeMemIoResource(_In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor, _Out_opt_ PULONGLONG Start)
Definition: memres.c:58

Referenced by IopArbPortInitialize().

◆ RtlCmDecodeMemIoResource()

ULONGLONG NTAPI RtlCmDecodeMemIoResource ( _In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR  Descriptor,
_Out_opt_ PULONGLONG  Start 
)

Definition at line 58 of file memres.c.

61{
62 if (Start != NULL)
63 *Start = Descriptor->u.Generic.Start.QuadPart;
64
66 Descriptor->Flags,
67 Descriptor->u.Generic.Length);
68}
static ULONGLONG RtlpDecodeMemIoValue(_In_ UCHAR Type, _In_ USHORT Flags, _In_ ULONG Encoded)
Definition: memres.c:30
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342

Referenced by IopArbPortUnpackResource().

◆ RtlIoDecodeMemIoResource()

ULONGLONG NTAPI RtlIoDecodeMemIoResource ( _In_ PIO_RESOURCE_DESCRIPTOR  Descriptor,
_Out_opt_ PULONGLONG  Alignment,
_Out_opt_ PULONGLONG  MinimumAddress,
_Out_opt_ PULONGLONG  MaximumAddress 
)

Definition at line 79 of file memres.c.

84{
85 if (Alignment != NULL)
86 {
88 Descriptor->Flags,
89 Descriptor->u.Generic.Alignment);
90 }
91
92 if (MinimumAddress != NULL)
93 *MinimumAddress = Descriptor->u.Generic.MinimumAddress.QuadPart;
94
95 if (MaximumAddress != NULL)
96 *MaximumAddress = Descriptor->u.Generic.MaximumAddress.QuadPart;
97
99 Descriptor->Flags,
100 Descriptor->u.Generic.Length);
101}
static _Out_opt_ PULONGLONG _Out_opt_ PULONGLONG MinimumAddress
static _Out_opt_ PULONGLONG _Out_opt_ PULONGLONG _Out_opt_ PULONGLONG MaximumAddress

Referenced by IopArbPortScoreRequirement(), and IopArbPortUnpackRequirements().

Variable Documentation

◆ IopRootPortArbiter

ARBITER_INSTANCE IopRootPortArbiter
extern

Definition at line 27 of file pnpinit.c.

Referenced by IopArbPortInitialize().