ReactOS  0.4.15-dev-4616-g17e0e44
usage.c File Reference
#include <hal.h>
#include <debug.h>
Include dependency graph for usage.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI HalpGetResourceSortValue (IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor, OUT PULONG Scale, OUT PLARGE_INTEGER Value)
 
VOID NTAPI HalpBuildPartialFromIdt (IN ULONG Entry, IN PCM_PARTIAL_RESOURCE_DESCRIPTOR RawDescriptor, IN PCM_PARTIAL_RESOURCE_DESCRIPTOR TranslatedDescriptor)
 
VOID NTAPI HalpBuildPartialFromAddress (IN INTERFACE_TYPE Interface, IN PADDRESS_USAGE CurrentAddress, IN ULONG Element, IN PCM_PARTIAL_RESOURCE_DESCRIPTOR RawDescriptor, IN PCM_PARTIAL_RESOURCE_DESCRIPTOR TranslatedDescriptor)
 
VOID NTAPI HalpReportResourceUsage (IN PUNICODE_STRING HalName, IN INTERFACE_TYPE InterfaceType)
 
VOID NTAPI HalpRegisterVector (IN UCHAR Flags, IN ULONG BusVector, IN ULONG SystemVector, IN KIRQL Irql)
 
VOID NTAPI HalpEnableInterruptHandler (IN UCHAR Flags, IN ULONG BusVector, IN ULONG SystemVector, IN KIRQL Irql, IN PVOID Handler, IN KINTERRUPT_MODE Mode)
 
VOID NTAPI HalpGetNMICrashFlag (VOID)
 

Variables

BOOLEAN HalpGetInfoFromACPI
 
BOOLEAN HalpNMIDumpFlag
 
PUCHAR KdComPortInUse
 
PADDRESS_USAGE HalpAddressUsageList
 
IDTUsageFlags HalpIDTUsageFlags [MAXIMUM_IDTVECTOR+1]
 
IDTUsage HalpIDTUsage [MAXIMUM_IDTVECTOR+1]
 
USHORT HalpComPortIrqMapping [5][2]
 
ADDRESS_USAGE HalpComIoSpace
 
ADDRESS_USAGE HalpDefaultIoSpace
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file usage.c.

Function Documentation

◆ HalpBuildPartialFromAddress()

VOID NTAPI HalpBuildPartialFromAddress ( IN INTERFACE_TYPE  Interface,
IN PADDRESS_USAGE  CurrentAddress,
IN ULONG  Element,
IN PCM_PARTIAL_RESOURCE_DESCRIPTOR  RawDescriptor,
IN PCM_PARTIAL_RESOURCE_DESCRIPTOR  TranslatedDescriptor 
)

Definition at line 200 of file usage.c.

205 {
207 
208  /* Set the type and make it exclusive */
209  RawDescriptor->Type = CurrentAddress->Type;
210  RawDescriptor->ShareDisposition = CmResourceShareDriverExclusive;
211 
212  /* Check what this is */
213  if (RawDescriptor->Type == CmResourceTypePort)
214  {
215  /* Write out port data */
216  AddressSpace = 1;
217  RawDescriptor->Flags = CM_RESOURCE_PORT_IO;
218  RawDescriptor->u.Port.Start.HighPart = 0;
219  RawDescriptor->u.Port.Start.LowPart = CurrentAddress->Element[Element].Start;
220  RawDescriptor->u.Port.Length = CurrentAddress->Element[Element].Length;
221 
222  /* Determine if 16-bit port addresses are allowed */
223  RawDescriptor->Flags |= HalpIs16BitPortDecodeSupported();
224  }
225  else
226  {
227  /* Write out memory data */
228  AddressSpace = 0;
229  RawDescriptor->Flags = (CurrentAddress->Flags & IDT_READ_ONLY) ?
232  RawDescriptor->u.Memory.Start.HighPart = 0;
233  RawDescriptor->u.Memory.Start.LowPart = CurrentAddress->Element[Element].Start;
234  RawDescriptor->u.Memory.Length = CurrentAddress->Element[Element].Length;
235  }
236 
237  /* Make an identical copy to begin with */
238  RtlCopyMemory(TranslatedDescriptor, RawDescriptor, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
239 
240  /* Check what this is */
241  if (RawDescriptor->Type == CmResourceTypePort)
242  {
243  /* Translate the port */
245  0,
246  RawDescriptor->u.Port.Start,
247  &AddressSpace,
248  &TranslatedDescriptor->u.Port.Start);
249 
250  /* If it turns out this is memory once translated, flag it */
251  if (AddressSpace == 0) TranslatedDescriptor->Flags = CM_RESOURCE_PORT_MEMORY;
252 
253  }
254  else
255  {
256  /* Translate the memory */
258  0,
259  RawDescriptor->u.Memory.Start,
260  &AddressSpace,
261  &TranslatedDescriptor->u.Memory.Start);
262  }
263 }
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2272
#define CM_RESOURCE_MEMORY_READ_WRITE
Definition: cmtypes.h:120
#define CmResourceTypePort
Definition: hwresource.cpp:123
#define CM_RESOURCE_MEMORY_READ_ONLY
Definition: cmtypes.h:121
struct _LARGE_INTEGER::@2249 u
ULONG NTAPI HalpIs16BitPortDecodeSupported(VOID)
Definition: halacpi.c:961
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 CM_RESOURCE_PORT_MEMORY
Definition: cmtypes.h:108
IN PVOID IN PVOID IN USHORT IN USHORT IN PINTERFACE Interface
Definition: pci.h:361
#define CM_RESOURCE_PORT_IO
Definition: cmtypes.h:109
unsigned int ULONG
Definition: retypes.h:1
#define IDT_READ_ONLY
Definition: halp.h:52
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263

Referenced by HalpReportResourceUsage().

◆ HalpBuildPartialFromIdt()

VOID NTAPI HalpBuildPartialFromIdt ( IN ULONG  Entry,
IN PCM_PARTIAL_RESOURCE_DESCRIPTOR  RawDescriptor,
IN PCM_PARTIAL_RESOURCE_DESCRIPTOR  TranslatedDescriptor 
)

Definition at line 162 of file usage.c.

165 {
166  /* Exclusive interrupt entry */
167  RawDescriptor->Type = CmResourceTypeInterrupt;
168  RawDescriptor->ShareDisposition = CmResourceShareDriverExclusive;
169 
170  /* Check the interrupt type */
172  {
173  /* Latched */
174  RawDescriptor->Flags = CM_RESOURCE_INTERRUPT_LATCHED;
175  }
176  else
177  {
178  /* Level */
179  RawDescriptor->Flags = CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE;
180  }
181 
182  /* Get vector and level from IDT usage */
183  RawDescriptor->u.Interrupt.Vector = HalpIDTUsage[Entry].BusReleativeVector;
184  RawDescriptor->u.Interrupt.Level = HalpIDTUsage[Entry].BusReleativeVector;
185 
186  /* Affinity is all the CPUs */
187  RawDescriptor->u.Interrupt.Affinity = HalpActiveProcessors;
188 
189  /* The translated copy is identical */
190  RtlCopyMemory(TranslatedDescriptor, RawDescriptor, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
191 
192  /* But the vector and IRQL must be set correctly */
193  TranslatedDescriptor->u.Interrupt.Vector = Entry;
194  TranslatedDescriptor->u.Interrupt.Level = HalpIDTUsage[Entry].Irql;
195 }
LONG HalpActiveProcessors
Definition: processor.c:17
struct _Entry Entry
Definition: kefuncs.h:629
IDTUsage HalpIDTUsage[256]
Definition: usage.c:20
IDTUsageFlags HalpIDTUsageFlags[256]
Definition: usage.c:19
UCHAR BusReleativeVector
Definition: halp.h:32
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
KIRQL Irql
Definition: halp.h:31
#define CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE
Definition: cmtypes.h:143
#define CmResourceTypeInterrupt
Definition: hwresource.cpp:124
#define IDT_LATCHED
Definition: halp.h:20
#define CM_RESOURCE_INTERRUPT_LATCHED
Definition: cmtypes.h:144
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
base of all file and directory entries
Definition: entries.h:82

Referenced by HalpReportResourceUsage().

◆ HalpEnableInterruptHandler()

VOID NTAPI HalpEnableInterruptHandler ( IN UCHAR  Flags,
IN ULONG  BusVector,
IN ULONG  SystemVector,
IN KIRQL  Irql,
IN PVOID  Handler,
IN KINTERRUPT_MODE  Mode 
)

Definition at line 572 of file usage.c.

578 {
579  /* Set the IDT_LATCHED flag for latched interrupts */
580  if (Mode == Latched) Flags |= IDT_LATCHED;
581 
582  /* Register the vector */
583  HalpRegisterVector(Flags, BusVector, SystemVector, Irql);
584 
585  /* Connect the interrupt */
586  KeRegisterInterruptHandler(SystemVector, Handler);
587 
588  /* Enable the interrupt */
589  HalEnableSystemInterrupt(SystemVector, Irql, Mode);
590 }
BOOLEAN NTAPI HalEnableSystemInterrupt(IN ULONG Vector, IN KIRQL Irql, IN KINTERRUPT_MODE InterruptMode)
Definition: pic.c:295
_In_ ULONG Mode
Definition: hubbusif.h:303
VOID NTAPI HalpRegisterVector(IN UCHAR Flags, IN ULONG BusVector, IN ULONG SystemVector, IN KIRQL Irql)
Definition: usage.c:34
_Out_ PKIRQL Irql
Definition: csq.h:179
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER Handler
Definition: acpixf.h:668
FORCEINLINE VOID KeRegisterInterruptHandler(IN ULONG Vector, IN PVOID Handler)
Definition: ke.h:297
#define IDT_LATCHED
Definition: halp.h:20

◆ HalpGetNMICrashFlag()

VOID NTAPI HalpGetNMICrashFlag ( VOID  )

Definition at line 595 of file usage.c.

596 {
598  UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\CrashControl");
601  HANDLE Handle;
603  KEY_VALUE_PARTIAL_INFORMATION KeyValueInformation;
604 
605  /* Set default */
606  HalpNMIDumpFlag = 0;
607 
608  /* Initialize attributes */
610  &KeyName,
612  NULL,
613  NULL);
614 
615  /* Open crash key */
616  Status = ZwOpenKey(&Handle, KEY_READ, &ObjectAttributes);
617  if (NT_SUCCESS(Status))
618  {
619  /* Query key value */
620  RtlInitUnicodeString(&ValueName, L"NMICrashDump");
621  Status = ZwQueryValueKey(Handle,
622  &ValueName,
624  &KeyValueInformation,
625  sizeof(KeyValueInformation),
626  &ResultLength);
627  if (NT_SUCCESS(Status))
628  {
629  /* Check for valid data */
631  {
632  /* Read the flag */
633  HalpNMIDumpFlag = KeyValueInformation.Data[0];
634  }
635  }
636 
637  /* We're done */
638  ZwClose(Handle);
639  }
640 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define KEY_READ
Definition: nt_native.h:1023
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
#define L(x)
Definition: ntvdm.h:50
BOOLEAN HalpNMIDumpFlag
Definition: usage.c:18
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2697
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:240
#define NULL
Definition: types.h:112
_In_ HANDLE Handle
Definition: extypes.h:390
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3776
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by HalpInitializePciBus().

◆ HalpGetResourceSortValue()

VOID NTAPI HalpGetResourceSortValue ( IN PCM_PARTIAL_RESOURCE_DESCRIPTOR  Descriptor,
OUT PULONG  Scale,
OUT PLARGE_INTEGER  Value 
)

Definition at line 122 of file usage.c.

125 {
126  /* Sorting depends on resource type */
127  switch (Descriptor->Type)
128  {
130 
131  /* Interrupt goes by level */
132  *Scale = 0;
133  *Value = RtlConvertUlongToLargeInteger(Descriptor->u.Interrupt.Level);
134  break;
135 
136  case CmResourceTypePort:
137 
138  /* Port goes by port address */
139  *Scale = 1;
140  *Value = Descriptor->u.Port.Start;
141  break;
142 
144 
145  /* Memory goes by base address */
146  *Scale = 2;
147  *Value = Descriptor->u.Memory.Start;
148  break;
149 
150  default:
151 
152  /* Anything else */
153  *Scale = 4;
155  break;
156  }
157 }
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:339
#define CmResourceTypePort
Definition: hwresource.cpp:123
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406
NTSYSAPI ULONGLONG WINAPI RtlConvertUlongToLargeInteger(ULONG)
Definition: largeint.c:47
#define CmResourceTypeInterrupt
Definition: hwresource.cpp:124
#define CmResourceTypeMemory
Definition: hwresource.cpp:125

Referenced by HalpReportResourceUsage().

◆ HalpRegisterVector()

VOID NTAPI HalpRegisterVector ( IN UCHAR  Flags,
IN ULONG  BusVector,
IN ULONG  SystemVector,
IN KIRQL  Irql 
)

Definition at line 555 of file usage.c.

559 {
560  /* Save the vector flags */
561  HalpIDTUsageFlags[SystemVector].Flags = Flags;
562 
563  /* Save the vector data */
564  HalpIDTUsage[SystemVector].Irql = Irql;
565  HalpIDTUsage[SystemVector].BusReleativeVector = (UCHAR)BusVector;
566 }
IDTUsage HalpIDTUsage[256]
Definition: usage.c:20
IDTUsageFlags HalpIDTUsageFlags[256]
Definition: usage.c:19
_Out_ PKIRQL Irql
Definition: csq.h:179
UCHAR BusReleativeVector
Definition: halp.h:32
UCHAR Flags
Definition: halp.h:26
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
KIRQL Irql
Definition: halp.h:31
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ HalpReportResourceUsage()

VOID NTAPI HalpReportResourceUsage ( IN PUNICODE_STRING  HalName,
IN INTERFACE_TYPE  InterfaceType 
)

Definition at line 268 of file usage.c.

270 {
271  PCM_RESOURCE_LIST RawList, TranslatedList;
272  PCM_FULL_RESOURCE_DESCRIPTOR RawFull, TranslatedFull;
273  PCM_PARTIAL_RESOURCE_DESCRIPTOR CurrentRaw, CurrentTranslated, SortedRaw, SortedTranslated;
274  CM_PARTIAL_RESOURCE_DESCRIPTOR RawPartial, TranslatedPartial;
275  PCM_PARTIAL_RESOURCE_LIST RawPartialList = NULL, TranslatedPartialList = NULL;
277  ULONG i, j, k, ListSize, Count, Port, Element, CurrentScale, SortScale, ReportType, FlagMatch;
278  ADDRESS_USAGE *CurrentAddress;
279  LARGE_INTEGER CurrentSortValue, SortValue;
280  DbgPrint("%wZ Detected\n", HalName);
281 
282  /* Check if KD is using a COM port */
283  if (KdComPortInUse)
284  {
285  /* Enter it into the I/O space */
289 
290 #if defined(SARCH_XBOX)
291  /*
292  * Do not claim interrupt resources for the KD COM port.
293  * The actual COM port lacks SERIRQ, IRQ 4 is hardwired to the NIC.
294  */
296 #else
297  /* Use the debug port table if we have one */
299 
300  /* Check if we're using ACPI */
301  if (!HalpGetInfoFromACPI)
302  {
303  /* No, so use our local table */
304  for (i = 0, Port = HalpComPortIrqMapping[i][0];
305  Port;
306  i++, Port = HalpComPortIrqMapping[i][0])
307  {
308  /* Is this the port we want? */
309  if (Port == (ULONG_PTR)KdComPortInUse)
310  {
311  /* Register it */
316  HIGH_LEVEL);
317  }
318  }
319  }
320 #endif
321  }
322 
323  /* On non-ACPI systems, we need to build an address map */
325 
326  /* Allocate the master raw and translated lists */
328  TranslatedList = ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE * 2, TAG_HAL);
329  if (!(RawList) || !(TranslatedList))
330  {
331  /* Bugcheck the system */
332  KeBugCheckEx(HAL_MEMORY_ALLOCATION,
333  4 * PAGE_SIZE,
334  1,
335  (ULONG_PTR)__FILE__,
336  __LINE__);
337  }
338 
339  /* Zero out the lists */
340  RtlZeroMemory(RawList, PAGE_SIZE * 2);
341  RtlZeroMemory(TranslatedList, PAGE_SIZE * 2);
342 
343  /* Set the interface type to begin with */
345 
346  /* Loop all IDT entries that are not IRQs */
347  for (i = 0; i < PRIMARY_VECTOR_BASE; i++)
348  {
349  /* Check if the IDT isn't owned */
351  {
352  /* Then register it for internal usage */
355  }
356  }
357 
358  /* Our full raw descriptors start here */
359  RawFull = RawList->List;
360 
361  /* Keep track of the current partial raw and translated descriptors */
362  CurrentRaw = (PCM_PARTIAL_RESOURCE_DESCRIPTOR)RawList->List;
363  CurrentTranslated = (PCM_PARTIAL_RESOURCE_DESCRIPTOR)TranslatedList->List;
364 
365  /* Do two passes */
366  for (ReportType = 0; ReportType < 2; ReportType++)
367  {
368  /* Pass 0 is for device usage */
369  if (ReportType == 0)
370  {
371  FlagMatch = IDT_DEVICE & ~IDT_REGISTERED;
373  }
374  else
375  {
376  /* Past 1 is for internal HAL usage */
377  FlagMatch = IDT_INTERNAL & ~IDT_REGISTERED;
379  }
380 
381  /* Reset loop variables */
382  i = Element = 0;
383 
384  /* Start looping our address uage list and interrupts */
385  CurrentAddress = HalpAddressUsageList;
386  while (TRUE)
387  {
388  /* Check for valid vector number */
389  if (i <= MAXIMUM_IDTVECTOR)
390  {
391  /* Check if this entry should be parsed */
392  if ((HalpIDTUsageFlags[i].Flags & FlagMatch))
393  {
394  /* Parse it */
395  HalpBuildPartialFromIdt(i, &RawPartial, &TranslatedPartial);
396  i++;
397  }
398  else
399  {
400  /* Skip this entry */
401  i++;
402  continue;
403  }
404  }
405  else
406  {
407  /* This is an address instead */
408  if (!CurrentAddress) break;
409 
410  /* Check if the address should be reported */
411  if (!(CurrentAddress->Flags & FlagMatch) ||
412  !(CurrentAddress->Element[Element].Length))
413  {
414  /* Nope, skip it */
415  Element = 0;
416  CurrentAddress = CurrentAddress->Next;
417  continue;
418  }
419 
420  /* Otherwise, parse the entry */
422  CurrentAddress,
423  Element,
424  &RawPartial,
425  &TranslatedPartial);
426  Element++;
427  }
428 
429  /* Check for interface change */
430  if (RawFull->InterfaceType != Interface)
431  {
432  /* We need to add another full descriptor */
433  RawList->Count++;
434  TranslatedList->Count++;
435 
436  /* The full descriptor follows wherever we were */
437  RawFull = (PCM_FULL_RESOURCE_DESCRIPTOR)CurrentRaw;
438  TranslatedFull = (PCM_FULL_RESOURCE_DESCRIPTOR)CurrentTranslated;
439 
440  /* And it is of this new interface type */
441  RawFull->InterfaceType = Interface;
442  TranslatedFull->InterfaceType = Interface;
443 
444  /* And its partial descriptors begin here */
445  RawPartialList = &RawFull->PartialResourceList;
446  TranslatedPartialList = &TranslatedFull->PartialResourceList;
447 
448  /* And our next full descriptor should follow here */
449  CurrentRaw = RawFull->PartialResourceList.PartialDescriptors;
450  CurrentTranslated = TranslatedFull->PartialResourceList.PartialDescriptors;
451  }
452 
453  /* We have written a new partial descriptor */
454  RawPartialList->Count++;
455  TranslatedPartialList->Count++;
456 
457  /* Copy our local descriptors into the actual list */
458  RtlCopyMemory(CurrentRaw, &RawPartial, sizeof(RawPartial));
459  RtlCopyMemory(CurrentTranslated, &TranslatedPartial, sizeof(TranslatedPartial));
460 
461  /* Move to the next partial descriptor */
462  CurrentRaw++;
463  CurrentTranslated++;
464  }
465  }
466 
467  /* Get the final list of the size for the kernel call later */
468  ListSize = (ULONG)((ULONG_PTR)CurrentRaw - (ULONG_PTR)RawList);
469 
470  /* Now reset back to the first full descriptor */
471  RawFull = RawList->List;
472  TranslatedFull = TranslatedList->List;
473 
474  /* And loop all the full descriptors */
475  for (i = 0; i < RawList->Count; i++)
476  {
477  /* Get the first partial descriptor in this list */
478  CurrentRaw = RawFull->PartialResourceList.PartialDescriptors;
479  CurrentTranslated = TranslatedFull->PartialResourceList.PartialDescriptors;
480 
481  /* Get the count of partials in this list */
482  Count = RawFull->PartialResourceList.Count;
483 
484  /* Loop all the partials in this list */
485  for (j = 0; j < Count; j++)
486  {
487  /* Get the sort value at this point */
488  HalpGetResourceSortValue(CurrentRaw, &CurrentScale, &CurrentSortValue);
489 
490  /* Save the current sort pointer */
491  SortedRaw = CurrentRaw;
492  SortedTranslated = CurrentTranslated;
493 
494  /* Loop all descriptors starting from this one */
495  for (k = j; k < Count; k++)
496  {
497  /* Get the sort value at the sort point */
498  HalpGetResourceSortValue(SortedRaw, &SortScale, &SortValue);
499 
500  /* Check if a swap needs to occur */
501  if ((SortScale < CurrentScale) ||
502  ((SortScale == CurrentScale) &&
503  (SortValue.QuadPart <= CurrentSortValue.QuadPart)))
504  {
505  /* Swap raw partial with the sort location partial */
506  RtlCopyMemory(&RawPartial, CurrentRaw, sizeof(RawPartial));
507  RtlCopyMemory(CurrentRaw, SortedRaw, sizeof(RawPartial));
508  RtlCopyMemory(SortedRaw, &RawPartial, sizeof(RawPartial));
509 
510  /* Swap translated partial in the same way */
511  RtlCopyMemory(&TranslatedPartial, CurrentTranslated, sizeof(TranslatedPartial));
512  RtlCopyMemory(CurrentTranslated, SortedTranslated, sizeof(TranslatedPartial));
513  RtlCopyMemory(SortedTranslated, &TranslatedPartial, sizeof(TranslatedPartial));
514 
515  /* Update the sort value at this point */
516  HalpGetResourceSortValue(CurrentRaw, &CurrentScale, &CurrentSortValue);
517  }
518 
519  /* The sort location has been updated */
520  SortedRaw++;
521  SortedTranslated++;
522  }
523 
524  /* Move to the next partial */
525  CurrentRaw++;
526  CurrentTranslated++;
527  }
528 
529  /* Move to the next full descriptor */
530  RawFull = (PCM_FULL_RESOURCE_DESCRIPTOR)CurrentRaw;
531  TranslatedFull = (PCM_FULL_RESOURCE_DESCRIPTOR)CurrentTranslated;
532  }
533 
534  /* Mark this is an ACPI system, if it is */
535  HalpMarkAcpiHal();
536 
537  /* Tell the kernel about all this */
539  RawList,
540  TranslatedList,
541  ListSize);
542 
543  /* Free our lists */
544  ExFreePool(RawList);
545  ExFreePool(TranslatedList);
546 
547  /* Get the machine's serial number */
549 }
VOID NTAPI HalpBuildPartialFromIdt(IN ULONG Entry, IN PCM_PARTIAL_RESOURCE_DESCRIPTOR RawDescriptor, IN PCM_PARTIAL_RESOURCE_DESCRIPTOR TranslatedDescriptor)
Definition: usage.c:162
CPPORT Port[4]
Definition: headless.c:35
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR * PCM_PARTIAL_RESOURCE_DESCRIPTOR
enum _INTERFACE_TYPE INTERFACE_TYPE
#define DbgPrint
Definition: hal.h:12
PADDRESS_USAGE HalpAddressUsageList
Definition: usage.c:20
struct _HalAddressUsage::@1480 Element[]
CM_FULL_RESOURCE_DESCRIPTOR List[1]
Definition: hwresource.cpp:165
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
IDTUsage HalpIDTUsage[256]
Definition: usage.c:20
VOID NTAPI HalpRegisterVector(IN UCHAR Flags, IN ULONG BusVector, IN ULONG SystemVector, IN KIRQL Irql)
Definition: usage.c:34
#define PRIMARY_VECTOR_BASE
Definition: halp.h:16
VOID NTAPI HalpBuildAddressMap(VOID)
Definition: halacpi.c:944
IDTUsageFlags HalpIDTUsageFlags[256]
Definition: usage.c:19
UCHAR BusReleativeVector
Definition: halp.h:32
uint32_t ULONG_PTR
Definition: typedefs.h:65
CM_PARTIAL_RESOURCE_LIST PartialResourceList
Definition: hwresource.cpp:160
BOOLEAN HalpGetInfoFromACPI
Definition: usage.c:17
PWCHAR HalName
Definition: halacpi.c:45
struct _CM_FULL_RESOURCE_DESCRIPTOR * PCM_FULL_RESOURCE_DESCRIPTOR
UCHAR Flags
Definition: halp.h:26
ADDRESS_USAGE HalpComIoSpace
Definition: usage.c:33
#define PtrToUlong(u)
Definition: config.h:107
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
int Count
Definition: noreturn.cpp:7
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
PUCHAR KdComPortInUse
Definition: usage.c:17
NTSTATUS NTAPI HalpMarkAcpiHal(VOID)
Definition: misc.c:57
#define IDT_REGISTERED
Definition: halp.h:19
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned char UCHAR
Definition: xmlstorage.h:181
CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1]
Definition: hwresource.cpp:119
#define IDT_INTERNAL
Definition: halp.h:21
#define TAG_HAL
Definition: hal.h:61
#define PAGE_SIZE
Definition: env_spec_w32.h:49
UCHAR Flags
Definition: halp.h:180
NTSTATUS NTAPI IoReportHalResourceUsage(PUNICODE_STRING HalDescription, PCM_RESOURCE_LIST RawList, PCM_RESOURCE_LIST TranslatedList, ULONG ListSize)
Definition: iorsrce.c:1079
#define HIGH_LEVEL
Definition: env_spec_w32.h:703
USHORT HalpComPortIrqMapping[5][2]
Definition: usage.c:24
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
IN PVOID IN PVOID IN USHORT IN USHORT IN PINTERFACE Interface
Definition: pci.h:361
#define NULL
Definition: types.h:112
VOID NTAPI HalpBuildPartialFromAddress(IN INTERFACE_TYPE Interface, IN PADDRESS_USAGE CurrentAddress, IN ULONG Element, IN PCM_PARTIAL_RESOURCE_DESCRIPTOR RawDescriptor, IN PCM_PARTIAL_RESOURCE_DESCRIPTOR TranslatedDescriptor)
Definition: usage.c:200
#define IDT_LATCHED
Definition: halp.h:20
VOID NTAPI HalpReportSerialNumber(VOID)
Definition: misc.c:26
BOOLEAN NTAPI HalpGetDebugPortTable(VOID)
Definition: halacpi.c:952
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI HalpGetResourceSortValue(IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor, OUT PULONG Scale, OUT PLARGE_INTEGER Value)
Definition: usage.c:122
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define ULONG_PTR
Definition: config.h:101
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define IDT_DEVICE
Definition: halp.h:22
struct _HalAddressUsage * Next
Definition: halp.h:178
int k
Definition: mpi.c:3369
#define MAXIMUM_IDTVECTOR
Definition: asm.h:280
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID InterfaceType
Definition: wdffdo.h:461
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:108
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
LONGLONG QuadPart
Definition: typedefs.h:114

Variable Documentation

◆ HalpAddressUsageList

PADDRESS_USAGE HalpAddressUsageList

Definition at line 20 of file usage.c.

Referenced by HalInitSystem(), and HalpReportResourceUsage().

◆ HalpComIoSpace

ADDRESS_USAGE HalpComIoSpace
Initial value:
=
{
{
{0x2F8, 0x8},
{0,0},
}
}
#define CmResourceTypePort
Definition: hwresource.cpp:123
#define IDT_INTERNAL
Definition: halp.h:21
#define NULL
Definition: types.h:112

Definition at line 33 of file usage.c.

Referenced by HalpReportResourceUsage().

◆ HalpComPortIrqMapping

USHORT HalpComPortIrqMapping[5][2]
Initial value:
=
{
{0x3F8, 4},
{0x2F8, 3},
{0x3E8, 4},
{0x2E8, 3},
{0, 0}
}

Definition at line 24 of file usage.c.

Referenced by HalpReportResourceUsage().

◆ HalpDefaultIoSpace

ADDRESS_USAGE HalpDefaultIoSpace

Definition at line 42 of file usage.c.

Referenced by HalInitSystem().

◆ HalpGetInfoFromACPI

BOOLEAN HalpGetInfoFromACPI

Definition at line 17 of file usage.c.

Referenced by HalpReportResourceUsage().

◆ HalpIDTUsage

IDTUsage HalpIDTUsage[MAXIMUM_IDTVECTOR+1]

Definition at line 22 of file usage.c.

◆ HalpIDTUsageFlags

IDTUsageFlags HalpIDTUsageFlags[MAXIMUM_IDTVECTOR+1]

Definition at line 21 of file usage.c.

◆ HalpNMIDumpFlag

BOOLEAN HalpNMIDumpFlag

Definition at line 18 of file usage.c.

Referenced by HalpGetNMICrashFlag().

◆ KdComPortInUse

PUCHAR KdComPortInUse

Definition at line 19 of file usage.c.