The first possibility that comes to mind is that the user input buffer does not start at the page border. If your starting address is 0x800 bytes across the page, then the offset on the first call to sg_set_page
will be 0x800. This will create a DMA address ending in 0x800. This is a common thing, and it is not a mistake.
Since pci_map_sg
combines pages, this first segment can be more than one page. Importantly, pci_map_sg
creates contiguous blocks of DMA address memory, but it does not create a list of low-level PCIe transactions. On x64, you are likely to get a large area because most x64 platforms have IOMMUs.
Many of the devices I'm dealing with have DMA mechanisms that allow me to specify a logical transmission length of several megabytes. Typically, a DMA implementation at a PCIe endpoint is responsible for starting a new PCIe transaction at each 4 KB boundary, and the programmer can ignore this limitation. If the resources in the FPGA are too limited to handle this, you might consider writing driver code to convert a list of Linux memory blocks into a (much longer) PCIe transaction list.
source share