Align OF_getencprop_alloc API with OF_getencprop and OF_getprop_alloc

Change OF_getencprop_alloc semantics to be combination of malloc and
OF_getencprop and return size of the property, not number of elements
allocated.

For the use cases where number of elements is preferred introduce
OF_getencprop_alloc_multi helper function that copies semantics
of OF_getencprop_alloc prior to this change.

This is to make OF_getencprop_alloc and OF_getencprop_alloc_multi
function signatures consistent with OF_getencprop_alloc and
OF_getencprop_alloc_multi.

Functionality-wise this patch is mostly rename of OF_getencprop_alloc
to OF_getencprop_alloc_multi except two calls in ofw_bus_setup_iinfo
where 1 was used as a block size.
This commit is contained in:
Oleksandr Tymoshenko 2018-04-09 22:06:16 +00:00
parent c7fb0e1ddf
commit f7604b1b27
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=332341
26 changed files with 70 additions and 55 deletions

View File

@ -195,7 +195,7 @@ aml8726_usb_phy_attach(device_t dev)
err = 0;
len = OF_getencprop_alloc(node, "usb-pwr-en",
len = OF_getencprop_alloc_multi(node, "usb-pwr-en",
3 * sizeof(pcell_t), (void **)&prop);
npwr_en = (len > 0) ? len : 0;

View File

@ -167,7 +167,7 @@ aml8726_usb_phy_attach(device_t dev)
err = 0;
len = OF_getencprop_alloc(node, "usb-pwr-en",
len = OF_getencprop_alloc_multi(node, "usb-pwr-en",
3 * sizeof(pcell_t), (void **)&prop);
npwr_en = (len > 0) ? len : 0;
@ -188,7 +188,7 @@ aml8726_usb_phy_attach(device_t dev)
OF_prop_free(prop);
len = OF_getencprop_alloc(node, "usb-hub-rst",
len = OF_getencprop_alloc_multi(node, "usb-hub-rst",
3 * sizeof(pcell_t), (void **)&prop);
if (len > 0) {
sc->hub_rst.dev = OF_device_from_xref(prop[0]);

View File

@ -188,7 +188,7 @@ al_msix_attach(device_t dev)
sc->gic_dev = gic_dev;
/* Manually read range of interrupts from DTB */
nintr = OF_getencprop_alloc(node, "interrupts", sizeof(*intr),
nintr = OF_getencprop_alloc_multi(node, "interrupts", sizeof(*intr),
(void **)&intr);
if (nintr == 0) {
device_printf(dev, "Cannot read interrupts prop from DTB\n");

View File

@ -101,7 +101,8 @@ at91_pinctrl_setup_dinfo(device_t dev, phandle_t node)
}
resource_list_init(&ndi->rl);
nreg = OF_getencprop_alloc(node, "reg", sizeof(*reg), (void **)&reg);
nreg = OF_getencprop_alloc_multi(node, "reg", sizeof(*reg),
(void **)&reg);
if (nreg == -1)
nreg = 0;
if (nreg % (sc->acells + sc->scells) != 0) {
@ -127,7 +128,7 @@ at91_pinctrl_setup_dinfo(device_t dev, phandle_t node)
}
OF_prop_free(reg);
nintr = OF_getencprop_alloc(node, "interrupts", sizeof(*intr),
nintr = OF_getencprop_alloc_multi(node, "interrupts", sizeof(*intr),
(void **)&intr);
if (nintr > 0) {
if (OF_searchencprop(node, "interrupt-parent", &iparent,
@ -393,7 +394,7 @@ pinctrl_configure_pins(device_t bus, phandle_t cfgxref)
node = OF_node_from_xref(cfgxref);
memset(name, 0, sizeof(name));
OF_getprop(node, "name", name, sizeof(name));
npins = OF_getencprop_alloc(node, "atmel,pins", sizeof(*cfgdata),
npins = OF_getencprop_alloc_multi(node, "atmel,pins", sizeof(*cfgdata),
(void **)&cfgdata);
if (npins < 0) {
printf("We're doing it wrong %s\n", name);

View File

@ -623,7 +623,7 @@ bcm_gpio_get_ro_pins(struct bcm_gpio_softc *sc, phandle_t node,
pcell_t *pins;
/* Get the property data. */
npins = OF_getencprop_alloc(node, propname, sizeof(*pins),
npins = OF_getencprop_alloc_multi(node, propname, sizeof(*pins),
(void **)&pins);
if (npins < 0)
return (-1);
@ -1214,8 +1214,8 @@ bcm_gpio_configure_pins(device_t dev, phandle_t cfgxref)
cfgnode = OF_node_from_xref(cfgxref);
pins = NULL;
pintuples = OF_getencprop_alloc(cfgnode, "brcm,pins", sizeof(*pins),
(void **)&pins);
pintuples = OF_getencprop_alloc_multi(cfgnode, "brcm,pins",
sizeof(*pins), (void **)&pins);
char name[32];
OF_getprop(cfgnode, "name", &name, sizeof(name));
@ -1233,8 +1233,8 @@ bcm_gpio_configure_pins(device_t dev, phandle_t cfgxref)
}
pulls = NULL;
pulltuples = OF_getencprop_alloc(cfgnode, "brcm,pull", sizeof(*pulls),
(void **)&pulls);
pulltuples = OF_getencprop_alloc_multi(cfgnode, "brcm,pull",
sizeof(*pulls), (void **)&pulls);
if ((pulls != NULL) && (pulltuples != pintuples)) {
OF_prop_free(pins);

View File

@ -153,8 +153,8 @@ iomux_configure_pins(device_t dev, phandle_t cfgxref)
sc = device_get_softc(dev);
cfgnode = OF_node_from_xref(cfgxref);
ntuples = OF_getencprop_alloc(cfgnode, "fsl,pins", sizeof(*cfgtuples),
(void **)&cfgtuples);
ntuples = OF_getencprop_alloc_multi(cfgnode, "fsl,pins",
sizeof(*cfgtuples), (void **)&cfgtuples);
if (ntuples < 0)
return (ENOENT);
if (ntuples == 0)

View File

@ -125,7 +125,7 @@ tegra_drm_encoder_attach(struct tegra_drm_encoder *output, phandle_t node)
/* XXX parse output panel here */
rv = OF_getencprop_alloc(node, "nvidia,edid", 1,
rv = OF_getencprop_alloc(node, "nvidia,edid",
(void **)&output->edid);
/* EDID exist but have invalid size */
@ -174,4 +174,4 @@ int tegra_drm_encoder_exit(struct tegra_drm_encoder *output,
/* detach panel */
}
return (0);
}
}

View File

@ -777,8 +777,9 @@ ti_adc_attach(device_t dev)
if ((OF_getencprop(child, "ti,charge-delay", &cell,
sizeof(cell))) > 0)
sc->sc_charge_delay = cell;
nwire_configs = OF_getencprop_alloc(child, "ti,wire-config",
sizeof(*wire_configs), (void **)&wire_configs);
nwire_configs = OF_getencprop_alloc_multi(child,
"ti,wire-config", sizeof(*wire_configs),
(void **)&wire_configs);
if (nwire_configs != sc->sc_tsc_wires) {
device_printf(sc->sc_dev,
"invalid number of ti,wire-config: %d (should be %d)\n",
@ -795,8 +796,8 @@ ti_adc_attach(device_t dev)
/* Read "adc" node properties */
child = ofw_bus_find_child(node, "adc");
if (child != 0) {
sc->sc_adc_nchannels = OF_getencprop_alloc(child, "ti,adc-channels",
sizeof(*channels), (void **)&channels);
sc->sc_adc_nchannels = OF_getencprop_alloc_multi(child,
"ti,adc-channels", sizeof(*channels), (void **)&channels);
if (sc->sc_adc_nchannels > 0) {
for (i = 0; i < sc->sc_adc_nchannels; i++)
sc->sc_adc_channels[i] = channels[i];

View File

@ -340,8 +340,8 @@ ti_pinmux_configure_pins(device_t dev, phandle_t cfgxref)
sc = device_get_softc(dev);
cfgnode = OF_node_from_xref(cfgxref);
ntuples = OF_getencprop_alloc(cfgnode, "pinctrl-single,pins", sizeof(*cfgtuples),
(void **)&cfgtuples);
ntuples = OF_getencprop_alloc_multi(cfgnode, "pinctrl-single,pins",
sizeof(*cfgtuples), (void **)&cfgtuples);
if (ntuples < 0)
return (ENOENT);

View File

@ -289,7 +289,7 @@ cpufreq_dt_attach(device_t dev)
return (ENXIO);
}
sc->nopp = OF_getencprop_alloc(node, "operating-points",
sc->nopp = OF_getencprop_alloc_multi(node, "operating-points",
sizeof(*sc->opp), (void **)&opp);
if (sc->nopp == -1)
return (ENXIO);

View File

@ -185,7 +185,7 @@ qman_portals_fdt_attach(device_t dev)
get_addr_props(ofw_bus_get_node(device_get_parent(dev)), &paddr, &size);
get_addr_props(node, &addr, &size);
nrange = OF_getencprop_alloc(node, "ranges",
nrange = OF_getencprop_alloc_multi(node, "ranges",
sizeof(*range), (void **)&range);
if (nrange < addr + paddr + size)
return (ENXIO);

View File

@ -1409,7 +1409,7 @@ clk_parse_ofw_out_names(device_t dev, phandle_t node, const char ***out_names,
if (!OF_hasprop(node, "clock-indices"))
return (name_items);
rv = OF_getencprop_alloc(node, "clock-indices", sizeof (uint32_t),
rv = OF_getencprop_alloc_multi(node, "clock-indices", sizeof (uint32_t),
(void **)indices);
if (rv != name_items) {
device_printf(dev, " Size of 'clock-output-names' and "

View File

@ -563,7 +563,7 @@ phy_get_by_ofw_property(device_t consumer_dev, phandle_t cnode, char *name,
"%s called on not ofw based device\n", __func__);
return (ENXIO);
}
ncells = OF_getencprop_alloc(cnode, name, sizeof(pcell_t),
ncells = OF_getencprop_alloc_multi(cnode, name, sizeof(pcell_t),
(void **)&cells);
if (ncells < 1)
return (ENXIO);

View File

@ -1085,7 +1085,7 @@ regulator_get_by_ofw_property(device_t cdev, phandle_t cnode, char *name,
}
cells = NULL;
ncells = OF_getencprop_alloc(cnode, name, sizeof(*cells),
ncells = OF_getencprop_alloc_multi(cnode, name, sizeof(*cells),
(void **)&cells);
if (ncells <= 0)
return (ENXIO);

View File

@ -236,7 +236,7 @@ syscon_get_by_ofw_property(device_t cdev, phandle_t cnode, char *name,
"%s called on not ofw based device\n", __func__);
return (ENXIO);
}
ncells = OF_getencprop_alloc(cnode, name, sizeof(pcell_t),
ncells = OF_getencprop_alloc_multi(cnode, name, sizeof(pcell_t),
(void **)&cells);
if (ncells < 1)
return (ENXIO);

View File

@ -58,7 +58,7 @@ enable_disable_all(device_t consumer, boolean_t enable)
boolean_t anyerrors;
cnode = ofw_bus_get_node(consumer);
ncells = OF_getencprop_alloc(cnode, "clocks", sizeof(*clks),
ncells = OF_getencprop_alloc_multi(cnode, "clocks", sizeof(*clks),
(void **)&clks);
if (enable && ncells < 2) {
device_printf(consumer, "Warning: No clocks specified in fdt "
@ -102,7 +102,7 @@ fdt_clock_get_info(device_t consumer, int n, struct fdt_clock_info *info)
uint32_t *clks;
cnode = ofw_bus_get_node(consumer);
ncells = OF_getencprop_alloc(cnode, "clocks", sizeof(*clks),
ncells = OF_getencprop_alloc_multi(cnode, "clocks", sizeof(*clks),
(void **)&clks);
if (ncells <= 0)
return (ENXIO);

View File

@ -46,7 +46,7 @@ fdt_pinctrl_configure(device_t client, u_int index)
char name[16];
snprintf(name, sizeof(name), "pinctrl-%u", index);
nconfigs = OF_getencprop_alloc(ofw_bus_get_node(client), name,
nconfigs = OF_getencprop_alloc_multi(ofw_bus_get_node(client), name,
sizeof(*configs), (void **)&configs);
if (nconfigs < 0)
return (ENOENT);
@ -122,7 +122,7 @@ pinctrl_configure_children(device_t pinctrl, phandle_t parent)
if (!ofw_bus_node_status_okay(node))
continue;
pinctrl_configure_children(pinctrl, node);
nconfigs = OF_getencprop_alloc(node, "pinctrl-0",
nconfigs = OF_getencprop_alloc_multi(node, "pinctrl-0",
sizeof(*configs), (void **)&configs);
if (nconfigs <= 0)
continue;

View File

@ -216,7 +216,7 @@ gpioregulator_parse_fdt(struct gpioregulator_softc *sc)
return (error);
/* "states" property (required) */
len = OF_getencprop_alloc(node, "states", sizeof(*pstates),
len = OF_getencprop_alloc_multi(node, "states", sizeof(*pstates),
(void **)&pstates);
if (len < 2) {
device_printf(sc->dev, "invalid 'states' property\n");

View File

@ -364,7 +364,7 @@ ofw_gpiobus_parse_gpios_impl(device_t consumer, phandle_t cnode, char *pname,
pcell_t *gpios;
phandle_t gpio;
ncells = OF_getencprop_alloc(cnode, pname, sizeof(*gpios),
ncells = OF_getencprop_alloc_multi(cnode, pname, sizeof(*gpios),
(void **)&gpios);
if (ncells == -1) {
device_printf(consumer,

View File

@ -319,10 +319,10 @@ ofw_bus_setup_iinfo(phandle_t node, struct ofw_bus_iinfo *ii, int intrsz)
addrc = 2;
ii->opi_addrc = addrc * sizeof(pcell_t);
ii->opi_imapsz = OF_getencprop_alloc(node, "interrupt-map", 1,
ii->opi_imapsz = OF_getencprop_alloc(node, "interrupt-map",
(void **)&ii->opi_imap);
if (ii->opi_imapsz > 0) {
msksz = OF_getencprop_alloc(node, "interrupt-map-mask", 1,
msksz = OF_getencprop_alloc(node, "interrupt-map-mask",
(void **)&ii->opi_imapmsk);
/*
* Failure to get the mask is ignored; a full mask is used
@ -449,7 +449,8 @@ ofw_bus_msimap(phandle_t node, uint16_t pci_rid, phandle_t *msi_parent,
int err, i;
/* TODO: This should be OF_searchprop_alloc if we had it */
len = OF_getencprop_alloc(node, "msi-map", sizeof(*map), (void **)&map);
len = OF_getencprop_alloc_multi(node, "msi-map", sizeof(*map),
(void **)&map);
if (len < 0) {
if (msi_parent != NULL) {
*msi_parent = 0;
@ -506,7 +507,8 @@ ofw_bus_reg_to_rl_helper(device_t dev, phandle_t node, pcell_t acells, pcell_t s
if (ret == -1)
name = NULL;
ret = OF_getencprop_alloc(node, reg_source, sizeof(*reg), (void **)&reg);
ret = OF_getencprop_alloc_multi(node, reg_source, sizeof(*reg),
(void **)&reg);
nreg = (ret == -1) ? 0 : ret;
if (nreg % (acells + scells) != 0) {
@ -584,7 +586,7 @@ ofw_bus_intr_to_rl(device_t dev, phandle_t node,
int err, i, irqnum, nintr, rid;
boolean_t extended;
nintr = OF_getencprop_alloc(node, "interrupts", sizeof(*intr),
nintr = OF_getencprop_alloc_multi(node, "interrupts", sizeof(*intr),
(void **)&intr);
if (nintr > 0) {
iparent = ofw_bus_find_iparent(node);
@ -607,7 +609,7 @@ ofw_bus_intr_to_rl(device_t dev, phandle_t node,
}
extended = false;
} else {
nintr = OF_getencprop_alloc(node, "interrupts-extended",
nintr = OF_getencprop_alloc_multi(node, "interrupts-extended",
sizeof(*intr), (void **)&intr);
if (nintr <= 0)
return (0);
@ -650,7 +652,7 @@ ofw_bus_intr_by_rid(device_t dev, phandle_t node, int wanted_rid,
int err, i, nintr, rid;
boolean_t extended;
nintr = OF_getencprop_alloc(node, "interrupts", sizeof(*intr),
nintr = OF_getencprop_alloc_multi(node, "interrupts", sizeof(*intr),
(void **)&intr);
if (nintr > 0) {
iparent = ofw_bus_find_iparent(node);
@ -673,7 +675,7 @@ ofw_bus_intr_by_rid(device_t dev, phandle_t node, int wanted_rid,
}
extended = false;
} else {
nintr = OF_getencprop_alloc(node, "interrupts-extended",
nintr = OF_getencprop_alloc_multi(node, "interrupts-extended",
sizeof(*intr), (void **)&intr);
if (nintr <= 0)
return (ESRCH);
@ -821,7 +823,7 @@ ofw_bus_parse_xref_list_internal(phandle_t node, const char *list_name,
int rv, i, j, nelems, cnt;
elems = NULL;
nelems = OF_getencprop_alloc(node, list_name, sizeof(*elems),
nelems = OF_getencprop_alloc_multi(node, list_name, sizeof(*elems),
(void **)&elems);
if (nelems <= 0)
return (ENOENT);

View File

@ -488,9 +488,22 @@ OF_getprop_alloc_multi(phandle_t package, const char *propname, int elsz, void *
return (len / elsz);
}
ssize_t
OF_getencprop_alloc(phandle_t package, const char *name, void **buf)
{
ssize_t ret;
ret = OF_getencprop_alloc_multi(package, name, sizeof(pcell_t),
buf);
if (ret < 0)
return (ret);
else
return (ret * sizeof(pcell_t));
}
ssize_t
OF_getencprop_alloc(phandle_t package, const char *name, int elsz, void **buf)
OF_getencprop_alloc_multi(phandle_t package, const char *name, int elsz,
void **buf)
{
ssize_t retval;
pcell_t *cell;
@ -499,11 +512,6 @@ OF_getencprop_alloc(phandle_t package, const char *name, int elsz, void **buf)
retval = OF_getprop_alloc_multi(package, name, elsz, buf);
if (retval == -1)
return (-1);
if (retval * elsz % 4 != 0) {
free(*buf, M_OFWPROP);
*buf = NULL;
return (-1);
}
cell = *buf;
for (i = 0; i < retval * elsz / 4; i++)

View File

@ -120,6 +120,8 @@ ssize_t OF_getprop_alloc(phandle_t node, const char *propname,
ssize_t OF_getprop_alloc_multi(phandle_t node, const char *propname,
int elsz, void **buf);
ssize_t OF_getencprop_alloc(phandle_t node, const char *propname,
void **buf);
ssize_t OF_getencprop_alloc_multi(phandle_t node, const char *propname,
int elsz, void **buf);
void OF_prop_free(void *buf);
int OF_nextprop(phandle_t node, const char *propname, char *buf,

View File

@ -258,7 +258,7 @@ bgx_fdt_traverse_nodes(uint8_t unit, phandle_t start, char *name,
BGX_NODE_NAME, sizeof(BGX_NODE_NAME) - 1) != 0)
continue;
/* Get reg */
err = OF_getencprop_alloc(node, "reg", sizeof(*reg),
err = OF_getencprop_alloc_multi(node, "reg", sizeof(*reg),
(void **)&reg);
if (err == -1) {
free(reg, M_OFWPROP);

View File

@ -196,8 +196,8 @@ jz4780_pinctrl_configure_pins(device_t dev, phandle_t cfgxref)
node = OF_node_from_xref(cfgxref);
len = OF_getencprop_alloc(node, "ingenic,pins", sizeof(uint32_t) * 4,
(void **)&value);
len = OF_getencprop_alloc_multi(node, "ingenic,pins",
sizeof(uint32_t) * 4, (void **)&value);
if (len < 0) {
device_printf(dev,
"missing ingenic,pins attribute in FDT\n");

View File

@ -59,7 +59,7 @@ assert_deassert_all(device_t consumer, boolean_t assert)
boolean_t anyerrors;
rnode = ofw_bus_get_node(consumer);
ncells = OF_getencprop_alloc(rnode, "resets", sizeof(*resets),
ncells = OF_getencprop_alloc_multi(rnode, "resets", sizeof(*resets),
(void **)&resets);
if (!assert && ncells < 2) {
device_printf(consumer, "Warning: No resets specified in fdt "

View File

@ -374,7 +374,8 @@ fdt_lbc_reg_decode(phandle_t node, struct lbc_softc *sc,
return (ENXIO);
tuple_size = sizeof(pcell_t) * (addr_cells + size_cells);
tuples = OF_getencprop_alloc(node, "reg", tuple_size, (void **)&reg);
tuples = OF_getencprop_alloc_multi(node, "reg", tuple_size,
(void **)&reg);
debugf("addr_cells = %d, size_cells = %d\n", addr_cells, size_cells);
debugf("tuples = %d, tuple size = %d\n", tuples, tuple_size);
if (tuples <= 0)
@ -545,7 +546,7 @@ lbc_attach(device_t dev)
tuple_size = sizeof(pcell_t) * (sc->sc_addr_cells + par_addr_cells +
sc->sc_size_cells);
tuples = OF_getencprop_alloc(node, "ranges", tuple_size,
tuples = OF_getencprop_alloc_multi(node, "ranges", tuple_size,
(void **)&ranges);
if (tuples < 0) {
device_printf(dev, "could not retrieve 'ranges' property\n");