linux-stable/drivers/memory
Andrew Gabbasov 16b7cb2803 memory: renesas-rpc-if: Avoid unaligned bus access for HyperFlash
[ Upstream commit 1869023e24 ]

HyperFlash devices in Renesas SoCs use 2-bytes addressing, according
to HW manual paragraph 62.3.3 (which officially describes Serial Flash
access, but seems to be applicable to HyperFlash too). And 1-byte bus
read operations to 2-bytes unaligned addresses in external address space
read mode work incorrectly (returns the other byte from the same word).

Function memcpy_fromio(), used by the driver to read data from the bus,
in ARM64 architecture (to which Renesas cores belong) uses 8-bytes
bus accesses for appropriate aligned addresses, and 1-bytes accesses
for other addresses. This results in incorrect data read from HyperFlash
in unaligned cases.

This issue can be reproduced using something like the following commands
(where mtd1 is a parition on Hyperflash storage, defined properly
in a device tree):

[Correct fragment, read from Hyperflash]

    root@rcar-gen3:~# dd if=/dev/mtd1 of=/tmp/zz bs=32 count=1
    root@rcar-gen3:~# hexdump -C /tmp/zz
    00000000  f4 03 00 aa f5 03 01 aa  f6 03 02 aa f7 03 03 aa  |................|
    00000010  00 00 80 d2 40 20 18 d5  00 06 81 d2 a0 18 a6 f2  |....@ ..........|
    00000020

[Incorrect read of the same fragment: see the difference at offsets 8-11]

    root@rcar-gen3:~# dd if=/dev/mtd1 of=/tmp/zz bs=12 count=1
    root@rcar-gen3:~# hexdump -C /tmp/zz
    00000000  f4 03 00 aa f5 03 01 aa  03 03 aa aa              |............|
    0000000c

Fix this issue by creating a local replacement of the copying function,
that performs only properly aligned bus accesses, and is used for reading
from HyperFlash.

Fixes: ca7d8b980b ("memory: add Renesas RPC-IF driver")
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>
Link: https://lore.kernel.org/r/20210922184830.29147-1-andrew_gabbasov@mentor.com
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-07-12 16:34:52 +02:00
..
samsung memory: samsung: exynos5422-dmc: Fix refcount leak in of_get_dram_timings 2022-06-29 09:03:31 +02:00
tegra memory: tegra20-emc: Add runtime dependency on devfreq governor module 2021-11-25 09:48:30 +01:00
.gitignore .gitignore: prefix local generated files with a slash 2021-05-02 00:43:35 +09:00
atmel-ebi.c memory: atmel-ebi: Fix missing of_node_put in atmel_ebi_probe 2022-04-20 09:34:09 +02:00
atmel-sdramc.c
brcmstb_dpfe.c
bt1-l2-ctl.c
da8xx-ddrctl.c
dfl-emif.c
emif-asm-offsets.c
emif.c memory: emif: check the pointer temp in get_device_details() 2022-04-08 14:23:20 +02:00
emif.h
fsl-corenet-cf.c memory: fsl-corenet-cf: Remove redundant dev_err call in ccf_probe() 2021-04-01 19:56:52 +02:00
fsl_ifc.c memory: fsl_ifc: fix leak of irq and nand_irq in fsl_ifc_ctrl_probe 2021-11-18 19:16:51 +01:00
jedec_ddr.h
jedec_ddr_data.c
jz4780-nemc.c
Kconfig Char/Misc driver patches for 5.12-rc1 2021-02-24 10:25:37 -08:00
Makefile
mtk-smi.c memory: mtk-smi: Add device-link between smi-larb and smi-common 2021-04-13 16:56:31 +02:00
mvebu-devbus.c
of_memory.c
of_memory.h
omap-gpmc.c memory: omap-gpmc: Drop custom PM calls with cpu_pm notifier 2021-07-29 09:02:27 +02:00
pl172.c amba: Make the remove callback return void 2021-02-02 14:25:50 +01:00
pl353-smc.c Memory controller drivers for v5.14 - PL353 2021-06-12 08:53:06 -07:00
renesas-rpc-if.c memory: renesas-rpc-if: Avoid unaligned bus access for HyperFlash 2022-07-12 16:34:52 +02:00
stm32-fmc2-ebi.c memory: stm32-fmc2-ebi: add missing of_node_put for loop iteration 2021-05-11 08:49:18 -04:00
ti-aemif.c
ti-emif-pm.c memory: ti-emif-pm: Drop of_match_ptr from of_device_id table 2021-02-08 18:13:24 +01:00
ti-emif-sram-pm.S