From nobody Tue Jan 24 22:13:27 2023 X-Original-To: dev-commits-src-branches@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 4P1h7X1lChz3bgPN; Tue, 24 Jan 2023 22:13:28 +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 4P1h7X1G5sz3H67; Tue, 24 Jan 2023 22:13:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598408; 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=Cz3TujFLaM7WpjTriHT3d5d36RyBU6tfanhDZgGQXh4=; b=I18oN8Y1NEKkFKikTSNVMo7J2C9HVenNwZ8pdg9k/gkqG8k1I4hLVRq8v5P+Y2Q+Ad5+Pf xzKoV8OfK8U2N38XZakMWl5WzENwlpmPmntMknMaldKvC/r3jVUbdn3DHKs5qDv6j1C+hf v4M09qlNkyD4iCkFZsT3sOVCJ0HgQ0EGFzzYh5QB2x6OLO8AGVuAe8oUz0m4Y0WMhxAjDj npI+IFcCnIiZxsiHMhzvrmwZO3fGwLkr0NpsZqHOgVwbWZHcdycBBObyavFzuyEz620cqd T+gCHuukzAe/k/f/+RD+Yfh6aKfv/eT00s0tkLYxDR3QKFwKykThyD8JSHhO9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598408; 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=Cz3TujFLaM7WpjTriHT3d5d36RyBU6tfanhDZgGQXh4=; b=evzTSs1O04a68hOuXBfYbxoxXRd8asezCbeLyuI1JJdJ5NKIdVIrigu2SRHy7N7/Qn7Kaa bBme/Fhu5TBaGlr+sN9zOm5GVZ5iD7otCxN+oXo0LtcMc8+95Hg1HLj/JYopHrovB+fh+h Nx2AFrSBDrdltnjIOr3ayZWTlkF/Z0iRpJse3h7+INBrnYJHJdp08CCT5VL1le9x0W9cpL vKWkeszlf7tCifcvjwEJaYfAUqnpUoT0sVPbjxQXmxlqXu8GCCd/oMUioYrS4mh2aQs+J5 tWGoi81//WhUkjTrUDVw+vrj6C0yA0Y4RIVF9/xKyZUWuqKO4bi8p7gwqtjYEA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674598408; a=rsa-sha256; cv=none; b=t+dnrIOoLuCFZb1j+gjL0OIzrBBqooUWRL6BR6wxyRlsGsouFTImgkdqqqAWAtKBQ325XU SPWXePWrc1YtbF9Ijb32LcJJF3kgxIg4ONLbp2uL5mJ2BV3CTs4sgUiepaJ96gtMf+x6bl DpNsMuAJi10B/HCIAzpat2pMOJffiDxA+z+UuUfxubr7/coalmNrZukwUysY9hNZ56oYY6 b/LtfDFznT1lIM78Rk+WTimtH90KOg7zJLUdhZmXnfdT+A0DPyzoA8qak9/BPlSo0ZP0rQ YP9aAPP2wjiLYvLYKJV+dHnafS49FLuauzte4z/nOgYQpDIXgbMeVonzjjBBJg== 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 4P1h7X0FV6zQVr; Tue, 24 Jan 2023 22:13:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30OMDR3G088468; Tue, 24 Jan 2023 22:13:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30OMDRqt088467; Tue, 24 Jan 2023 22:13:27 GMT (envelope-from git) Date: Tue, 24 Jan 2023 22:13:27 GMT Message-Id: <202301242213.30OMDRqt088467@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: 454b52dc3709 - stable/13 - stand/ofw: Add ofw_path_to_handle List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 454b52dc3709f167a91d8c9199fe01f8579c9ffb Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=454b52dc3709f167a91d8c9199fe01f8579c9ffb commit 454b52dc3709f167a91d8c9199fe01f8579c9ffb Author: Warner Losh AuthorDate: 2022-11-30 22:10:00 +0000 Commit: Warner Losh CommitDate: 2023-01-24 21:49:40 +0000 stand/ofw: Add ofw_path_to_handle ofw_path_to_handle converts a path string to a phandle_t. It searches down the path for the first device whose type matches the passed-in string. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D37556 (cherry picked from commit ed3cc2f24829e6c5827f142cfcd9729331a1106c) --- stand/libofw/devicename.c | 33 +++++++++++++++++++++++++++++++++ stand/libofw/libofw.h | 2 ++ 2 files changed, 35 insertions(+) diff --git a/stand/libofw/devicename.c b/stand/libofw/devicename.c index ecf966506194..6ed2343ee7bd 100644 --- a/stand/libofw/devicename.c +++ b/stand/libofw/devicename.c @@ -62,6 +62,38 @@ ofw_getdev(void **vdev, const char *devspec, const char **path) return(ofw_parsedev(dev, devspec, path)); } +/* + * Search the OFW (path) for a node that's of (want_type). + */ +phandle_t +ofw_path_to_handle(const char *ofwpath, const char *want_type, const char **path) +{ + const char *p, *s; + char name[256]; + char type[64]; + phandle_t handle; + int len; + + for (p = s = ofwpath; *s != '\0'; p = s) { + if ((s = strchr(p + 1, '/')) == NULL) + s = strchr(p, '\0'); + len = s - ofwpath; + if (len >= sizeof(name)) + return ((phandle_t)-1); + bcopy(ofwpath, name, len); + name[len] = '\0'; + if ((handle = OF_finddevice(name)) == -1) + continue; + if (OF_getprop(handle, "device_type", type, sizeof(type)) == -1) + continue; + if (strcmp(want_type, type) == 0) { + *path = s; + return (handle); + } + } + return ((phandle_t)-1); +} + /* * Point (dev) at an allocated device specifier matching the string version * at the beginning of (devspec). Return a pointer to the remaining @@ -82,6 +114,7 @@ ofw_parsedev(struct ofw_devdesc **dev, const char *devspec, const char **path) int len; int i; + /* XXX next step: use devparse -- don't forget to hack ofw_disk like you did ofw_net */ for (p = s = devspec; *s != '\0'; p = s) { if ((s = strchr(p + 1, '/')) == NULL) s = strchr(p, '\0'); diff --git a/stand/libofw/libofw.h b/stand/libofw/libofw.h index 59c7ec1fa6b7..0494a78135e7 100644 --- a/stand/libofw/libofw.h +++ b/stand/libofw/libofw.h @@ -61,6 +61,8 @@ extern int ofw_autoload(void); void ofw_memmap(int); +phandle_t ofw_path_to_handle(const char *ofwpath, const char *want_type, const char **path); + struct preloaded_file; struct file_format;