Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/fdt Consolidate FDT [find "names" index by string] l...



details:   https://anonhg.NetBSD.org/src/rev/409ba24fc833
branches:  trunk
changeset: 449230:409ba24fc833
user:      jakllsch <jakllsch%NetBSD.org@localhost>
date:      Wed Feb 27 16:56:00 2019 +0000

description:
Consolidate FDT [find "names" index by string] logic.

diffstat:

 sys/dev/fdt/fdt_clock.c   |  51 +++++++++++++++-------------------------------
 sys/dev/fdt/fdt_dma.c     |  34 +++++-------------------------
 sys/dev/fdt/fdt_phy.c     |  34 +++++-------------------------
 sys/dev/fdt/fdt_pinctrl.c |  22 ++++++-------------
 sys/dev/fdt/fdt_reset.c   |  34 +++++-------------------------
 sys/dev/fdt/fdt_subr.c    |  49 +++++++++++++++++++++++++++-----------------
 sys/dev/fdt/fdtvar.h      |   3 +-
 7 files changed, 74 insertions(+), 153 deletions(-)

diffs (truncated from 403 to 300 lines):

diff -r 67be2a3ef66b -r 409ba24fc833 sys/dev/fdt/fdt_clock.c
--- a/sys/dev/fdt/fdt_clock.c   Wed Feb 27 16:30:40 2019 +0000
+++ b/sys/dev/fdt/fdt_clock.c   Wed Feb 27 16:56:00 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_clock.c,v 1.7 2019/02/27 16:30:40 jakllsch Exp $ */
+/* $NetBSD: fdt_clock.c,v 1.8 2019/02/27 16:56:00 jakllsch Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdt_clock.c,v 1.7 2019/02/27 16:30:40 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_clock.c,v 1.8 2019/02/27 16:56:00 jakllsch Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -123,25 +123,14 @@
 static struct clk *
 fdtbus_clock_get_prop(int phandle, const char *clkname, const char *prop)
 {
-       struct clk *clk = NULL;
-       const char *p;
        u_int index;
-       int len, resid;
+       int err;
 
-       p = fdtbus_get_prop(phandle, prop, &len);
-       if (p == NULL)
+       err = fdtbus_get_index(phandle, prop, clkname, &index);
+       if (err != 0)
                return NULL;
 
-       for (index = 0, resid = len; resid > 0; index++) {
-               if (strcmp(p, clkname) == 0) {
-                       clk = fdtbus_clock_get_index(phandle, index);
-                       break;
-               }
-               resid -= strlen(p) + 1;
-               p += strlen(p) + 1;
-       }
-
-       return clk;
+       return fdtbus_clock_get_index(phandle, index);
 }
 
 static u_int
@@ -182,26 +171,20 @@
 fdtbus_clock_byname(const char *clkname)
 {
        struct fdtbus_clock_controller *cc;
-       u_int len, resid, index, clock_cells;
-       const char *p;
+       u_int index, clock_cells;
+       int err;
 
        LIST_FOREACH(cc, &fdtbus_clock_controllers, cc_next) {
-               if (!of_hasprop(cc->cc_phandle, "clock-output-names"))
+               err = fdtbus_get_index(cc->cc_phandle, "clock-output-names", clkname, &index);
+               if (err != 0)
+                       continue;
+               if (of_getprop_uint32(cc->cc_phandle, "#clock-cells", &clock_cells))
                        continue;
-               p = fdtbus_get_prop(cc->cc_phandle, "clock-output-names", &len);
-               for (index = 0, resid = len; resid > 0; index++) {
-                       if (strcmp(p, clkname) == 0) {
-                               if (of_getprop_uint32(cc->cc_phandle, "#clock-cells", &clock_cells))
-                                       break;
-                               const u_int index_raw = htobe32(index);
-                               return cc->cc_funcs->decode(cc->cc_dev,
-                                   cc->cc_phandle,
-                                   clock_cells > 0 ? &index_raw : NULL,
-                                   clock_cells > 0 ? 4 : 0);
-                       }
-                       resid -= strlen(p) + 1;
-                       p += strlen(p) + 1;
-               }
+               const u_int index_raw = htobe32(index);
+               return cc->cc_funcs->decode(cc->cc_dev,
+                   cc->cc_phandle,
+                   clock_cells > 0 ? &index_raw : NULL,
+                   clock_cells > 0 ? 4 : 0);
        }
 
        return NULL;
diff -r 67be2a3ef66b -r 409ba24fc833 sys/dev/fdt/fdt_dma.c
--- a/sys/dev/fdt/fdt_dma.c     Wed Feb 27 16:30:40 2019 +0000
+++ b/sys/dev/fdt/fdt_dma.c     Wed Feb 27 16:56:00 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_dma.c,v 1.3 2019/02/27 16:30:40 jakllsch Exp $ */
+/* $NetBSD: fdt_dma.c,v 1.4 2019/02/27 16:56:00 jakllsch Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdt_dma.c,v 1.3 2019/02/27 16:30:40 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_dma.c,v 1.4 2019/02/27 16:56:00 jakllsch Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -132,36 +132,14 @@
 struct fdtbus_dma *
 fdtbus_dma_get(int phandle, const char *name, void (*cb)(void *), void *cbarg)
 {
-       struct fdtbus_dma *dma = NULL;
-       char *dma_names = NULL;
-       const char *p;
        u_int index;
-       int len, resid;
+       int err;
 
-       len = OF_getproplen(phandle, "dma-names");
-       if (len <= 0)
+       err = fdtbus_get_index(phandle, "dma-names", name, &index);
+       if (err != 0)
                return NULL;
 
-       dma_names = kmem_alloc(len, KM_SLEEP);
-       if (OF_getprop(phandle, "dma-names", dma_names, len) != len) {
-               kmem_free(dma_names, len);
-               return NULL;
-       }
-
-       p = dma_names;
-       for (index = 0, resid = len; resid > 0; index++) {
-               if (strcmp(p, name) == 0) {
-                       dma = fdtbus_dma_get_index(phandle, index, cb, cbarg);
-                       break;
-               }
-               resid -= strlen(p) + 1;
-               p += strlen(p) + 1;
-       }
-
-       if (dma_names)
-               kmem_free(dma_names, len);
-
-       return dma;
+       return fdtbus_dma_get_index(phandle, index, cb, cbarg);
 }
 
 void
diff -r 67be2a3ef66b -r 409ba24fc833 sys/dev/fdt/fdt_phy.c
--- a/sys/dev/fdt/fdt_phy.c     Wed Feb 27 16:30:40 2019 +0000
+++ b/sys/dev/fdt/fdt_phy.c     Wed Feb 27 16:56:00 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_phy.c,v 1.4 2019/02/27 16:30:40 jakllsch Exp $ */
+/* $NetBSD: fdt_phy.c,v 1.5 2019/02/27 16:56:00 jakllsch Exp $ */
 
 /*-
  * Copyright (c) 2015-2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdt_phy.c,v 1.4 2019/02/27 16:30:40 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_phy.c,v 1.5 2019/02/27 16:56:00 jakllsch Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -131,36 +131,14 @@
 struct fdtbus_phy *
 fdtbus_phy_get(int phandle, const char *phyname)
 {
-       struct fdtbus_phy *phy = NULL;
-       char *phy_names = NULL;
-       const char *p;
        u_int index;
-       int len, resid;
+       int err;
 
-       len = OF_getproplen(phandle, "phy-names");
-       if (len <= 0)
+       err = fdtbus_get_index(phandle, "phy-names", phyname, &index);
+       if (err != 0)
                return NULL;
 
-       phy_names = kmem_alloc(len, KM_SLEEP);
-       if (OF_getprop(phandle, "phy-names", phy_names, len) != len) {
-               kmem_free(phy_names, len);
-               return NULL;
-       }
-
-       p = phy_names;
-       for (index = 0, resid = len; resid > 0; index++) {
-               if (strcmp(p, phyname) == 0) {
-                       phy = fdtbus_phy_get_index(phandle, index);
-                       break;
-               }
-               resid -= strlen(p) + 1;
-               p += strlen(p) + 1;
-       }
-
-       if (phy_names)
-               kmem_free(phy_names, len);
-
-       return phy;
+       return fdtbus_phy_get_index(phandle, index);
 }
 
 void
diff -r 67be2a3ef66b -r 409ba24fc833 sys/dev/fdt/fdt_pinctrl.c
--- a/sys/dev/fdt/fdt_pinctrl.c Wed Feb 27 16:30:40 2019 +0000
+++ b/sys/dev/fdt/fdt_pinctrl.c Wed Feb 27 16:56:00 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_pinctrl.c,v 1.7 2019/01/23 04:23:01 thorpej Exp $ */
+/* $NetBSD: fdt_pinctrl.c,v 1.8 2019/02/27 16:56:00 jakllsch Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdt_pinctrl.c,v 1.7 2019/01/23 04:23:01 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_pinctrl.c,v 1.8 2019/02/27 16:56:00 jakllsch Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -118,22 +118,14 @@
 int
 fdtbus_pinctrl_set_config(int phandle, const char *cfgname)
 {
-       const char *pinctrl_names, *name;
-       int len, index;
+       u_int index;
+       int err;
 
-       if ((len = OF_getproplen(phandle, "pinctrl-names")) < 0)
+       err = fdtbus_get_index(phandle, "pinctrl-names", cfgname, &index);
+       if (err != 0)
                return -1;
 
-       pinctrl_names = fdtbus_get_string(phandle, "pinctrl-names");
-
-       for (name = pinctrl_names, index = 0; len > 0;
-            len -= strlen(name) + 1, name += strlen(name) + 1, index++) {
-               if (strcmp(name, cfgname) == 0)
-                       return fdtbus_pinctrl_set_config_index(phandle, index);
-       }
-
-       /* Not found */
-       return -1;
+       return fdtbus_pinctrl_set_config_index(phandle, index);
 }
 
 static void
diff -r 67be2a3ef66b -r 409ba24fc833 sys/dev/fdt/fdt_reset.c
--- a/sys/dev/fdt/fdt_reset.c   Wed Feb 27 16:30:40 2019 +0000
+++ b/sys/dev/fdt/fdt_reset.c   Wed Feb 27 16:56:00 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_reset.c,v 1.3 2019/02/27 16:30:40 jakllsch Exp $ */
+/* $NetBSD: fdt_reset.c,v 1.4 2019/02/27 16:56:00 jakllsch Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdt_reset.c,v 1.3 2019/02/27 16:30:40 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_reset.c,v 1.4 2019/02/27 16:56:00 jakllsch Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -131,36 +131,14 @@
 struct fdtbus_reset *
 fdtbus_reset_get(int phandle, const char *rstname)
 {
-       struct fdtbus_reset *rst = NULL;
-       char *reset_names = NULL;
-       const char *p;
        u_int index;
-       int len, resid;
+       int err;
 
-       len = OF_getproplen(phandle, "reset-names");
-       if (len <= 0)
+       err = fdtbus_get_index(phandle, "reset-names", rstname, &index);
+       if (err != 0)
                return NULL;
 
-       reset_names = kmem_alloc(len, KM_SLEEP);
-       if (OF_getprop(phandle, "reset-names", reset_names, len) != len) {
-               kmem_free(reset_names, len);
-               return NULL;
-       }
-
-       p = reset_names;
-       for (index = 0, resid = len; resid > 0; index++) {
-               if (strcmp(p, rstname) == 0) {
-                       rst = fdtbus_reset_get_index(phandle, index);
-                       break;
-               }
-               resid -= strlen(p) + 1;
-               p += strlen(p) + 1;
-       }



Home | Main Index | Thread Index | Old Index