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_reg_byname



details:   https://anonhg.NetBSD.org/src/rev/041037970a9c
branches:  trunk
changeset: 355969:041037970a9c
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Fri Aug 25 12:28:10 2017 +0000

description:
Add fdtbus_get_reg_byname

diffstat:

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

diffs (69 lines):

diff -r 8b8583936081 -r 041037970a9c sys/dev/fdt/fdt_subr.c
--- a/sys/dev/fdt/fdt_subr.c    Fri Aug 25 11:35:03 2017 +0000
+++ b/sys/dev/fdt/fdt_subr.c    Fri Aug 25 12:28:10 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_subr.c,v 1.17 2017/07/19 20:18:07 jmcneill Exp $ */
+/* $NetBSD: fdt_subr.c,v 1.18 2017/08/25 12:28:10 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.17 2017/07/19 20:18:07 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_subr.c,v 1.18 2017/08/25 12:28:10 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -199,6 +199,32 @@
 }
 
 int
+fdtbus_get_reg_byname(int phandle, const char *name, bus_addr_t *paddr,
+    bus_size_t *psize)
+{
+       const char *reg_names, *p;
+       u_int index;
+       int len, resid;
+       int error = ENOENT;
+
+       reg_names = fdtbus_get_prop(phandle, "reg-names", &len);
+       if (len <= 0)
+               return error;
+
+       p = reg_names;
+       for (index = 0, resid = len; resid > 0; index++) {
+               if (strcmp(p, name) == 0) {
+                       error = fdtbus_get_reg(phandle, index, paddr, psize);
+                       break;
+               }
+               resid -= strlen(p);
+               p += strlen(p) + 1;
+       }
+
+       return error;
+}
+
+int
 fdtbus_get_reg(int phandle, u_int index, bus_addr_t *paddr, bus_size_t *psize)
 {
        uint64_t addr, size;
diff -r 8b8583936081 -r 041037970a9c sys/dev/fdt/fdtvar.h
--- a/sys/dev/fdt/fdtvar.h      Fri Aug 25 11:35:03 2017 +0000
+++ b/sys/dev/fdt/fdtvar.h      Fri Aug 25 12:28:10 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.25 2017/08/13 18:27:11 jmcneill Exp $ */
+/* $NetBSD: fdtvar.h,v 1.26 2017/08/25 12:28:10 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -227,6 +227,8 @@
                    const struct fdtbus_phy_controller_func *);
 
 int            fdtbus_get_reg(int, u_int, bus_addr_t *, bus_size_t *);
+int            fdtbus_get_reg_byname(int, const char *, bus_addr_t *,
+                   bus_size_t *);
 int            fdtbus_get_reg64(int, u_int, uint64_t *, uint64_t *);
 int            fdtbus_get_phandle(int, const char *);
 int            fdtbus_get_phandle_from_native(int);



Home | Main Index | Thread Index | Old Index