What's the difference between streaming mappings and coherent mapping in DMA

843 Views Asked by At

According to Linux Device Drivers book author says something like: one have to make sure that DMA address mapping range between Operating system and The hardware should be equal

The first question that must be answered before attempting DMA is where the given device is capable of such an operation on the current host

From Kernel.org it says first step for The setup for streaming mappings is performed via a call to

        int dma_set_mask(struct device *dev, u64 mask);
    

And first step for DMA coherent mapping/consistent allocations is performed via a call

       to dma_set_coherent_mask()   

In E1000E driver and also in RealTek drivers do both because they use this function call in probe function of pci driver

       dma_set_mask_and_coherent    

Which is for both streaming and coherent mapping informing kernel the bit mask supported by hardware 64

This is how RealTek Device driver enables both DMA mappings

      dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES,
                     &tp->RxPhyAddr, GFP_KERNEL);

inside open function of net_device

And for streaming DMA mapping this used

     alloc_pages_node  // allocating Kernel page for DMA
     dma_map_page(d, data, 0, R8169_RX_BUF_SIZE, DMA_FROM_DEVICE); //Enabling Streaming mappingg?

also in open function

My question is why two mappings for DMA, why real drivers use both Streaming and Coherent mappings?

Like in RealTek device it just use single page streaming mappings plus coherent mapping so basically its connecting Rx Descriptor Array represented by pointer with Coherent mapping and Page streaming mapping connected to an array which it calls Rx_databuff[256U] of type page *

0

There are 0 best solutions below