SWIOTLB mechanism overview

Revision as of 16:23, 22 November 2023 by Registered User (→‎STM32 memory space)
Applicable for STM32MP25x lines

1. Purpose[edit source]

This page explains the SWIOTLB mechanism on platform which embed more than 2GB of DDR. This SWITOLB mechanism is a native Linux kernel feature which is enabled by default.

2. STM32 memory space[edit source]

To understand the need of the SWIOTLB feature, the STM32 memory space has to be inspected. Basically, it can be represented as following:

  • The first 2GB [0x0000 0000 - 0x7fff ffff] of the memory space is used for internal memory and peripherals registers.
  • The rest of the memory space is used for the DDR:
    • [0x8000 0000 - 0xffff ffff] for a 2GB DDR.
    • [0x8000 0000 - 0x17fff ffff] for a 4GB DDR.

The CPU (cortex-A35) and some peripherals are "master" on the bus and can access directly to the DDR. Those peripherals are basically ones which embed a DMA: HPDMA, ETH, SDMMC, DCMIPP, USB3, USBH, DCMIPP, LTDC, VDENC, VENC, PCIE. Except the Cortex-A35, all those peripherals are only 32 bits compatible, meaning that they can't access to an address greater than 0xffffffff. It is not a problem for a 2GB DDR (or shorter) but for DDR greater than 2GB it is. Indeed, if a buffer is allocated inside an area above the first 2GB of DDR then bus master can't access to it.

The SWIOTLB mechanism solves this issue.

Alternate text
STM32 Memory space

3. SWIOTLB feature[edit source]

SWIOTLB (S'oftware Input Output Translation Lookaside Buffer) feature avoid a DMA to access to a buffer out of his bound. As soon a dma_map_xxx API is call, swiotlb code checks the DMA capability (32bit/more) of the requester:

  • if the address of the buffer to transmit is in the range of the DMA capability, then no problem
  • if the address of the buffer to transmit is higher than the DMA capability then the SWIOTLB copies the buffer to transmit in an area (the "aperture") which is accessible by the DMA. The DMA will then copy this new allocated buffer (the "bounce buffer"). This copy is done thanks a memcpy and can impact performances.
Alternate text
STM32 Memory space

Useful information about SWIOTLB:

  • SWIOTLB reserves by default 64MB of DDR. If this value is not enough then it can be changed by changing the kernel command line.
    • swiotlb=n with n = the number of TLB slabs requested. On our STM32 platform a slab = 2MB. So if you need 128MB for the SWIOTLB area you need to set in kernel command line: swiotlb=65536.
  • SWIOTLB can't recopy a buffer greater than 256KB. If you try to recopy a buffer greater than 256KB you get the following kernel log

More details explained here [1]

4. Good practices[edit source]

5. References[edit source]

  1. [1], swiotlb tutorial