Where appropriate, use the endian-flipping OF_getencprop() instead of

OF_getprop() to get encode-int encoded values from the OF tree. This is
a no-op at present, since all existing PowerPC ports are big-endian, but
it is a correctness improvement and will be required if we have a
little-endian kernel at some future point.

Where it is totally impossible for the code ever to be used on a
little-endian system (much of powerpc/powermac, for instance), I have not
necessarily made the appropriate changes.

MFC after:	1 month
This commit is contained in:
Nathan Whitehorn 2015-11-17 16:07:43 +00:00
parent d6d3f24890
commit 509142e189
15 changed files with 71 additions and 65 deletions

View File

@ -493,9 +493,9 @@ moea64_add_ofw_mappings(mmu_t mmup, phandle_t mmu, size_t sz)
int i, j;
bzero(translations, sz);
OF_getprop(OF_finddevice("/"), "#address-cells", &acells,
OF_getencprop(OF_finddevice("/"), "#address-cells", &acells,
sizeof(acells));
if (OF_getprop(mmu, "translations", trans_cells, sz) == -1)
if (OF_getencprop(mmu, "translations", trans_cells, sz) == -1)
panic("moea64_bootstrap: can't get ofw translations");
CTR0(KTR_PMAP, "moea64_add_ofw_mappings: translations");
@ -856,7 +856,7 @@ moea64_late_bootstrap(mmu_t mmup, vm_offset_t kernelstart, vm_offset_t kernelend
*/
chosen = OF_finddevice("/chosen");
if (chosen != -1 && OF_getprop(chosen, "mmu", &mmui, 4) != -1) {
if (chosen != -1 && OF_getencprop(chosen, "mmu", &mmui, 4) != -1) {
mmu = OF_instance_to_package(mmui);
if (mmu == -1 ||
(sz = OF_getproplen(mmu, "translations")) == -1)

View File

@ -154,17 +154,17 @@ parse_ofw_memory(phandle_t node, const char *prop, struct mem_region *output)
* be found.
*/
phandle = OF_finddevice("/");
if (OF_getprop(phandle, "#address-cells", &address_cells,
if (OF_getencprop(phandle, "#address-cells", &address_cells,
sizeof(address_cells)) < (ssize_t)sizeof(address_cells))
address_cells = 1;
if (OF_getprop(phandle, "#size-cells", &size_cells,
if (OF_getencprop(phandle, "#size-cells", &size_cells,
sizeof(size_cells)) < (ssize_t)sizeof(size_cells))
size_cells = 1;
/*
* Get memory.
*/
if (node == -1 || (sz = OF_getprop(node, prop,
if (node == -1 || (sz = OF_getencprop(node, prop,
OFmem, sizeof(OFmem))) <= 0)
panic("Physical memory map not found");
@ -572,10 +572,10 @@ OF_get_addr_props(phandle_t node, uint32_t *addrp, uint32_t *sizep, int *pcip)
uint32_t addr, size;
int pci, res;
res = OF_getprop(node, "#address-cells", &addr, sizeof(addr));
res = OF_getencprop(node, "#address-cells", &addr, sizeof(addr));
if (res == -1)
addr = 2;
res = OF_getprop(node, "#size-cells", &size, sizeof(size));
res = OF_getencprop(node, "#size-cells", &size, sizeof(size));
if (res == -1)
size = 1;
pci = 0;
@ -624,7 +624,7 @@ OF_decode_addr(phandle_t dev, int regno, bus_space_tag_t *tag,
OF_get_addr_props(bridge, &naddr, &nsize, &pci);
if (pci)
*tag = &bs_le_tag;
res = OF_getprop(dev, (pci) ? "assigned-addresses" : "reg",
res = OF_getencprop(dev, (pci) ? "assigned-addresses" : "reg",
cell, sizeof(cell));
if (res == -1)
return (ENXIO);
@ -653,7 +653,7 @@ OF_decode_addr(phandle_t dev, int regno, bus_space_tag_t *tag,
OF_get_addr_props(parent, &nbridge, NULL, &pcib);
if (pcib)
*tag = &bs_le_tag;
res = OF_getprop(bridge, "ranges", cell, sizeof(cell));
res = OF_getencprop(bridge, "ranges", cell, sizeof(cell));
if (res == -1)
goto next;
if (res % sizeof(cell[0]))

View File

@ -136,10 +136,11 @@ ofw_pci_init(device_t dev)
sc = device_get_softc(dev);
sc->sc_initialized = 1;
if (OF_getprop(node, "reg", &sc->sc_pcir, sizeof(sc->sc_pcir)) == -1)
if (OF_getencprop(node, "reg", (pcell_t *)&sc->sc_pcir,
sizeof(sc->sc_pcir)) == -1)
return (ENXIO);
if (OF_getprop(node, "bus-range", busrange, sizeof(busrange)) != 8)
if (OF_getencprop(node, "bus-range", busrange, sizeof(busrange)) != 8)
busrange[0] = 0;
sc->sc_dev = dev;
@ -498,11 +499,11 @@ ofw_pci_nranges(phandle_t node)
int host_address_cells = 1, pci_address_cells = 3, size_cells = 2;
ssize_t nbase_ranges;
OF_getprop(OF_parent(node), "#address-cells", &host_address_cells,
OF_getencprop(OF_parent(node), "#address-cells", &host_address_cells,
sizeof(host_address_cells));
OF_getprop(node, "#address-cells", &pci_address_cells,
OF_getencprop(node, "#address-cells", &pci_address_cells,
sizeof(pci_address_cells));
OF_getprop(node, "#size-cells", &size_cells, sizeof(size_cells));
OF_getencprop(node, "#size-cells", &size_cells, sizeof(size_cells));
nbase_ranges = OF_getproplen(node, "ranges");
if (nbase_ranges <= 0)
@ -521,11 +522,11 @@ ofw_pci_fill_ranges(phandle_t node, struct ofw_pci_range *ranges)
int nranges;
int i, j, k;
OF_getprop(OF_parent(node), "#address-cells", &host_address_cells,
OF_getencprop(OF_parent(node), "#address-cells", &host_address_cells,
sizeof(host_address_cells));
OF_getprop(node, "#address-cells", &pci_address_cells,
OF_getencprop(node, "#address-cells", &pci_address_cells,
sizeof(pci_address_cells));
OF_getprop(node, "#size-cells", &size_cells, sizeof(size_cells));
OF_getencprop(node, "#size-cells", &size_cells, sizeof(size_cells));
nbase_ranges = OF_getproplen(node, "ranges");
if (nbase_ranges <= 0)
@ -534,7 +535,7 @@ ofw_pci_fill_ranges(phandle_t node, struct ofw_pci_range *ranges)
(pci_address_cells + host_address_cells + size_cells);
base_ranges = malloc(nbase_ranges, M_DEVBUF, M_WAITOK);
OF_getprop(node, "ranges", base_ranges, nbase_ranges);
OF_getencprop(node, "ranges", base_ranges, nbase_ranges);
for (i = 0, j = 0; i < nranges; i++) {
ranges[i].pci_hi = base_ranges[j++];

View File

@ -156,7 +156,8 @@ ofw_pcibus_enum_devtree(device_t dev, u_int domain, u_int busno)
node = ofw_bus_get_node(dev);
for (child = OF_child(node); child != 0; child = OF_peer(child)) {
if (OF_getprop(child, "reg", &pcir, sizeof(pcir)) == -1)
if (OF_getencprop(child, "reg", (pcell_t *)&pcir,
sizeof(pcir)) == -1)
continue;
slot = OFW_PCI_PHYS_HI_DEVICE(pcir.phys_hi);
func = OFW_PCI_PHYS_HI_FUNCTION(pcir.phys_hi);
@ -305,11 +306,12 @@ ofw_pcibus_assign_interrupt(device_t dev, device_t child)
*/
iparent = -1;
if (OF_getprop(node, "interrupt-parent", &iparent, sizeof(iparent)) < 0)
if (OF_getencprop(node, "interrupt-parent", &iparent,
sizeof(iparent)) < 0)
iparent = -1;
icells = 1;
if (iparent != -1)
OF_getprop(OF_node_from_xref(iparent), "#interrupt-cells",
OF_getencprop(OF_node_from_xref(iparent), "#interrupt-cells",
&icells, sizeof(icells));
/*
@ -317,12 +319,12 @@ ofw_pcibus_assign_interrupt(device_t dev, device_t child)
* fully specified (i.e. does not need routing)
*/
isz = OF_getprop(node, "AAPL,interrupts", intr, sizeof(intr));
isz = OF_getencprop(node, "AAPL,interrupts", intr, sizeof(intr));
if (isz == sizeof(intr[0])*icells)
return ((iparent == -1) ? intr[0] : ofw_bus_map_intr(dev,
iparent, icells, intr));
isz = OF_getprop(node, "interrupts", intr, sizeof(intr));
isz = OF_getencprop(node, "interrupts", intr, sizeof(intr));
if (isz == sizeof(intr[0])*icells) {
if (iparent != -1)
intr[0] = ofw_bus_map_intr(dev, iparent, icells, intr);

View File

@ -127,9 +127,9 @@ openpic_ofw_attach(device_t dev)
node = ofw_bus_get_node(dev);
if (OF_getprop(node, "phandle", &xref, sizeof(xref)) == -1 &&
OF_getprop(node, "ibm,phandle", &xref, sizeof(xref)) == -1 &&
OF_getprop(node, "linux,phandle", &xref, sizeof(xref)) == -1)
if (OF_getencprop(node, "phandle", &xref, sizeof(xref)) == -1 &&
OF_getencprop(node, "ibm,phandle", &xref, sizeof(xref)) == -1 &&
OF_getencprop(node, "linux,phandle", &xref, sizeof(xref)) == -1)
xref = node;
return (openpic_common_attach(dev, xref));

View File

@ -176,7 +176,7 @@ cpcht_attach(device_t dev)
node = ofw_bus_get_node(dev);
sc = device_get_softc(dev);
if (OF_getprop(node, "reg", reg, sizeof(reg)) < 12)
if (OF_getencprop(node, "reg", reg, sizeof(reg)) < 12)
return (ENXIO);
if (OF_getproplen(node, "ranges") <= 0)
@ -219,7 +219,7 @@ cpcht_configure_htbridge(device_t dev, phandle_t child)
u_int b, f, s;
sc = device_get_softc(dev);
if (OF_getprop(child, "reg", &pcir, sizeof(pcir)) == -1)
if (OF_getencprop(child, "reg", (pcell_t *)&pcir, sizeof(pcir)) == -1)
return;
b = OFW_PCI_PHYS_HI_BUS(pcir.phys_hi);

View File

@ -186,11 +186,11 @@ kiic_attach(device_t self)
return (ENOMEM);
}
if (OF_getprop(node, "AAPL,i2c-rate", &rate, 4) != 4) {
if (OF_getencprop(node, "AAPL,i2c-rate", &rate, 4) != 4) {
device_printf(self, "cannot get i2c-rate\n");
return (ENXIO);
}
if (OF_getprop(node, "AAPL,address-step", &sc->sc_regstep, 4) != 4) {
if (OF_getencprop(node, "AAPL,address-step", &sc->sc_regstep, 4) != 4) {
device_printf(self, "unable to find i2c address step\n");
return (ENXIO);
}

View File

@ -177,7 +177,7 @@ macgpio_attach(device_t dev)
continue;
}
if (OF_getprop(child,"reg",&dinfo->gpio_num,
if (OF_getencprop(child, "reg", &dinfo->gpio_num,
sizeof(dinfo->gpio_num)) != sizeof(dinfo->gpio_num)) {
/*
* Some early GPIO controllers don't provide GPIO
@ -191,9 +191,9 @@ macgpio_attach(device_t dev)
resource_list_init(&dinfo->mdi_resources);
if (OF_getprop(child, "interrupts", &irq, sizeof(irq)) ==
if (OF_getencprop(child, "interrupts", &irq, sizeof(irq)) ==
sizeof(irq)) {
OF_searchprop(child, "interrupt-parent", &iparent,
OF_searchencprop(child, "interrupt-parent", &iparent,
sizeof(iparent));
resource_list_add(&dinfo->mdi_resources, SYS_RES_IRQ,
0, MAP_IRQ(iparent, irq), MAP_IRQ(iparent, irq),

View File

@ -142,11 +142,11 @@ mphyp_bootstrap(mmu_t mmup, vm_offset_t kernelstart, vm_offset_t kernelend)
node = OF_peer(node);
}
res = OF_getprop(node, "ibm,pft-size", prop, sizeof(prop));
res = OF_getencprop(node, "ibm,pft-size", prop, sizeof(prop));
if (res <= 0)
panic("mmu_phyp: unknown PFT size");
final_pteg_count = 1 << prop[1];
res = OF_getprop(node, "ibm,slb-size", prop, sizeof(prop[0]));
res = OF_getencprop(node, "ibm,slb-size", prop, sizeof(prop[0]));
if (res > 0)
n_slbs = prop[0];

View File

@ -147,7 +147,7 @@ uart_phyp_probe_node(struct uart_phyp_softc *sc)
return (ENXIO);
reg = -1;
OF_getprop(node, "reg", &reg, sizeof(reg));
OF_getencprop(node, "reg", &reg, sizeof(reg));
if (reg == -1)
return (ENXIO);
sc->vtermid = reg;
@ -200,7 +200,7 @@ uart_phyp_cnprobe(struct consdev *cp)
/* Check if OF has an active stdin/stdout */
input = -1;
if (OF_getprop(chosen, "stdout", &stdout,
if (OF_getencprop(chosen, "stdout", &stdout,
sizeof(stdout)) == sizeof(stdout) && stdout != 0)
input = OF_instance_to_package(stdout);
if (input == -1)

View File

@ -159,7 +159,7 @@ llan_attach(device_t dev)
node = ofw_bus_get_node(dev);
OF_getprop(node, "local-mac-address", sc->mac_address,
sizeof(sc->mac_address));
OF_getprop(node, "reg", &sc->unit, sizeof(sc->unit));
OF_getencprop(node, "reg", &sc->unit, sizeof(sc->unit));
mtx_init(&sc->io_lock, "llan", NULL, MTX_DEF);

View File

@ -290,7 +290,8 @@ vscsi_attach(device_t dev)
mtx_init(&sc->io_lock, "vscsi", NULL, MTX_DEF);
/* Get properties */
OF_getprop(ofw_bus_get_node(dev), "reg", &sc->unit, sizeof(sc->unit));
OF_getencprop(ofw_bus_get_node(dev), "reg", &sc->unit,
sizeof(sc->unit));
/* Setup interrupt */
sc->irqid = 0;

View File

@ -172,7 +172,7 @@ parse_drconf_memory(struct mem_region *ofmem, int *msz,
vm_offset_t base;
int i, idx, len, lasz, lmsz, res;
uint32_t flags, lmb_size[2];
uint64_t *dmem;
uint32_t *dmem;
lmsz = *msz;
lasz = *asz;
@ -182,7 +182,8 @@ parse_drconf_memory(struct mem_region *ofmem, int *msz,
/* No drconf node, return. */
return (0);
res = OF_getprop(phandle, "ibm,lmb-size", lmb_size, sizeof(lmb_size));
res = OF_getencprop(phandle, "ibm,lmb-size", lmb_size,
sizeof(lmb_size));
if (res == -1)
return (0);
printf("Logical Memory Block size: %d MB\n", lmb_size[1] >> 20);
@ -207,8 +208,8 @@ parse_drconf_memory(struct mem_region *ofmem, int *msz,
*/
cell_t arr[len/sizeof(cell_t)];
res = OF_getprop(phandle, "ibm,dynamic-memory", &arr,
sizeof(arr));
res = OF_getencprop(phandle, "ibm,dynamic-memory", arr,
sizeof(arr));
if (res == -1)
return (0);
@ -216,12 +217,12 @@ parse_drconf_memory(struct mem_region *ofmem, int *msz,
idx = arr[0];
/* First address, in arr[1], arr[2]*/
dmem = (uint64_t*)&arr[1];
dmem = &arr[1];
for (i = 0; i < idx; i++) {
base = *dmem;
dmem += 2;
flags = *dmem;
base = ((uint64_t)dmem[0] << 32) + dmem[1];
dmem += 4;
flags = dmem[1];
/* Use region only if available and not reserved. */
if ((flags & 0x8) && !(flags & 0x80)) {
ofmem[lmsz].mr_start = base;
@ -231,7 +232,7 @@ parse_drconf_memory(struct mem_region *ofmem, int *msz,
lmsz++;
lasz++;
}
dmem++;
dmem += 2;
}
}
@ -281,7 +282,7 @@ chrp_timebase_freq(platform_t plat, struct cpuref *cpuref)
phandle = cpuref->cr_hwref;
OF_getprop(phandle, "timebase-frequency", &ticks, sizeof(ticks));
OF_getencprop(phandle, "timebase-frequency", &ticks, sizeof(ticks));
if (ticks <= 0)
panic("Unable to determine timebase frequency!");
@ -327,10 +328,10 @@ chrp_smp_first_cpu(platform_t plat, struct cpuref *cpuref)
return (ENOENT);
cpuref->cr_hwref = cpu;
res = OF_getprop(cpu, "ibm,ppc-interrupt-server#s", &cpuid,
res = OF_getencprop(cpu, "ibm,ppc-interrupt-server#s", &cpuid,
sizeof(cpuid));
if (res <= 0)
res = OF_getprop(cpu, "reg", &cpuid, sizeof(cpuid));
res = OF_getencprop(cpu, "reg", &cpuid, sizeof(cpuid));
if (res <= 0)
cpuid = 0;
cpuref->cr_cpuid = cpuid;
@ -349,7 +350,7 @@ chrp_smp_next_cpu(platform_t plat, struct cpuref *cpuref)
res = OF_getproplen(cpuref->cr_hwref, "ibm,ppc-interrupt-server#s");
if (res > 0) {
cell_t interrupt_servers[res/sizeof(cell_t)];
OF_getprop(cpuref->cr_hwref, "ibm,ppc-interrupt-server#s",
OF_getencprop(cpuref->cr_hwref, "ibm,ppc-interrupt-server#s",
interrupt_servers, res);
for (i = 0; i < res/sizeof(cell_t) - 1; i++) {
if (interrupt_servers[i] == cpuref->cr_cpuid) {
@ -371,10 +372,10 @@ chrp_smp_next_cpu(platform_t plat, struct cpuref *cpuref)
return (ENOENT);
cpuref->cr_hwref = cpu;
res = OF_getprop(cpu, "ibm,ppc-interrupt-server#s", &cpuid,
res = OF_getencprop(cpu, "ibm,ppc-interrupt-server#s", &cpuid,
sizeof(cpuid));
if (res <= 0)
res = OF_getprop(cpu, "reg", &cpuid, sizeof(cpuid));
res = OF_getencprop(cpu, "reg", &cpuid, sizeof(cpuid));
if (res <= 0)
cpuid = 0;
cpuref->cr_cpuid = cpuid;
@ -393,7 +394,7 @@ chrp_smp_get_bsp(platform_t plat, struct cpuref *cpuref)
if (chosen == 0)
return (ENXIO);
res = OF_getprop(chosen, "cpu", &inst, sizeof(inst));
res = OF_getencprop(chosen, "cpu", &inst, sizeof(inst));
if (res < 0)
return (ENXIO);
@ -401,10 +402,10 @@ chrp_smp_get_bsp(platform_t plat, struct cpuref *cpuref)
/* Pick the primary thread. Can it be any other? */
cpuref->cr_hwref = bsp;
res = OF_getprop(bsp, "ibm,ppc-interrupt-server#s", &cpuid,
res = OF_getencprop(bsp, "ibm,ppc-interrupt-server#s", &cpuid,
sizeof(cpuid));
if (res <= 0)
res = OF_getprop(bsp, "reg", &cpuid, sizeof(cpuid));
res = OF_getencprop(bsp, "reg", &cpuid, sizeof(cpuid));
if (res <= 0)
cpuid = 0;
cpuref->cr_cpuid = cpuid;

View File

@ -88,19 +88,20 @@ phyp_iommu_set_dma_tag(device_t bus, device_t dev, bus_dma_tag_t tag)
return (ENXIO);
node = ofw_bus_get_node(p);
if (OF_getprop(node, "ibm,#dma-size-cells", &dma_scells,
if (OF_getencprop(node, "ibm,#dma-size-cells", &dma_scells,
sizeof(cell_t)) <= 0)
OF_searchprop(node, "#size-cells", &dma_scells, sizeof(cell_t));
if (OF_getprop(node, "ibm,#dma-address-cells", &dma_acells,
OF_searchencprop(node, "#size-cells", &dma_scells,
sizeof(cell_t));
if (OF_getencprop(node, "ibm,#dma-address-cells", &dma_acells,
sizeof(cell_t)) <= 0)
OF_searchprop(node, "#address-cells", &dma_acells,
OF_searchencprop(node, "#address-cells", &dma_acells,
sizeof(cell_t));
if (ofw_bus_has_prop(p, "ibm,my-dma-window"))
OF_getprop(node, "ibm,my-dma-window", dmawindow,
OF_getencprop(node, "ibm,my-dma-window", dmawindow,
sizeof(cell_t)*(dma_scells + dma_acells + 1));
else
OF_getprop(node, "ibm,dma-window", dmawindow,
OF_getencprop(node, "ibm,dma-window", dmawindow,
sizeof(cell_t)*(dma_scells + dma_acells + 1));
struct dma_window *window = malloc(sizeof(struct dma_window),

View File

@ -133,7 +133,7 @@ rtaspci_attach(device_t dev)
sc->ex_write_pci_config = rtas_token_lookup("ibm,write-pci-config");
sc->sc_extended_config = 0;
OF_getprop(ofw_bus_get_node(dev), "ibm,pci-config-space-type",
OF_getencprop(ofw_bus_get_node(dev), "ibm,pci-config-space-type",
&sc->sc_extended_config, sizeof(sc->sc_extended_config));
return (ofw_pci_attach(dev));