Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mtd: sh_flctl: pass FIFO as physical address

By convention, the FIFO address we pass using dmaengine_slave_config
is a physical address in the form that is understood by the DMA
engine, as a dma_addr_t, phys_addr_t or resource_size_t.

The sh_flctl driver however passes a virtual __iomem address that
gets cast to dma_addr_t in the slave driver. This happens to work
on shmobile because that platform sets up an identity mapping for
its MMIO regions, but such code is not portable to other platforms,
and prevents us from ever changing the platform mapping or reusing
the driver on other architectures like ARM64 that might not have the
mapping.

We also get a warning about a type mismatch for the case that
dma_addr_t is wider than a pointer, i.e. when CONFIG_LPAE is set:

drivers/mtd/nand/sh_flctl.c: In function 'flctl_setup_dma':
drivers/mtd/nand/sh_flctl.c:163:17: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
cfg.dst_addr = (dma_addr_t)FLDTFIFO(flctl);

This changes the driver to instead pass the physical address of
the FIFO that is extracted from the MMIO resource, making the
code more portable and avoiding the warning.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>

authored by

Arnd Bergmann and committed by
Brian Norris
1873315f 0ed6ca3a

+4 -2
+3 -2
drivers/mtd/nand/sh_flctl.c
··· 160 160 161 161 memset(&cfg, 0, sizeof(cfg)); 162 162 cfg.direction = DMA_MEM_TO_DEV; 163 - cfg.dst_addr = (dma_addr_t)FLDTFIFO(flctl); 163 + cfg.dst_addr = flctl->fifo; 164 164 cfg.src_addr = 0; 165 165 ret = dmaengine_slave_config(flctl->chan_fifo0_tx, &cfg); 166 166 if (ret < 0) ··· 176 176 177 177 cfg.direction = DMA_DEV_TO_MEM; 178 178 cfg.dst_addr = 0; 179 - cfg.src_addr = (dma_addr_t)FLDTFIFO(flctl); 179 + cfg.src_addr = flctl->fifo; 180 180 ret = dmaengine_slave_config(flctl->chan_fifo0_rx, &cfg); 181 181 if (ret < 0) 182 182 goto err; ··· 1095 1095 flctl->reg = devm_ioremap_resource(&pdev->dev, res); 1096 1096 if (IS_ERR(flctl->reg)) 1097 1097 return PTR_ERR(flctl->reg); 1098 + flctl->fifo = res->start + 0x24; /* FLDTFIFO */ 1098 1099 1099 1100 irq = platform_get_irq(pdev, 0); 1100 1101 if (irq < 0) {
+1
include/linux/mtd/sh_flctl.h
··· 147 147 struct platform_device *pdev; 148 148 struct dev_pm_qos_request pm_qos; 149 149 void __iomem *reg; 150 + resource_size_t fifo; 150 151 151 152 uint8_t done_buff[2048 + 64]; /* max size 2048 + 64 */ 152 153 int read_bytes;