From 011666b0a8c74e747a5483f15fb01e9ac7dac93c Mon Sep 17 00:00:00 2001 From: ian Date: Sat, 23 May 2015 22:36:41 +0000 Subject: MFC r277098, r279235: Introduce ofw_bus_reg_to_rl() to replace part of common bus code Fix endianness on FDT read in ARM GIC --- sys/dev/fdt/simplebus.c | 31 +----------------------------- sys/dev/ofw/ofw_bus_subr.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++ sys/dev/ofw/ofw_bus_subr.h | 2 ++ sys/dev/ofw/ofwbus.c | 32 +------------------------------ 4 files changed, 52 insertions(+), 61 deletions(-) (limited to 'sys/dev') diff --git a/sys/dev/fdt/simplebus.c b/sys/dev/fdt/simplebus.c index d432791..7c2f0c6 100644 --- a/sys/dev/fdt/simplebus.c +++ b/sys/dev/fdt/simplebus.c @@ -253,10 +253,6 @@ simplebus_setup_dinfo(device_t dev, phandle_t node) { struct simplebus_softc *sc; struct simplebus_devinfo *ndi; - uint32_t *reg; - uint64_t phys, size; - int i, j, k; - int nreg; sc = device_get_softc(dev); @@ -267,32 +263,7 @@ simplebus_setup_dinfo(device_t dev, phandle_t node) } resource_list_init(&ndi->rl); - nreg = OF_getencprop_alloc(node, "reg", sizeof(*reg), (void **)®); - if (nreg == -1) - nreg = 0; - if (nreg % (sc->acells + sc->scells) != 0) { - if (bootverbose) - device_printf(dev, "Malformed reg property on <%s>\n", - ndi->obdinfo.obd_name); - nreg = 0; - } - - for (i = 0, k = 0; i < nreg; i += sc->acells + sc->scells, k++) { - phys = size = 0; - for (j = 0; j < sc->acells; j++) { - phys <<= 32; - phys |= reg[i + j]; - } - for (j = 0; j < sc->scells; j++) { - size <<= 32; - size |= reg[i + sc->acells + j]; - } - - resource_list_add(&ndi->rl, SYS_RES_MEMORY, k, - phys, phys + size - 1, size); - } - free(reg, M_OFWPROP); - + ofw_bus_reg_to_rl(dev, node, sc->acells, sc->scells, &ndi->rl); ofw_bus_intr_to_rl(dev, node, &ndi->rl); return (ndi); diff --git a/sys/dev/ofw/ofw_bus_subr.c b/sys/dev/ofw/ofw_bus_subr.c index cd11693..f628b00 100644 --- a/sys/dev/ofw/ofw_bus_subr.c +++ b/sys/dev/ofw/ofw_bus_subr.c @@ -370,6 +370,54 @@ ofw_bus_search_intrmap(void *intr, int intrsz, void *regs, int physsz, } int +ofw_bus_reg_to_rl(device_t dev, phandle_t node, pcell_t acells, pcell_t scells, + struct resource_list *rl) +{ + uint64_t phys, size; + ssize_t i, j, rid, nreg, ret; + uint32_t *reg; + char *name; + + /* + * This may be just redundant when having ofw_bus_devinfo + * but makes this routine independent of it. + */ + ret = OF_getencprop_alloc(node, "name", sizeof(*name), (void **)&name); + if (ret == -1) + name = NULL; + + ret = OF_getencprop_alloc(node, "reg", sizeof(*reg), (void **)®); + nreg = (ret == -1) ? 0 : ret; + + if (nreg % (acells + scells) != 0) { + if (bootverbose) + device_printf(dev, "Malformed reg property on <%s>\n", + (name == NULL) ? "unknown" : name); + nreg = 0; + } + + for (i = 0, rid = 0; i < nreg; i += acells + scells, rid++) { + phys = size = 0; + for (j = 0; j < acells; j++) { + phys <<= 32; + phys |= reg[i + j]; + } + for (j = 0; j < scells; j++) { + size <<= 32; + size |= reg[i + acells + j]; + } + /* Skip the dummy reg property of glue devices like ssm(4). */ + if (size != 0) + resource_list_add(rl, SYS_RES_MEMORY, rid, + phys, phys + size - 1, size); + } + free(name, M_OFWPROP); + free(reg, M_OFWPROP); + + return (0); +} + +int ofw_bus_intr_to_rl(device_t dev, phandle_t node, struct resource_list *rl) { phandle_t iparent; diff --git a/sys/dev/ofw/ofw_bus_subr.h b/sys/dev/ofw/ofw_bus_subr.h index 59f83fc..53a609b 100644 --- a/sys/dev/ofw/ofw_bus_subr.h +++ b/sys/dev/ofw/ofw_bus_subr.h @@ -73,6 +73,8 @@ int ofw_bus_search_intrmap(void *, int, void *, int, void *, int, void *, void *, void *, int, phandle_t *); /* Routines for parsing device-tree data into resource lists. */ +int ofw_bus_reg_to_rl(device_t, phandle_t, pcell_t, pcell_t, + struct resource_list *); int ofw_bus_intr_to_rl(device_t, phandle_t, struct resource_list *); /* Helper to get device status property */ diff --git a/sys/dev/ofw/ofwbus.c b/sys/dev/ofw/ofwbus.c index e135513..6a6095a 100644 --- a/sys/dev/ofw/ofwbus.c +++ b/sys/dev/ofw/ofwbus.c @@ -442,10 +442,6 @@ ofwbus_setup_dinfo(device_t dev, phandle_t node) struct ofwbus_softc *sc; struct ofwbus_devinfo *ndi; const char *nodename; - uint32_t *reg; - uint64_t phys, size; - int i, j, rid; - int nreg; sc = device_get_softc(dev); @@ -462,33 +458,7 @@ ofwbus_setup_dinfo(device_t dev, phandle_t node) } resource_list_init(&ndi->ndi_rl); - nreg = OF_getencprop_alloc(node, "reg", sizeof(*reg), (void **)®); - if (nreg == -1) - nreg = 0; - if (nreg % (sc->acells + sc->scells) != 0) { - if (bootverbose) - device_printf(dev, "Malformed reg property on <%s>\n", - nodename); - nreg = 0; - } - - for (i = 0, rid = 0; i < nreg; i += sc->acells + sc->scells, rid++) { - phys = size = 0; - for (j = 0; j < sc->acells; j++) { - phys <<= 32; - phys |= reg[i + j]; - } - for (j = 0; j < sc->scells; j++) { - size <<= 32; - size |= reg[i + sc->acells + j]; - } - /* Skip the dummy reg property of glue devices like ssm(4). */ - if (size != 0) - resource_list_add(&ndi->ndi_rl, SYS_RES_MEMORY, rid, - phys, phys + size - 1, size); - } - free(reg, M_OFWPROP); - + ofw_bus_reg_to_rl(dev, node, sc->acells, sc->scells, &ndi->ndi_rl); ofw_bus_intr_to_rl(dev, node, &ndi->ndi_rl); return (ndi); -- cgit v1.1