Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5e115054 authored by Richard Kuo's avatar Richard Kuo
Browse files

Hexagon: use correct translations for DMA mappings



With physical offsets, pa<->va translations aren't just based
on PAGE_OFFSET anymore.

Signed-off-by: default avatarRichard Kuo <rkuo@codeaurora.org>
parent c710f590
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -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
+17 −10
Original line number Diff line number Diff line
/*
 * 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
@@ -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))
@@ -60,6 +66,12 @@ 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);

@@ -67,7 +79,7 @@ static void *hexagon_dma_alloc_coherent(struct device *dev, size_t size,
			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);
	}

@@ -75,7 +87,7 @@ static void *hexagon_dma_alloc_coherent(struct device *dev, size_t 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;

@@ -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;
@@ -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