From nobody Tue Aug 8 13:14:01 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RKttd4zfkz4mKn5; Tue, 8 Aug 2023 13:14:01 +0000 (UTC) (envelope-from git@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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RKttd40Q5z3HNH; Tue, 8 Aug 2023 13:14:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691500441; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6YmjmJTc4AFRfv9xoNAJZf3sPakxws3eCGu9IOZLcNY=; b=ARV26ZJo0fl0B+eBZH3YWAiIoCBPZ+sAFpw97sYryeedmBF13NyoxdFtTgcWe94FrL8g8C dEdjqjL0wKDqeyo09rDOo1AWGw/QecZnhowfuUSIALxn3pwiLjfgM7+Uc6k9vKMZ2EXAQQ CIZCW58QUPe6ZLoMPzoicEESZL4aZo+w+YMEhELmxPZMroln/Ma0NQC/soxLR/fiPO7jGK buKFjwDER7ay9j1SBXu8jXLQhbmom+sQEBr53OqItnFzIWEHK4Dpi3Dfi589CU3HJ8dUoI 3Fbe6C6c4QfPY6p1UWd/BiEMSNMjRsT8ieK9eKnlEKAG2PUmK+47jJc2GpFgJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691500441; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6YmjmJTc4AFRfv9xoNAJZf3sPakxws3eCGu9IOZLcNY=; b=Jh4hP+FvjyEPsO5fWDePgB/dBIA+fhJBFF7eyzH6YHZsvSUqzQzK9/44xTczwKcG/3JHYm +HJ3dshyJOBkkiqRHqUlIRwBa4J63spQkOwy7c4rEK4mFcEZoHOA6FzFAMw7ZhJb8wr2dv Gp4xLOW63pI2PagnImlfTu5UxEdbCKY1wev91XSJGrTmABlJiQbz7dSzVlORBgZDf8sn6c Sbbpck1JmptoZMyST68VnZgeL2yCUjWzVgmmfrXYBkcEZ2tjL7iPCuN8uCss5km15TRRJY 6H7IwDvILHuMkKKEKCE09uOoAqfUTc2ROuLzI4Z7c873XSvNPrbUXRungiP9nw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1691500441; a=rsa-sha256; cv=none; b=jlDWshPigzp9xVuMtFoeS0v0LroBDTdGpqG0Ir1LeAnDu3dFgCxxwQ7DJ7rin8TFCfE653 4/tWHUpql0YkNA+Ln3zLs8Q5nedu4ZHe14l7N29NIPyu+ht72I7tXR6E66w70BFRze6DJq ks+Wou8UR4A20MxcxxTbANi4AxzI0XeNufv42skpNbMyi/MM9lXodnYTAvFqOsPav0kcVQ bcY/qmLGDkNIY3woTLTzlRNDp6W8JrFZ07NvYdb68vTab/7lWjdmkpQotM4Gg9l2k/LdFO TkMNewfrx1zmvCxELlg/QiRN8FqZ9CIf96q79NeU3oU9YoM83WhvdqBdy7ro5Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RKttd34sVzbbv; Tue, 8 Aug 2023 13:14:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 378DE1Rw008014; Tue, 8 Aug 2023 13:14:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 378DE1a1008013; Tue, 8 Aug 2023 13:14:01 GMT (envelope-from git) Date: Tue, 8 Aug 2023 13:14:01 GMT Message-Id: <202308081314.378DE1a1008013@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Emmanuel Vadot Subject: git: fdfd3a90b6ce - main - ofw: Add a ofw_firmware driver List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: manu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: fdfd3a90b6ceba838a40c3c51472883e7de8a440 Auto-Submitted: auto-generated The branch main has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=fdfd3a90b6ceba838a40c3c51472883e7de8a440 commit fdfd3a90b6ceba838a40c3c51472883e7de8a440 Author: Emmanuel Vadot AuthorDate: 2022-12-06 10:57:37 +0000 Commit: Emmanuel Vadot CommitDate: 2023-08-08 13:13:31 +0000 ofw: Add a ofw_firmware driver Some SoCs have an external firmware doing power management, clock and other stuffs. (Xilinx, ARM Juno etc ...) The way it is represent in the DTB is usually having a 'firmware' node under the root node and have some nodes under it with the correct compatible strings. The firmware node itself doesn't have any compatible strings. This driver is simple subclassed from simplebus and attaches at BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE so early drivers (like clock drivers) can still have a change to attach early. Reviewed by: andrew Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D37612 --- sys/conf/files | 1 + sys/dev/ofw/ofw_firmware.c | 161 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+) diff --git a/sys/conf/files b/sys/conf/files index 8838137f6989..3d405b3d86b5 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -2579,6 +2579,7 @@ dev/ofw/ofw_bus_if.m optional fdt dev/ofw/ofw_bus_subr.c optional fdt dev/ofw/ofw_cpu.c optional fdt dev/ofw/ofw_fdt.c optional fdt +dev/ofw/ofw_firmware.c optional fdt dev/ofw/ofw_if.m optional fdt dev/ofw/ofw_graph.c optional fdt dev/ofw/ofw_subr.c optional fdt diff --git a/sys/dev/ofw/ofw_firmware.c b/sys/dev/ofw/ofw_firmware.c new file mode 100644 index 000000000000..faba123c3e09 --- /dev/null +++ b/sys/dev/ofw/ofw_firmware.c @@ -0,0 +1,161 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2022 Beckhoff Automation GmbH & Co. KG + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +struct ofw_firmware_softc { + struct simplebus_softc sc; + device_t dev; +}; + +static struct simplebus_devinfo * +ofw_firmware_setup_dinfo(device_t dev, phandle_t node, + struct simplebus_devinfo *di) +{ + struct simplebus_softc *sc; + struct simplebus_devinfo *ndi; + + sc = device_get_softc(dev); + if (di == NULL) + ndi = malloc(sizeof(*ndi), M_DEVBUF, M_WAITOK | M_ZERO); + else + ndi = di; + if (ofw_bus_gen_setup_devinfo(&ndi->obdinfo, node) != 0) { + if (di == NULL) + free(ndi, M_DEVBUF); + return (NULL); + } + + /* reg resources is from the parent but interrupts is on the node itself */ + resource_list_init(&ndi->rl); + ofw_bus_reg_to_rl(dev, OF_parent(node), sc->acells, sc->scells, &ndi->rl); + ofw_bus_intr_to_rl(dev, node, &ndi->rl, NULL); + + return (ndi); +} + +static device_t +ofw_firmware_add_device(device_t dev, phandle_t node, u_int order, + const char *name, int unit, struct simplebus_devinfo *di) +{ + struct simplebus_devinfo *ndi; + device_t cdev; + + if ((ndi = ofw_firmware_setup_dinfo(dev, node, di)) == NULL) + return (NULL); + cdev = device_add_child_ordered(dev, order, name, unit); + if (cdev == NULL) { + device_printf(dev, "<%s>: device_add_child failed\n", + ndi->obdinfo.obd_name); + resource_list_free(&ndi->rl); + ofw_bus_gen_destroy_devinfo(&ndi->obdinfo); + if (di == NULL) + free(ndi, M_DEVBUF); + return (NULL); + } + device_set_ivars(cdev, ndi); + + return(cdev); +} + +static int +ofw_firmware_probe(device_t dev) +{ + const char *name; + + name = ofw_bus_get_name(dev); + if (name == NULL || strcmp(name, "firmware") != 0) + return (ENXIO); + + device_set_desc(dev, "OFW Firmware Group"); + return (0); +} + +static int +ofw_firmware_attach(device_t dev) +{ + struct ofw_firmware_softc *sc; + phandle_t node, child; + device_t cdev; + + sc = device_get_softc(dev); + sc->dev = dev; + node = ofw_bus_get_node(dev); + + if (OF_getencprop(node, "#address-cells", &sc->sc.acells, + sizeof(sc->sc.acells)) == -1) { + if (OF_getencprop(OF_parent(node), "#address-cells", &sc->sc.acells, + sizeof(sc->sc.acells)) == -1) { + sc->sc.acells = 2; + } + } + if (OF_getencprop(node, "#size-cells", &sc->sc.scells, + sizeof(sc->sc.scells)) == -1) { + if (OF_getencprop(OF_parent(node), "#size-cells", &sc->sc.scells, + sizeof(sc->sc.scells)) == -1) { + sc->sc.scells = 1; + } + } + + for (child = OF_child(node); child != 0; child = OF_peer(child)) { + cdev = ofw_firmware_add_device(dev, child, 0, NULL, -1, NULL); + if (cdev != NULL) + device_probe_and_attach(cdev); + } + + return (bus_generic_attach(dev)); +} + +static device_method_t ofw_firmware_methods[] = { + /* device_if */ + DEVMETHOD(device_probe, ofw_firmware_probe), + DEVMETHOD(device_attach, ofw_firmware_attach), + + DEVMETHOD_END +}; + +DEFINE_CLASS_1(ofw_firmware, ofw_firmware_driver, ofw_firmware_methods, + sizeof(struct ofw_firmware_softc), simplebus_driver); + +EARLY_DRIVER_MODULE(ofw_firmware, simplebus, ofw_firmware_driver, 0, 0, + BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE); +MODULE_VERSION(ofw_firmware, 1);