From owner-svn-src-all@freebsd.org Sat Feb 17 06:57:37 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2CF5BF143E0; Sat, 17 Feb 2018 06:57:37 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4D31F6AB55; Sat, 17 Feb 2018 06:57:35 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id DF0BC19441; Sat, 17 Feb 2018 06:57:34 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w1H6vYFH027759; Sat, 17 Feb 2018 06:57:34 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w1H6vYdk027757; Sat, 17 Feb 2018 06:57:34 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201802170657.w1H6vYdk027757@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Sat, 17 Feb 2018 06:57:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r329444 - head/sbin/devmatch X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: head/sbin/devmatch X-SVN-Commit-Revision: 329444 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Feb 2018 06:57:37 -0000 Author: imp Date: Sat Feb 17 06:57:34 2018 New Revision: 329444 URL: https://svnweb.freebsd.org/changeset/base/329444 Log: Add option to parse NOMATCH event and suggest modules to load Add --nomatch/-p to search for individual drivers based on a NOMATCH event from devd. Submitted by: hps (earlier version) Sponsored by: Netflix Modified: head/sbin/devmatch/devmatch.8 head/sbin/devmatch/devmatch.c Modified: head/sbin/devmatch/devmatch.8 ============================================================================== --- head/sbin/devmatch/devmatch.8 Sat Feb 17 06:57:30 2018 (r329443) +++ head/sbin/devmatch/devmatch.8 Sat Feb 17 06:57:34 2018 (r329444) @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd February 12, 2018 +.Dd February 16, 2018 .Dt DEVMATCH 8 .Os .Sh NAME @@ -33,9 +33,10 @@ .Nd print information about unattached devices .Sh SYNOPSIS .Nm -.Op Fl aduv +.Op Fl adpuv .Op Fl -all .Op Fl -dump +.Op Fl -nomatch .Op Fl -unbound .Op Fl -verbose .Sh DESCRIPTION @@ -50,6 +51,10 @@ Include all devices, not just the ones that are unatta Produce a human readable dump of the .Pa linker.hints file. +.It Fl p Fl -nomatch +Parse and use a standard NOMATCH event from +.Xr devd 8 +for matching instead of searching the device tree. .It Fl u Fl -unbound Attempt to produce a list of those drivers with PNP info whose driver tables with that PNP info can't be found. Modified: head/sbin/devmatch/devmatch.c ============================================================================== --- head/sbin/devmatch/devmatch.c Sat Feb 17 06:57:30 2018 (r329443) +++ head/sbin/devmatch/devmatch.c Sat Feb 17 06:57:34 2018 (r329444) @@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$"); static struct option longopts[] = { { "all", no_argument, NULL, 'a' }, { "dump", no_argument, NULL, 'd' }, + { "nomatch", required_argument, NULL, 'p' }, { "unbound", no_argument, NULL, 'u' }, { "verbose", no_argument, NULL, 'v' }, { NULL, 0, NULL, 0 } @@ -54,6 +55,7 @@ static struct option longopts[] = { static int all_flag; static int dump_flag; +static char *nomatch_str; static int unbound_flag; static int verbose_flag; @@ -398,6 +400,46 @@ find_unmatched(struct devinfo_dev *dev, void *arg) } static void +find_nomatch(char *nomatch) +{ + char *bus, *pnpinfo, *tmp; + + /* + * Find our bus name. It will include the unit number. We have to search + * backwards to avoid false positive for any PNP string that has ' on ' + * in them, which would come earlier in the string. Like if there were + * an 'Old Bard' ethernet card made by 'Stratford on Avon Hardware' or + * something silly like that. + */ + tmp = nomatch + strlen(nomatch) - 4; + while (tmp > nomatch && strncmp(tmp, " on ", 4) != 0) + tmp--; + if (tmp == nomatch) + errx(1, "No bus found in nomatch string: '%s'", nomatch); + bus = tmp + 4; + *tmp = '\0'; + tmp = bus + strlen(bus) - 1; + while (tmp > bus && isdigit(*tmp)) + tmp--; + *++tmp = '\0'; + + /* + * Note: the NOMATCH events place both the bus location as well as the + * pnp info after the 'at' and we don't know where one stops and the + * other begins, so we pass the whole thing to our search routine. + */ + if (*nomatch == '?') + nomatch++; + if (strncmp(nomatch, " at ", 4) != 0) + errx(1, "Malformed NOMATCH string: '%s'", nomatch); + pnpinfo = nomatch + 4; + + search_hints(bus, "", pnpinfo); + + exit(0); +} + +static void usage(void) { @@ -410,7 +452,7 @@ main(int argc, char **argv) struct devinfo_dev *root; int ch; - while ((ch = getopt_long(argc, argv, "aduv", + while ((ch = getopt_long(argc, argv, "adp:uv", longopts, NULL)) != -1) { switch (ch) { case 'a': @@ -419,6 +461,9 @@ main(int argc, char **argv) case 'd': dump_flag++; break; + case 'p': + nomatch_str = optarg; + break; case 'u': unbound_flag++; break; @@ -441,6 +486,8 @@ main(int argc, char **argv) exit(0); } + if (nomatch_str != NULL) + find_nomatch(nomatch_str); if (devinfo_init()) err(1, "devinfo_init"); if ((root = devinfo_handle_to_device(DEVINFO_ROOT_DEVICE)) == NULL)