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

Commit 4009793e authored by Vitaly Andrianov's avatar Vitaly Andrianov Committed by Marek Szyprowski
Browse files

drivers: cma: represent physical addresses as phys_addr_t



This commit changes the CMA early initialization code to use phys_addr_t
for representing physical addresses instead of unsigned long.

Without this change, among other things, dma_declare_contiguous() simply
discards any memory regions whose address is not representable as unsigned
long.

This is a problem on 32-bit PAE machines where unsigned long is 32-bit
but physical address space is larger.

Signed-off-by: default avatarVitaly Andrianov <vitalya@ti.com>
Signed-off-by: default avatarCyril Chemparathy <cyril@ti.com>
Acked-by: default avatarMichal Nazarewicz <mina86@mina86.com>
Signed-off-by: default avatarMarek Szyprowski <m.szyprowski@samsung.com>
parent 387870f2
Loading
Loading
Loading
Loading
+10 −14
Original line number Original line Diff line number Diff line
@@ -57,8 +57,8 @@ struct cma *dma_contiguous_default_area;
 * Users, who want to set the size of global CMA area for their system
 * Users, who want to set the size of global CMA area for their system
 * should use cma= kernel parameter.
 * should use cma= kernel parameter.
 */
 */
static const unsigned long size_bytes = CMA_SIZE_MBYTES * SZ_1M;
static const phys_addr_t size_bytes = CMA_SIZE_MBYTES * SZ_1M;
static long size_cmdline = -1;
static phys_addr_t size_cmdline = -1;


static int __init early_cma(char *p)
static int __init early_cma(char *p)
{
{
@@ -70,7 +70,7 @@ early_param("cma", early_cma);


#ifdef CONFIG_CMA_SIZE_PERCENTAGE
#ifdef CONFIG_CMA_SIZE_PERCENTAGE


static unsigned long __init __maybe_unused cma_early_percent_memory(void)
static phys_addr_t __init __maybe_unused cma_early_percent_memory(void)
{
{
	struct memblock_region *reg;
	struct memblock_region *reg;
	unsigned long total_pages = 0;
	unsigned long total_pages = 0;
@@ -88,7 +88,7 @@ static unsigned long __init __maybe_unused cma_early_percent_memory(void)


#else
#else


static inline __maybe_unused unsigned long cma_early_percent_memory(void)
static inline __maybe_unused phys_addr_t cma_early_percent_memory(void)
{
{
	return 0;
	return 0;
}
}
@@ -106,7 +106,7 @@ static inline __maybe_unused unsigned long cma_early_percent_memory(void)
 */
 */
void __init dma_contiguous_reserve(phys_addr_t limit)
void __init dma_contiguous_reserve(phys_addr_t limit)
{
{
	unsigned long selected_size = 0;
	phys_addr_t selected_size = 0;


	pr_debug("%s(limit %08lx)\n", __func__, (unsigned long)limit);
	pr_debug("%s(limit %08lx)\n", __func__, (unsigned long)limit);


@@ -126,7 +126,7 @@ void __init dma_contiguous_reserve(phys_addr_t limit)


	if (selected_size) {
	if (selected_size) {
		pr_debug("%s: reserving %ld MiB for global area\n", __func__,
		pr_debug("%s: reserving %ld MiB for global area\n", __func__,
			 selected_size / SZ_1M);
			 (unsigned long)selected_size / SZ_1M);


		dma_declare_contiguous(NULL, selected_size, 0, limit);
		dma_declare_contiguous(NULL, selected_size, 0, limit);
	}
	}
@@ -227,11 +227,11 @@ core_initcall(cma_init_reserved_areas);
 * called by board specific code when early allocator (memblock or bootmem)
 * called by board specific code when early allocator (memblock or bootmem)
 * is still activate.
 * is still activate.
 */
 */
int __init dma_declare_contiguous(struct device *dev, unsigned long size,
int __init dma_declare_contiguous(struct device *dev, phys_addr_t size,
				  phys_addr_t base, phys_addr_t limit)
				  phys_addr_t base, phys_addr_t limit)
{
{
	struct cma_reserved *r = &cma_reserved[cma_reserved_count];
	struct cma_reserved *r = &cma_reserved[cma_reserved_count];
	unsigned long alignment;
	phys_addr_t alignment;


	pr_debug("%s(size %lx, base %08lx, limit %08lx)\n", __func__,
	pr_debug("%s(size %lx, base %08lx, limit %08lx)\n", __func__,
		 (unsigned long)size, (unsigned long)base,
		 (unsigned long)size, (unsigned long)base,
@@ -268,10 +268,6 @@ int __init dma_declare_contiguous(struct device *dev, unsigned long size,
		if (!addr) {
		if (!addr) {
			base = -ENOMEM;
			base = -ENOMEM;
			goto err;
			goto err;
		} else if (addr + size > ~(unsigned long)0) {
			memblock_free(addr, size);
			base = -EINVAL;
			goto err;
		} else {
		} else {
			base = addr;
			base = addr;
		}
		}
@@ -285,14 +281,14 @@ int __init dma_declare_contiguous(struct device *dev, unsigned long size,
	r->size = size;
	r->size = size;
	r->dev = dev;
	r->dev = dev;
	cma_reserved_count++;
	cma_reserved_count++;
	pr_info("CMA: reserved %ld MiB at %08lx\n", size / SZ_1M,
	pr_info("CMA: reserved %ld MiB at %08lx\n", (unsigned long)size / SZ_1M,
		(unsigned long)base);
		(unsigned long)base);


	/* Architecture specific contiguous memory fixup. */
	/* Architecture specific contiguous memory fixup. */
	dma_contiguous_early_fixup(base, size);
	dma_contiguous_early_fixup(base, size);
	return 0;
	return 0;
err:
err:
	pr_err("CMA: failed to reserve %ld MiB\n", size / SZ_1M);
	pr_err("CMA: failed to reserve %ld MiB\n", (unsigned long)size / SZ_1M);
	return base;
	return base;
}
}


+2 −2
Original line number Original line Diff line number Diff line
@@ -68,7 +68,7 @@ struct device;
extern struct cma *dma_contiguous_default_area;
extern struct cma *dma_contiguous_default_area;


void dma_contiguous_reserve(phys_addr_t addr_limit);
void dma_contiguous_reserve(phys_addr_t addr_limit);
int dma_declare_contiguous(struct device *dev, unsigned long size,
int dma_declare_contiguous(struct device *dev, phys_addr_t size,
			   phys_addr_t base, phys_addr_t limit);
			   phys_addr_t base, phys_addr_t limit);


struct page *dma_alloc_from_contiguous(struct device *dev, int count,
struct page *dma_alloc_from_contiguous(struct device *dev, int count,
@@ -83,7 +83,7 @@ bool dma_release_from_contiguous(struct device *dev, struct page *pages,
static inline void dma_contiguous_reserve(phys_addr_t limit) { }
static inline void dma_contiguous_reserve(phys_addr_t limit) { }


static inline
static inline
int dma_declare_contiguous(struct device *dev, unsigned long size,
int dma_declare_contiguous(struct device *dev, phys_addr_t size,
			   phys_addr_t base, phys_addr_t limit)
			   phys_addr_t base, phys_addr_t limit)
{
{
	return -ENOSYS;
	return -ENOSYS;