Module Name: src
Committed By: jmcneill
Date: Fri Apr 21 21:08:57 UTC 2017
Modified Files:
src/sys/dev/fdt: fdt_subr.c
Log Message:
Avoid using kmem in fdtbus_get_reg so we can use it early at boot to read
the physical memory layout of the system.
To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/fdt/fdt_subr.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/fdt/fdt_subr.c
diff -u src/sys/dev/fdt/fdt_subr.c:1.6 src/sys/dev/fdt/fdt_subr.c:1.7
--- src/sys/dev/fdt/fdt_subr.c:1.6 Thu Apr 13 22:12:53 2017
+++ src/sys/dev/fdt/fdt_subr.c Fri Apr 21 21:08:57 2017
@@ -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 <[email protected]>
@@ -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 @@ fdtbus_get_reg(int phandle, u_int index,
{
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 @@ fdtbus_get_reg(int phandle, u_int index,
if (addr_cells == -1 || size_cells == -1)
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)
+ buf = fdt_getprop(fdtbus_get_data(),
+ fdtbus_phandle2offset(phandle), "reg", &len);
+ if (buf == NULL || len <= 0)
return -1;
- const u_int nregs = len / reglen;
-
- if (index >= nregs)
+ const u_int reglen = size_cells * 4 + addr_cells * 4;
+ if (reglen == 0)
return -1;
- buf = kmem_alloc(len, KM_SLEEP);
- if (buf == NULL)
+ if (index >= len / reglen)
return -1;
- len = OF_getprop(phandle, "reg", buf, len);
-
switch (addr_cells) {
case 0:
addr = 0;
@@ -221,7 +214,5 @@ fdtbus_get_reg(int phandle, u_int index,
if (psize)
*psize = size;
- kmem_free(buf, len);
-
return 0;
}