git: ca25b1b26379 - main - devinfo: Support PCI DBSF and ACPI handles for -p
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 06 Mar 2026 21:32:42 UTC
The branch main has been updated by jhb:
URL: https://cgit.FreeBSD.org/src/commit/?id=ca25b1b26379e27bf2bab7742a7b383ca0bfc7d2
commit ca25b1b26379e27bf2bab7742a7b383ca0bfc7d2
Author: John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2026-03-06 20:36:05 +0000
Commit: John Baldwin <jhb@FreeBSD.org>
CommitDate: 2026-03-06 20:36:05 +0000
devinfo: Support PCI DBSF and ACPI handles for -p
When matching on a name of a device, match on ACPI handles and PCI
selectors in addition to device names. This can be useful for
matching on devices without an attached driver.
For example: devinfo -p pci0:0:31:0
Reviewed by: imp
Sponsored by: Chelsio Communications
Differential Revision: https://reviews.freebsd.org/D55673
---
usr.sbin/devinfo/devinfo.8 | 22 +++++++++++++++++-
usr.sbin/devinfo/devinfo.c | 58 +++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 78 insertions(+), 2 deletions(-)
diff --git a/usr.sbin/devinfo/devinfo.8 b/usr.sbin/devinfo/devinfo.8
index 8bf4f9d10e17..b8acdcf524ee 100644
--- a/usr.sbin/devinfo/devinfo.8
+++ b/usr.sbin/devinfo/devinfo.8
@@ -26,7 +26,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd August 28, 2025
+.Dd March 6, 2026
.Dt DEVINFO 8
.Os
.Sh NAME
@@ -53,6 +53,26 @@ The following options are accepted:
Display the path of
.Ar dev
back to the root of the device tree.
+.Ar dev
+can either be a device name,
+the absolute path of an ACPI handle
+.Po must begin with a
+.Dq \e
+.Pc ,
+or a PCI selector
+.Po
+either
+.Sy pci Ns Fa domain Ns : Ns Fa bus Ns : Ns Fa slot Ns : Ns Fa function
+or
+.Sy pci Ns Fa bus Ns : Ns Fa slot Ns : Ns Fa function
+.Pc .
+.Pp
+If
+.Fl v
+is specified,
+each device is output on a separate line including the device name and
+additional verbose information;
+otherwise, a space-separated list of device names is output.
.It Fl r
Causes hardware resource information
.Pq such as IRQ, I/O ports, I/O memory addresses
diff --git a/usr.sbin/devinfo/devinfo.c b/usr.sbin/devinfo/devinfo.c
index 43d88481d903..bea082ba6285 100644
--- a/usr.sbin/devinfo/devinfo.c
+++ b/usr.sbin/devinfo/devinfo.c
@@ -275,13 +275,69 @@ print_device_path_entry(struct devinfo_dev *dev)
printf("\n");
}
+/*
+ * This assumes the string to be compared in *cp is either space or
+ * nul terminated.
+ */
+static bool
+match_value(const char *cp, const char *name)
+{
+ const char *end;
+ size_t len;
+
+ end = strchr(cp, ' ');
+ if (end == NULL)
+ return (strcmp(cp, name) == 0);
+
+ if (end == cp)
+ return (false);
+
+ /* NB: strncmp(3) would return zero if name matches a prefix. */
+ len = end - cp;
+ return (strlen(name) == len && memcmp(name, cp, len) == 0);
+}
+
+static bool
+device_matches_name(struct devinfo_dev *dev, const char *name)
+{
+ const char *cp, *val;
+
+ if (strcmp(dev->dd_name, name) == 0)
+ return (true);
+
+ if (*dev->dd_location) {
+ /* Permit matches on the ACPI handle stored in location. */
+ if (name[0] == '\\' && (cp = strstr(dev->dd_location,
+ "handle=\\")) != NULL) {
+ if (match_value(cp + strlen("handle="), name))
+ return (true);
+ }
+
+ /* Permit matches on the PCI dbsf stored in location. */
+ if (strncmp(name, "pci", strlen("pci")) == 0 &&
+ (cp = strstr(dev->dd_location, "dbsf=pci")) != NULL) {
+ cp += strlen("dbsf=pci");
+ val = name + strlen("pci");
+ if (match_value(cp, val))
+ return (true);
+
+ /* Also match on pci<b>:<s>:<f> for domain 0. */
+ if (strncmp(cp, "0:", strlen("0:")) == 0 &&
+ match_value(cp + strlen("0:"), val))
+ return (true);
+ }
+ }
+
+ return (false);
+}
+
static int
print_device_path(struct devinfo_dev *dev, void *xname)
{
const char *name = xname;
int rv;
- if (strcmp(dev->dd_name, name) == 0) {
+ if (device_matches_name(dev, name)) {
print_device_path_entry(dev);
return (1);
}