From owner-svn-src-stable-12@freebsd.org Sat Oct 31 17:09:26 2020 Return-Path: Delivered-To: svn-src-stable-12@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 415FB451BD8; Sat, 31 Oct 2020 17:09:26 +0000 (UTC) (envelope-from mmel@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 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 4CNlyt14m6z3TRc; Sat, 31 Oct 2020 17:09:26 +0000 (UTC) (envelope-from mmel@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 0839FAF1D; Sat, 31 Oct 2020 17:09:26 +0000 (UTC) (envelope-from mmel@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 09VH9PbN062203; Sat, 31 Oct 2020 17:09:25 GMT (envelope-from mmel@FreeBSD.org) Received: (from mmel@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 09VH9PBa062201; Sat, 31 Oct 2020 17:09:25 GMT (envelope-from mmel@FreeBSD.org) Message-Id: <202010311709.09VH9PBa062201@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mmel set sender to mmel@FreeBSD.org using -f From: Michal Meloun Date: Sat, 31 Oct 2020 17:09:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r367224 - in stable/12/sys/dev: extres/syscon fdt X-SVN-Group: stable-12 X-SVN-Commit-Author: mmel X-SVN-Commit-Paths: in stable/12/sys/dev: extres/syscon fdt X-SVN-Commit-Revision: 367224 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 31 Oct 2020 17:09:26 -0000 Author: mmel Date: Sat Oct 31 17:09:25 2020 New Revision: 367224 URL: https://svnweb.freebsd.org/changeset/base/367224 Log: MFC r366156: Correctly handle nodes compatible with "syscon", "simple-bus". Syscon can also have child nodes that share a registration file with it. To do this correctly, follow these steps: - subclass syscon from simplebus and expose it if the node is also "simple-bus" compatible. - block simplebus probe for this compatible string, so it's priority (bus pass) doesn't colide with syscon driver. Modified: stable/12/sys/dev/extres/syscon/syscon_generic.c stable/12/sys/dev/extres/syscon/syscon_generic.h stable/12/sys/dev/fdt/simplebus.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/dev/extres/syscon/syscon_generic.c ============================================================================== --- stable/12/sys/dev/extres/syscon/syscon_generic.c Sat Oct 31 17:07:43 2020 (r367223) +++ stable/12/sys/dev/extres/syscon/syscon_generic.c Sat Oct 31 17:09:25 2020 (r367224) @@ -59,7 +59,7 @@ static int syscon_generic_write_4(struct syscon *sysco uint32_t val); static int syscon_generic_modify_4(struct syscon *syscon, bus_size_t offset, uint32_t clear_bits, uint32_t set_bits); - +static int syscon_generic_detach(device_t dev); /* * Generic syscon driver (FDT) */ @@ -148,7 +148,7 @@ static int syscon_generic_attach(device_t dev) { struct syscon_generic_softc *sc; - int rid; + int rid, rv; sc = device_get_softc(dev); sc->dev = dev; @@ -166,9 +166,20 @@ syscon_generic_attach(device_t dev) ofw_bus_get_node(dev)); if (sc->syscon == NULL) { device_printf(dev, "Failed to create/register syscon\n"); + syscon_generic_detach(dev); return (ENXIO); } - return (0); + if (ofw_bus_is_compatible(dev, "simple-bus")) { + rv = simplebus_attach_impl(sc->dev); + if (rv != 0) { + device_printf(dev, "Failed to create simplebus\n"); + syscon_generic_detach(dev); + return (ENXIO); + } + sc->simplebus_attached = true; + } + + return (bus_generic_attach(dev)); } static int @@ -181,7 +192,8 @@ syscon_generic_detach(device_t dev) syscon_unregister(sc->syscon); free(sc->syscon, M_SYSCON); } - + if (sc->simplebus_attached) + simplebus_detach(dev); SYSCON_LOCK_DESTROY(sc); if (sc->mem_res != NULL) @@ -198,8 +210,8 @@ static device_method_t syscon_generic_dmethods[] = { DEVMETHOD_END }; -DEFINE_CLASS_0(syscon_generic, syscon_generic_driver, syscon_generic_dmethods, - sizeof(struct syscon_generic_softc)); +DEFINE_CLASS_1(syscon_generic_dev, syscon_generic_driver, syscon_generic_dmethods, + sizeof(struct syscon_generic_softc), simplebus_driver); static devclass_t syscon_generic_devclass; EARLY_DRIVER_MODULE(syscon_generic, simplebus, syscon_generic_driver, Modified: stable/12/sys/dev/extres/syscon/syscon_generic.h ============================================================================== --- stable/12/sys/dev/extres/syscon/syscon_generic.h Sat Oct 31 17:07:43 2020 (r367223) +++ stable/12/sys/dev/extres/syscon/syscon_generic.h Sat Oct 31 17:09:25 2020 (r367224) @@ -29,11 +29,15 @@ #ifndef DEV_SYSCON_GENERIC_H #define DEV_SYSCON_GENERIC_H +#include + struct syscon_generic_softc { + struct simplebus_softc simplebus; device_t dev; struct syscon *syscon; struct resource *mem_res; struct mtx mtx; + bool simplebus_attached; }; DECLARE_CLASS(syscon_generic_driver); Modified: stable/12/sys/dev/fdt/simplebus.c ============================================================================== --- stable/12/sys/dev/fdt/simplebus.c Sat Oct 31 17:07:43 2020 (r367223) +++ stable/12/sys/dev/fdt/simplebus.c Sat Oct 31 17:09:25 2020 (r367224) @@ -116,6 +116,16 @@ simplebus_probe(device_t dev) if (!ofw_bus_status_okay(dev)) return (ENXIO); + /* + * XXX We should attach only to pure' compatible = "simple-bus"', + * without any other compatible string. + * For now, filter only know cases: + * "syscon", "simple-bus"; is handled by fdt/syscon driver + * "simple-mfd", "simple-bus"; is handled by fdt/simple-mfd driver + */ + if (ofw_bus_is_compatible(dev, "syscon") || + ofw_bus_is_compatible(dev, "simple-mfd")) + return (ENXIO); /* * FDT data puts a "simple-bus" compatible string on many things that