diff options
| author | jmcneill <jmcneill@NetBSD.org> | 2017-07-08 12:36:51 +0000 |
|---|---|---|
| committer | jmcneill <jmcneill@NetBSD.org> | 2017-07-08 12:36:51 +0000 |
| commit | a3bd2ae45351802f34c694061b2cbfeff91b32bb (patch) | |
| tree | ae650ca6fb4d651dabe950803bb4e1ec20c699ed /sys/dev/fdt | |
| parent | 785b4c1c656be5b2866df5c5e1f76b96d36f79c4 (diff) | |
Add fdtbus_get_string_index helper.
Diffstat (limited to 'sys/dev/fdt')
| -rw-r--r-- | sys/dev/fdt/fdt_subr.c | 24 | ||||
| -rw-r--r-- | sys/dev/fdt/fdtvar.h | 3 |
2 files changed, 24 insertions, 3 deletions
diff --git a/sys/dev/fdt/fdt_subr.c b/sys/dev/fdt/fdt_subr.c index d789b5dc2c1..8b0b86152a8 100644 --- a/sys/dev/fdt/fdt_subr.c +++ b/sys/dev/fdt/fdt_subr.c @@ -1,4 +1,4 @@ -/* $NetBSD: fdt_subr.c,v 1.15 2017/07/02 15:27:58 jmcneill Exp $ */ +/* $NetBSD: fdt_subr.c,v 1.16 2017/07/08 12:36:51 jmcneill Exp $ */ /*- * Copyright (c) 2015 Jared D. McNeill <jmcneill@invisible.ca> @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: fdt_subr.c,v 1.15 2017/07/02 15:27:58 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fdt_subr.c,v 1.16 2017/07/08 12:36:51 jmcneill Exp $"); #include <sys/param.h> #include <sys/bus.h> @@ -422,3 +422,23 @@ fdtbus_get_string(int phandle, const char *prop) return fdt_getprop(fdtbus_get_data(), off, prop, NULL); } + +const char * +fdtbus_get_string_index(int phandle, const char *prop, u_int index) +{ + const char *names, *name; + int len, cur; + + if ((len = OF_getproplen(phandle, prop)) < 0) + return NULL; + + names = fdtbus_get_string(phandle, prop); + + for (name = names, cur = 0; len > 0; + name += strlen(name) + 1, cur++) { + if (index == cur) + return name; + } + + return NULL; +} diff --git a/sys/dev/fdt/fdtvar.h b/sys/dev/fdt/fdtvar.h index a2900121e79..2d22eab680c 100644 --- a/sys/dev/fdt/fdtvar.h +++ b/sys/dev/fdt/fdtvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: fdtvar.h,v 1.23 2017/07/02 15:27:58 jmcneill Exp $ */ +/* $NetBSD: fdtvar.h,v 1.24 2017/07/08 12:36:51 jmcneill Exp $ */ /*- * Copyright (c) 2015 Jared D. McNeill <jmcneill@invisible.ca> @@ -297,6 +297,7 @@ bool fdtbus_status_okay(int); const void * fdtbus_get_prop(int, const char *, int *); const char * fdtbus_get_string(int, const char *); +const char * fdtbus_get_string_index(int, const char *, u_int); int fdtbus_print(void *, const char *); |
