⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pci.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
📖 第 1 页 / 共 2 页
字号:
           Device->PciConfig.BaseClass,
           Device->PciConfig.SubClass,
           Device->PciConfig.ProgIf);
  Index++;

  Index += swprintf(&Buffer[Index],
           L"PCI\\CC_%02X%02X",
           Device->PciConfig.BaseClass,
           Device->PciConfig.SubClass);
  Index++;

  Buffer[Index] = UNICODE_NULL;

  BufferU.Length = BufferU.MaximumLength = (USHORT)Index * sizeof(WCHAR);
  BufferU.Buffer = Buffer;

  return PciDuplicateUnicodeString(0, &BufferU, CompatibleIDs);
}


NTSTATUS
PciCreateDeviceDescriptionString(PUNICODE_STRING DeviceDescription,
                                 PPCI_DEVICE Device)
{
  PCWSTR Description;

  switch (Device->PciConfig.BaseClass)
  {
    case PCI_CLASS_PRE_20:
      switch (Device->PciConfig.SubClass)
      {
        case PCI_SUBCLASS_PRE_20_VGA:
          Description = L"VGA device";
          break;

        default:
        case PCI_SUBCLASS_PRE_20_NON_VGA:
          Description = L"PCI device";
          break;
      }
      break;

    case PCI_CLASS_MASS_STORAGE_CTLR:
      switch (Device->PciConfig.SubClass)
      {
        case PCI_SUBCLASS_MSC_SCSI_BUS_CTLR:
          Description = L"SCSI controller";
          break;

        case PCI_SUBCLASS_MSC_IDE_CTLR:
          Description = L"IDE controller";
          break;

        case PCI_SUBCLASS_MSC_FLOPPY_CTLR:
          Description = L"Floppy disk controller";
          break;

        case PCI_SUBCLASS_MSC_IPI_CTLR:
          Description = L"IPI controller";
          break;

        case PCI_SUBCLASS_MSC_RAID_CTLR:
          Description = L"RAID controller";
          break;

        default:
          Description = L"Mass storage controller";
          break;
      }
      break;

    case PCI_CLASS_NETWORK_CTLR:
      switch (Device->PciConfig.SubClass)
      {
        case PCI_SUBCLASS_NET_ETHERNET_CTLR:
          Description = L"Ethernet controller";
          break;

        case PCI_SUBCLASS_NET_TOKEN_RING_CTLR:
          Description = L"Token-Ring controller";
          break;

        case PCI_SUBCLASS_NET_FDDI_CTLR:
          Description = L"FDDI controller";
          break;

        case PCI_SUBCLASS_NET_ATM_CTLR:
          Description = L"ATM controller";
          break;

        default:
          Description = L"Network controller";
          break;
      }
      break;

    case PCI_CLASS_DISPLAY_CTLR:
      switch (Device->PciConfig.SubClass)
      {
        case PCI_SUBCLASS_VID_VGA_CTLR:
          Description = L"VGA display controller";
          break;

        case PCI_SUBCLASS_VID_XGA_CTLR:
          Description = L"XGA display controller";
          break;

        case PCI_SUBLCASS_VID_3D_CTLR:
          Description = L"Multimedia display controller";
          break;

        default:
          Description = L"Other display controller";
          break;
      }
      break;

    case PCI_CLASS_MULTIMEDIA_DEV:
      switch (Device->PciConfig.SubClass)
      {
        case PCI_SUBCLASS_MM_VIDEO_DEV:
          Description = L"Multimedia video device";
          break;

        case PCI_SUBCLASS_MM_AUDIO_DEV:
          Description = L"Multimedia audio device";
          break;

        case PCI_SUBCLASS_MM_TELEPHONY_DEV:
          Description = L"Multimedia telephony device";
          break;

        default:
          Description = L"Other multimedia device";
          break;
      }
      break;

    case PCI_CLASS_MEMORY_CTLR:
      switch (Device->PciConfig.SubClass)
      {
        case PCI_SUBCLASS_MEM_RAM:
          Description = L"PCI Memory";
          break;

        case PCI_SUBCLASS_MEM_FLASH:
          Description = L"PCI Flash Memory";
          break;

        default:
          Description = L"Other memory controller";
          break;
      }
      break;

    case PCI_CLASS_BRIDGE_DEV:
      switch (Device->PciConfig.SubClass)
      {
        case PCI_SUBCLASS_BR_HOST:
          Description = L"PCI-Host bridge";
          break;

        case PCI_SUBCLASS_BR_ISA:
          Description = L"PCI-ISA bridge";
          break;

        case PCI_SUBCLASS_BR_EISA:
          Description = L"PCI-EISA bridge";
          break;

        case PCI_SUBCLASS_BR_MCA:
          Description = L"PCI-Micro Channel bridge";
          break;

        case PCI_SUBCLASS_BR_PCI_TO_PCI:
          Description = L"PCI-PCI bridge";
          break;

        case PCI_SUBCLASS_BR_PCMCIA:
          Description = L"PCI-PCMCIA bridge";
          break;

        case PCI_SUBCLASS_BR_NUBUS:
          Description = L"PCI-NUBUS bridge";
          break;

        case PCI_SUBCLASS_BR_CARDBUS:
          Description = L"PCI-CARDBUS bridge";
          break;

        default:
          Description = L"Other bridge device";
          break;
      }
      break;

    case PCI_CLASS_SIMPLE_COMMS_CTLR:
      switch (Device->PciConfig.SubClass)
      {

        default:
          Description = L"Communication device";
          break;
      }
      break;

    case PCI_CLASS_BASE_SYSTEM_DEV:
      switch (Device->PciConfig.SubClass)
      {

        default:
          Description = L"System device";
          break;
      }
      break;

    case PCI_CLASS_INPUT_DEV:
      switch (Device->PciConfig.SubClass)
      {

        default:
          Description = L"Input device";
          break;
      }
      break;

    case PCI_CLASS_DOCKING_STATION:
      switch (Device->PciConfig.SubClass)
      {

        default:
          Description = L"Docking station";
          break;
      }
      break;

    case PCI_CLASS_PROCESSOR:
      switch (Device->PciConfig.SubClass)
      {

        default:
          Description = L"Processor";
          break;
      }
      break;

    case PCI_CLASS_SERIAL_BUS_CTLR:
      switch (Device->PciConfig.SubClass)
      {
        case PCI_SUBCLASS_SB_IEEE1394:
          Description = L"FireWire controller";
          break;

        case PCI_SUBCLASS_SB_ACCESS:
          Description = L"ACCESS bus controller";
          break;

        case PCI_SUBCLASS_SB_SSA:
          Description = L"SSA controller";
          break;

        case PCI_SUBCLASS_SB_USB:
          Description = L"USB controller";
          break;

        case PCI_SUBCLASS_SB_FIBRE_CHANNEL:
          Description = L"Fibre Channel controller";
          break;

        default:
          Description = L"Other serial bus controller";
          break;
      }
      break;

    default:
      Description = L"Other PCI Device";
      break;
  }

  return RtlCreateUnicodeString(DeviceDescription, Description) ? STATUS_SUCCESS : STATUS_INSUFFICIENT_RESOURCES;
}


NTSTATUS
PciCreateDeviceLocationString(PUNICODE_STRING DeviceLocation,
                              PPCI_DEVICE Device)
{
  WCHAR Buffer[256];

  swprintf(Buffer,
           L"PCI-Bus %lu, Device %u, Function %u",
           Device->BusNumber,
           Device->SlotNumber.u.bits.DeviceNumber,
           Device->SlotNumber.u.bits.FunctionNumber);

  return RtlCreateUnicodeString(DeviceLocation, Buffer) ? STATUS_SUCCESS : STATUS_INSUFFICIENT_RESOURCES;
}

NTSTATUS
PciDuplicateUnicodeString(
    IN ULONG Flags,
    IN PCUNICODE_STRING SourceString,
    OUT PUNICODE_STRING DestinationString)
{
    if (SourceString == NULL || DestinationString == NULL
     || SourceString->Length > SourceString->MaximumLength
     || (SourceString->Length == 0 && SourceString->MaximumLength > 0 && SourceString->Buffer == NULL)
     || Flags == RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING || Flags >= 4)
    {
        return STATUS_INVALID_PARAMETER;
    }


    if ((SourceString->Length == 0)
     && (Flags != (RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE | 
                   RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING)))
    {
        DestinationString->Length = 0;
        DestinationString->MaximumLength = 0;
        DestinationString->Buffer = NULL;
    }
    else
    {
        USHORT DestMaxLength = SourceString->Length;

        if (Flags & RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE)
            DestMaxLength += sizeof(UNICODE_NULL);

        DestinationString->Buffer = ExAllocatePoolWithTag(PagedPool, DestMaxLength, TAG_PCI);
        if (DestinationString->Buffer == NULL)
            return STATUS_NO_MEMORY;

        RtlCopyMemory(DestinationString->Buffer, SourceString->Buffer, SourceString->Length);
        DestinationString->Length = SourceString->Length;
        DestinationString->MaximumLength = DestMaxLength;

        if (Flags & RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE)
            DestinationString->Buffer[DestinationString->Length / sizeof(WCHAR)] = 0;
    }

    return STATUS_SUCCESS;
}

/* EOF */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -