ReactOS  0.4.13-dev-482-ge57f103
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

INIT_FUNCTION VOID NTAPI HalpGetResourceSortValue (IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor, OUT PULONG Scale, OUT PLARGE_INTEGER Value)
 
INIT_FUNCTION VOID NTAPI HalpBuildPartialFromIdt (IN ULONG Entry, IN PCM_PARTIAL_RESOURCE_DESCRIPTOR RawDescriptor, IN PCM_PARTIAL_RESOURCE_DESCRIPTOR TranslatedDescriptor)
 
INIT_FUNCTION 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)
 
INIT_FUNCTION VOID NTAPI HalpReportResourceUsage (IN PUNICODE_STRING HalName, IN INTERFACE_TYPE InterfaceType)
 
INIT_FUNCTION VOID NTAPI HalpRegisterVector (IN UCHAR Flags, IN ULONG BusVector, IN ULONG SystemVector, IN KIRQL Irql)
 
INIT_FUNCTION VOID NTAPI HalpEnableInterruptHandler (IN UCHAR Flags, IN ULONG BusVector, IN ULONG SystemVector, IN KIRQL Irql, IN PVOID Handler, IN KINTERRUPT_MODE Mode)
 
INIT_FUNCTION 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()

INIT_FUNCTION 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 184 of file usage.c.

189 {
191 
192  /* Set the type and make it exclusive */
193  RawDescriptor->Type = CurrentAddress->Type;
194  RawDescriptor->ShareDisposition = CmResourceShareDriverExclusive;
195 
196  /* Check what this is */
197  if (RawDescriptor->Type == CmResourceTypePort)
198  {
199  /* Write out port data */
200  AddressSpace = 1;
201  RawDescriptor->Flags = CM_RESOURCE_PORT_IO;
202  RawDescriptor->u.Port.Start.HighPart = 0;
203  RawDescriptor->u.Port.Start.LowPart = CurrentAddress->Element[Element].Start;
204  RawDescriptor->u.Port.Length = CurrentAddress->Element[Element].Length;
205 
206  /* Determine if 16-bit port addresses are allowed */
207  RawDescriptor->Flags |= HalpIs16BitPortDecodeSupported();
208  }
209  else
210  {
211  /* Write out memory data */
212  AddressSpace = 0;
213  RawDescriptor->Flags = (CurrentAddress->Flags & IDT_READ_ONLY) ?
216  RawDescriptor->u.Memory.Start.HighPart = 0;
217  RawDescriptor->u.Memory.Start.LowPart = CurrentAddress->Element[Element].Start;
218  RawDescriptor->u.Memory.Length = CurrentAddress->Element[Element].Length;
219  }
220 
221  /* Make an identical copy to begin with */
222  RtlCopyMemory(TranslatedDescriptor, RawDescriptor, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
223 
224  /* Check what this is */
225  if (RawDescriptor->Type == CmResourceTypePort)
226  {
227  /* Translate the port */
229  0,
230  RawDescriptor->u.Port.Start,
231  &AddressSpace,
232  &TranslatedDescriptor->u.Port.Start);
233 
234  /* If it turns out this is memory once translated, flag it */
235  if (AddressSpace == 0) TranslatedDescriptor->Flags = CM_RESOURCE_PORT_MEMORY;
236 
237  }
238  else
239  {
240  /* Translate the memory */
242  0,
243  RawDescriptor->u.Memory.Start,
244  &AddressSpace,
245  &TranslatedDescriptor->u.Memory.Start);
246  }
247 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
#define CM_RESOURCE_MEMORY_READ_WRITE
Definition: cmtypes.h:120
#define CmResourceTypePort
Definition: hwresource.cpp:123
INIT_FUNCTION ULONG NTAPI HalpIs16BitPortDecodeSupported(VOID)
Definition: halacpi.c:961
#define CM_RESOURCE_MEMORY_READ_ONLY
Definition: cmtypes.h:121
IN PVOID IN PVOID IN USHORT IN USHORT IN PINTERFACE Interface
Definition: pci.h:359
struct _LARGE_INTEGER::@2199 u
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
#define CM_RESOURCE_PORT_IO
Definition: cmtypes.h:109
unsigned int ULONG
Definition: retypes.h:1
#define IDT_READ_ONLY
Definition: halp.h:64

Referenced by HalpReportResourceUsage().

◆ HalpBuildPartialFromIdt()

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

Definition at line 146 of file usage.c.

149 {
150  /* Exclusive interrupt entry */
151  RawDescriptor->Type = CmResourceTypeInterrupt;
152  RawDescriptor->ShareDisposition = CmResourceShareDriverExclusive;
153 
154  /* Check the interrupt type */
156  {
157  /* Latched */
158  RawDescriptor->Flags = CM_RESOURCE_INTERRUPT_LATCHED;
159  }
160  else
161  {
162  /* Level */
163  RawDescriptor->Flags = CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE;
164  }
165 
166  /* Get vector and level from IDT usage */
167  RawDescriptor->u.Interrupt.Vector = HalpIDTUsage[Entry].BusReleativeVector;
168  RawDescriptor->u.Interrupt.Level = HalpIDTUsage[Entry].BusReleativeVector;
169 
170  /* Affinity is all the CPUs */
171  RawDescriptor->u.Interrupt.Affinity = HalpActiveProcessors;
172 
173  /* The translated copy is identical */
174  RtlCopyMemory(TranslatedDescriptor, RawDescriptor, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
175 
176  /* But the vector and IRQL must be set correctly */
177  TranslatedDescriptor->u.Interrupt.Vector = Entry;
178  TranslatedDescriptor->u.Interrupt.Level = HalpIDTUsage[Entry].Irql;
179 }
LONG HalpActiveProcessors
Definition: processor.c:17
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
struct _Entry Entry
Definition: kefuncs.h:640
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
base of all file and directory entries
Definition: entries.h:82

Referenced by HalpReportResourceUsage().

◆ HalpEnableInterruptHandler()

INIT_FUNCTION 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 548 of file usage.c.

554 {
555  /* Set the IDT_LATCHED flag for latched interrupts */
556  if (Mode == Latched) Flags |= IDT_LATCHED;
557 
558  /* Register the vector */
559  HalpRegisterVector(Flags, BusVector, SystemVector, Irql);
560 
561  /* Connect the interrupt */
562  KeRegisterInterruptHandler(SystemVector, Handler);
563 
564  /* Enable the interrupt */
565  HalEnableSystemInterrupt(SystemVector, Irql, Mode);
566 }
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:656
FORCEINLINE VOID KeRegisterInterruptHandler(IN ULONG Vector, IN PVOID Handler)
Definition: ke.h:242
#define IDT_LATCHED
Definition: halp.h:20

◆ HalpGetNMICrashFlag()

INIT_FUNCTION VOID NTAPI HalpGetNMICrashFlag ( VOID  )

Definition at line 571 of file usage.c.

572 {
574  UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\CrashControl");
577  HANDLE Handle;
579  KEY_VALUE_PARTIAL_INFORMATION KeyValueInformation;
580 
581  /* Set default */
582  HalpNMIDumpFlag = 0;
583 
584  /* Initialize attributes */
586  &KeyName,
588  NULL,
589  NULL);
590 
591  /* Open crash key */
592  Status = ZwOpenKey(&Handle, KEY_READ, &ObjectAttributes);
593  if (NT_SUCCESS(Status))
594  {
595  /* Query key value */
596  RtlInitUnicodeString(&ValueName, L"NMICrashDump");
597  Status = ZwQueryValueKey(Handle,
598  &ValueName,
600  &KeyValueInformation,
601  sizeof(KeyValueInformation),
602  &ResultLength);
603  if (NT_SUCCESS(Status))
604  {
605  /* Check for valid data */
607  {
608  /* Read the flag */
609  HalpNMIDumpFlag = KeyValueInformation.Data[0];
610  }
611  }
612 
613  /* We're done */
614  ZwClose(Handle);
615  }
616 }
IN CINT OUT PVOID IN ULONG OUT PULONG ResultLength
Definition: conport.c:47
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
#define KEY_READ
Definition: nt_native.h:1023
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
smooth NULL
Definition: ftsmooth.c:416
BOOLEAN HalpNMIDumpFlag
Definition: usage.c:57
_In_ HANDLE Handle
Definition: extypes.h:390
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
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
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by HalpInitializePciBus().

◆ HalpGetResourceSortValue()

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

Definition at line 106 of file usage.c.

109 {
110  /* Sorting depends on resource type */
111  switch (Descriptor->Type)
112  {
114 
115  /* Interrupt goes by level */
116  *Scale = 0;
117  *Value = RtlConvertUlongToLargeInteger(Descriptor->u.Interrupt.Level);
118  break;
119 
120  case CmResourceTypePort:
121 
122  /* Port goes by port address */
123  *Scale = 1;
124  *Value = Descriptor->u.Port.Start;
125  break;
126 
128 
129  /* Memory goes by base address */
130  *Scale = 2;
131  *Value = Descriptor->u.Memory.Start;
132  break;
133 
134  default:
135 
136  /* Anything else */
137  *Scale = 4;
139  break;
140  }
141 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2327
#define CmResourceTypePort
Definition: hwresource.cpp:123
NTSYSAPI ULONGLONG WINAPI RtlConvertUlongToLargeInteger(ULONG)
Definition: largeint.c:47
#define CmResourceTypeInterrupt
Definition: hwresource.cpp:124
#define CmResourceTypeMemory
Definition: hwresource.cpp:125
_In_ PSTORAGE_PROPERTY_ID _Outptr_ PSTORAGE_DESCRIPTOR_HEADER * Descriptor
Definition: classpnp.h:966

Referenced by HalpReportResourceUsage().

◆ HalpRegisterVector()

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

Definition at line 531 of file usage.c.

535 {
536  /* Save the vector flags */
537  HalpIDTUsageFlags[SystemVector].Flags = Flags;
538 
539  /* Save the vector data */
540  HalpIDTUsage[SystemVector].Irql = Irql;
541  HalpIDTUsage[SystemVector].BusReleativeVector = (UCHAR)BusVector;
542 }
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
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
UCHAR Flags
Definition: halp.h:26
KIRQL Irql
Definition: halp.h:31
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ HalpReportResourceUsage()

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

Definition at line 252 of file usage.c.

254 {
255  PCM_RESOURCE_LIST RawList, TranslatedList;
256  PCM_FULL_RESOURCE_DESCRIPTOR RawFull, TranslatedFull;
257  PCM_PARTIAL_RESOURCE_DESCRIPTOR CurrentRaw, CurrentTranslated, SortedRaw, SortedTranslated;
258  CM_PARTIAL_RESOURCE_DESCRIPTOR RawPartial, TranslatedPartial;
259  PCM_PARTIAL_RESOURCE_LIST RawPartialList = NULL, TranslatedPartialList = NULL;
261  ULONG i, j, k, ListSize, Count, Port, Element, CurrentScale, SortScale, ReportType, FlagMatch;
262  ADDRESS_USAGE *CurrentAddress;
263  LARGE_INTEGER CurrentSortValue, SortValue;
264  DbgPrint("%wZ Detected\n", HalName);
265 
266  /* Check if KD is using a COM port */
267  if (KdComPortInUse)
268  {
269  /* Enter it into the I/O space */
273 
274  /* Use the debug port table if we have one */
276 
277  /* Check if we're using ACPI */
278  if (!HalpGetInfoFromACPI)
279  {
280  /* No, so use our local table */
281  for (i = 0, Port = HalpComPortIrqMapping[i][0];
282  Port;
283  i++, Port = HalpComPortIrqMapping[i][0])
284  {
285  /* Is this the port we want? */
286  if (Port == (ULONG_PTR)KdComPortInUse)
287  {
288  /* Register it */
293  HIGH_LEVEL);
294  }
295  }
296  }
297  }
298 
299  /* On non-ACPI systems, we need to build an address map */
301 
302  /* Allocate the master raw and translated lists */
304  TranslatedList = ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE * 2, TAG_HAL);
305  if (!(RawList) || !(TranslatedList))
306  {
307  /* Bugcheck the system */
308  KeBugCheckEx(HAL_MEMORY_ALLOCATION,
309  4 * PAGE_SIZE,
310  1,
311  (ULONG_PTR)__FILE__,
312  __LINE__);
313  }
314 
315  /* Zero out the lists */
316  RtlZeroMemory(RawList, PAGE_SIZE * 2);
317  RtlZeroMemory(TranslatedList, PAGE_SIZE * 2);
318 
319  /* Set the interface type to begin with */
321 
322  /* Loop all IDT entries that are not IRQs */
323  for (i = 0; i < PRIMARY_VECTOR_BASE; i++)
324  {
325  /* Check if the IDT isn't owned */
327  {
328  /* Then register it for internal usage */
331  }
332  }
333 
334  /* Our full raw descriptors start here */
335  RawFull = RawList->List;
336 
337  /* Keep track of the current partial raw and translated descriptors */
338  CurrentRaw = (PCM_PARTIAL_RESOURCE_DESCRIPTOR)RawList->List;
339  CurrentTranslated = (PCM_PARTIAL_RESOURCE_DESCRIPTOR)TranslatedList->List;
340 
341  /* Do two passes */
342  for (ReportType = 0; ReportType < 2; ReportType++)
343  {
344  /* Pass 0 is for device usage */
345  if (ReportType == 0)
346  {
347  FlagMatch = IDT_DEVICE & ~IDT_REGISTERED;
348  Interface = InterfaceType;
349  }
350  else
351  {
352  /* Past 1 is for internal HAL usage */
353  FlagMatch = IDT_INTERNAL & ~IDT_REGISTERED;
355  }
356 
357  /* Reset loop variables */
358  i = Element = 0;
359 
360  /* Start looping our address uage list and interrupts */
361  CurrentAddress = HalpAddressUsageList;
362  while (TRUE)
363  {
364  /* Check for valid vector number */
365  if (i <= MAXIMUM_IDTVECTOR)
366  {
367  /* Check if this entry should be parsed */
368  if ((HalpIDTUsageFlags[i].Flags & FlagMatch))
369  {
370  /* Parse it */
371  HalpBuildPartialFromIdt(i, &RawPartial, &TranslatedPartial);
372  i++;
373  }
374  else
375  {
376  /* Skip this entry */
377  i++;
378  continue;
379  }
380  }
381  else
382  {
383  /* This is an address instead */
384  if (!CurrentAddress) break;
385 
386  /* Check if the address should be reported */
387  if (!(CurrentAddress->Flags & FlagMatch) ||
388  !(CurrentAddress->Element[Element].Length))
389  {
390  /* Nope, skip it */
391  Element = 0;
392  CurrentAddress = CurrentAddress->Next;
393  continue;
394  }
395 
396  /* Otherwise, parse the entry */
398  CurrentAddress,
399  Element,
400  &RawPartial,
401  &TranslatedPartial);
402  Element++;
403  }
404 
405  /* Check for interface change */
406  if (RawFull->InterfaceType != Interface)
407  {
408  /* We need to add another full descriptor */
409  RawList->Count++;
410  TranslatedList->Count++;
411 
412  /* The full descriptor follows wherever we were */
413  RawFull = (PCM_FULL_RESOURCE_DESCRIPTOR)CurrentRaw;
414  TranslatedFull = (PCM_FULL_RESOURCE_DESCRIPTOR)CurrentTranslated;
415 
416  /* And it is of this new interface type */
417  RawFull->InterfaceType = Interface;
418  TranslatedFull->InterfaceType = Interface;
419 
420  /* And its partial descriptors begin here */
421  RawPartialList = &RawFull->PartialResourceList;
422  TranslatedPartialList = &TranslatedFull->PartialResourceList;
423 
424  /* And our next full descriptor should follow here */
425  CurrentRaw = RawFull->PartialResourceList.PartialDescriptors;
426  CurrentTranslated = TranslatedFull->PartialResourceList.PartialDescriptors;
427  }
428 
429  /* We have written a new partial descriptor */
430  RawPartialList->Count++;
431  TranslatedPartialList->Count++;
432 
433  /* Copy our local descriptors into the actual list */
434  RtlCopyMemory(CurrentRaw, &RawPartial, sizeof(RawPartial));
435  RtlCopyMemory(CurrentTranslated, &TranslatedPartial, sizeof(TranslatedPartial));
436 
437  /* Move to the next partial descriptor */
438  CurrentRaw++;
439  CurrentTranslated++;
440  }
441  }
442 
443  /* Get the final list of the size for the kernel call later */
444  ListSize = (ULONG)((ULONG_PTR)CurrentRaw - (ULONG_PTR)RawList);
445 
446  /* Now reset back to the first full descriptor */
447  RawFull = RawList->List;
448  TranslatedFull = TranslatedList->List;
449 
450  /* And loop all the full descriptors */
451  for (i = 0; i < RawList->Count; i++)
452  {
453  /* Get the first partial descriptor in this list */
454  CurrentRaw = RawFull->PartialResourceList.PartialDescriptors;
455  CurrentTranslated = TranslatedFull->PartialResourceList.PartialDescriptors;
456 
457  /* Get the count of partials in this list */
458  Count = RawFull->PartialResourceList.Count;
459 
460  /* Loop all the partials in this list */
461  for (j = 0; j < Count; j++)
462  {
463  /* Get the sort value at this point */
464  HalpGetResourceSortValue(CurrentRaw, &CurrentScale, &CurrentSortValue);
465 
466  /* Save the current sort pointer */
467  SortedRaw = CurrentRaw;
468  SortedTranslated = CurrentTranslated;
469 
470  /* Loop all descriptors starting from this one */
471  for (k = j; k < Count; k++)
472  {
473  /* Get the sort value at the sort point */
474  HalpGetResourceSortValue(SortedRaw, &SortScale, &SortValue);
475 
476  /* Check if a swap needs to occur */
477  if ((SortScale < CurrentScale) ||
478  ((SortScale == CurrentScale) &&
479  (SortValue.QuadPart <= CurrentSortValue.QuadPart)))
480  {
481  /* Swap raw partial with the sort location partial */
482  RtlCopyMemory(&RawPartial, CurrentRaw, sizeof(RawPartial));
483  RtlCopyMemory(CurrentRaw, SortedRaw, sizeof(RawPartial));
484  RtlCopyMemory(SortedRaw, &RawPartial, sizeof(RawPartial));
485 
486  /* Swap translated partial in the same way */
487  RtlCopyMemory(&TranslatedPartial, CurrentTranslated, sizeof(TranslatedPartial));
488  RtlCopyMemory(CurrentTranslated, SortedTranslated, sizeof(TranslatedPartial));
489  RtlCopyMemory(SortedTranslated, &TranslatedPartial, sizeof(TranslatedPartial));
490 
491  /* Update the sort value at this point */
492  HalpGetResourceSortValue(CurrentRaw, &CurrentScale, &CurrentSortValue);
493  }
494 
495  /* The sort location has been updated */
496  SortedRaw++;
497  SortedTranslated++;
498  }
499 
500  /* Move to the next partial */
501  CurrentRaw++;
502  CurrentTranslated++;
503  }
504 
505  /* Move to the next full descriptor */
506  RawFull = (PCM_FULL_RESOURCE_DESCRIPTOR)CurrentRaw;
507  TranslatedFull = (PCM_FULL_RESOURCE_DESCRIPTOR)CurrentTranslated;
508  }
509 
510  /* Mark this is an ACPI system, if it is */
511  HalpMarkAcpiHal();
512 
513  /* Tell the kernel about all this */
515  RawList,
516  TranslatedList,
517  ListSize);
518 
519  /* Free our lists */
520  ExFreePool(RawList);
521  ExFreePool(TranslatedList);
522 
523  /* Get the machine's serial number */
525 }
CPPORT Port[4]
Definition: headless.c:34
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR * PCM_PARTIAL_RESOURCE_DESCRIPTOR
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
INIT_FUNCTION NTSTATUS NTAPI HalpMarkAcpiHal(VOID)
Definition: misc.c:64
enum _INTERFACE_TYPE INTERFACE_TYPE
INIT_FUNCTION 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:184
PADDRESS_USAGE HalpAddressUsageList
Definition: usage.c:59
#define DbgPrint
Definition: loader.c:25
INIT_FUNCTION VOID NTAPI HalpBuildAddressMap(VOID)
Definition: halacpi.c:944
CM_FULL_RESOURCE_DESCRIPTOR List[1]
Definition: hwresource.cpp:165
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
INIT_FUNCTION VOID NTAPI HalpBuildPartialFromIdt(IN ULONG Entry, IN PCM_PARTIAL_RESOURCE_DESCRIPTOR RawDescriptor, IN PCM_PARTIAL_RESOURCE_DESCRIPTOR TranslatedDescriptor)
Definition: usage.c:146
#define PRIMARY_VECTOR_BASE
Definition: halp.h:16
INIT_FUNCTION BOOLEAN NTAPI HalpGetDebugPortTable(VOID)
Definition: halacpi.c:952
IDTUsageFlags HalpIDTUsageFlags[256]
Definition: usage.c:19
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
UCHAR BusReleativeVector
Definition: halp.h:32
uint32_t ULONG_PTR
Definition: typedefs.h:63
CM_PARTIAL_RESOURCE_LIST PartialResourceList
Definition: hwresource.cpp:160
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
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
BOOLEAN HalpGetInfoFromACPI
Definition: usage.c:56
PWCHAR HalName
Definition: halacpi.c:45
struct _CM_FULL_RESOURCE_DESCRIPTOR * PCM_FULL_RESOURCE_DESCRIPTOR
smooth NULL
Definition: ftsmooth.c:416
UCHAR Flags
Definition: halp.h:26
#define MAXIMUM_IDTVECTOR
Definition: asm.h:277
ADDRESS_USAGE HalpComIoSpace
Definition: usage.c:72
#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
IN PVOID IN PVOID IN USHORT IN USHORT IN PINTERFACE Interface
Definition: pci.h:359
PUCHAR KdComPortInUse
Definition: usage.c:17
#define IDT_REGISTERED
Definition: halp.h:19
struct _HalAddressUsage::@1488 Element[]
INIT_FUNCTION VOID NTAPI HalpGetResourceSortValue(IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor, OUT PULONG Scale, OUT PLARGE_INTEGER Value)
Definition: usage.c:106
#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:55
#define PAGE_SIZE
Definition: env_spec_w32.h:49
UCHAR Flags
Definition: halp.h:540
NTSTATUS NTAPI IoReportHalResourceUsage(PUNICODE_STRING HalDescription, PCM_RESOURCE_LIST RawList, PCM_RESOURCE_LIST TranslatedList, ULONG ListSize)
Definition: iorsrce.c:1070
#define HIGH_LEVEL
Definition: env_spec_w32.h:703
USHORT HalpComPortIrqMapping[5][2]
Definition: usage.c:63
#define IDT_LATCHED
Definition: halp.h:20
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ULONG_PTR
Definition: config.h:101
#define IDT_DEVICE
Definition: halp.h:22
struct _HalAddressUsage * Next
Definition: halp.h:538
int k
Definition: mpi.c:3369
INIT_FUNCTION VOID NTAPI HalpReportSerialNumber(VOID)
Definition: misc.c:33
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:107
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
LONGLONG QuadPart
Definition: typedefs.h:112

Variable Documentation

◆ HalpAddressUsageList

PADDRESS_USAGE HalpAddressUsageList

Definition at line 59 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
smooth NULL
Definition: ftsmooth.c:416
#define IDT_INTERNAL
Definition: halp.h:21

Definition at line 72 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 63 of file usage.c.

Referenced by HalpReportResourceUsage().

◆ HalpDefaultIoSpace

ADDRESS_USAGE HalpDefaultIoSpace
Initial value:
=
{
{
{0x00, 0x20},
{0xC0, 0x20},
{0x80, 0x10},
{0x20, 0x2},
{0xA0, 0x2},
{0x40, 0x4},
{0x48, 0x4},
{0x92, 0x1},
{0x70, 0x2},
{0xF0, 0x10},
{0xCF8, 0x8},
{0,0},
}
}
#define CmResourceTypePort
Definition: hwresource.cpp:123
smooth NULL
Definition: ftsmooth.c:416
#define IDT_INTERNAL
Definition: halp.h:21

Definition at line 81 of file usage.c.

Referenced by HalInitSystem().

◆ HalpGetInfoFromACPI

BOOLEAN HalpGetInfoFromACPI

Definition at line 56 of file usage.c.

Referenced by HalpReportResourceUsage().

◆ HalpIDTUsage

IDTUsage HalpIDTUsage[MAXIMUM_IDTVECTOR+1]

Definition at line 61 of file usage.c.

◆ HalpIDTUsageFlags

IDTUsageFlags HalpIDTUsageFlags[MAXIMUM_IDTVECTOR+1]

Definition at line 60 of file usage.c.

◆ HalpNMIDumpFlag

BOOLEAN HalpNMIDumpFlag

Definition at line 57 of file usage.c.

Referenced by HalpGetNMICrashFlag().

◆ KdComPortInUse

PUCHAR KdComPortInUse

Definition at line 58 of file usage.c.