Skip to content

Commit

Permalink
Hexagon: use correct translations for DMA mappings
Browse files Browse the repository at this point in the history
With physical offsets, pa<->va translations aren't just based
on PAGE_OFFSET anymore.

Signed-off-by: Richard Kuo <[email protected]>
  • Loading branch information
Richard Kuo committed May 1, 2013
1 parent c710f59 commit 5e11505
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
5 changes: 5 additions & 0 deletions arch/hexagon/include/asm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ static inline void clear_page(void *page)
*/
#define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)

#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT)
#define pfn_to_virt(pfn) __va((pfn) << PAGE_SHIFT)

#define page_to_virt(page) __va(page_to_phys(page))

/*
* For port to Hexagon Virtual Machine, MAYBE we check for attempts
* to reference reserved HVM space, but in any case, the VM will be
Expand Down
27 changes: 17 additions & 10 deletions arch/hexagon/kernel/dma.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DMA implementation for Hexagon
*
* Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
* Copyright (c) 2010-2012, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
Expand All @@ -23,12 +23,18 @@
#include <linux/genalloc.h>
#include <asm/dma-mapping.h>
#include <linux/module.h>
#include <asm/page.h>

struct dma_map_ops *dma_ops;
EXPORT_SYMBOL(dma_ops);

int bad_dma_address; /* globals are automatically initialized to zero */

static inline void *dma_addr_to_virt(dma_addr_t dma_addr)
{
return phys_to_virt((unsigned long) dma_addr);
}

int dma_supported(struct device *dev, u64 mask)
{
if (mask == DMA_BIT_MASK(32))
Expand Down Expand Up @@ -60,22 +66,28 @@ static void *hexagon_dma_alloc_coherent(struct device *dev, size_t size,
{
void *ret;

/*
* Our max_low_pfn should have been backed off by 16MB in
* mm/init.c to create DMA coherent space. Use that as the VA
* for the pool.
*/

if (coherent_pool == NULL) {
coherent_pool = gen_pool_create(PAGE_SHIFT, -1);

if (coherent_pool == NULL)
panic("Can't create %s() memory pool!", __func__);
else
gen_pool_add(coherent_pool,
(PAGE_OFFSET + (max_low_pfn << PAGE_SHIFT)),
pfn_to_virt(max_low_pfn),
hexagon_coherent_pool_size, -1);
}

ret = (void *) gen_pool_alloc(coherent_pool, size);

if (ret) {
memset(ret, 0, size);
*dma_addr = (dma_addr_t) (ret - PAGE_OFFSET);
*dma_addr = (dma_addr_t) virt_to_phys(ret);
} else
*dma_addr = ~0;

Expand Down Expand Up @@ -118,8 +130,8 @@ static int hexagon_map_sg(struct device *hwdev, struct scatterlist *sg,

s->dma_length = s->length;

flush_dcache_range(PAGE_OFFSET + s->dma_address,
PAGE_OFFSET + s->dma_address + s->length);
flush_dcache_range(dma_addr_to_virt(s->dma_address),
dma_addr_to_virt(s->dma_address + s->length));
}

return nents;
Expand Down Expand Up @@ -149,11 +161,6 @@ static inline void dma_sync(void *addr, size_t size,
}
}

static inline void *dma_addr_to_virt(dma_addr_t dma_addr)
{
return phys_to_virt((unsigned long) dma_addr);
}

/**
* hexagon_map_page() - maps an address for device DMA
* @dev: pointer to DMA device
Expand Down

0 comments on commit 5e11505

Please sign in to comment.