Just make pcix work already
Best regards,
Alex Ionescu
On Sat, Feb 28, 2015 at 11:52 PM, <cgutman(a)svn.reactos.org> wrote:
  Author: cgutman
 Date: Sun Mar  1 07:52:32 2015
 New Revision: 66511
 URL: 
http://svn.reactos.org/svn/reactos?rev=66511&view=rev
 Log:
 [PCI]
 - Handle 64-bit PCI base address registers (BARs)
 - Fix maximum address in resource requirements for 20-bit resources
 - Fix flags on memory and I/O port resources
 [NTOS]
 - Fix handling of 64-bit resources
 Modified:
     trunk/reactos/drivers/bus/pci/pdo.c
     trunk/reactos/ntoskrnl/io/pnpmgr/pnpres.c
 Modified: trunk/reactos/drivers/bus/pci/pdo.c
 URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/bus/pci/pdo.c?rev=…
 ==============================================================================
 --- trunk/reactos/drivers/bus/pci/pdo.c [iso-8859-1] (original)
 +++ trunk/reactos/drivers/bus/pci/pdo.c [iso-8859-1] Sun Mar  1 07:52:32
 2015
 @@ -21,6 +21,9 @@
  #define DBGPRINT(...)
  #endif
 +#define PCI_ADDRESS_MEMORY_ADDRESS_MASK_64     0xfffffffffffffff0ull
 +#define PCI_ADDRESS_IO_ADDRESS_MASK_64         0xfffffffffffffffcull
 +
  /*** PRIVATE
 *****************************************************************/
  static NTSTATUS
 @@ -191,80 +194,159 @@
      return STATUS_SUCCESS;
  }
 +static BOOLEAN
 +PdoReadPciBar(PPDO_DEVICE_EXTENSION DeviceExtension,
 +              ULONG Offset,
 +              PULONG OriginalValue,
 +              PULONG NewValue)
 +{
 +    ULONG Size;
 +    ULONG AllOnes;
 +
 +    /* Read the original value */
 +    Size = HalGetBusDataByOffset(PCIConfiguration,
 +                                 DeviceExtension->PciDevice->BusNumber,
 +
  DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
 +                                 OriginalValue,
 +                                 Offset,
 +                                 sizeof(ULONG));
 +    if (Size != sizeof(ULONG))
 +    {
 +        DPRINT1("Wrong size %lu\n", Size);
 +        return FALSE;
 +    }
 +
 +    /* Write all ones to determine which bits are held to zero */
 +    AllOnes = MAXULONG;
 +    Size = HalSetBusDataByOffset(PCIConfiguration,
 +                                 DeviceExtension->PciDevice->BusNumber,
 +
  DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
 +                                 &AllOnes,
 +                                 Offset,
 +                                 sizeof(ULONG));
 +    if (Size != sizeof(ULONG))
 +    {
 +        DPRINT1("Wrong size %lu\n", Size);
 +        return FALSE;
 +    }
 +
 +    /* Get the range length */
 +    Size = HalGetBusDataByOffset(PCIConfiguration,
 +                                 DeviceExtension->PciDevice->BusNumber,
 +
  DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
 +                                 NewValue,
 +                                 Offset,
 +                                 sizeof(ULONG));
 +    if (Size != sizeof(ULONG))
 +    {
 +        DPRINT1("Wrong size %lu\n", Size);
 +        return FALSE;
 +    }
 +
 +    /* Restore original value */
 +    Size = HalSetBusDataByOffset(PCIConfiguration,
 +                                 DeviceExtension->PciDevice->BusNumber,
 +
  DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
 +                                 OriginalValue,
 +                                 Offset,
 +                                 sizeof(ULONG));
 +    if (Size != sizeof(ULONG))
 +    {
 +        DPRINT1("Wrong size %lu\n", Size);
 +        return FALSE;
 +    }
 +
 +    return TRUE;
 +}
  static BOOLEAN
  PdoGetRangeLength(PPDO_DEVICE_EXTENSION DeviceExtension,
 -                  ULONG Offset,
 -                  PULONG Base,
 -                  PULONG Length,
 -                  PULONG Flags)
 -{
 -    ULONG OrigValue;
 -    ULONG BaseValue;
 -    ULONG NewValue;
 -    ULONG Size;
 -    ULONG XLength;
 -
 -    /* Save original value */
 -    Size= HalGetBusDataByOffset(PCIConfiguration,
 -                                DeviceExtension->PciDevice->BusNumber,
 -
 DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
 -                                &OrigValue,
 -                                Offset,
 -                                sizeof(ULONG));
 -    if (Size != sizeof(ULONG))
 -    {
 -        DPRINT1("Wrong size %lu\n", Size);
 +                  UCHAR Bar,
 +                  PULONGLONG Base,
 +                  PULONGLONG Length,
 +                  PULONG Flags,
 +                  PUCHAR NextBar,
 +                  PULONGLONG MaximumAddress)
 +{
 +    union {
 +        struct {
 +            ULONG Bar0;
 +            ULONG Bar1;
 +        } Bars;
 +        ULONGLONG Bar;
 +    } OriginalValue;
 +    union {
 +        struct {
 +            ULONG Bar0;
 +            ULONG Bar1;
 +        } Bars;
 +        ULONGLONG Bar;
 +    } NewValue;
 +    ULONG Offset;
 +
 +    /* Compute the offset of this BAR in PCI config space */
 +    Offset = 0x10 + Bar * 4;
 +
 +    /* Assume this is a 32-bit BAR until we find wrong */
 +    *NextBar = Bar + 1;
 +
 +    /* Initialize BAR values to zero */
 +    OriginalValue.Bar = 0ULL;
 +    NewValue.Bar = 0ULL;
 +
 +    /* Read the first BAR */
 +    if (!PdoReadPciBar(DeviceExtension, Offset,
 +                       &OriginalValue.Bars.Bar0,
 +                       &NewValue.Bars.Bar0))
 +    {
          return FALSE;
      }
 -
 -    BaseValue = (OrigValue & PCI_ADDRESS_IO_SPACE)
 -                ? (OrigValue & PCI_ADDRESS_IO_ADDRESS_MASK)
 -                : (OrigValue & PCI_ADDRESS_MEMORY_ADDRESS_MASK);
 -
 -    *Base = BaseValue;
 -
 -    /* Set magic value */
 -    NewValue = MAXULONG;
 -    Size= HalSetBusDataByOffset(PCIConfiguration,
 -                                DeviceExtension->PciDevice->BusNumber,
 -
 DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
 -                                &NewValue,
 -                                Offset,
 -                                sizeof(ULONG));
 -    if (Size != sizeof(ULONG))
 -    {
 -        DPRINT1("Wrong size %lu\n", Size);
 -        return FALSE;
 -    }
 -
 -    /* Get the range length */
 -    Size= HalGetBusDataByOffset(PCIConfiguration,
 -                                DeviceExtension->PciDevice->BusNumber,
 -
 DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
 -                                &NewValue,
 -                                Offset,
 -                                sizeof(ULONG));
 -    if (Size != sizeof(ULONG))
 -    {
 -        DPRINT1("Wrong size %lu\n", Size);
 -        return FALSE;
 -    }
 -
 -    /* Restore original value */
 -    Size= HalSetBusDataByOffset(PCIConfiguration,
 -                                DeviceExtension->PciDevice->BusNumber,
 -
 DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
 -                                &OrigValue,
 -                                Offset,
 -                                sizeof(ULONG));
 -    if (Size != sizeof(ULONG))
 -    {
 -        DPRINT1("Wrong size %lu\n", Size);
 -        return FALSE;
 -    }
 -
 -    if (NewValue == 0)
 +
 +    /* Check if this is a memory BAR */
 +    if (!(OriginalValue.Bars.Bar0 & PCI_ADDRESS_IO_SPACE))
 +    {
 +        /* Write the maximum address if the caller asked for it */
 +        if (MaximumAddress != NULL)
 +        {
 +            if ((OriginalValue.Bars.Bar0 & PCI_ADDRESS_MEMORY_TYPE_MASK)
 == PCI_TYPE_32BIT)
 +            {
 +                *MaximumAddress = 0x00000000FFFFFFFFULL;
 +            }
 +            else if ((OriginalValue.Bars.Bar0 &
 PCI_ADDRESS_MEMORY_TYPE_MASK) == PCI_TYPE_20BIT)
 +            {
 +                *MaximumAddress = 0x00000000000FFFFFULL;
 +            }
 +            else if ((OriginalValue.Bars.Bar0 &
 PCI_ADDRESS_MEMORY_TYPE_MASK) == PCI_TYPE_64BIT)
 +            {
 +                *MaximumAddress = 0xFFFFFFFFFFFFFFFFULL;
 +            }
 +        }
 +
 +        /* Check if this is a 64-bit BAR */
 +        if ((OriginalValue.Bars.Bar0 & PCI_ADDRESS_MEMORY_TYPE_MASK) ==
 PCI_TYPE_64BIT)
 +        {
 +            /* We've now consumed the next BAR too */
 +            *NextBar = Bar + 2;
 +
 +            /* Read the next BAR */
 +            if (!PdoReadPciBar(DeviceExtension, Offset + 4,
 +                               &OriginalValue.Bars.Bar1,
 +                               &NewValue.Bars.Bar1))
 +            {
 +                return FALSE;
 +            }
 +        }
 +    }
 +    else
 +    {
 +        /* Write the maximum I/O port address */
 +        if (MaximumAddress != NULL)
 +        {
 +            *MaximumAddress = 0x00000000FFFFFFFFULL;
 +        }
 +    }
 +
 +    if (NewValue.Bar == 0)
      {
          DPRINT("Unused address register\n");
          *Base = 0;
 @@ -272,48 +354,16 @@
          *Flags = 0;
          return TRUE;
      }
 -
 -    XLength = ~((NewValue & PCI_ADDRESS_IO_SPACE)
 -                ? (NewValue & PCI_ADDRESS_IO_ADDRESS_MASK)
 -                : (NewValue & PCI_ADDRESS_MEMORY_ADDRESS_MASK)) + 1;
 -
 -#if 0
 -    DbgPrint("BaseAddress 0x%08lx  Length 0x%08lx",
 -             BaseValue, XLength);
 -
 -    if (NewValue & PCI_ADDRESS_IO_SPACE)
 -    {
 -        DbgPrint("  IO range");
 -    }
 -    else
 -    {
 -        DbgPrint("  Memory range");
 -        if ((NewValue & PCI_ADDRESS_MEMORY_TYPE_MASK) == 0)
 -        {
 -            DbgPrint(" in 32-Bit address space");
 -        }
 -        else if ((NewValue & PCI_ADDRESS_MEMORY_TYPE_MASK) == 2)
 -        {
 -            DbgPrint(" below 1BM ");
 -        }
 -        else if ((NewValue & PCI_ADDRESS_MEMORY_TYPE_MASK) == 4)
 -        {
 -            DbgPrint(" in 64-Bit address space");
 -        }
 -
 -        if (NewValue & PCI_ADDRESS_MEMORY_PREFETCHABLE)
 -        {
 -            DbgPrint(" prefetchable");
 -        }
 -    }
 -
 -    DbgPrint("\n");
 -#endif
 -
 -    *Length = XLength;
 -    *Flags = (NewValue & PCI_ADDRESS_IO_SPACE)
 -             ? (NewValue & ~PCI_ADDRESS_IO_ADDRESS_MASK)
 -             : (NewValue & ~PCI_ADDRESS_MEMORY_ADDRESS_MASK);
 +
 +    *Base = OriginalValue.Bar & PCI_ADDRESS_MEMORY_ADDRESS_MASK_64;
 +
 +    *Length = ~((NewValue.Bar & PCI_ADDRESS_IO_SPACE)
 +                ? (NewValue.Bar & PCI_ADDRESS_IO_ADDRESS_MASK_64)
 +                : (NewValue.Bar & PCI_ADDRESS_MEMORY_ADDRESS_MASK_64)) +
 1;
 +
 +    *Flags = (NewValue.Bar & PCI_ADDRESS_IO_SPACE)
 +             ? (NewValue.Bar & ~PCI_ADDRESS_IO_ADDRESS_MASK_64)
 +             : (NewValue.Bar & ~PCI_ADDRESS_MEMORY_ADDRESS_MASK_64);
      return TRUE;
  }
 @@ -332,10 +382,11 @@
      ULONG Size;
      ULONG ResCount = 0;
      ULONG ListSize;
 -    ULONG i;
 -    ULONG Base;
 -    ULONG Length;
 +    UCHAR Bar;
 +    ULONGLONG Base;
 +    ULONGLONG Length;
      ULONG Flags;
 +    ULONGLONG MaximumAddress;
      UNREFERENCED_PARAMETER(IrpSp);
      DPRINT("PdoQueryResourceRequirements() called\n");
 @@ -361,13 +412,15 @@
      ResCount = 0;
      if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_DEVICE_TYPE)
      {
 -        for (i = 0; i < PCI_TYPE0_ADDRESSES; i++)
 +        for (Bar = 0; Bar < PCI_TYPE0_ADDRESSES;)
          {
              if (!PdoGetRangeLength(DeviceExtension,
 -                                   0x10 + i * 4,
 +                                   Bar,
                                     &Base,
                                     &Length,
 -                                   &Flags))
 +                                   &Flags,
 +                                   &Bar,
 +                                   NULL))
                  break;
              if (Length != 0)
 @@ -381,13 +434,15 @@
      }
      else if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_BRIDGE_TYPE)
      {
 -        for (i = 0; i < PCI_TYPE1_ADDRESSES; i++)
 +        for (Bar = 0; Bar < PCI_TYPE1_ADDRESSES;)
          {
              if (!PdoGetRangeLength(DeviceExtension,
 -                                   0x10 + i * 4,
 +                                   Bar,
                                     &Base,
                                     &Length,
 -                                   &Flags))
 +                                   &Flags,
 +                                   &Bar,
 +                                   NULL))
                  break;
              if (Length != 0)
 @@ -442,13 +497,15 @@
      Descriptor = &ResourceList->List[0].Descriptors[0];
      if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_DEVICE_TYPE)
      {
 -        for (i = 0; i < PCI_TYPE0_ADDRESSES; i++)
 +        for (Bar = 0; Bar < PCI_TYPE0_ADDRESSES;)
          {
              if (!PdoGetRangeLength(DeviceExtension,
 -                                   0x10 + i * 4,
 +                                   Bar,
                                     &Base,
                                     &Length,
 -                                   &Flags))
 +                                   &Flags,
 +                                   &Bar,
 +                                   &MaximumAddress))
              {
                  DPRINT1("PdoGetRangeLength() failed\n");
                  break;
 @@ -472,19 +529,20 @@
                  Descriptor->u.Port.Length = Length;
                  Descriptor->u.Port.Alignment = 1;
 -                Descriptor->u.Port.MinimumAddress.QuadPart =
 (ULONGLONG)Base;
 -                Descriptor->u.Port.MaximumAddress.QuadPart =
 (ULONGLONG)(Base + Length - 1);
 +                Descriptor->u.Port.MinimumAddress.QuadPart = Base;
 +                Descriptor->u.Port.MaximumAddress.QuadPart = Base +
 Length - 1;
              }
              else
              {
                  Descriptor->Type = CmResourceTypeMemory;
                  Descriptor->ShareDisposition =
 CmResourceShareDeviceExclusive;
 -                Descriptor->Flags = CM_RESOURCE_MEMORY_READ_WRITE;
 +                Descriptor->Flags = CM_RESOURCE_MEMORY_READ_WRITE |
 +                    (Flags & PCI_ADDRESS_MEMORY_PREFETCHABLE) ?
 CM_RESOURCE_MEMORY_PREFETCHABLE : 0;
                  Descriptor->u.Memory.Length = Length;
                  Descriptor->u.Memory.Alignment = 1;
 -                Descriptor->u.Memory.MinimumAddress.QuadPart =
 (ULONGLONG)Base;
 -                Descriptor->u.Memory.MaximumAddress.QuadPart =
 (ULONGLONG)(Base + Length - 1);
 +                Descriptor->u.Memory.MinimumAddress.QuadPart = Base;
 +                Descriptor->u.Memory.MaximumAddress.QuadPart = Base +
 Length - 1;
              }
              Descriptor++;
 @@ -500,19 +558,20 @@
                  Descriptor->u.Port.Length = Length;
                  Descriptor->u.Port.Alignment = Length;
 -                Descriptor->u.Port.MinimumAddress.QuadPart = (ULONGLONG)0;
 -                Descriptor->u.Port.MaximumAddress.QuadPart =
 (ULONGLONG)0x00000000FFFFFFFF;
 +                Descriptor->u.Port.MinimumAddress.QuadPart = 0;
 +                Descriptor->u.Port.MaximumAddress.QuadPart =
 MaximumAddress;
              }
              else
              {
                  Descriptor->Type = CmResourceTypeMemory;
                  Descriptor->ShareDisposition =
 CmResourceShareDeviceExclusive;
 -                Descriptor->Flags = CM_RESOURCE_MEMORY_READ_WRITE;
 +                Descriptor->Flags = CM_RESOURCE_MEMORY_READ_WRITE |
 +                    (Flags & PCI_ADDRESS_MEMORY_PREFETCHABLE) ?
 CM_RESOURCE_MEMORY_PREFETCHABLE : 0;
                  Descriptor->u.Memory.Length = Length;
                  Descriptor->u.Memory.Alignment = Length;
 -                Descriptor->u.Port.MinimumAddress.QuadPart = (ULONGLONG)0;
 -                Descriptor->u.Port.MaximumAddress.QuadPart =
 (ULONGLONG)0x00000000FFFFFFFF;
 +                Descriptor->u.Port.MinimumAddress.QuadPart = 0;
 +                Descriptor->u.Port.MaximumAddress.QuadPart =
 MaximumAddress;
              }
              Descriptor++;
          }
 @@ -532,13 +591,15 @@
      }
      else if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_BRIDGE_TYPE)
      {
 -        for (i = 0; i < PCI_TYPE1_ADDRESSES; i++)
 +        for (Bar = 0; Bar < PCI_TYPE1_ADDRESSES;)
          {
              if (!PdoGetRangeLength(DeviceExtension,
 -                                   0x10 + i * 4,
 +                                   Bar,
                                     &Base,
                                     &Length,
 -                                   &Flags))
 +                                   &Flags,
 +                                   &Bar,
 +                                   &MaximumAddress))
              {
                  DPRINT1("PdoGetRangeLength() failed\n");
                  break;
 @@ -562,19 +623,20 @@
                  Descriptor->u.Port.Length = Length;
                  Descriptor->u.Port.Alignment = 1;
 -                Descriptor->u.Port.MinimumAddress.QuadPart =
 (ULONGLONG)Base;
 -                Descriptor->u.Port.MaximumAddress.QuadPart =
 (ULONGLONG)(Base + Length - 1);
 +                Descriptor->u.Port.MinimumAddress.QuadPart = Base;
 +                Descriptor->u.Port.MaximumAddress.QuadPart = Base +
 Length - 1;
              }
              else
              {
                  Descriptor->Type = CmResourceTypeMemory;
                  Descriptor->ShareDisposition =
 CmResourceShareDeviceExclusive;
 -                Descriptor->Flags = CM_RESOURCE_MEMORY_READ_WRITE;
 +                Descriptor->Flags = CM_RESOURCE_MEMORY_READ_WRITE |
 +                    (Flags & PCI_ADDRESS_MEMORY_PREFETCHABLE) ?
 CM_RESOURCE_MEMORY_PREFETCHABLE : 0;
                  Descriptor->u.Memory.Length = Length;
                  Descriptor->u.Memory.Alignment = 1;
 -                Descriptor->u.Memory.MinimumAddress.QuadPart =
 (ULONGLONG)Base;
 -                Descriptor->u.Memory.MaximumAddress.QuadPart =
 (ULONGLONG)(Base + Length - 1);
 +                Descriptor->u.Memory.MinimumAddress.QuadPart = Base;
 +                Descriptor->u.Memory.MaximumAddress.QuadPart = Base +
 Length - 1;
              }
              Descriptor++;
 @@ -590,19 +652,20 @@
                  Descriptor->u.Port.Length = Length;
                  Descriptor->u.Port.Alignment = Length;
 -                Descriptor->u.Port.MinimumAddress.QuadPart = (ULONGLONG)0;
 -                Descriptor->u.Port.MaximumAddress.QuadPart =
 (ULONGLONG)0x00000000FFFFFFFF;
 +                Descriptor->u.Port.MinimumAddress.QuadPart = 0;
 +                Descriptor->u.Port.MaximumAddress.QuadPart =
 MaximumAddress;
              }
              else
              {
                  Descriptor->Type = CmResourceTypeMemory;
                  Descriptor->ShareDisposition =
 CmResourceShareDeviceExclusive;
 -                Descriptor->Flags = CM_RESOURCE_MEMORY_READ_WRITE;
 +                Descriptor->Flags = CM_RESOURCE_MEMORY_READ_WRITE |
 +                    (Flags & PCI_ADDRESS_MEMORY_PREFETCHABLE) ?
 CM_RESOURCE_MEMORY_PREFETCHABLE : 0;
                  Descriptor->u.Memory.Length = Length;
                  Descriptor->u.Memory.Alignment = Length;
 -                Descriptor->u.Port.MinimumAddress.QuadPart = (ULONGLONG)0;
 -                Descriptor->u.Port.MaximumAddress.QuadPart =
 (ULONGLONG)0x00000000FFFFFFFF;
 +                Descriptor->u.Port.MinimumAddress.QuadPart = 0;
 +                Descriptor->u.Port.MaximumAddress.QuadPart =
 MaximumAddress;
              }
              Descriptor++;
          }
 @@ -645,9 +708,9 @@
      ULONG Size;
      ULONG ResCount = 0;
      ULONG ListSize;
 -    ULONG i;
 -    ULONG Base;
 -    ULONG Length;
 +    UCHAR Bar;
 +    ULONGLONG Base;
 +    ULONGLONG Length;
      ULONG Flags;
      DPRINT("PdoQueryResources() called\n");
 @@ -674,13 +737,15 @@
      ResCount = 0;
      if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_DEVICE_TYPE)
      {
 -        for (i = 0; i < PCI_TYPE0_ADDRESSES; i++)
 +        for (Bar = 0; Bar < PCI_TYPE0_ADDRESSES;)
          {
              if (!PdoGetRangeLength(DeviceExtension,
 -                                   0x10 + i * 4,
 +                                   Bar,
                                     &Base,
                                     &Length,
 -                                   &Flags))
 +                                   &Flags,
 +                                   &Bar,
 +                                   NULL))
                  break;
              if (Length)
 @@ -694,13 +759,15 @@
      }
      else if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_BRIDGE_TYPE)
      {
 -        for (i = 0; i < PCI_TYPE1_ADDRESSES; i++)
 +        for (Bar = 0; Bar < PCI_TYPE1_ADDRESSES;)
          {
              if (!PdoGetRangeLength(DeviceExtension,
 -                                   0x10 + i * 4,
 +                                   Bar,
                                     &Base,
                                     &Length,
 -                                   &Flags))
 +                                   &Flags,
 +                                   &Bar,
 +                                   NULL))
                  break;
              if (Length != 0)
 @@ -749,17 +816,16 @@
      Descriptor = &PartialList->PartialDescriptors[0];
      if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_DEVICE_TYPE)
      {
 -        for (i = 0; i < PCI_TYPE0_ADDRESSES; i++)
 +        for (Bar = 0; Bar < PCI_TYPE0_ADDRESSES;)
          {
              if (!PdoGetRangeLength(DeviceExtension,
 -                                   0x10 + i * 4,
 +                                   Bar,
                                     &Base,
                                     &Length,
 -                                   &Flags))
 -            {
 -                DPRINT1("PdoGetRangeLength() failed\n");
 +                                   &Flags,
 +                                   &Bar,
 +                                   NULL))
                  break;
 -            }
              if (Length == 0)
              {
 @@ -771,7 +837,9 @@
              {
                  Descriptor->Type = CmResourceTypePort;
                  Descriptor->ShareDisposition =
 CmResourceShareDeviceExclusive;
 -                Descriptor->Flags = CM_RESOURCE_PORT_IO;
 +                Descriptor->Flags = CM_RESOURCE_PORT_IO |
 +                                    CM_RESOURCE_PORT_16_BIT_DECODE |
 +                                    CM_RESOURCE_PORT_POSITIVE_DECODE;
                  Descriptor->u.Port.Start.QuadPart = (ULONGLONG)Base;
                  Descriptor->u.Port.Length = Length;
 @@ -782,7 +850,8 @@
              {
                  Descriptor->Type = CmResourceTypeMemory;
                  Descriptor->ShareDisposition =
 CmResourceShareDeviceExclusive;
 -                Descriptor->Flags = CM_RESOURCE_MEMORY_READ_WRITE;
 +                Descriptor->Flags = CM_RESOURCE_MEMORY_READ_WRITE |
 +                    (Flags & PCI_ADDRESS_MEMORY_PREFETCHABLE) ?
 CM_RESOURCE_MEMORY_PREFETCHABLE : 0;
                  Descriptor->u.Memory.Start.QuadPart = (ULONGLONG)Base;
                  Descriptor->u.Memory.Length = Length;
 @@ -811,17 +880,16 @@
      }
      else if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_BRIDGE_TYPE)
      {
 -        for (i = 0; i < PCI_TYPE1_ADDRESSES; i++)
 +        for (Bar = 0; Bar < PCI_TYPE1_ADDRESSES;)
          {
              if (!PdoGetRangeLength(DeviceExtension,
 -                                   0x10 + i * 4,
 +                                   Bar,
                                     &Base,
                                     &Length,
 -                                   &Flags))
 -            {
 -                DPRINT1("PdoGetRangeLength() failed\n");
 +                                   &Flags,
 +                                   &Bar,
 +                                   NULL))
                  break;
 -            }
              if (Length == 0)
              {
 @@ -833,7 +901,9 @@
              {
                  Descriptor->Type = CmResourceTypePort;
                  Descriptor->ShareDisposition =
 CmResourceShareDeviceExclusive;
 -                Descriptor->Flags = CM_RESOURCE_PORT_IO;
 +                Descriptor->Flags = CM_RESOURCE_PORT_IO |
 +                                    CM_RESOURCE_PORT_16_BIT_DECODE |
 +                                    CM_RESOURCE_PORT_POSITIVE_DECODE;
                  Descriptor->u.Port.Start.QuadPart = (ULONGLONG)Base;
                  Descriptor->u.Port.Length = Length;
 @@ -844,7 +914,8 @@
              {
                  Descriptor->Type = CmResourceTypeMemory;
                  Descriptor->ShareDisposition =
 CmResourceShareDeviceExclusive;
 -                Descriptor->Flags = CM_RESOURCE_MEMORY_READ_WRITE;
 +                Descriptor->Flags = CM_RESOURCE_MEMORY_READ_WRITE |
 +                    (Flags & PCI_ADDRESS_MEMORY_PREFETCHABLE) ?
 CM_RESOURCE_MEMORY_PREFETCHABLE : 0;
                  Descriptor->u.Memory.Start.QuadPart = (ULONGLONG)Base;
                  Descriptor->u.Memory.Length = Length;
 Modified: trunk/reactos/ntoskrnl/io/pnpmgr/pnpres.c
 URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/pnpmgr/pnpres.…
 ==============================================================================
 --- trunk/reactos/ntoskrnl/io/pnpmgr/pnpres.c   [iso-8859-1] (original)
 +++ trunk/reactos/ntoskrnl/io/pnpmgr/pnpres.c   [iso-8859-1] Sun Mar  1
 07:52:32 2015
 @@ -73,7 +73,7 @@
     IN PIO_RESOURCE_DESCRIPTOR IoDesc,
     OUT PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDesc)
  {
 -   LONGLONG Start;
 +   ULONGLONG Start;
     CM_PARTIAL_RESOURCE_DESCRIPTOR ConflictingDesc;
     ASSERT(IoDesc->Type == CmDesc->Type);
 @@ -82,16 +82,16 @@
     /* HACK */
     if (IoDesc->u.Memory.Alignment == 0) IoDesc->u.Memory.Alignment = 1;
 -   for (Start = IoDesc->u.Memory.MinimumAddress.QuadPart;
 -        Start <= IoDesc->u.Memory.MaximumAddress.QuadPart -
 IoDesc->u.Memory.Length + 1;
 +   for (Start = (ULONGLONG)IoDesc->u.Memory.MinimumAddress.QuadPart;
 +        Start <= (ULONGLONG)IoDesc->u.Memory.MaximumAddress.QuadPart -
 IoDesc->u.Memory.Length + 1;
          Start += IoDesc->u.Memory.Alignment)
     {
          CmDesc->u.Memory.Length = IoDesc->u.Memory.Length;
 -        CmDesc->u.Memory.Start.QuadPart = Start;
 +        CmDesc->u.Memory.Start.QuadPart = (LONGLONG)Start;
          if (IopCheckDescriptorForConflict(CmDesc, &ConflictingDesc))
          {
 -            Start += ConflictingDesc.u.Memory.Start.QuadPart +
 +            Start += (ULONGLONG)ConflictingDesc.u.Memory.Start.QuadPart +
                       ConflictingDesc.u.Memory.Length;
          }
          else
 @@ -110,7 +110,7 @@
     IN PIO_RESOURCE_DESCRIPTOR IoDesc,
     OUT PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDesc)
  {
 -   LONGLONG Start;
 +   ULONGLONG Start;
     CM_PARTIAL_RESOURCE_DESCRIPTOR ConflictingDesc;
     ASSERT(IoDesc->Type == CmDesc->Type);
 @@ -119,16 +119,16 @@
     /* HACK */
     if (IoDesc->u.Port.Alignment == 0) IoDesc->u.Port.Alignment = 1;
 -   for (Start = IoDesc->u.Port.MinimumAddress.QuadPart;
 -        Start <= IoDesc->u.Port.MaximumAddress.QuadPart -
 IoDesc->u.Port.Length + 1;
 +   for (Start = (ULONGLONG)IoDesc->u.Port.MinimumAddress.QuadPart;
 +       Start <= (ULONGLONG)IoDesc->u.Port.MaximumAddress.QuadPart -
 IoDesc->u.Port.Length + 1;
          Start += IoDesc->u.Port.Alignment)
     {
          CmDesc->u.Port.Length = IoDesc->u.Port.Length;
 -        CmDesc->u.Port.Start.QuadPart = Start;
 +        CmDesc->u.Port.Start.QuadPart = (LONGLONG)Start;
          if (IopCheckDescriptorForConflict(CmDesc, &ConflictingDesc))
          {
 -            Start += ConflictingDesc.u.Port.Start.QuadPart +
 ConflictingDesc.u.Port.Length;
 +            Start += (ULONGLONG)ConflictingDesc.u.Port.Start.QuadPart +
 ConflictingDesc.u.Port.Length;
          }
          else
          {
 @@ -300,8 +300,8 @@
                      case CmResourceTypePort:
                          /* Make sure the length matches and it satisfies
 our address range */
                          if (CmDesc->u.Memory.Length ==
 IoDesc->u.Memory.Length &&
 -                            CmDesc->u.Memory.Start.QuadPart >=
 IoDesc->u.Memory.MinimumAddress.QuadPart &&
 -                            CmDesc->u.Memory.Start.QuadPart +
 CmDesc->u.Memory.Length - 1 <= IoDesc->u.Memory.MaximumAddress.QuadPart)
 +                            (ULONGLONG)CmDesc->u.Memory.Start.QuadPart >=
 (ULONGLONG)IoDesc->u.Memory.MinimumAddress.QuadPart &&
 +                            (ULONGLONG)CmDesc->u.Memory.Start.QuadPart +
 CmDesc->u.Memory.Length - 1 <=
 (ULONGLONG)IoDesc->u.Memory.MaximumAddress.QuadPart)
                          {
                              /* Found it */
                              Matched = TRUE;
 @@ -564,11 +564,11 @@
           switch (ResDesc->Type)
           {
               case CmResourceTypeMemory:
 -                 if ((ResDesc->u.Memory.Start.QuadPart <
 ResDesc2->u.Memory.Start.QuadPart &&
 -                      ResDesc->u.Memory.Start.QuadPart +
 ResDesc->u.Memory.Length >
 -                      ResDesc2->u.Memory.Start.QuadPart) ||
 (ResDesc2->u.Memory.Start.QuadPart <
 -                      ResDesc->u.Memory.Start.QuadPart &&
 ResDesc2->u.Memory.Start.QuadPart +
 -                      ResDesc2->u.Memory.Length >
 ResDesc->u.Memory.Start.QuadPart))
 +                 if (((ULONGLONG)ResDesc->u.Memory.Start.QuadPart <
 (ULONGLONG)ResDesc2->u.Memory.Start.QuadPart &&
 +                      (ULONGLONG)ResDesc->u.Memory.Start.QuadPart +
 ResDesc->u.Memory.Length >
 +                      (ULONGLONG)ResDesc2->u.Memory.Start.QuadPart) ||
 ((ULONGLONG)ResDesc2->u.Memory.Start.QuadPart <
 +                      (ULONGLONG)ResDesc->u.Memory.Start.QuadPart &&
 (ULONGLONG)ResDesc2->u.Memory.Start.QuadPart +
 +                      ResDesc2->u.Memory.Length >
 (ULONGLONG)ResDesc->u.Memory.Start.QuadPart))
                   {
                        if (!Silent)
                        {
 @@ -585,11 +585,11 @@
                   break;
               case CmResourceTypePort:
 -                 if ((ResDesc->u.Port.Start.QuadPart <
 ResDesc2->u.Port.Start.QuadPart &&
 -                      ResDesc->u.Port.Start.QuadPart +
 ResDesc->u.Port.Length >
 -                      ResDesc2->u.Port.Start.QuadPart) ||
 (ResDesc2->u.Port.Start.QuadPart <
 -                      ResDesc->u.Port.Start.QuadPart &&
 ResDesc2->u.Port.Start.QuadPart +
 -                      ResDesc2->u.Port.Length >
 ResDesc->u.Port.Start.QuadPart))
 +                 if (((ULONGLONG)ResDesc->u.Port.Start.QuadPart <
 (ULONGLONG)ResDesc2->u.Port.Start.QuadPart &&
 +                      (ULONGLONG)ResDesc->u.Port.Start.QuadPart +
 ResDesc->u.Port.Length >
 +                      (ULONGLONG)ResDesc2->u.Port.Start.QuadPart) ||
 ((ULONGLONG)ResDesc2->u.Port.Start.QuadPart <
 +                      (ULONGLONG)ResDesc->u.Port.Start.QuadPart &&
 (ULONGLONG)ResDesc2->u.Port.Start.QuadPart +
 +                      ResDesc2->u.Port.Length >
 (ULONGLONG)ResDesc->u.Port.Start.QuadPart))
                   {
                        if (!Silent)
                        {