bcm2835_spi...fer_prologue(9)
π NAME π
okay bestie, welcome to bcm2835_spi_transfer_prologue(9) in the Kernel API Manual β this page is literally about how to transfer first few bytes without DMA. tiny prologue, big main-character energy β¨
β¨ SYNOPSIS β¨
void bcm2835_spi_transfer_prologue (struct spi_controller *ctlr , struct
spi_transfer *tfr , struct bcm2835_spi *bs , u32 cs );
π ARGUMENTS π
ctlrβ SPI host controller. the host with the most, basically.tfrβ SPI transfer. the actual transfer being served.bsβ BCM2835 SPI controller. our specific controller bestie.csβ CS register. yes, the register. iconic.
π DESCRIPTION π
so hereβs the DMA-mode limitation, and itβs giving strict 4 byte chunk energy: the FIFO must be accessed in 4 byte chunks. Only the final write access is permitted to transmit less than 4 bytes, and the SPI controller deduces its intended size from the DLEN register. slay, but also constraint.
okay so picture a TX or RX sglist with multiple entries, one per page, and the first entry starts in the middle of a page. that first entryβs length may not be a multiple of 4. subsequent entries are fine because they span an entire page, hence they do have a length thatβs a multiple of 4. periodt.
this cannot happen with kmalloc'ed buffers (which is what most clients use) because they are contiguous in physical memory and therefore not split on page boundaries by spi_map_buf. but it can happen with vmalloc'ed buffers. not the vmalloc plot twist π
the DMA engine is incapable of combining sglist entries into a continuous stream of 4 byte chunks β it treats every entry separately: a TX entry is rounded up to a multiple of 4 bytes by transmitting surplus bytes, and an RX entry is rounded up by throwing away received bytes. the audacity, honestly.
overcome this limitation by transferring the first few bytes without DMA: E.g. if the first TX sglist entryβs length is 23 and the first RXβs is 42, write 3 bytes to the TX FIFO but read only 2 bytes from the RX FIFO. the residue of 1 byte in the RX FIFO is picked up by DMA. together with the rest of the first RX sglist entry it makes up a multiple of 4 bytes. math ate, truly.
should the RX prologue be larger β say, 3 vis-Γ -vis a TX prologue of 1 β write 1 + 4 = 5 bytes to the TX FIFO and read 3 bytes from the RX FIFO.
Caution bestie: the additional4bytes spill over to the second TXsglistentry if the length of the first is exactly1. π
at most 6 bytes are written and at most 3 bytes read. do we know the transfer has this many bytes? yes β see BCM2835_SPI_DMA_MIN_LENGTH. slay, itβs documented.
the FIFO is normally accessed with 8-bit width by the CPU and 32-bit width by the DMA engine. toggling the DMA Enable flag in the CS register switches the width but also garbles the FIFOβs contents. the prologue must therefore be transmitted in 32-bit width to ensure that the following DMA transfer can pick up the residue in the RX FIFO in ungarbled form. no cap, width matters.
π¦ SEE ALSO π¦
Kernel file ./drivers/spi/spi-bcm2835.c β and the whole friend group is:
struct bcm2835_spi(9)struct bcm2835_spidev(9)bcm2835_rd_fifo_count(9)bcm2835_wr_fifo_count(9)bcm2835_wait_tx_fifo_empty(9)bcm2835_rd_fifo_blind(9)bcm2835_wr_fifo_blind(9)bcm2835_spi_undo_prologue(9)bcm2835_spi_dma_rx_done(9)bcm2835_spi_dma_tx_done(9)bcm2835_spi_prepare_sg(9)bcm2835_spi_transfer_one_dma(9)
mwah π this page comes from ./drivers/spi, dated October 2026 β go forth and prologue responsibly, bestie π«Άβ¨
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms