diff options
author | Warner Losh <imp@FreeBSD.org> | 2022-11-30 22:10:00 +0000 |
---|---|---|
committer | Warner Losh <imp@FreeBSD.org> | 2023-01-24 21:49:40 +0000 |
commit | 454b52dc3709f167a91d8c9199fe01f8579c9ffb (patch) | |
tree | 58d4754dbccb1f3e3294329c3962a017206a9825 | |
parent | 5df48d2d03860a81d7a1867aeac3c5768109eeac (diff) | |
download | src-454b52dc3709f167a91d8c9199fe01f8579c9ffb.tar.gz src-454b52dc3709f167a91d8c9199fe01f8579c9ffb.zip |
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)
-rw-r--r-- | stand/libofw/devicename.c | 33 | ||||
-rw-r--r-- | stand/libofw/libofw.h | 2 |
2 files changed, 35 insertions, 0 deletions
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 @@ -63,6 +63,38 @@ ofw_getdev(void **vdev, const char *devspec, const char **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 * text in (path). @@ -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; |