Commit a3ae97f4 authored by Kevin Groeneveld's avatar Kevin Groeneveld Committed by Vinod Koul

dmaengine: imx-sdma: fix init of uart scripts

Commit b98ce2f4 ("dmaengine: imx-sdma: add uart rom script") broke
uart rx on imx5 when using sdma firmware from older Freescale 2.6.35
kernel. In this case reading addr->uartXX_2_mcu_addr was going out of
bounds of the firmware memory and corrupting the uart script addresses.

Simply adding a bounds check before accessing addr->uartXX_2_mcu_addr
does not work as the uartXX_2_mcu_addr members are now beyond the size
of the older firmware and the uart addresses would never be populated
in that case. There are other ways to fix this but overall the logic
seems clearer to me to revert the uartXX_2_mcu_ram_addr structure
entries back to uartXX_2_mcu_addr, change the newer entries to
uartXX_2_mcu_rom_addr and update the logic accordingly.

I have tested this patch on:
1. An i.MX53 system with sdma firmware from Freescale 2.6.35 kernel.
   Without this patch uart rx is broken in this scenario, with the
   patch uart rx is restored.
2. An i.MX6D system with no external sdma firmware. uart is okay with
   or without this patch.
3. An i.MX8MM system using current sdma-imx7d.bin firmware from
   linux-firmware. uart is okay with or without this patch and I
   confirmed the rom version of the uart script is being used which was
   the intention and reason for commit b98ce2f4 ("dmaengine:
   imx-sdma: add uart rom script") in the first place.

Fixes: b98ce2f4 ("dmaengine: imx-sdma: add uart rom script")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarKevin Groeneveld <kgroeneveld@lenbrook.com>
Reviewed-by: default avatarLucas Stach <l.stach@pengutronix.de>
Reviewed-by: default avatarFabio Estevam <festevam@gmail.com>
Acked-by: default avatarRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Link: https://lore.kernel.org/r/20220410223118.15086-1-kgroeneveld@lenbrook.comSigned-off-by: default avatarVinod Koul <vkoul@kernel.org>
parent 12e45e89
...@@ -198,12 +198,12 @@ struct sdma_script_start_addrs { ...@@ -198,12 +198,12 @@ struct sdma_script_start_addrs {
s32 per_2_firi_addr; s32 per_2_firi_addr;
s32 mcu_2_firi_addr; s32 mcu_2_firi_addr;
s32 uart_2_per_addr; s32 uart_2_per_addr;
s32 uart_2_mcu_ram_addr; s32 uart_2_mcu_addr;
s32 per_2_app_addr; s32 per_2_app_addr;
s32 mcu_2_app_addr; s32 mcu_2_app_addr;
s32 per_2_per_addr; s32 per_2_per_addr;
s32 uartsh_2_per_addr; s32 uartsh_2_per_addr;
s32 uartsh_2_mcu_ram_addr; s32 uartsh_2_mcu_addr;
s32 per_2_shp_addr; s32 per_2_shp_addr;
s32 mcu_2_shp_addr; s32 mcu_2_shp_addr;
s32 ata_2_mcu_addr; s32 ata_2_mcu_addr;
...@@ -232,8 +232,8 @@ struct sdma_script_start_addrs { ...@@ -232,8 +232,8 @@ struct sdma_script_start_addrs {
s32 mcu_2_ecspi_addr; s32 mcu_2_ecspi_addr;
s32 mcu_2_sai_addr; s32 mcu_2_sai_addr;
s32 sai_2_mcu_addr; s32 sai_2_mcu_addr;
s32 uart_2_mcu_addr; s32 uart_2_mcu_rom_addr;
s32 uartsh_2_mcu_addr; s32 uartsh_2_mcu_rom_addr;
/* End of v3 array */ /* End of v3 array */
s32 mcu_2_zqspi_addr; s32 mcu_2_zqspi_addr;
/* End of v4 array */ /* End of v4 array */
...@@ -1796,17 +1796,17 @@ static void sdma_add_scripts(struct sdma_engine *sdma, ...@@ -1796,17 +1796,17 @@ static void sdma_add_scripts(struct sdma_engine *sdma,
saddr_arr[i] = addr_arr[i]; saddr_arr[i] = addr_arr[i];
/* /*
* get uart_2_mcu_addr/uartsh_2_mcu_addr rom script specially because * For compatibility with NXP internal legacy kernel before 4.19 which
* they are now replaced by uart_2_mcu_ram_addr/uartsh_2_mcu_ram_addr * is based on uart ram script and mainline kernel based on uart rom
* to be compatible with legacy freescale/nxp sdma firmware, and they * script, both uart ram/rom scripts are present in newer sdma
* are located in the bottom part of sdma_script_start_addrs which are * firmware. Use the rom versions if they are present (V3 or newer).
* beyond the SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V1.
*/ */
if (addr->uart_2_mcu_addr) if (sdma->script_number >= SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V3) {
sdma->script_addrs->uart_2_mcu_addr = addr->uart_2_mcu_addr; if (addr->uart_2_mcu_rom_addr)
if (addr->uartsh_2_mcu_addr) sdma->script_addrs->uart_2_mcu_addr = addr->uart_2_mcu_rom_addr;
sdma->script_addrs->uartsh_2_mcu_addr = addr->uartsh_2_mcu_addr; if (addr->uartsh_2_mcu_rom_addr)
sdma->script_addrs->uartsh_2_mcu_addr = addr->uartsh_2_mcu_rom_addr;
}
} }
static void sdma_load_firmware(const struct firmware *fw, void *context) static void sdma_load_firmware(const struct firmware *fw, void *context)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment