From 1fd68993a9a5fbb0307078e17eb6ede551aedddf Mon Sep 17 00:00:00 2001 From: Patrick Wildt Date: Wed, 27 Jul 2016 11:45:03 +0000 Subject: Instead of passing the raw reg property to simplebus nodes, pass a pre-processed array of fdt_reg structs. This means that the drivers don't have to understand the cell properties themselves but can rely on the 64-bit addr/size pairs. ok kettenis@ --- sys/arch/arm/include/fdt.h | 4 ++-- sys/arch/arm/simplebus/simplebus.c | 40 ++++++++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 10 deletions(-) (limited to 'sys/arch/arm') diff --git a/sys/arch/arm/include/fdt.h b/sys/arch/arm/include/fdt.h index cc7c6041229..b506f5fb8ef 100644 --- a/sys/arch/arm/include/fdt.h +++ b/sys/arch/arm/include/fdt.h @@ -1,4 +1,4 @@ -/* $OpenBSD: fdt.h,v 1.3 2016/07/13 20:42:44 patrick Exp $ */ +/* $OpenBSD: fdt.h,v 1.4 2016/07/27 11:45:02 patrick Exp $ */ /* * Copyright (c) 2016 Patrick Wildt * @@ -26,7 +26,7 @@ struct fdt_attach_args { int fa_node; bus_space_tag_t fa_iot; bus_dma_tag_t fa_dmat; - uint32_t *fa_reg; + struct fdt_reg *fa_reg; int fa_nreg; uint32_t *fa_intr; int fa_nintr; diff --git a/sys/arch/arm/simplebus/simplebus.c b/sys/arch/arm/simplebus/simplebus.c index c818814b62a..557999ae9ba 100644 --- a/sys/arch/arm/simplebus/simplebus.c +++ b/sys/arch/arm/simplebus/simplebus.c @@ -1,4 +1,4 @@ -/* $OpenBSD: simplebus.c,v 1.7 2016/07/18 11:53:32 patrick Exp $ */ +/* $OpenBSD: simplebus.c,v 1.8 2016/07/27 11:45:02 patrick Exp $ */ /* * Copyright (c) 2016 Patrick Wildt * @@ -22,6 +22,7 @@ #include #include +#include #include @@ -125,7 +126,8 @@ simplebus_attach_node(struct device *self, int node) struct simplebus_softc *sc = (struct simplebus_softc *)self; struct fdt_attach_args fa; char buffer[128]; - int len; + int i, len, line; + uint32_t *cell, *reg; if (!OF_getprop(node, "compatible", buffer, sizeof(buffer))) return; @@ -143,11 +145,33 @@ simplebus_attach_node(struct device *self, int node) fa.fa_scells = sc->sc_scells; len = OF_getproplen(node, "reg"); - if (len > 0 && (len % sizeof(uint32_t)) == 0) { - fa.fa_reg = malloc(len, M_DEVBUF, M_WAITOK); - fa.fa_nreg = len / sizeof(uint32_t); - - OF_getpropintarray(node, "reg", fa.fa_reg, len); + line = (sc->sc_acells + sc->sc_scells) * sizeof(uint32_t); + if (len > 0 && line > 0 && (len % line) == 0) { + reg = malloc(len, M_TEMP, M_WAITOK); + OF_getpropintarray(node, "reg", reg, len); + + fa.fa_reg = malloc((len / line) * sizeof(struct fdt_reg), + M_DEVBUF, M_WAITOK | M_ZERO); + fa.fa_nreg = (len / line); + + for (i = 0, cell = reg; i < len / line; i++) { + if (sc->sc_acells >= 1) + fa.fa_reg[i].addr = cell[0]; + if (sc->sc_acells == 2) { + fa.fa_reg[i].addr <<= 32; + fa.fa_reg[i].addr |= cell[1]; + } + cell += sc->sc_acells; + if (sc->sc_scells >= 1) + fa.fa_reg[i].size = cell[0]; + if (sc->sc_scells == 2) { + fa.fa_reg[i].size <<= 32; + fa.fa_reg[i].size |= cell[1]; + } + cell += sc->sc_scells; + } + + free(reg, M_TEMP, len); } len = OF_getproplen(node, "interrupts"); @@ -162,7 +186,7 @@ simplebus_attach_node(struct device *self, int node) config_found(self, &fa, NULL); - free(fa.fa_reg, M_DEVBUF, fa.fa_nreg * sizeof(uint32_t)); + free(fa.fa_reg, M_DEVBUF, fa.fa_nreg * sizeof(struct fdt_reg)); free(fa.fa_intr, M_DEVBUF, fa.fa_nintr * sizeof(uint32_t)); } -- cgit v1.2.3