Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/fdt Avoid using kmem in fdtbus_get_reg so we can use...



details:   https://anonhg.NetBSD.org/src/rev/27ad38da7a51
branches:  trunk
changeset: 823397:27ad38da7a51
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Fri Apr 21 21:08:57 2017 +0000

description:
Avoid using kmem in fdtbus_get_reg so we can use it early at boot to read
the physical memory layout of the system.

diffstat:

 sys/dev/fdt/fdt_subr.c |  27 +++++++++------------------
 1 files changed, 9 insertions(+), 18 deletions(-)

diffs (67 lines):

diff -r c5a636425323 -r 27ad38da7a51 sys/dev/fdt/fdt_subr.c
--- a/sys/dev/fdt/fdt_subr.c    Fri Apr 21 20:17:26 2017 +0000
+++ b/sys/dev/fdt/fdt_subr.c    Fri Apr 21 21:08:57 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_subr.c,v 1.6 2017/04/13 22:12:53 jmcneill Exp $ */
+/* $NetBSD: fdt_subr.c,v 1.7 2017/04/21 21:08:57 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.6 2017/04/13 22:12:53 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_subr.c,v 1.7 2017/04/21 21:08:57 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -161,7 +161,7 @@
 {
        bus_addr_t addr;
        bus_size_t size;
-       uint8_t *buf;
+       const uint8_t *buf;
        int len;
 
        const int addr_cells = fdtbus_get_addr_cells(phandle);
@@ -169,25 +169,18 @@
        if (addr_cells == -1 || size_cells == -1)
                return -1;
 
+       buf = fdt_getprop(fdtbus_get_data(),
+           fdtbus_phandle2offset(phandle), "reg", &len);
+       if (buf == NULL || len <= 0)
+               return -1;
+
        const u_int reglen = size_cells * 4 + addr_cells * 4;
        if (reglen == 0)
                return -1;
 
-       len = OF_getproplen(phandle, "reg");
-       if (len <= 0)
+       if (index >= len / reglen)
                return -1;
 
-       const u_int nregs = len / reglen;
-
-       if (index >= nregs)
-               return -1;
-
-       buf = kmem_alloc(len, KM_SLEEP);
-       if (buf == NULL)
-               return -1;
-
-       len = OF_getprop(phandle, "reg", buf, len);
-
        switch (addr_cells) {
        case 0:
                addr = 0;
@@ -221,7 +214,5 @@
        if (psize)
                *psize = size;
 
-       kmem_free(buf, len);
-
        return 0;
 }



Home | Main Index | Thread Index | Old Index