From owner-svn-src-head@freebsd.org Fri Dec 6 22:32:06 2019 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id B20481B9226; Fri, 6 Dec 2019 22:32:06 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47V6lV4Klyz40jy; Fri, 6 Dec 2019 22:32:06 +0000 (UTC) (envelope-from ian@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 796DB8391; Fri, 6 Dec 2019 22:32:06 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id xB6MW6lH052875; Fri, 6 Dec 2019 22:32:06 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xB6MW6Y7052874; Fri, 6 Dec 2019 22:32:06 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201912062232.xB6MW6Y7052874@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Fri, 6 Dec 2019 22:32:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r355467 - head/sys/dev/gpio X-SVN-Group: head X-SVN-Commit-Author: ian X-SVN-Commit-Paths: head/sys/dev/gpio X-SVN-Commit-Revision: 355467 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Dec 2019 22:32:06 -0000 Author: ian Date: Fri Dec 6 22:32:06 2019 New Revision: 355467 URL: https://svnweb.freebsd.org/changeset/base/355467 Log: Implement bus_rescan for gpiobus(4). This allows on-the-fly reconfiguration of gpio devices by using kenv to add hints for a new device and then do 'devctl rescan gpiobus4' to make the new device(s) attach. It's not particularly easy to detect whether the 'at' hint has been deleted for a child device that's currently attached, so this doesn't handle that. But the user can use devctl commands to manually detach an existing device. Modified: head/sys/dev/gpio/gpiobus.c Modified: head/sys/dev/gpio/gpiobus.c ============================================================================== --- head/sys/dev/gpio/gpiobus.c Fri Dec 6 22:20:26 2019 (r355466) +++ head/sys/dev/gpio/gpiobus.c Fri Dec 6 22:32:06 2019 (r355467) @@ -716,6 +716,21 @@ gpiobus_add_child(device_t dev, u_int order, const cha return (child); } +static int +gpiobus_rescan(device_t dev) +{ + + /* + * Re-scan is supposed to remove and add children, but if someone has + * deleted the hints for a child we attached earlier, we have no easy + * way to handle that. So this just attaches new children for whom new + * hints or drivers have arrived since we last tried. + */ + bus_enumerate_hinted_children(dev); + bus_generic_attach(dev); + return (0); +} + static void gpiobus_hinted_child(device_t bus, const char *dname, int dunit) { @@ -725,6 +740,10 @@ gpiobus_hinted_child(device_t bus, const char *dname, const char *pins; int irq, pinmask; + if (device_find_child(bus, dname, dunit) != NULL) { + return; + } + child = BUS_ADD_CHILD(bus, 0, dname, dunit); devi = GPIOBUS_IVAR(child); if (resource_int_value(dname, dunit, "pins", &pinmask) == 0) { @@ -1077,6 +1096,7 @@ static device_method_t gpiobus_methods[] = { DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), DEVMETHOD(bus_get_resource_list, gpiobus_get_resource_list), DEVMETHOD(bus_add_child, gpiobus_add_child), + DEVMETHOD(bus_rescan, gpiobus_rescan), DEVMETHOD(bus_probe_nomatch, gpiobus_probe_nomatch), DEVMETHOD(bus_print_child, gpiobus_print_child), DEVMETHOD(bus_child_pnpinfo_str, gpiobus_child_pnpinfo_str),