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

ARM: sa1100/assabet: move dmabounce hack to ohci driver

The sa1111 platform is one of the two remaining users of the old Arm
specific "dmabounce" code, which is an earlier implementation of the
generic swiotlb.

Linus Walleij submitted a patch that removes dmabounce support from
the ixp4xx, and I had a look at the other user, which is the sa1111
companion chip.

Looking at how dmabounce is used, I could narrow it down to one driver
one three machines:

- dmabounce is only initialized on assabet/neponset, jornada720 and
badge4, which are the platforms that have an sa1111 and support
DMA on it.

- All three of these suffer from "erratum #7" that requires only
doing DMA to half the memory sections based on one of the address
lines, in addition, the neponset also can't DMA to the RAM that
is connected to sa1111 itself.

- the pxa lubbock machine also has sa1111, but does not support DMA
on it and does not set dmabounce.

- only the OHCI and audio devices on sa1111 support DMA, but as
there is no audio driver for this hardware, only OHCI remains.

In the OHCI code, I noticed that two other platforms already have
a local bounce buffer support in the form of the "local_mem"
allocator. Specifically, TMIO and SM501 use this on a few other ARM
boards with 16KB or 128KB of local SRAM that can be accessed from the
OHCI and from the CPU.

While this is not the same problem as on sa1111, I could not find a
reason why we can't re-use the existing implementation but replace the
physical SRAM address mapping with a locally allocated DMA buffer.

There are two main downsides:

- rather than using a dynamically sized pool, this buffer needs
to be allocated at probe time using a fixed size. Without
having any idea of what it should be, I picked a size of
64KB, which is between what the other two OHCI front-ends use
in their SRAM. If anyone has a better idea what that size
is reasonable, this can be trivially changed.

- Previously, only USB transfers to unaddressable memory needed
to go through the bounce buffer, now all of them do, which may
impact runtime performance for USB endpoints that do a lot of
transfers.

On the upside, the local_mem support uses write-combining buffers,
which should be a bit faster for transfers to the device compared to
normal uncached coherent memory as used in dmabounce.

Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Laurentiu Tudor <laurentiu.tudor@nxp.com>
Cc: linux-usb@vger.kernel.org
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Christoph Hellwig <hch@lst.de>

authored by

Arnd Bergmann and committed by
Christoph Hellwig
9ba26f5c 0bf28fc4

+40 -68
+1 -1
arch/arm/common/Kconfig
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 config SA1111 3 3 bool 4 - select DMABOUNCE if !ARCH_PXA 4 + select ZONE_DMA if ARCH_SA1100 5 5 6 6 config DMABOUNCE 7 7 bool
-64
arch/arm/common/sa1111.c
··· 1389 1389 } 1390 1390 EXPORT_SYMBOL(sa1111_driver_unregister); 1391 1391 1392 - #ifdef CONFIG_DMABOUNCE 1393 - /* 1394 - * According to the "Intel StrongARM SA-1111 Microprocessor Companion 1395 - * Chip Specification Update" (June 2000), erratum #7, there is a 1396 - * significant bug in the SA1111 SDRAM shared memory controller. If 1397 - * an access to a region of memory above 1MB relative to the bank base, 1398 - * it is important that address bit 10 _NOT_ be asserted. Depending 1399 - * on the configuration of the RAM, bit 10 may correspond to one 1400 - * of several different (processor-relative) address bits. 1401 - * 1402 - * This routine only identifies whether or not a given DMA address 1403 - * is susceptible to the bug. 1404 - * 1405 - * This should only get called for sa1111_device types due to the 1406 - * way we configure our device dma_masks. 1407 - */ 1408 - static int sa1111_needs_bounce(struct device *dev, dma_addr_t addr, size_t size) 1409 - { 1410 - /* 1411 - * Section 4.6 of the "Intel StrongARM SA-1111 Development Module 1412 - * User's Guide" mentions that jumpers R51 and R52 control the 1413 - * target of SA-1111 DMA (either SDRAM bank 0 on Assabet, or 1414 - * SDRAM bank 1 on Neponset). The default configuration selects 1415 - * Assabet, so any address in bank 1 is necessarily invalid. 1416 - */ 1417 - return (machine_is_assabet() || machine_is_pfs168()) && 1418 - (addr >= 0xc8000000 || (addr + size) >= 0xc8000000); 1419 - } 1420 - 1421 - static int sa1111_notifier_call(struct notifier_block *n, unsigned long action, 1422 - void *data) 1423 - { 1424 - struct sa1111_dev *dev = to_sa1111_device(data); 1425 - 1426 - switch (action) { 1427 - case BUS_NOTIFY_ADD_DEVICE: 1428 - if (dev->dev.dma_mask && dev->dma_mask < 0xffffffffUL) { 1429 - int ret = dmabounce_register_dev(&dev->dev, 1024, 4096, 1430 - sa1111_needs_bounce); 1431 - if (ret) 1432 - dev_err(&dev->dev, "failed to register with dmabounce: %d\n", ret); 1433 - } 1434 - break; 1435 - 1436 - case BUS_NOTIFY_DEL_DEVICE: 1437 - if (dev->dev.dma_mask && dev->dma_mask < 0xffffffffUL) 1438 - dmabounce_unregister_dev(&dev->dev); 1439 - break; 1440 - } 1441 - return NOTIFY_OK; 1442 - } 1443 - 1444 - static struct notifier_block sa1111_bus_notifier = { 1445 - .notifier_call = sa1111_notifier_call, 1446 - }; 1447 - #endif 1448 - 1449 1392 static int __init sa1111_init(void) 1450 1393 { 1451 1394 int ret = bus_register(&sa1111_bus_type); 1452 - #ifdef CONFIG_DMABOUNCE 1453 - if (ret == 0) 1454 - bus_register_notifier(&sa1111_bus_type, &sa1111_bus_notifier); 1455 - #endif 1456 1395 if (ret == 0) 1457 1396 platform_driver_register(&sa1111_device_driver); 1458 1397 return ret; ··· 1400 1461 static void __exit sa1111_exit(void) 1401 1462 { 1402 1463 platform_driver_unregister(&sa1111_device_driver); 1403 - #ifdef CONFIG_DMABOUNCE 1404 - bus_unregister_notifier(&sa1111_bus_type, &sa1111_bus_notifier); 1405 - #endif 1406 1464 bus_unregister(&sa1111_bus_type); 1407 1465 } 1408 1466
+14 -3
drivers/usb/core/hcd.c
··· 1251 1251 EXPORT_SYMBOL_GPL(usb_hcd_unlink_urb_from_ep); 1252 1252 1253 1253 /* 1254 - * Some usb host controllers can only perform dma using a small SRAM area. 1254 + * Some usb host controllers can only perform dma using a small SRAM area, 1255 + * or have restrictions on addressable DRAM. 1255 1256 * The usb core itself is however optimized for host controllers that can dma 1256 1257 * using regular system memory - like pci devices doing bus mastering. 1257 1258 * ··· 3118 3117 if (IS_ERR(hcd->localmem_pool)) 3119 3118 return PTR_ERR(hcd->localmem_pool); 3120 3119 3121 - local_mem = devm_memremap(hcd->self.sysdev, phys_addr, 3122 - size, MEMREMAP_WC); 3120 + /* 3121 + * if a physical SRAM address was passed, map it, otherwise 3122 + * allocate system memory as a buffer. 3123 + */ 3124 + if (phys_addr) 3125 + local_mem = devm_memremap(hcd->self.sysdev, phys_addr, 3126 + size, MEMREMAP_WC); 3127 + else 3128 + local_mem = dmam_alloc_attrs(hcd->self.sysdev, size, &dma, 3129 + GFP_KERNEL, 3130 + DMA_ATTR_WRITE_COMBINE); 3131 + 3123 3132 if (IS_ERR(local_mem)) 3124 3133 return PTR_ERR(local_mem); 3125 3134
+25
drivers/usb/host/ohci-sa1111.c
··· 203 203 goto err1; 204 204 } 205 205 206 + /* 207 + * According to the "Intel StrongARM SA-1111 Microprocessor Companion 208 + * Chip Specification Update" (June 2000), erratum #7, there is a 209 + * significant bug in the SA1111 SDRAM shared memory controller. If 210 + * an access to a region of memory above 1MB relative to the bank base, 211 + * it is important that address bit 10 _NOT_ be asserted. Depending 212 + * on the configuration of the RAM, bit 10 may correspond to one 213 + * of several different (processor-relative) address bits. 214 + * 215 + * Section 4.6 of the "Intel StrongARM SA-1111 Development Module 216 + * User's Guide" mentions that jumpers R51 and R52 control the 217 + * target of SA-1111 DMA (either SDRAM bank 0 on Assabet, or 218 + * SDRAM bank 1 on Neponset). The default configuration selects 219 + * Assabet, so any address in bank 1 is necessarily invalid. 220 + * 221 + * As a workaround, use a bounce buffer in addressable memory 222 + * as local_mem, relying on ZONE_DMA to provide an area that 223 + * fits within the above constraints. 224 + * 225 + * SZ_64K is an estimate for what size this might need. 226 + */ 227 + ret = usb_hcd_setup_local_mem(hcd, 0, 0, SZ_64K); 228 + if (ret) 229 + goto err1; 230 + 206 231 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { 207 232 dev_dbg(&dev->dev, "request_mem_region failed\n"); 208 233 ret = -EBUSY;