--- zzzz-none-000/linux-3.10.107/arch/x86/kernel/pci-dma.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/arch/x86/kernel/pci-dma.c 2021-02-04 17:41:59.000000000 +0000 @@ -58,17 +58,6 @@ /* Number of entries preallocated for DMA-API debugging */ #define PREALLOC_DMA_DEBUG_ENTRIES 65536 -int dma_set_mask(struct device *dev, u64 mask) -{ - if (!dev->dma_mask || !dma_supported(dev, mask)) - return -EIO; - - *dev->dma_mask = mask; - - return 0; -} -EXPORT_SYMBOL(dma_set_mask); - void __init pci_iommu_alloc(void) { struct iommu_table_entry *p; @@ -97,12 +86,17 @@ dma_mask = dma_alloc_coherent_mask(dev, flag); - flag |= __GFP_ZERO; + flag &= ~__GFP_ZERO; again: page = NULL; /* CMA can be used only in the context which permits sleeping */ - if (flag & __GFP_WAIT) + if (gfpflags_allow_blocking(flag)) { page = dma_alloc_from_contiguous(dev, count, get_order(size)); + if (page && page_to_phys(page) + size > dma_mask) { + dma_release_from_contiguous(dev, page, count); + page = NULL; + } + } /* fallback */ if (!page) page = alloc_pages_node(dev_to_node(dev), flag, get_order(size)); @@ -120,7 +114,7 @@ return NULL; } - + memset(page_address(page), 0, size); *dma_addr = addr; return page_address(page); } @@ -135,6 +129,21 @@ free_pages((unsigned long)vaddr, get_order(size)); } +bool arch_dma_alloc_attrs(struct device **dev, gfp_t *gfp) +{ + if (!*dev) + *dev = &x86_dma_fallback_dev; + + *gfp &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32); + *gfp = dma_alloc_coherent_gfp_flags(*dev, *gfp); + + if (!is_device_dma_capable(*dev)) + return false; + return true; + +} +EXPORT_SYMBOL(arch_dma_alloc_attrs); + /* * See for the iommu kernel * parameter documentation.