Pali Rohár [Fri, 31 Dec 2021 13:39:51 +0000 (14:39 +0100)]
lspci: Do not show -[00]- bus in tree output
Secondary or subordinate bus cannot be zero. Zero value could indicate
either invalid secondary bus value or the fact that secondary bus value was
not filled or indicates non-compliant PCI-to-PCI bridge. This change makes
tree output better readable when bus numbers are not known or not provided.
Pali Rohár [Tue, 28 Dec 2021 19:14:47 +0000 (20:14 +0100)]
lspci: Build tree based on PCI_FILL_PARENT information
Topology reported by system (libpci provider) may be different from
topology built based on primary/secondary/subordinate numbers from PCI
bridges by lspci.
This happens for example when some non-compliant PCI-to-PCI bridge
with Type 0 header (e.g. Marvell one) is available in the system.
So add additional edges reported by libpci when building tree in lspci.
Pali Rohár [Mon, 20 Dec 2021 21:39:42 +0000 (22:39 +0100)]
lspci: Retrieve prog if, subsystem ids and revision id via libpci
Use pci_fill_info with CLASS_EXT and SUBSYS to fill this information.
lspci in some places reads class from what libpci provider fills in
dev->device_class and in some other places it reads directly from config
space. In dev->device_class is stored class possible different class as in
config space (e.g. if kernel is fixing class because device has bogus
information stored in config space).
With this change is class always read from dev->device_class which reflects
and respects lspci -b option (Bus-centric view). Same applies for subsystem
ids and revision id (note that prog if is part of class).
Pali Rohár [Mon, 20 Dec 2021 21:07:28 +0000 (22:07 +0100)]
libpci: Add new options for pci_fill_info: CLASS_EXT and SUBSYS
This change extends libpci library and allows providers to fill these
informations (Programming interface, Revision id and Subsystem ids) via
native system APIs, which sometimes may differs from what is stored in PCI
config space.
Programming interface is part of 24-bit Device Class number but apparently
libpci exports only high 16-bit of this number via device_class member.
Pali Rohár [Sat, 20 Nov 2021 14:13:20 +0000 (15:13 +0100)]
lspci: Use PCI_FILL_BRIDGE_BASES to detect if range behind bridge is disabled or unsupported
Show resources behind bridge as reported by PCI_FILL_BRIDGE_BASES.
I/O or Prefetchable memory behind bridge is unsupported by bridge if both
base and limit bridge registers are read-only and returns zero. So if base
and limit registers returns zero (which is valid enabled range) and kernel
reports that particular resource is disabled it means that resource is
unsupported. Both I/O or Prefetchable memory resources are only optional.
Pali Rohár [Sun, 26 Dec 2021 21:12:00 +0000 (22:12 +0100)]
lspci: Define PCI_U64_FMT_U format for printing u64
Windows CRTDLL and MSVCRT runtime system libraries do not support %llu
format string in printf. They support only %I64u format string. Fix this
problem by providing PCI_U64_FMT_U macro in the same way as existing
PCI_U64_FMT_X macro (for %llx).
For C99 systems this PCI_U64_FMT_U macro is defined to C99 PRIu64 constant.
This change fixes printing unsigned decimal 64-bit numbers by lspci on
Window systems independently of used compiler (MinGW or MSVC).
Pali Rohár [Sun, 26 Dec 2021 21:11:51 +0000 (22:11 +0100)]
lspci: Replace unsigned long long type by u64 and %llx format by PCI_U64_FMT_X
pciutils already provides and uses u64 type together with PCI_U64_FMT_X
format macro for printing hex value of this type. So use u64 and
PCI_U64_FMT_X also on other few remaining places.
This change fixes printing hexadecimal 64-bit numbers by lspci on Window
systems independently of used compiler (MinGW or MSVC).
Pali Rohár [Sun, 26 Dec 2021 21:11:30 +0000 (22:11 +0100)]
libpci: For PCI_OS_WINDOWS include windows.h instead of windef.h
According to Win32 API guidelines applications should include <windows.h>
instead of <windef.h>. This change fixes compilation under MSVC as MSVC
<windef.h> header file expects that some other Win32 header files from
<window.h> are already included.
Pali Rohár [Sun, 26 Dec 2021 21:11:22 +0000 (22:11 +0100)]
libpci: For PCI_OS_WINDOWS define strncasecmp as alias for _strnicmp
CRTDLL, MSVCRT and UCRT runtimes provides strncasecmp()-like functionality
in _strnicmp() function. As opposite of strcasecmp() for which there are
_stricmp() and _strcmpi() variants, for strncasecmp() there is only
_strnicmp() function.
Without this change linking final setpci.exe executable undef MSVC fails.
Pali Rohár [Sun, 26 Dec 2021 23:47:53 +0000 (00:47 +0100)]
libpci: For MSVC < 19.00 define snprintf outside of endian section
snprintf() macro is not endian specific and therefore should be declared
outside of the endian section.
This also fixes snprintf() function for new MinGW-w64 toolchains where
snprintf() is defined as wrapper around _snprintf() which do not return
negative value on overflow. libpci would call MinGW-w64 patched snprintf()
function and not broken system function _snprintf().
Martin Mares [Fri, 21 Jan 2022 13:09:16 +0000 (14:09 +0100)]
pci.h: The error callback is now declared with PCI_NONRET
Users of the repeatedly complain that the library crashes, which is
usually caused by providing an error hook which returns to the library.
Let's try warning them more explicitly.
i386-ports.c: In function ‘conf12_setup_io’:
i386-io-windows.h:1021: warning: ‘old_token’ may be used uninitialized in this function
i386-io-windows.h:1021: note: ‘old_token’ was declared here
It is always properly initialized when accessed, just gcc compiler does not see it.
Pali Rohár [Sun, 26 Dec 2021 17:18:59 +0000 (18:18 +0100)]
lib: Fix definition of strcasecmp() for PCI_OS_WINDOWS
UCRT, MSVCRT and CRTDLL runtime libraries provides only _strcmpi()
function and not strcmpi().
MinGW32 has static libraries libcoldname.a and libmoldname.a which provides
strcmpi() function (as link-time redirect to _strcmpi()). libcoldname.a is
automatically linked when compiling for CRTDLL runtime and libmoldname.a
for MSVCRT runtime.
MinGW-w64 has only libmoldname.a library with strcmpi() function and it is
linked to final executable only when compiling for MSVCRT runtime.
when linking with MSVCRT.
To prevent dependency on particular linking configuration and MinGW
toolchain, use set strcasecmp() as alias to _strcmpi() function which is
provided by any runtime library.
Pali Rohár [Sun, 26 Dec 2021 17:19:25 +0000 (18:19 +0100)]
compat/getopt: Fix compatibility with non-GNU C library
Remove "#if defined(__GNU_LIBRARY__)" guard for getopt() function
prototype in compat/getopt.h header file. The only purpose of
compat/getopt.h header is to provide getopt() function prototype for
compatibility purpose on every platform, specially those which do not use
GNU C library (e.g. Windows).
Without this change i586-mingw32msvc-gcc compiler complains that function
getopt() is used without defined prototype.
Also remove inclusion of #include <string.h> header file in compat/getopt.c
source file. Probably due to compatibility purposes compat/getopt.c file
has defined custom prototype for function strncmp() incompatible with C99
(length argument in C99 should be of type size_t). Including C99 prototype
of strncmp() function from MinGW32 <string.h> header file cause compile
errors for i586-mingw32msvc-gcc compiler. Instead of including <stringh>
provides custom and simple my_strncmp() implementation.
Thsi change fixes compilation of compat/getopt.c with i586-mingw32msvc-gcc,
i686-w64-mingw32-gcc, x86_64-w64-mingw32-gcc and also MSVC cl compilers.
Add PCIe 3.0+ decoding of the LnkCtl2 Compliance Preset/De-emphasis field
As of PCIe 3.0, the LnkCtl2 "Compliance De-emphasis" field has been
renamed to "Compliance Preset/De-emphasis", and there are several new
bit encodings for various de-emphasis and preshoot combinations.
The name of the PCI_EXP_LNKCTL2_COM_DEEMPHASIS() macro is not changed
by this commit, as it is part of the libpci API.
Reported-by: Tim CC Chen(陳志佳) <Tim.CC.Chen@wnc.com.tw> Signed-off-by: Lennert Buytenhek <buytenh@arista.com>
Pali Rohár [Sun, 26 Dec 2021 23:34:08 +0000 (00:34 +0100)]
lspci: Show Slot Power Limit values above EFh
PCI Express Base Specification rev. 3.0 has the following definition for
the Slot Power Limit Value:
=======================================================================
When the Slot Power Limit Scale field equals 00b (1.0x) and Slot Power
Limit Value exceeds EFh, the following alternative encodings are used:
F0h = 250 W Slot Power Limit
F1h = 275 W Slot Power Limit
F2h = 300 W Slot Power Limit
F3h to FFh = Reserved for Slot Power Limit values above 300 W
=======================================================================
Replace function power_limit() by show_power_limit() which also prints
power limit value. Show reserved value as string ">300W".
Pali Rohár [Sun, 26 Dec 2021 22:47:03 +0000 (23:47 +0100)]
libpci: Fix intel_sanity_check() function
Function intel_sanity_check() calls conf1_read() which access d->domain
field. But intel_sanity_check() does not initialize this field and so
conf1_read() access some random data on stack.
Tests showed that intel_sanity_check() always fails as in d->domain is
stored some non-zero number.
Fix this issue by zeroing struct pci_dev d in intel_sanity_check() as
sanity check is verifying PCI devices at domain 0.
Pali Rohár [Sun, 26 Dec 2021 22:04:03 +0000 (23:04 +0100)]
lspci: Print buses of multibus PCI domain in ascending order
Currently PCI domains are printed in ascending order. Devices on each PCI
bus are also printed in ascending order. PCI buses behind PCI-to-PCI
bridges are also printed in ascending order.
But buses of PCI domain are currently printed in descending order because
function new_bus() puts newly created bus at the beginning of linked list.
In most cases PCI domain contains only one (top level) bus, so in most
cases it is not visible this inconsistency.
Multibus PCI domains (where PCI domain contains more independent top level
PCI buses) are available on ARM devices.
This change fixes print order of multibus PCI domains, so also top level
PCI buses are printed in ascending order, like PCI buses behind PCI-to-PCI
bridges.
Pali Rohár [Mon, 20 Dec 2021 15:56:59 +0000 (16:56 +0100)]
dump: Allow more leading zeros in dump line number
U-Boot's "pci display.b" command prints pci config space dump with 8 digits
in line number. So allow up to the 8 digits in line number to easily parse
U-Boot's pci config space dumps.
Pali Rohár [Sun, 26 Dec 2021 17:48:00 +0000 (18:48 +0100)]
win32: Remove old config.h and config.mk files
These files are old and cannot be used for compiling pcitutils anymore
(e.g. they use non-existent option TOOLPREFIX). As configure script now
works fine also for Windows build, remove these old win32 config files.
Pali Rohár [Sun, 26 Dec 2021 17:44:44 +0000 (18:44 +0100)]
Makefile: Add new option COMPAT_GETOPT
This new option controls if compat/getopt.c should be compiled and linked
into lspci and setpci binaries. Useful for ancient platforms.
For example it is required to set COMPAT_GETOPT=yes for all versions of
MinGW32 with CRTDLL (as this MinGW32 variant does not have linkable
getopt() implementation). And also for MinGW32 with MSVCRT older than 3.0.
Pali Rohár [Sun, 26 Dec 2021 17:42:35 +0000 (18:42 +0100)]
Makefile: Append EXEEXT variable to executable filename rules
If x86_64-w64-mingw32-gcc compiler is called with -o filename option
without any file extension then compiler automatically appends suffix
".exe" to output filename.
This behavior of x86_64-w64-mingw32-gcc compiler basically breaks pattern
rule of type '%: %.o' as x86_64-w64-mingw32-gcc compiler cannot generate
arbitrary output file via -o option just by stripping .o extension from
filename.
When generating executables by x86_64-w64-mingw32-gcc compiler it is
really the best option to specify .exe suffix in -o option.
So introduce a new makefile variable EXEEXT which will be automatically
appended to any executable filename. For Windows and DOS systems set it
to ".exe". For other systems set it just to empty string "".
GNU automake uses same makefile variable for same purpose.
Pali Rohár [Sun, 26 Dec 2021 18:06:53 +0000 (19:06 +0100)]
libpci: For PCI_OS_WINDOWS allows to load pci.ids from executable directory
For Windows applications it is common to have all support data files in the
same directory where is stored executable itself, instead of in directory
hardcoded at compile time.
When PCI_PATH_IDS_DIR is set to "." it means that pci.ids file is located
in the current working directory. This is also unsuitable for Windows
command line applications stored in %PATH% because cmd.exe starts in some
default user or system location.
Adds a new option to allow specifying PCI_PATH_IDS_DIR to empty string ""
and for PCI_OS_WINDOWS platform it would mean to locate pci.ids file in the
same directory where is stored currently running executable. On Windows it
is always possible to detected this directory.
Pali Rohár [Sat, 25 Dec 2021 14:52:20 +0000 (15:52 +0100)]
libpci: i386-io-windows.h: Enable I/O access via native NT ProcessUserModeIOPL syscall
libpci uses WinIo library from http://www.internals.com/ which is archived
at https://web.archive.org/web/20151005172744/http://www.internals.com/
This external WinIo library has two big issues:
1. Library license is incompatible with pciutils license.
2. It silently and automatically installs 3rd-party NT kernel module
WinIo.sys which is bundled in WinIO.dll binary.
That NT kernel module creates a device file "\\.\WinIo" which can be opened
by any running process. Via this device file can any process (including
unprivileged or those running under Guest account) ask that kernel module
to configure x86 TSS I/O port permissions for access to any I/O port. That
NT kernel module does not implement any permission checks and automatically
accept all requests.
Change in this commit replaces insecure WinIO.dll library and WinIo.sys
kernel module by proper NT system solution: Usage of ProcessUserModeIOPL
syscall (equivalent of iopl(3) on Linux) which is supported directly by NT
kernel. It does not require any external 3rd-party library or NT kernel
module.
This syscall can be invoked by NtSetInformationProcess() function from
ntdll.dll library (which is part of NT system) and for privileged processes
kernel changes x86 IOPL to 3.
Privileged process is that which has SeTcbPrivilege (Act as part of the
operating system privilege) or is running under account from local
Administrators group with SeImpersonatePrivilege (Impersonate a client
after authentication privilege). SeImpersonatePrivilege is enabled by
default for accounts from local Administrators group.
Usage of privileges is not easy operation and needs to call lot of
functions to gain required permissions, achieve thread-safety and follow
suggested guidelines. Hence code is quite long.
Privileges (including SeTcbPrivilege) can be enabled / disabled in User
Accounts settings by local Administrators and change takes effect after
next login, not immediately.
Pali Rohár [Sat, 25 Dec 2021 12:45:28 +0000 (13:45 +0100)]
libpci: i386-io-windows.h: Fix definitions of I/O port functions for UCRT, CRTDLL and for 64-bit mode
Functions _outp(), _outpw(), _outpd(), _inp(), _inpw() and _inpd() are
available only in 32-bit version of the old MSVCRT library. They are not
available in 64-bit version of old MSVCRT library and neither the oldest
CRTDLL library or in new UCRT library.
Function prototypes for 32-bit mode should be available in <conio.h> header
file. But they are missing in some MinGW toolchains.
For 64-bit mode I/O port functions are defined only as inline functions or
intrinsics macros in <intrin.h> header file but under different names:
__outbyte(), __outword(), __outdword(), __inbyte(), __inword(), __indword()
This header file is available also in UCRT-compatible compilers.
When compiling with the oldest CRTDLL library and not using <intrin.h>
header file, it is required to provide own implementation of these
functions. Do it via inline assembly.
With this change it is possible to compile i386-io-windows.h with all
combination of toolchains, compilers, crt library and arch mode.
The most important is the fix to allow compilation with modern UCRT
library.
Gustavo Pimentel [Wed, 18 Nov 2020 22:56:52 +0000 (23:56 +0100)]
lspci: Add PCIe 6.0 data rate (64 GT/s) support
This enables "lspci" to show PCIe 6.0 data rate (64 GT/s) properly
according to the contents in register PCI_EXP_LNKCAP, PCI_EXP_LNKSTA
and PCI_EXP_LNKCTL2.
configure: Support cross-building for GNU/kFreeBSD
We need to set a sys variable matching what would be found in the GNU
triplet for the GNU/kFreeBSD architecture, otherwise the later code will
not match correctly.
Sean V Kelley [Wed, 24 Jun 2020 22:39:40 +0000 (15:39 -0700)]
pciutils: Add decode support for RCECs
Root Complex Event Collectors provide support for terminating error
and PME messages from RCiEPs. This patch provides basic decoding for
the lspci RCEC Endpoint Association Extended Capability. See PCIe 5.0-1,
sec 7.9.10 for further details.
Suggested-by: Bjorn Helgaas <bhelgaas@google.com> Signed-off-by: Sean V Kelley <sean.v.kelley@linux.intel.com>
Martin Mares [Sun, 31 May 2020 10:24:41 +0000 (12:24 +0200)]
Hurd: Do not identify devices during scan
Let us keep the bus scan light-weight. Whoever is interested
in device IDs, still has to call pci_fill_info(PCI_FILL_IDENT),
which handles this in generic way.