Use proper interface for FDT parsing and memory mapping in CESA

Improvements after r301220.
Bus space methods are not called so simple pmap_mapdev will suffice.
Use OF_getencprop to get buffer with already converted endianess.

Pointed out by: ian
Submitted by:   Michal Stanek <mst@semihalf.com>
Obtained from:  Semihalf
This commit is contained in:
zbb 2016-06-03 18:54:16 +00:00
parent 08f6ef2014
commit 67a23aa29f
2 changed files with 13 additions and 12 deletions

View File

@ -970,29 +970,30 @@ cesa_setup_sram(struct cesa_softc *sc)
pcell_t sram_handle, sram_reg[2]; pcell_t sram_handle, sram_reg[2];
int rv; int rv;
rv = OF_getprop(ofw_bus_get_node(sc->sc_dev), "sram-handle", rv = OF_getencprop(ofw_bus_get_node(sc->sc_dev), "sram-handle",
(void *)&sram_handle, sizeof(sram_handle)); (void *)&sram_handle, sizeof(sram_handle));
if (rv <= 0) if (rv <= 0)
return (rv); return (rv);
sram_ihandle = (ihandle_t)sram_handle; sram_ihandle = (ihandle_t)sram_handle;
sram_ihandle = fdt32_to_cpu(sram_ihandle);
sram_node = OF_instance_to_package(sram_ihandle); sram_node = OF_instance_to_package(sram_ihandle);
rv = OF_getprop(sram_node, "reg", (void *)sram_reg, sizeof(sram_reg)); rv = OF_getencprop(sram_node, "reg", (void *)sram_reg, sizeof(sram_reg));
if (rv <= 0) if (rv <= 0)
return (rv); return (rv);
sc->sc_sram_base_pa = fdt32_to_cpu(sram_reg[0]); sc->sc_sram_base_pa = sram_reg[0];
/* Store SRAM size to be able to unmap in detach() */ /* Store SRAM size to be able to unmap in detach() */
sc->sc_sram_size = fdt32_to_cpu(sram_reg[1]); sc->sc_sram_size = sram_reg[1];
#if defined(SOC_MV_ARMADA38X) #if defined(SOC_MV_ARMADA38X)
void *sram_va;
/* SRAM memory was not mapped in platform_sram_devmap(), map it now */ /* SRAM memory was not mapped in platform_sram_devmap(), map it now */
rv = bus_space_map(fdtbus_bs_tag, sc->sc_sram_base_pa, sc->sc_sram_size, sram_va = pmap_mapdev(sc->sc_sram_base_pa, sc->sc_sram_size);
0, &(sc->sc_sram_base_va)); if (sram_va == NULL)
if (rv != 0) return (ENOMEM);
return (rv); sc->sc_sram_base_va = (vm_offset_t)sram_va;
#endif #endif
return (0); return (0);
} }
@ -1246,7 +1247,7 @@ cesa_attach(device_t dev)
bus_teardown_intr(dev, sc->sc_res[RES_CESA_IRQ], sc->sc_icookie); bus_teardown_intr(dev, sc->sc_res[RES_CESA_IRQ], sc->sc_icookie);
err2: err2:
#if defined(SOC_MV_ARMADA38X) #if defined(SOC_MV_ARMADA38X)
bus_space_unmap(fdtbus_bs_tag, sc->sc_sram_base_va, sc->sc_sram_size); pmap_unmapdev(sc->sc_sram_base_va, sc->sc_sram_size);
#endif #endif
err1: err1:
bus_release_resources(dev, cesa_res_spec, sc->sc_res); bus_release_resources(dev, cesa_res_spec, sc->sc_res);
@ -1297,7 +1298,7 @@ cesa_detach(device_t dev)
#if defined(SOC_MV_ARMADA38X) #if defined(SOC_MV_ARMADA38X)
/* Unmap SRAM memory */ /* Unmap SRAM memory */
bus_space_unmap(fdtbus_bs_tag, sc->sc_sram_base_va, sc->sc_sram_size); pmap_unmapdev(sc->sc_sram_base_va, sc->sc_sram_size);
#endif #endif
/* Destroy mutexes */ /* Destroy mutexes */
mtx_destroy(&sc->sc_sessions_lock); mtx_destroy(&sc->sc_sessions_lock);

View File

@ -267,7 +267,7 @@ struct cesa_softc {
/* CESA SRAM Address */ /* CESA SRAM Address */
bus_addr_t sc_sram_base_pa; bus_addr_t sc_sram_base_pa;
bus_space_handle_t sc_sram_base_va; vm_offset_t sc_sram_base_va;
bus_size_t sc_sram_size; bus_size_t sc_sram_size;
}; };