Skip to content

Commit

Permalink
of: Calculate device DMA masks based on DT dma-range size
Browse files Browse the repository at this point in the history
Calculate the dma_mask and coherent_dma_mask based on the dma-range values
set in DT for the device.

Limit the mask to lower of the default mask and mask calculated.

Signed-off-by: Murali Karicheri <[email protected]>
Signed-off-by: Bjorn Helgaas <[email protected]>
Reviewed-by: Catalin Marinas <[email protected]>
CC: Joerg Roedel <[email protected]>
CC: Grant Likely <[email protected]>
CC: Rob Herring <[email protected]>
CC: Will Deacon <[email protected]>
CC: Russell King <[email protected]>
CC: Arnd Bergmann <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
  • Loading branch information
Murali Karicheri authored and bjorn-helgaas committed Mar 12, 2015
1 parent 22b3c18 commit 9a6d729
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions drivers/of/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ void of_dma_configure(struct device *dev, struct device_node *np)
struct iommu_ops *iommu;

/*
* Set default dma-mask to 32 bit. Drivers are expected to setup
* the correct supported dma_mask.
* Set default coherent_dma_mask to 32 bit. Drivers are expected to
* setup the correct supported mask.
*/
dev->coherent_dma_mask = DMA_BIT_MASK(32);
if (!dev->coherent_dma_mask)
dev->coherent_dma_mask = DMA_BIT_MASK(32);

/*
* Set it to coherent_dma_mask by default if the architecture
Expand Down Expand Up @@ -128,6 +129,15 @@ void of_dma_configure(struct device *dev, struct device_node *np)

dev->dma_pfn_offset = offset;

/*
* Limit coherent and dma mask based on size and default mask
* set by the driver.
*/
dev->coherent_dma_mask = min(dev->coherent_dma_mask,
DMA_BIT_MASK(ilog2(dma_addr + size)));
*dev->dma_mask = min((*dev->dma_mask),
DMA_BIT_MASK(ilog2(dma_addr + size)));

coherent = of_dma_is_coherent(np);
dev_dbg(dev, "device is%sdma coherent\n",
coherent ? " " : " not ");
Expand Down

0 comments on commit 9a6d729

Please sign in to comment.