From nobody Wed Nov 30 22:31:29 2022 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 4NMv7j5cphz4jCSb; Wed, 30 Nov 2022 22:31:29 +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 4NMv7j4j18z44hl; Wed, 30 Nov 2022 22:31:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669847489; 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=enDPNMLthYufY390aUbCM3ap3vS6cQWlsYwhBRBgzyo=; b=kznYI3fDXm6o9ofcrOoFC6gARvS8zHhUf7JPNnUhzoX9Wuqkc4NDMOWrFIWbAqhW609g4I iKoj6cLMxnD+WAOMpcw1CJAZgLuI18FhhSyvCQh7PxSl/pF9dBfYZhM2lAK8Bs0Jp7iEji DVKOlXCeHfqi/8mJP5lRFNj9Jxg+k2VnaIoI0wSWfoC0obpoEp7exApn9HtOBxTCSft0AI feP7iUUkJH/cEirEuykLFr6dEhjLjLnSRMqcEQTlpg+Jr2Q+8OzODZP3uhcFD/FiWK7VvD nbu4iypqJrE36rsPf1sTqPpJ0aMEjPZaw5dMozHydSQvmGR6gLOvto7VKhkbwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669847489; 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=enDPNMLthYufY390aUbCM3ap3vS6cQWlsYwhBRBgzyo=; b=rjCN+VLsU32vlEMcB26SZQ973KLmOcvVSQ+YlWzfFHdRO9/ircFSqUOIQkQVeoRjDrwOkz ROyrn3V52wMkQIffoo6NmBsgOUs046tkuQEdLdyC/Wkpp7sEF9eb7h5mjobX2uXIa54cvU BmI9Qtf270rFEqXs8favYMlB79OayDkRKjcjYwb6Ilf7mGAoUbUhFTcpUeczNr68Dz/tur ig4+8LUNRWaDv5ebKnlbax0zqXt3uldWO4s9m+BgvUo6dL2gkzeOQUUhIRbM7R0W4FXNsS x/+4v4hdSbnQIhcRMpL3JNlH2CKevwxQ66tKwLzipA6mZT2srBHq5Fh+LHdATA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1669847489; a=rsa-sha256; cv=none; b=otYihLjmbDe4h2fWearv6ylEWhz3dFWpu3cALtQmaFRmei63LYuV5tFXIlzKh0dRwKRjo0 KNEOgTQ7eXCLL6rZjU49cuMxQheJkP6xl4f26cK0bbS/+D8BtczZZiZK23ylLRukC2s4WQ vku6wyNdxLkRawL5qqL3ywW4zqm/IFczse+XFY16JpkcH3EVqGLbMRKIl2fJ8kopBBj1gl 6P4A2jeCAwbOjhhbgP739JAqDlg/ZnM9ZWSNJmOFvIsqjwI9BkxNfvcr2vg9+0Mr8e/RUP UMzq6FRpIHPIdswMRH5pIf7Fn4nynmTSGyvhCEG42IszNJeWmUhnNcaT97jZWg== 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 4NMv7j3XHlzDgw; Wed, 30 Nov 2022 22:31:29 +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 2AUMVTWr023688; Wed, 30 Nov 2022 22:31:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2AUMVToL023687; Wed, 30 Nov 2022 22:31:29 GMT (envelope-from git) Date: Wed, 30 Nov 2022 22:31:29 GMT Message-Id: <202211302231.2AUMVToL023687@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: ed3cc2f24829 - main - stand/ofw: Add ofw_path_to_handle 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: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ed3cc2f24829e6c5827f142cfcd9729331a1106c Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=ed3cc2f24829e6c5827f142cfcd9729331a1106c commit ed3cc2f24829e6c5827f142cfcd9729331a1106c Author: Warner Losh AuthorDate: 2022-11-30 22:10:00 +0000 Commit: Warner Losh CommitDate: 2022-11-30 22:30:33 +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 --- 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;