2019-05-27 14:55:01 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2009-05-08 00:31:42 +08:00
|
|
|
/*
|
|
|
|
* mach-davinci/sram.c - DaVinci simple SRAM allocator
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 David Brownell
|
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
2012-10-06 01:04:41 +08:00
|
|
|
#include <linux/io.h>
|
2009-05-08 00:31:42 +08:00
|
|
|
#include <linux/genalloc.h>
|
|
|
|
|
|
|
|
#include <mach/common.h>
|
2015-01-30 17:45:33 +08:00
|
|
|
#include "sram.h"
|
2009-05-08 00:31:42 +08:00
|
|
|
|
|
|
|
static struct gen_pool *sram_pool;
|
|
|
|
|
2012-10-06 01:04:43 +08:00
|
|
|
struct gen_pool *sram_get_gen_pool(void)
|
|
|
|
{
|
|
|
|
return sram_pool;
|
|
|
|
}
|
|
|
|
|
2009-05-08 00:31:42 +08:00
|
|
|
void *sram_alloc(size_t len, dma_addr_t *dma)
|
|
|
|
{
|
|
|
|
dma_addr_t dma_base = davinci_soc_info.sram_dma;
|
|
|
|
|
|
|
|
if (dma)
|
|
|
|
*dma = 0;
|
|
|
|
if (!sram_pool || (dma && !dma_base))
|
|
|
|
return NULL;
|
|
|
|
|
2013-11-13 07:09:54 +08:00
|
|
|
return gen_pool_dma_alloc(sram_pool, len, dma);
|
2009-05-08 00:31:42 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(sram_alloc);
|
|
|
|
|
|
|
|
void sram_free(void *addr, size_t len)
|
|
|
|
{
|
|
|
|
gen_pool_free(sram_pool, (unsigned long) addr, len);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(sram_free);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* REVISIT This supports CPU and DMA access to/from SRAM, but it
|
|
|
|
* doesn't (yet?) support some other notable uses of SRAM: as TCM
|
|
|
|
* for data and/or instructions; and holding code needed to enter
|
|
|
|
* and exit suspend states (while DRAM can't be used).
|
|
|
|
*/
|
|
|
|
static int __init sram_init(void)
|
|
|
|
{
|
2012-10-06 01:04:41 +08:00
|
|
|
phys_addr_t phys = davinci_soc_info.sram_dma;
|
2009-05-08 00:31:42 +08:00
|
|
|
unsigned len = davinci_soc_info.sram_len;
|
|
|
|
int status = 0;
|
2013-04-10 17:27:14 +08:00
|
|
|
void __iomem *addr;
|
2009-05-08 00:31:42 +08:00
|
|
|
|
|
|
|
if (len) {
|
2009-06-06 12:45:14 +08:00
|
|
|
len = min_t(unsigned, len, SRAM_SIZE);
|
2009-05-08 00:31:42 +08:00
|
|
|
sram_pool = gen_pool_create(ilog2(SRAM_GRANULARITY), -1);
|
|
|
|
if (!sram_pool)
|
|
|
|
status = -ENOMEM;
|
|
|
|
}
|
2012-10-06 01:04:41 +08:00
|
|
|
|
|
|
|
if (sram_pool) {
|
|
|
|
addr = ioremap(phys, len);
|
|
|
|
if (!addr)
|
|
|
|
return -ENOMEM;
|
2013-04-10 17:27:14 +08:00
|
|
|
status = gen_pool_add_virt(sram_pool, (unsigned long) addr,
|
2012-10-06 01:04:41 +08:00
|
|
|
phys, len, -1);
|
|
|
|
if (status < 0)
|
|
|
|
iounmap(addr);
|
|
|
|
}
|
|
|
|
|
2009-05-08 00:31:42 +08:00
|
|
|
WARN_ON(status < 0);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
core_initcall(sram_init);
|
|
|
|
|