Skip to content

Commit 6b70039

Browse files
committed
ARC: dma: non-coherent pages need V-P mapping if in HIGHMEM
Previously a non-coherent page (hardware IOC or simply driver needs) could be handled by cpu with paddr alone (kvaddr used to be needed for coherent mappings to enforce uncached semantics via a MMU mapping). Now however such a page might still require a V-P mapping if it was in physical address space > 32bits due to PAE40, which the CPU can't access directly with a paddr So decouple decision of kvaddr allocation from type of alloc request (coh/non-coh) Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
1 parent d98a15a commit 6b70039

1 file changed

Lines changed: 32 additions & 15 deletions

File tree

‎arch/arc/mm/dma.c‎

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,50 @@ static void *arc_dma_alloc(struct device *dev, size_t size,
2828
struct page *page;
2929
phys_addr_t paddr;
3030
void *kvaddr;
31+
int need_coh = 1, need_kvaddr = 0;
3132

3233
page = alloc_pages(gfp, order);
3334
if (!page)
3435
return NULL;
3536

36-
/* This is linear addr (0x8000_0000 based) */
37-
paddr = page_to_phys(page);
38-
39-
/* For now bus address is exactly same as paddr */
40-
*dma_handle = paddr;
41-
4237
/*
4338
* IOC relies on all data (even coherent DMA data) being in cache
4439
* Thus allocate normal cached memory
4540
*
4641
* The gains with IOC are two pronged:
47-
* -For streaming data, elides needs for cache maintenance, saving
42+
* -For streaming data, elides need for cache maintenance, saving
4843
* cycles in flush code, and bus bandwidth as all the lines of a
4944
* buffer need to be flushed out to memory
5045
* -For coherent data, Read/Write to buffers terminate early in cache
5146
* (vs. always going to memory - thus are faster)
5247
*/
5348
if ((is_isa_arcv2() && ioc_exists) ||
5449
dma_get_attr(DMA_ATTR_NON_CONSISTENT, attrs))
55-
return paddr;
50+
need_coh = 0;
51+
52+
/*
53+
* - A coherent buffer needs MMU mapping to enforce non-cachability
54+
* - A highmem page needs a virtual handle (hence MMU mapping)
55+
* independent of cachability
56+
*/
57+
if (PageHighMem(page) || need_coh)
58+
need_kvaddr = 1;
59+
60+
/* This is linear addr (0x8000_0000 based) */
61+
paddr = page_to_phys(page);
62+
63+
/* For now bus address is exactly same as paddr */
64+
*dma_handle = paddr;
5665

5766
/* This is kernel Virtual address (0x7000_0000 based) */
58-
kvaddr = ioremap_nocache((unsigned long)paddr, size);
59-
if (kvaddr == NULL) {
60-
__free_pages(page, order);
61-
return NULL;
67+
if (need_kvaddr) {
68+
kvaddr = ioremap_nocache((unsigned long)paddr, size);
69+
if (kvaddr == NULL) {
70+
__free_pages(page, order);
71+
return NULL;
72+
}
73+
} else {
74+
kvaddr = (void *)paddr;
6275
}
6376

6477
/*
@@ -71,7 +84,8 @@ static void *arc_dma_alloc(struct device *dev, size_t size,
7184
* Currently flush_cache_vmap nukes the L1 cache completely which
7285
* will be optimized as a separate commit
7386
*/
74-
dma_cache_wback_inv((unsigned long)paddr, size);
87+
if (need_coh)
88+
dma_cache_wback_inv((unsigned long)paddr, size);
7589

7690
return kvaddr;
7791
}
@@ -80,9 +94,12 @@ static void arc_dma_free(struct device *dev, size_t size, void *vaddr,
8094
dma_addr_t dma_handle, struct dma_attrs *attrs)
8195
{
8296
struct page *page = virt_to_page(dma_handle);
97+
int is_non_coh = 1;
98+
99+
is_non_coh = dma_get_attr(DMA_ATTR_NON_CONSISTENT, attrs) ||
100+
(is_isa_arcv2() && ioc_exists);
83101

84-
if (!dma_get_attr(DMA_ATTR_NON_CONSISTENT, attrs) &&
85-
!(is_isa_arcv2() && ioc_exists))
102+
if (PageHighMem(page) || !is_non_coh)
86103
iounmap((void __force __iomem *)vaddr);
87104

88105
__free_pages(page, get_order(size));

0 commit comments

Comments
 (0)