mapping.c (3f61fd41f38328f0a585eaba2d72d339fe9aecda) mapping.c (33dcb37cef741294b481f4d889a465b8091f11bf)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * arch-independent dma-mapping routines
4 *
5 * Copyright (c) 2006 SUSE Linux Products GmbH
6 * Copyright (c) 2006 Tejun Heo <teheo@suse.de>
7 */
8#include <linux/memblock.h> /* for max_pfn */

--- 136 unchanged lines hidden (view full) ---

145 if (!dma_is_direct(ops) && ops->get_sgtable)
146 return ops->get_sgtable(dev, sgt, cpu_addr, dma_addr, size,
147 attrs);
148 return dma_common_get_sgtable(dev, sgt, cpu_addr, dma_addr, size,
149 attrs);
150}
151EXPORT_SYMBOL(dma_get_sgtable_attrs);
152
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * arch-independent dma-mapping routines
4 *
5 * Copyright (c) 2006 SUSE Linux Products GmbH
6 * Copyright (c) 2006 Tejun Heo <teheo@suse.de>
7 */
8#include <linux/memblock.h> /* for max_pfn */

--- 136 unchanged lines hidden (view full) ---

145 if (!dma_is_direct(ops) && ops->get_sgtable)
146 return ops->get_sgtable(dev, sgt, cpu_addr, dma_addr, size,
147 attrs);
148 return dma_common_get_sgtable(dev, sgt, cpu_addr, dma_addr, size,
149 attrs);
150}
151EXPORT_SYMBOL(dma_get_sgtable_attrs);
152
153#ifdef CONFIG_MMU
153/*
154/*
155 * Return the page attributes used for mapping dma_alloc_* memory, either in
156 * kernel space if remapping is needed, or to userspace through dma_mmap_*.
157 */
158pgprot_t dma_pgprot(struct device *dev, pgprot_t prot, unsigned long attrs)
159{
160 if (dev_is_dma_coherent(dev) ||
161 (IS_ENABLED(CONFIG_DMA_NONCOHERENT_CACHE_SYNC) &&
162 (attrs & DMA_ATTR_NON_CONSISTENT)))
163 return prot;
164 if (IS_ENABLED(CONFIG_ARCH_HAS_DMA_MMAP_PGPROT))
165 return arch_dma_mmap_pgprot(dev, prot, attrs);
166 return pgprot_noncached(prot);
167}
168#endif /* CONFIG_MMU */
169
170/*
154 * Create userspace mapping for the DMA-coherent memory.
155 */
156int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,
157 void *cpu_addr, dma_addr_t dma_addr, size_t size,
158 unsigned long attrs)
159{
160#ifndef CONFIG_ARCH_NO_COHERENT_DMA_MMAP
161 unsigned long user_count = vma_pages(vma);
162 unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
163 unsigned long off = vma->vm_pgoff;
164 unsigned long pfn;
165 int ret = -ENXIO;
166
171 * Create userspace mapping for the DMA-coherent memory.
172 */
173int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,
174 void *cpu_addr, dma_addr_t dma_addr, size_t size,
175 unsigned long attrs)
176{
177#ifndef CONFIG_ARCH_NO_COHERENT_DMA_MMAP
178 unsigned long user_count = vma_pages(vma);
179 unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
180 unsigned long off = vma->vm_pgoff;
181 unsigned long pfn;
182 int ret = -ENXIO;
183
167 vma->vm_page_prot = arch_dma_mmap_pgprot(dev, vma->vm_page_prot, attrs);
184 vma->vm_page_prot = dma_pgprot(dev, vma->vm_page_prot, attrs);
168
169 if (dma_mmap_from_dev_coherent(dev, vma, cpu_addr, size, &ret))
170 return ret;
171
172 if (off >= count || user_count > count - off)
173 return -ENXIO;
174
175 if (!dev_is_dma_coherent(dev)) {

--- 215 unchanged lines hidden ---
185
186 if (dma_mmap_from_dev_coherent(dev, vma, cpu_addr, size, &ret))
187 return ret;
188
189 if (off >= count || user_count > count - off)
190 return -ENXIO;
191
192 if (!dev_is_dma_coherent(dev)) {

--- 215 unchanged lines hidden ---