/*
* The PCI Library -- List PCI devices on Win32 via Configuration Manager
*
* Copyright (c) 2021 Pali Rohár <pali@kernel.org>
*
* Can be freely distributed and used under the terms of the GNU GPL v2+.
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <windows.h>
#include <cfgmgr32.h>
#include <ctype.h> /* for isxdigit() */
#include <stdio.h> /* for sprintf() */
#include <string.h> /* for strlen(), strchr(), strncmp() */
#include <wchar.h> /* for wcslen(), wcscpy() */
#include "internal.h"
/* Unfortunately MinGW32 toolchain does not provide these cfgmgr32 constants. */
#ifndef RegDisposition_OpenExisting
#define RegDisposition_OpenExisting 0x00000001
#endif
#ifndef CM_REGISTRY_SOFTWARE
#define CM_REGISTRY_SOFTWARE 0x00000001
#endif
#ifndef CM_DRP_HARDWAREID
#define CM_DRP_HARDWAREID 0x00000002
#endif
#ifndef CM_DRP_SERVICE
#define CM_DRP_SERVICE 0x00000005
#endif
#ifndef CM_DRP_BUSNUMBER
#define CM_DRP_BUSNUMBER 0x00000016
#endif
#ifndef CM_DRP_ADDRESS
#define CM_DRP_ADDRESS 0x0000001D
#endif
#ifndef CR_INVALID_CONFLICT_LIST
#define CR_INVALID_CONFLICT_LIST 0x00000039
#endif
#ifndef CR_INVALID_INDEX
#define CR_INVALID_INDEX 0x0000003A
#endif
#ifndef CR_INVALID_STRUCTURE_SIZE
#define CR_INVALID_STRUCTURE_SIZE 0x0000003B
#endif
#ifndef fIOD_10_BIT_DECODE
#define fIOD_10_BIT_DECODE 0x0004
#endif
#ifndef fIOD_12_BIT_DECODE
#define fIOD_12_BIT_DECODE 0x0008
#endif
#ifndef fIOD_16_BIT_DECODE
#define fIOD_16_BIT_DECODE 0x0010
#endif
#ifndef fIOD_POSITIVE_DECODE
#define fIOD_POSITIVE_DECODE 0x0020
#endif
#ifndef fIOD_PASSIVE_DECODE
#define fIOD_PASSIVE_DECODE 0x0040
#endif
#ifndef fIOD_WINDOW_DECODE
#define fIOD_WINDOW_DECODE 0x0080
#endif
#ifndef fIOD_PORT_BAR
#define fIOD_PORT_BAR 0x0100
#endif
#ifndef fMD_WINDOW_DECODE
#define fMD_WINDOW_DECODE 0x0040
#endif
#ifndef fMD_MEMORY_BAR
#define fMD_MEMORY_BAR 0x0080
#endif
/*
* Unfortunately MinGW32 toolchain does not provide import library for these
* cfgmgr32.dll functions. So resolve pointers to these functions at runtime.
*/
#ifdef CM_Get_DevNode_Registry_PropertyA
#undef CM_Get_DevNode_Registry_PropertyA
#endif
static CONFIGRET (WINAPI *MyCM_Get_DevNode_Registry_PropertyA)(DEVINST dnDevInst, ULONG ulProperty, PULONG pulRegDataType, PVOID Buffer, PULONG pulLength, ULONG ulFlags);
#define CM_Get_DevNode_Registry_PropertyA MyCM_Get_DevNode_Registry_PropertyA
#ifdef CM_Get_DevNode_Registry_PropertyW
#undef CM_Get_DevNode_Registry_PropertyW
#endif
static CONFIGRET (WINAPI *MyCM_Get_DevNode_Registry_PropertyW)(DEVINST dnDevInst, ULONG ulProperty, PULONG pulRegDataType, PVOID Buffer, PULONG pulLength, ULONG ulFlags);
#define CM_Get_DevNode_Registry_PropertyW MyCM_Get_DevNode_Registry_PropertyW
#ifndef CM_Open_DevNode_Key
#undef CM_Open_DevNode_Key
#endif
static CONFIGRET (WINAPI *MyCM_Open_DevNode_Key)(DEVINST dnDevNode, REGSAM samDesired, ULONG ulHardwareProfile, REGDISPOSITION Disposition, PHKEY phkDevice, ULONG ulFlags);
#define CM_Open_DevNode_Key MyCM_Open_DevNode_Key
static BOOL
resolve_cfgmgr32_functions(void)
{
HMODULE cfgmgr32;
if (CM_Get_DevNode_Registry_PropertyA && CM_Get_DevNode_Registry_PropertyW && CM_Open_DevNode_Key)
return TRUE;
cfgmgr32 = GetModuleHandleA("cfgmgr32.dll");
if (!cfgmgr32)
return FALSE;
CM_Get_DevNode_Registry_PropertyA = (void *)GetProcAddress(cfgmgr32, "CM_Get_DevNode_Registry_PropertyA");
CM_Get_DevNode_Registry_PropertyW = (void *)GetProcAddress(cfgmgr32, "CM_Get_DevNode_Registry_PropertyW");
CM_Open_DevNode_Key = (void *)GetProcAddress(cfgmgr32, "CM_Open_DevNode_Key");
if (!CM_Get_DevNode_Registry_PropertyA || !CM_Get_DevNode_Registry_PropertyW || !CM_Open_DevNode_Key)
return FALSE;
return TRUE;
}
/*
* cfgmgr32.dll uses custom non-Win32 error numbers which are unsupported by
* Win32 APIs like GetLastError() and FormatMessage() functions.
*
* Windows 7 introduced new cfgmgr32.dll function CM_MapCrToWin32Err() for
* translating mapping CR_* errors to Win32 errors but most error codes are
* not mapped. So this function is unusable.
*
* Error strings for CR_* errors are defined in cmapi.rc file which is
* statically linked into some system libraries (e.g. filemgmt.dll,
* acledit.dll, netui0.dll or netui2.dll) but due to static linking it is
* not possible to access these error strings easily at runtime.
*
* So define own function for translating CR_* errors directly to strings.
*/
static const char *
cr_strerror(CONFIGRET cr_error_id)
{
static char unknown_error[sizeof("Unknown CR error XXXXXXXXXX")];
static const char *cr_errors[] = {
"The operation completed successfully",
"CR_DEFAULT",
"Not enough memory is available to process this command",
"A required pointer parameter is invalid",
"The ulFlags parameter specified is invalid for this operation",
"The device instance handle parameter is not valid",
"The supplied resource descriptor parameter is invalid",
"The supplied logical configuration parameter is invalid",
"CR_INVALID_ARBITRATOR",
"CR_INVALID_NODELIST",
"CR_DEVNODE_HAS_REQS/CR_DEVINST_HAS_REQS",
"The RESOURCEID parameter does not contain a valid RESOURCEID",
"CR_DLVXD_NOT_FOUND",
"The specified device instance handle does not correspond to a present device",
"There are no more logical configurations available",
"There are no more resource descriptions available",
"This device instance already exists",
"The supplied range list parameter is invalid",
"CR_INVALID_RANGE",
"A general internal error occurred",
"CR_NO_SUCH_LOGICAL_DEV",
"The device is disabled for this configuration",
"CR_NOT_SYSTEM_VM",
"A service or application refused to allow removal of this device",
"CR_APM_VETOED",
"CR_INVALID_LOAD_TYPE",
"An output parameter was too small to hold all the data available",
"CR_NO_ARBITRATOR",
"CR_NO_REGISTRY_HANDLE",
"A required entry in the registry is missing or an attempt to write to the registry failed",
"The specified Device ID is not a valid Device ID",
"One or more parameters were invalid",
"CR_INVALID_API",
"CR_DEVLOADER_NOT_READY",
"CR_NEED_RESTART",
"There are no more hardware profiles available",
"CR_DEVICE_NOT_THERE",
"The specified value does not exist in the registry",
"CR_WRONG_TYPE",
"The specified priority is invalid for this operation",
"This device cannot be disabled",
"CR_FREE_RESOURCES",
"CR_QUERY_VETOED",
"CR_CANT_SHARE_IRQ",
"CR_NO_DEPENDENT",
"CR_SAME_RESOURCES",
"The specified key does not exist in the registry",
"The specified machine name does not meet the UNC naming conventions",
"A general remote communication error occurred",
"The machine selected for remote communication is not available at this time",
"The Plug and Play service or another required service is not available",
"Access denied",
"This routine is not implemented in this version of the operating system",
"The specified property type is invalid for this operation",
"Device interface is active",
"No such device interface",
"Invalid reference string",
"Invalid conflict list",
"Invalid index",
"Invalid structure size"
};
if (cr_error_id <= 0 || cr_error_id >= sizeof(cr_errors)/sizeof(*cr_errors))
{
sprintf(unknown_error, "Unknown CR error %lu", cr_error_id);
return unknown_error;
}
return cr_errors[cr_error_id];
}
static const char *
win32_strerror(DWORD win32_error_id)
{
/*
* Use static buffer which is large enough.
* Hopefully no Win32 API error message string is longer than 4 kB.
*/
static char buffer[4096];
DWORD len;
len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, win32_error_id, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, sizeof(buffer), NULL);
/* FormatMessage() automatically appends ".\r\n" to the error message. */
if (len && buffer[len-1] == '\n')
没有合适的资源?快使用搜索试试~ 我知道了~
pciutils,用于生成pcilib,操作PIC接口
共124个文件
c:41个
h:17个
man:5个
需积分: 5 0 下载量 19 浏览量
2024-01-10
15:18:42
上传
评论
收藏 667KB ZIP 举报
温馨提示
pciutils,用于生成pcilib,操作PIC接口
资源推荐
资源详情
资源评论
收起资源包目录
pciutils,用于生成pcilib,操作PIC接口 (124个子文件)
bridge-ctl-vga16 7KB
broken-ecaps 13KB
win32-cfgmgr32.c 59KB
ls-caps.c 54KB
ls-ecaps.c 48KB
lspci.c 35KB
ecam.c 27KB
win32-kldbg.c 22KB
getopt.c 21KB
setpci.c 20KB
sysfs.c 15KB
init.c 12KB
ls-tree.c 11KB
mmio-ports.c 11KB
emulated.c 10KB
filter.c 9KB
fbsd-device.c 8KB
hurd.c 8KB
win32-sysdbg.c 8KB
names.c 7KB
i386-ports.c 7KB
generic.c 6KB
access.c 6KB
ls-kernel.c 6KB
names-parse.c 6KB
aix-device.c 6KB
names-net.c 5KB
darwin.c 5KB
proc.c 5KB
ls-vpd.c 5KB
names-cache.c 4KB
ls-map.c 4KB
dump.c 4KB
nbsd-libpci.c 3KB
caps.c 3KB
sylixos-device.c 3KB
names-hash.c 3KB
obsd-device.c 3KB
names-hwdb.c 3KB
common.c 3KB
params.c 2KB
ls-caps-vendor.c 2KB
example.c 1KB
cap-address-xlation 16KB
cap-aer-ecrc-label 17KB
cap-aer-hdr 17KB
cap-aer-log 17KB
cap-aer-root 33KB
cap-atomicops 3KB
cap-debug-port 910B
cap-doe 16KB
cap-dpc 5KB
cap-dvsec-cxl 33KB
cap-ea-1 17KB
cap-exp-aspm-latencies 17KB
cap-exp-dev2 18KB
cap-exp-lnkcap2 69KB
cap-exp-rev-slot 15KB
cap-ht 6KB
cap-l1-pm 16KB
cap-MSI-mapping 930B
cap-multicast 13KB
cap-pasid-pri 15KB
cap-pci-af 1KB
cap-pcie-1 17KB
cap-pcie-2 17KB
cap-ptm-1 15KB
cap-ptm-2 15KB
cap-rcec 16KB
cap-rebar 13KB
cap-vc-and-rcl 121KB
cap-vc-pat 13KB
cap-vendor-virtio 2KB
ChangeLog 76KB
configure 10KB
COPYING 18KB
gen-zone 1KB
.gitignore 73B
.gitignore 29B
header.h 82KB
i386-io-windows.h 43KB
pci.h 12KB
internal.h 5KB
getopt.h 4KB
lspci.h 3KB
i386-io-haiku.h 3KB
sysdep.h 2KB
types.h 2KB
pciutils.h 2KB
i386-io-linux.h 2KB
names.h 2KB
i386-io-sunos.h 1KB
i386-io-beos.h 1KB
i386-io-djgpp.h 844B
i386-io-hurd.h 812B
i386-io-cygwin.h 544B
pci.ids 1.3MB
winrsrc.rc.in 994B
libpci.pc.in 204B
pciutils.lsm 547B
共 124 条
- 1
- 2
资源评论
zhujian1333
- 粉丝: 1
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功