Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/fdt Add fdtbus_get_string_index helper.



details:   https://anonhg.NetBSD.org/src/rev/904e99167f4c
branches:  trunk
changeset: 825309:904e99167f4c
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sat Jul 08 12:36:51 2017 +0000

description:
Add fdtbus_get_string_index helper.

diffstat:

 sys/dev/fdt/fdt_subr.c |  24 ++++++++++++++++++++++--
 sys/dev/fdt/fdtvar.h   |   3 ++-
 2 files changed, 24 insertions(+), 3 deletions(-)

diffs (59 lines):

diff -r f9152e3ac1ad -r 904e99167f4c sys/dev/fdt/fdt_subr.c
--- a/sys/dev/fdt/fdt_subr.c    Sat Jul 08 11:12:24 2017 +0000
+++ b/sys/dev/fdt/fdt_subr.c    Sat Jul 08 12:36:51 2017 +0000
@@ -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@localhost>
@@ -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 @@
 
        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 -r f9152e3ac1ad -r 904e99167f4c sys/dev/fdt/fdtvar.h
--- a/sys/dev/fdt/fdtvar.h      Sat Jul 08 11:12:24 2017 +0000
+++ b/sys/dev/fdt/fdtvar.h      Sat Jul 08 12:36:51 2017 +0000
@@ -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@localhost>
@@ -297,6 +297,7 @@
 
 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 *);
 



Home | Main Index | Thread Index | Old Index