2
votes

I was reading section 'Part Id' of the following document I'm not sure how relevant this document to kernel 2.6.35 for instance; specifically it says:

..the DMA address of the memory must be within the dma_mask of the device..

and they recommend to pass certain flags, such as GFP_DMA, to kmalloc, so that it ensures the memory will fall within DMA mask provided.

However if the memory is allocated from cache pool created by kmem_cache_create, and with kmem_cache_alloc(.. GFP_ATOMIC), this doesn't meet requirements outlined in DMA-API.txt ?

On the other hand, LDD talks about __GFP_DMA flag with regard to legacy ISA devices, therefore I'm not sure this is applicable to PCI/PCIe devices.

This is x86 64-bit platform if it matters:

pci_set_dma_mask(dev, 0xffffffffffffffffULL);
pci_set_consistent_dma_mask(dev, 0xffffffffffffffffULL);

I would appreciate to hear some explanations on it.

1

1 Answers

2
votes
  1. For GFP_* for DMA

    On x86:

    • ISA - when using kmalloc() need to bitwise-or GFP_DMA with GFP_KERNEL (or _ATOMIC) because of the following:

      GFP_DMA guarantees:

      (1) physical addresses are consecutive when get_free_page returns more than one page and

      (2) only addresses lower than MAX_DMA_ADDRESS are returned. MAX_DMA_ADDRESS is 16MB on the PC because of ISA constraings

    • PCI - don't need to use GFP_DMA because there is no MAX_DMA_ADDRESS limit

  2. The dma_mask is checked by the device when calling dma_map_* or dma_alloc_coherent.

    dma_alloc_coherent ensures the memory allocated is able to be used by dma_map_* which gives other benifits too. (the implementation may choose to ignore flags that affect the location of the returned memory, like GFP_DMA)

You can refer to http://coweb.cc.gatech.edu/sysHackfest/uploads/58/DMA_howto.1.txt