0

[EDITED]

I have a board on arm64 with fpga (SoC).

The task is simple:

  • make possible to transfer data from/to "User Space" area (app) to/from "Kernel Space" phys mem (device mem = fpga regs), with and without dma support usage (streaming type). That dma is in the board (ZynqMP / GDMA).

I will have several devices - on fpga and outside, which should use this communication, but now I'm working only with fpga-ddr4 mem area.

Now I see the next logic flow:

  • some initialization (dma parameters and so on);
  • ioremap() a fpga device area;
  • make a buffer (by kzalloc() or another) - this buffer I should give to the US by mmap fops;
  • make a scatterlist from the buffer (pseudo-code below);
  • use the scatterlist with dmaengine to transfer data;
// scatterlist init pseudo-code

struct scatterlist sgl[2];
struct scatterlist *sge;
int i, buf_n, err_code;
__u8 *buffer; // allocated earlier

sg_init_table(sgl, ARRAY_SIZE(sgl));

for_each_sg(sgl, sge, ARRAY_SIZE(sgl), i) {
  struct page *pg = virt_to_page(buffer + i * PAGE_SIZE);
  dma_addr_t dma_handle = dma_map_page(&pdev->dev, pg, 0, PAGE_SIZE, direction /* DMA_TO_DEVICE */);
  if ((err_code = dma_mapping_error(&pdev->dev, dma_handle))) {
    dev_err(&pdev->dev, "dma page mapping failed! (code: %i)\n", err_code);
    break;
  }
  sg_set_page(sge, pg, PAGE_SIZE, 0);
}

dma_map_sg(&pdev->dev, sgl, ARRAY_SIZE(sgl), direction) // with appropriate check

Now I misunderstanding next - how or where the destination controled? I mean, I had allocated the buffer in RAM, make scatterlist from it and give this list by argument of dmaengine funtions for transferring. But I dont set/use ioremapped device mem area to save this buffer data! Is this dma works only with appropriate RAM memory area and I should copy buffer to the device area? Or, should I use the ioremapped area as my buffer? Is it right flow? Explain me my mistakes pleaes?

0 Answers0