]> git.ipfire.org Git - thirdparty/pciutils.git/log
thirdparty/pciutils.git
19 months agocxl: Rename variable to match other code
Ben Widawsky [Thu, 3 Jun 2021 19:02:17 +0000 (12:02 -0700)] 
cxl: Rename variable to match other code

The current variable is word sized, and so this makes the CXL code match
the rest of the code.

Signed-off-by: Ben Widawsky <ben.widawsky@intel.com>
Signed-off-by: Jaxon Haws <jaxon.haws@amd.com>
21 months agoAvoid adding multiple version tags to the same symbol
Martin Mares [Wed, 10 Aug 2022 06:34:28 +0000 (13:34 +0700)] 
Avoid adding multiple version tags to the same symbol

This is apparently forbidden in most versions of binutils.

2 years agoReleased as 3.8.0. v3.8.0
Martin Mares [Mon, 18 Apr 2022 16:48:26 +0000 (18:48 +0200)] 
Released as 3.8.0.

2 years agoFilters: Fixed symbol versioning
Martin Mares [Mon, 18 Apr 2022 16:47:00 +0000 (18:47 +0200)] 
Filters: Fixed symbol versioning

2 years agoREADME and ChangeLog for 3.8.0.
Martin Mares [Fri, 15 Apr 2022 23:55:33 +0000 (01:55 +0200)] 
README and ChangeLog for 3.8.0.

2 years agoDocument new filter syntax in man pages
Martin Mares [Fri, 15 Apr 2022 23:26:19 +0000 (01:26 +0200)] 
Document new filter syntax in man pages

2 years agoFilters now support partially specified classes and also prog-if's
Martin Mares [Fri, 15 Apr 2022 23:22:44 +0000 (01:22 +0200)] 
Filters now support partially specified classes and also prog-if's

Rewritten the filter parser, the old code was too twisted to extend.

2 years agopciutils.lsm: metalab.unc.edu is gone
Martin Mares [Fri, 15 Apr 2022 22:21:39 +0000 (00:21 +0200)] 
pciutils.lsm: metalab.unc.edu is gone

2 years agoUpdated pci.ids to today's snapshot
Martin Mares [Fri, 15 Apr 2022 22:17:33 +0000 (00:17 +0200)] 
Updated pci.ids to today's snapshot

2 years agolspci: Fix detection of memory space bar
Pali Rohár [Thu, 10 Mar 2022 20:38:18 +0000 (21:38 +0100)] 
lspci: Fix detection of memory space bar

intel-conf1 backend never show AtomicOpsCap: capabilities despite the fact
that is successfuly detects memory bars on device. But other backends show
this capability.

Error is in device_has_memory_space_bar() function, it expects that ->size
member is always filled. But size of the BAR is not available in PCI config
space and therefore raw backends cannot retrieve it.

Probably intention of the non-zero check was to verify that base address
was filled with non-zero size. So either base address is non-zero or length
is non-zero. Adjust check.

2 years agolspci: Fix detection of extended capabilities
Pali Rohár [Sat, 5 Mar 2022 23:22:54 +0000 (00:22 +0100)] 
lspci: Fix detection of extended capabilities

Bus may report all-ones when trying to access non-existent extended space.
Same check is also in lib/caps.c extended space parser.

2 years agolspci: Fix detection of virtual regions
Pali Rohár [Sat, 5 Mar 2022 23:22:03 +0000 (00:22 +0100)] 
lspci: Fix detection of virtual regions

There are many issues with detection of virtual regions.

1. Variable for detecting virtual region is global and if one BAR is marked
   as virtual then all remaining BARs are treated as virtual too as this
   variable is not reset at next loop iteration.

2. Lower address is read from flg variable which on backends without config
   space is initialized from PCI flags, not from base address.

3. Code mixes at many places PCI flags, resource flags, PCI addresses and
   resource addresses. Some backends reports PCI flags in PCI addresses,
   some not.

Cleanup mess of ->base_addr, ->flags and PCI_BASE_ADDRESS. If backend
provides ->flags value (test via PCI_FILL_IO_FLAGS) then use it instead of
reading flags from pci config space.

Fix reading of PCI hw_lower and hw_upper addresses. If PCI_BASE_ADDRESS
reports different type than what is stored in base_addr then completely
ignore hw_lower and hw_upper values. It means that backend either provide
fiction information or provide resources in different order as they are
stored in hardware. In any case values from HW cannot be used as they do
not match values reported by backend.

And in the last case, make virtual variable local to the current BAR
processing and do not increment loop variable i when 64-bit MEM type is
detected via data from config space. It could miss some virtual resource
reported by the backend.

This change fixes displaying resources of PCI devices which have some
unset/unused BARs in the middle and OS reports virtual regions and
remaining regions without holes. E.g. HW BARs 0, 2, 5 are used and OS
reports base_addr 0, 1, 2, 3.

2 years agolspci: Fix handling of truncated lines for msvcrt.dll
Pali Rohár [Sun, 27 Feb 2022 23:06:00 +0000 (00:06 +0100)] 
lspci: Fix handling of truncated lines for msvcrt.dll

msvcrt.dll's vsnprintf() implementation does not fill terminating null byte
when overflow occurs and buffer size is returned.

2 years agolibpci: i386-io-windows.h: Fix error handling for GetProcessImageFileNameW() and...
Pali Rohár [Sun, 10 Apr 2022 11:58:38 +0000 (13:58 +0200)] 
libpci: i386-io-windows.h: Fix error handling for GetProcessImageFileNameW() and GetModuleFileNameExW()

These functions may require buffer which is larger than MAX_PATH (wide)
characters and their error handling is more complicated. Fix it.

2 years agolibpci: i386-io-windows.h: Fix MinGW build with pre-4.00 MSVCRT runtime library
Pali Rohár [Sun, 27 Feb 2022 19:02:37 +0000 (20:02 +0100)] 
libpci: i386-io-windows.h: Fix MinGW build with pre-4.00 MSVCRT runtime library

Like CRTDLL library, pre-4.00 MSVCRT runtime library does not provide I/O port functions.

2 years agolibpci: Always call pci_set_name_list_path() in pci_init_name_list_path()
Pali Rohár [Sun, 27 Feb 2022 00:57:38 +0000 (01:57 +0100)] 
libpci: Always call pci_set_name_list_path() in pci_init_name_list_path()

If pci_init_name_list_path() does not call pci_set_name_list_path() then
a->id_file_name variable is NULL and pci_load_name_list() would crash as it
tries to do fopen(NULL, ...).

If libpci was configured at compile time to use current executable path for
locating pci.ids file and it is not possible to determinate current
executable path then call pci_set_name_list_path() with just filename
without path (this would fallback to the current working directory).

2 years agolibpci: Compile windows i386-ports only for x86 CPU
Pali Rohár [Sun, 2 Jan 2022 14:38:42 +0000 (15:38 +0100)] 
libpci: Compile windows i386-ports only for x86 CPU

There are already arm32 and arm64 port of MinGW-w64 toolchain.

2 years agofbsd-device: One more fix
Martin Mares [Fri, 15 Apr 2022 21:51:21 +0000 (23:51 +0200)] 
fbsd-device: One more fix

Finishes the incomplete fix from 5c649bdcedfd823670dcbd74e9c38849d068db80.

2 years agoFix lspci: Power Management Control/Status PCI to PCI Bridge Support Extensions
Mikhail Bratchikov [Tue, 5 Apr 2022 11:34:49 +0000 (14:34 +0300)] 
Fix lspci: Power Management Control/Status PCI to PCI Bridge Support Extensions

2 years agoREADME: Mention cfgmgr32 for Windows
Pali Rohár [Sat, 26 Feb 2022 14:41:19 +0000 (15:41 +0100)] 
README: Mention cfgmgr32 for Windows

2 years agoREADME: Update information about Windows
Pali Rohár [Thu, 10 Feb 2022 19:41:53 +0000 (20:41 +0100)] 
README: Update information about Windows

Basic support for 64-bit systems is there.

2 years agopcilib.man: Include information about win32-cfgmgr32
Pali Rohár [Tue, 4 Jan 2022 13:19:18 +0000 (14:19 +0100)] 
pcilib.man: Include information about win32-cfgmgr32

2 years agolspci: Do not access config space when it is emulated
Pali Rohár [Tue, 28 Dec 2021 19:29:21 +0000 (20:29 +0100)] 
lspci: Do not access config space when it is emulated

Emulated config space contains only few information so it could look like
some valid config space. libpci compose emulated config space either from
struct pci_dev or put some fake information (when struct pci_dev does not
have them).

To prevent showing to user fake/bogus information about PCI devices, show
only information which are directly stored in struct pci_dev when emulated
config space is used.

Do it via setting lspci's header type to invalid value (byte)-1, so lspci
code will handle device as unknown without trying to interpret values
config space. This header type is set only in lspci, not in libpci, so
other libpci applications would see valid config space.

lspci users are probably not interested in fake information provided by
libpci just for purpose to export syntactically valid config space.
Information stored in struct pci_dev are the correct one (or rather what OS
things that is correct).

2 years agolibpci: Add windows cfgmgr32 implementation
Pali Rohár [Fri, 31 Dec 2021 16:49:00 +0000 (17:49 +0100)] 
libpci: Add windows cfgmgr32 implementation

Access via cfgmgr32.dll library allows to list PCI devices and retrieve
their basic properties and system resource configuration. Access is
available to all users and should not require special privileges, access
tokens, rights or permissions.

This cfgmgr32.dll library does not provide access to PCI config space.

2 years agolibpci: Implement virtual config space for provides without access to config space
Pali Rohár [Sun, 2 Jan 2022 12:33:12 +0000 (13:33 +0100)] 
libpci: Implement virtual config space for provides without access to config space

Add a new pci_dev member no_config_access which signals that there is no
access to config space for particular device. Reading operation in this
case should return data from emulated virtual config space. For provides
there is a new helper function pci_generic_read() which emulates config
spaces based on struct pci_dev members.

2 years agolspci: Show information also for devices with unknown header type
Pali Rohár [Sun, 27 Feb 2022 15:06:59 +0000 (16:06 +0100)] 
lspci: Show information also for devices with unknown header type

lspci sees header type with 0x7f value in case config space is not
accessible. It may be because of permission issues or missing backend
(e.g. on Windows) or because device itself does not respond to config
cycles and config space is inaccessible.

Inaccessible config space is common scenario for switchable PCIe GPU
cards. Some Nvidia and also some AMD cards when sleep then lspci sees
all-ones in their config space. But kernel has registered those cards and
some of their properties are cached ans available via sysfs or procfs (from
time when card was awake).

Currently lspci shows error message "Unknown header type 7f" and does not
parse any value neither from config space nor from sysfs backend.

So try to show at least information which kernel provided into libpci
struct pci_dev.

Set unknown values to zeros (instead of all-ones which are returned from
config space) and add a new function show_htype_unknown() for showing
additional information in case header type is unknown.

This change will also help new windows backend which has only emulated
config space and therefore valid data only in struct pci_dev.

2 years agolibpci: Define some more PCI_IORESOURCE flags (compatible with ioport.h)
Pali Rohár [Fri, 31 Dec 2021 16:48:10 +0000 (17:48 +0100)] 
libpci: Define some more PCI_IORESOURCE flags (compatible with ioport.h)

These flags define mapping between PCI config space and system resources.
So non-sysfs/procfs providers can fill these flags too.

2 years agoTried to fix the fbsd-device back-end
Martin Mares [Thu, 14 Apr 2022 12:17:07 +0000 (14:17 +0200)] 
Tried to fix the fbsd-device back-end

It was left broken by the fill_info reform.

2 years agopciutils: Add decode support for Data Object Exchange Extended Capability
Jonathan Cameron [Thu, 10 Feb 2022 16:19:45 +0000 (16:19 +0000)] 
pciutils: Add decode support for Data Object Exchange Extended Capability

PCI Data Object Exchange [1] provides a mailbox interface used as the
transport for various protocols defined by PCI-SIG and others. Make the
limited information in config space available. Note the Read/Write
Mailbox registers themselves are not currently parsed as the usefulness
of accessing one dword of a protocol is probably limited.

In future, operating systems may provide means to safely query the
supported protocols, but those have not yet been defined.

Example output:

Capabilities: [100 v1] Data Object Exchange
DOECap: IntSup+
Interrupt Message Number 001
DOECtl: IntEn+
DOESta: Busy- IntSta- Error- ObjectReady+

[1] PCIe r6.0, sections 6.30 and 7.9.24

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2 years agolspci: Decode PCIe 6.0 Slot Power Limit values
Pali Rohár [Fri, 25 Feb 2022 18:12:09 +0000 (19:12 +0100)] 
lspci: Decode PCIe 6.0 Slot Power Limit values

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   > 239 W and ≤ 250 W Slot Power Limit
  F1h   > 250 W and ≤ 275 W Slot Power Limit
  F2h   > 275 W and ≤ 300 W Slot Power Limit
  F3h   > 300 W and ≤ 325 W Slot Power Limit
  F4h   > 325 W and ≤ 350 W Slot Power Limit
  F5h   > 350 W and ≤ 375 W Slot Power Limit
  F6h   > 375 W and ≤ 400 W Slot Power Limit
  F7h   > 400 W and ≤ 425 W Slot Power Limit
  F8h   > 425 W and ≤ 450 W Slot Power Limit
  F9h   > 450 W and ≤ 475 W Slot Power Limit
  FAh   > 475 W and ≤ 500 W Slot Power Limit
  FBh   > 500 W and ≤ 525 W Slot Power Limit
  FCh   > 525 W and ≤ 550 W Slot Power Limit
  FDh   > 550 W and ≤ 575 W Slot Power Limit
  FEh   > 575 W and ≤ 600 W Slot Power Limit
  FFh   Reserved for Slot Power Limit Values above 600 W

Previously only values F0h, F1h and F2h were covered.

2 years agoMerge remote-tracking branch 'github/master'
Martin Mares [Thu, 10 Feb 2022 12:50:32 +0000 (13:50 +0100)] 
Merge remote-tracking branch 'github/master'

2 years agolspci: Replace find_driver() via libpci PCI_FILL_DRIVER
Pali Rohár [Mon, 27 Dec 2021 13:06:18 +0000 (14:06 +0100)] 
lspci: Replace find_driver() via libpci PCI_FILL_DRIVER

And implement this show_kernel() and show_kernel_machine() for all
platforms.

2 years agolibpci: sysfs: Implement support for PCI_FILL_DRIVER
Pali Rohár [Mon, 27 Dec 2021 13:05:47 +0000 (14:05 +0100)] 
libpci: sysfs: Implement support for PCI_FILL_DRIVER

In sysfs is driver name stored as symlink path of "driver" node.

2 years agolibpci: proc: Implement support for PCI_FILL_DRIVER
Pali Rohár [Mon, 27 Dec 2021 13:05:32 +0000 (14:05 +0100)] 
libpci: proc: Implement support for PCI_FILL_DRIVER

File /proc/bus/pci/devices contains optional driver name in the last 18th field.

2 years agolibpci: Define new string property PCI_FILL_DRIVER
Pali Rohár [Mon, 27 Dec 2021 13:04:59 +0000 (14:04 +0100)] 
libpci: Define new string property PCI_FILL_DRIVER

This change extends libpci library and allows providers to fill
PCI_FILL_DRIVER via native system APIs. As it is string property there is
no need to increase ABI version.

Intended usage in application is just:

  const char *driver = pci_get_string_property(d->dev, PCI_FILL_DRIVER);

2 years agolspci: Do not show -[00]- bus in tree output
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.

2 years agolspci: Build tree based on PCI_FILL_PARENT information
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.

2 years agolibpci: sysfs: Implement support for PCI_FILL_PARENT
Pali Rohár [Tue, 28 Dec 2021 19:11:27 +0000 (20:11 +0100)] 
libpci: sysfs: Implement support for PCI_FILL_PARENT

2 years agolibpci: Add new option PCI_FILL_PARENT
Pali Rohár [Tue, 28 Dec 2021 19:09:57 +0000 (20:09 +0100)] 
libpci: Add new option PCI_FILL_PARENT

This change extends libpci and allows providers to fill parent pci_dev.
This is useful to retrieve topology as it is reported by the system itself.

2 years agolspci: Retrieve prog if, subsystem ids and revision id via libpci
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).

2 years agolibpci: sysfs: Implement CLASS_EXT and SUBSYS support
Pali Rohár [Mon, 27 Dec 2021 11:28:34 +0000 (12:28 +0100)] 
libpci: sysfs: Implement CLASS_EXT and SUBSYS support

In sysfs there are optional nodes with this information.

2 years agolibpci: generic: Implement SUBSYS also for PCI_HEADER_TYPE_BRIDGE
Pali Rohár [Mon, 20 Dec 2021 21:56:33 +0000 (22:56 +0100)] 
libpci: generic: Implement SUBSYS also for PCI_HEADER_TYPE_BRIDGE

Subsystem ids for PCI Bridges are stored in extended capability
PCI_CAP_ID_SSVID.

2 years agolibpci: generic: Implement CLASS_EXT and SUBSYS support
Pali Rohár [Mon, 27 Dec 2021 11:31:55 +0000 (12:31 +0100)] 
libpci: generic: Implement CLASS_EXT and SUBSYS support

PCI_FILL_SUBSYS is implemented only for PCI_HEADER_TYPE_NORMAL and
PCI_HEADER_TYPE_CARDBUS like in lspci.

2 years agolibpci: Add new options for pci_fill_info: CLASS_EXT and SUBSYS
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.

2 years agolspci: Use PCI_FILL_BRIDGE_BASES to detect if range behind bridge is disabled or...
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.

2 years agolibpci: Add support for filling bridge resources
Pali Rohár [Sat, 20 Nov 2021 13:36:40 +0000 (14:36 +0100)] 
libpci: Add support for filling bridge resources

Extend libpci API and ABI to fill bridge resources from sysfs.

2 years agolspci: Simplify printing range in show_range()
Pali Rohár [Sat, 20 Nov 2021 12:43:35 +0000 (13:43 +0100)] 
lspci: Simplify printing range in show_range()

Use just one printf() call with width format argument based on number of bits.

2 years agolspci: Show 16/32/64 bit width for address ranges behind bridge
Pali Rohár [Mon, 18 Oct 2021 14:58:33 +0000 (16:58 +0200)] 
lspci: Show 16/32/64 bit width for address ranges behind bridge

Type of address range is encoded in lower bits.

2 years agoMerge branch 'fill-info'
Martin Mares [Thu, 10 Feb 2022 12:49:06 +0000 (13:49 +0100)] 
Merge branch 'fill-info'

2 years agolibpci: i386-io-windows.h: Fix comment about CRTDLL
Pali Rohár [Thu, 10 Feb 2022 12:33:46 +0000 (13:33 +0100)] 
libpci: i386-io-windows.h: Fix comment about CRTDLL

There is no 64-bit version of CRTDLL library. MinGW-w64 provided bogus
64-bit import library for non-existent runtime DLL library, which was
recently deleted.

2 years agolspci: Define PCI_U64_FMT_U format for printing u64
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).

2 years agolspci: Replace unsigned long long type by u64 and %llx format by PCI_U64_FMT_X
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).

2 years agopciutils: Remove #include <unistd.h> from files which do not need it
Pali Rohár [Sun, 26 Dec 2021 21:11:36 +0000 (22:11 +0100)] 
pciutils: Remove #include <unistd.h> from files which do not need it

In more files is <unistd.h> header file included without any usage.

MSVC does not provide this header file so remove this useless usage of
<unistd.h> to allow compilation under MSVC.

2 years agolibpci: For PCI_OS_WINDOWS include windows.h instead of windef.h
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.

2 years agolibpci: For PCI_OS_WINDOWS define strncasecmp as alias for _strnicmp
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.

2 years agolibpci: For MSVC < 19.00 define snprintf outside of endian section
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().

2 years agolibpci: For MSVC < 19.00 define vsnprintf as alias for _vsnprintf
Pali Rohár [Sun, 26 Dec 2021 21:11:18 +0000 (22:11 +0100)] 
libpci: For MSVC < 19.00 define vsnprintf as alias for _vsnprintf

MSVC prior version 19.00 do not have vsnprintf() function, only
_vsnprintf().

2 years agoInstall lspci to /usr/bin on Linux systems
Martin Mares [Wed, 9 Feb 2022 20:20:50 +0000 (21:20 +0100)] 
Install lspci to /usr/bin on Linux systems

On Linux, lspci is useful even for ordinary users, although only
a subset of features is available.

2 years agoREADME: Added a note on dynamic linking and derived works
Martin Mares [Fri, 28 Jan 2022 16:09:34 +0000 (17:09 +0100)] 
README: Added a note on dynamic linking and derived works

2 years agoSimplified pci_fill_info() and friends fill-info
Martin Mares [Fri, 21 Jan 2022 20:39:18 +0000 (21:39 +0100)] 
Simplified pci_fill_info() and friends

Previously, we kept track of which fields were already filled, which
was quite brittle.

Now we keep only the set of already known fields in struct pci_dev.
We check if the current field is needed against this information.

Not only this simplifies the whole thing, but it also enables future
back-ends to call pci_fill_info() recursively as needed.

2 years agoAnother try at choosing the default compiler
Martin Mares [Fri, 21 Jan 2022 13:27:49 +0000 (14:27 +0100)] 
Another try at choosing the default compiler

Cross-compilers often provide only "gcc" and not "cc".

So let's try "cc" when building natively and "gcc" when cross-compiling.

2 years agolspci: Improvements to PCIe link speed downgrade reporting
Martin Mares [Fri, 21 Jan 2022 13:16:37 +0000 (14:16 +0100)] 
lspci: Improvements to PCIe link speed downgrade reporting

Do not report PCIe link downgrades for downstream ports.

Changed wording so that "overdriven" is reported instead of
"strange" for speeds greater than the maximum supported one.

Also report nothing instead of "ok".

Inspired by patches by Bjorn Helgaas and Matthew Wilcox.

2 years agopci.h: The error callback is now declared with PCI_NONRET
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.

2 years agotypes.h: Introduced PCI_NONRET
Martin Mares [Fri, 21 Jan 2022 13:09:04 +0000 (14:09 +0100)] 
types.h: Introduced PCI_NONRET

2 years agolspci: Update tests files with VF 10-Bit Tag Requester
Dongdong Liu [Tue, 9 Mar 2021 13:35:19 +0000 (21:35 +0800)] 
lspci: Update tests files with VF 10-Bit Tag Requester

Update the tests files with the new field 10BitTagReq
in SR-IOV Capabilities Register.

Signed-off-by: Dongdong Liu <liudongdong3@huawei.com>
2 years agolspci: Decode VF 10-Bit Tag Requester
Dongdong Liu [Tue, 9 Mar 2021 13:35:18 +0000 (21:35 +0800)] 
lspci: Decode VF 10-Bit Tag Requester

Decode VF 10-Bit Tag Requester Supported and Enable bit
in SR-IOV Capabilities Register.

Sample output:
  IOVCap: Migration- 10BitTagReq- Interrupt Message Number: 000
  IOVCtl: Enable+ Migration- Interrupt- MSE+ ARIHierarchy- 10BitTagReq-

Signed-off-by: Dongdong Liu <liudongdong3@huawei.com>
2 years agolspci: Bus mapping works in non-zero domain
Martin Mares [Fri, 21 Jan 2022 12:58:56 +0000 (13:58 +0100)] 
lspci: Bus mapping works in non-zero domain

2 years agoMakefile: don't hardcode gcc
Vladimír Čunát [Thu, 24 Sep 2020 08:28:18 +0000 (10:28 +0200)] 
Makefile: don't hardcode gcc

I believe "cc" is a much better default nowadays.
Another approach would be to (also) use "?=" for these variables.

2 years agolibpci: i386-io-windows.h: Mute false-positive warning
Pali Rohár [Fri, 31 Dec 2021 15:43:25 +0000 (16:43 +0100)] 
libpci: i386-io-windows.h: Mute false-positive warning

  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.

2 years agoi386-ports: Do not mark pci_access in conf12_cleanup() as unused
Pali Rohár [Sat, 1 Jan 2022 13:42:12 +0000 (14:42 +0100)] 
i386-ports: Do not mark pci_access in conf12_cleanup() as unused

It is used as argument for intel_cleanup_io() function.

2 years agolib: Fix definition of strcasecmp() for PCI_OS_WINDOWS
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.

2 years agocompat/getopt: Fix compatibility with non-GNU C 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.

2 years agopciutils: Do not include compat/getopt.h on MinGW32 >= 3.0
Pali Rohár [Sun, 26 Dec 2021 17:19:41 +0000 (18:19 +0100)] 
pciutils: Do not include compat/getopt.h on MinGW32 >= 3.0

MinGW32 since version 3.0 declares getopt() function prototype in
<unistd.h> header file.

2 years agoAdd PCIe 3.0+ decoding of the LnkCtl2 Compliance Preset/De-emphasis field
Lennert Buytenhek [Fri, 24 Dec 2021 08:48:01 +0000 (10:48 +0200)] 
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>
2 years agols-tree: Fix handling of truncated lines
Martin Mares [Tue, 28 Dec 2021 14:57:07 +0000 (15:57 +0100)] 
ls-tree: Fix handling of truncated lines

2 years agoi386-ports: Added missing #include <string.h>
Martin Mares [Tue, 28 Dec 2021 14:56:53 +0000 (15:56 +0100)] 
i386-ports: Added missing #include <string.h>

2 years agoMakefile: Add compat/getopt.h into PCIINC dependency list
Pali Rohár [Tue, 28 Dec 2021 14:01:25 +0000 (15:01 +0100)] 
Makefile: Add compat/getopt.h into PCIINC dependency list

2 years agoREADME: Add a note on C99
Martin Mares [Mon, 27 Dec 2021 00:10:21 +0000 (01:10 +0100)] 
README: Add a note on C99

2 years agoRenamed maint/RELEASE to appease case-insensitive filesystems
Martin Mares [Sun, 26 Dec 2021 23:56:49 +0000 (00:56 +0100)] 
Renamed maint/RELEASE to appease case-insensitive filesystems

2 years agolspci: Show Slot Power Limit values above EFh
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".

2 years agolibpci: Fix intel_sanity_check() function
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.

2 years agolspci: Print buses of multibus PCI domain in ascending order
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.

2 years agointel_cleanup_io() no longer returns a value
Martin Mares [Sun, 26 Dec 2021 22:02:47 +0000 (23:02 +0100)] 
intel_cleanup_io() no longer returns a value

The value was quite misleading, as witnessed by multiple implementations
doing it wrong. In fact, the only return value which ever made sense was -1.

2 years agodump: Allow more leading zeros in dump line number
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.

2 years agoREADME: Update information how to compile Windows port
Pali Rohár [Sun, 26 Dec 2021 21:30:19 +0000 (22:30 +0100)] 
README: Update information how to compile Windows port

2 years agowin32: Remove old config.h and config.mk files
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.

2 years agoconfigure: Generate config files for PCI_OS_WINDOWS
Pali Rohár [Sun, 26 Dec 2021 17:47:33 +0000 (18:47 +0100)] 
configure: Generate config files for PCI_OS_WINDOWS

This change adds support for using configure script for cross-compiling
pciutils on Linux for Windows platforms.

Following command can be used to compile pcitils for Windows platform:

  make CROSS_COMPILE=i586-mingw32msvc- HOST=i386-windows ZLIB=no IDSDIR=.

PCI_OS_WINDOWS does not support BSD DNS functions, so do not automatically
enable DNS support.

Library ioperm is cygwin specific and is used only for PCI_OS_CYGWIN.

2 years agoMakefile: Add new option COMPAT_GETOPT
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.

2 years agoMakefile: Append EXEEXT variable to executable filename rules
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.

2 years agoFactored out initialization of name list path
Martin Mares [Sun, 26 Dec 2021 21:41:05 +0000 (22:41 +0100)] 
Factored out initialization of name list path

2 years agolibpci: For PCI_OS_WINDOWS allows to load pci.ids from executable directory
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.

2 years agolibpci: i386-io-windows.h: Enable I/O access via native NT ProcessUserModeIOPL syscall
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.

2 years agolibpci: i386-io-windows.h: Fix definitions of I/O port functions for UCRT, CRTDLL...
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.

2 years agolibpci: i386-io-windows.h: Skip I/O setup on 16/32-bit non-NT systems
Pali Rohár [Sat, 25 Dec 2021 12:45:17 +0000 (13:45 +0100)] 
libpci: i386-io-windows.h: Skip I/O setup on 16/32-bit non-NT systems

16/32-bit non-NT systems allow applications to access PCI I/O ports without
any special setup.

2 years agoCleaned up previous commit
Martin Mares [Sun, 26 Dec 2021 21:20:23 +0000 (22:20 +0100)] 
Cleaned up previous commit

2 years agoFix the primitive system dependency discovery for Darwin systems
Laurin-Luis Lehning [Thu, 4 Mar 2021 18:55:31 +0000 (19:55 +0100)] 
Fix the primitive system dependency discovery for Darwin systems

2 years agoMan pages: clarify pci.ids location
Robert Elliott [Wed, 3 Mar 2021 20:12:25 +0000 (14:12 -0600)] 
Man pages: clarify pci.ids location

Include both the path and filename of pci.ids in the pci.ids man page
and the update-pciids man page

2 years agoupdate-pciids man page: add cross-references
Robert Elliott [Wed, 3 Mar 2021 20:11:12 +0000 (14:11 -0600)] 
update-pciids man page: add cross-references

Add cross-references to gzip, bzip2, curl, wget, and lynx.

2 years agoman pages: update cross-references to pci.ids
Robert Elliott [Wed, 3 Mar 2021 19:33:12 +0000 (13:33 -0600)] 
man pages: update cross-references to pci.ids

In the update-pciids man page:
* remove reference to setpci, since that does not use pci.ids
* add reference to pci.ids

Fixes: ef5b622f488e ("Added a man page for pci.ids")
2 years agoMakefile: Update uninstall target to match all install* targets
Martin Mares [Sun, 26 Dec 2021 21:13:40 +0000 (22:13 +0100)] 
Makefile: Update uninstall target to match all install* targets