Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/fdt Handle reg values beyond 4GB for platforms with ...
details: https://anonhg.NetBSD.org/src/rev/069c04a55373
branches: trunk
changeset: 353879:069c04a55373
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Fri May 26 18:56:27 2017 +0000
description:
Handle reg values beyond 4GB for platforms with 32-bit bus_addr_t.
fdtbus_get_reg will do a range check and return ERANGE if addr+size
exceeds 4GB.
Add fdtbus_get_reg64 to allow for fetching raw values w/o range check.
diffstat:
sys/dev/fdt/fdt_subr.c | 36 ++++++++++++++++++++++++++++--------
sys/dev/fdt/fdtvar.h | 3 ++-
2 files changed, 30 insertions(+), 9 deletions(-)
diffs (89 lines):
diff -r e81a0029cb8b -r 069c04a55373 sys/dev/fdt/fdt_subr.c
--- a/sys/dev/fdt/fdt_subr.c Fri May 26 15:40:27 2017 +0000
+++ b/sys/dev/fdt/fdt_subr.c Fri May 26 18:56:27 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_subr.c,v 1.10 2017/04/29 12:38:26 jmcneill Exp $ */
+/* $NetBSD: fdt_subr.c,v 1.11 2017/05/26 18:56:27 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.10 2017/04/29 12:38:26 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_subr.c,v 1.11 2017/05/26 18:56:27 jmcneill Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -159,27 +159,47 @@
int
fdtbus_get_reg(int phandle, u_int index, bus_addr_t *paddr, bus_size_t *psize)
{
- bus_addr_t addr;
- bus_size_t size;
+ uint64_t addr, size;
+ int error;
+
+ error = fdtbus_get_reg64(phandle, index, &addr, &size);
+ if (error)
+ return error;
+
+ if (sizeof(bus_addr_t) == 4 && (addr + size) > 0x100000000)
+ return ERANGE;
+
+ if (paddr)
+ *paddr = (bus_addr_t)addr;
+ if (psize)
+ *psize = (bus_size_t)size;
+
+ return 0;
+}
+
+int
+fdtbus_get_reg64(int phandle, u_int index, uint64_t *paddr, uint64_t *psize)
+{
+ uint64_t addr, size;
const uint8_t *buf;
int len;
const int addr_cells = fdtbus_get_addr_cells(phandle);
const int size_cells = fdtbus_get_size_cells(phandle);
if (addr_cells == -1 || size_cells == -1)
- return -1;
+ return EINVAL;
buf = fdt_getprop(fdtbus_get_data(),
fdtbus_phandle2offset(phandle), "reg", &len);
if (buf == NULL || len <= 0)
- return -1;
+ return EINVAL;
const u_int reglen = size_cells * 4 + addr_cells * 4;
if (reglen == 0)
- return -1;
+ return EINVAL;
if (index >= len / reglen)
- return -1;
+ return ENXIO;
switch (addr_cells) {
case 0:
diff -r e81a0029cb8b -r 069c04a55373 sys/dev/fdt/fdtvar.h
--- a/sys/dev/fdt/fdtvar.h Fri May 26 15:40:27 2017 +0000
+++ b/sys/dev/fdt/fdtvar.h Fri May 26 18:56:27 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.16 2017/04/29 12:49:05 jmcneill Exp $ */
+/* $NetBSD: fdtvar.h,v 1.17 2017/05/26 18:56:27 jmcneill Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -182,6 +182,7 @@
const struct fdtbus_dma_controller_func *);
int fdtbus_get_reg(int, u_int, 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);
i2c_tag_t fdtbus_get_i2c_tag(int);
Home |
Main Index |
Thread Index |
Old Index