0001
0002
0003
0004
0005
0006
0007 #include <linux/module.h>
0008 #include <linux/init.h>
0009 #include <linux/io.h>
0010 #include <linux/genalloc.h>
0011
0012 #include "common.h"
0013 #include "sram.h"
0014
0015 static struct gen_pool *sram_pool;
0016
0017 struct gen_pool *sram_get_gen_pool(void)
0018 {
0019 return sram_pool;
0020 }
0021
0022 void *sram_alloc(size_t len, dma_addr_t *dma)
0023 {
0024 dma_addr_t dma_base = davinci_soc_info.sram_dma;
0025
0026 if (dma)
0027 *dma = 0;
0028 if (!sram_pool || (dma && !dma_base))
0029 return NULL;
0030
0031 return gen_pool_dma_alloc(sram_pool, len, dma);
0032
0033 }
0034 EXPORT_SYMBOL(sram_alloc);
0035
0036 void sram_free(void *addr, size_t len)
0037 {
0038 gen_pool_free(sram_pool, (unsigned long) addr, len);
0039 }
0040 EXPORT_SYMBOL(sram_free);
0041
0042
0043
0044
0045
0046
0047
0048
0049 static int __init sram_init(void)
0050 {
0051 phys_addr_t phys = davinci_soc_info.sram_dma;
0052 unsigned len = davinci_soc_info.sram_len;
0053 int status = 0;
0054 void __iomem *addr;
0055
0056 if (len) {
0057 len = min_t(unsigned, len, SRAM_SIZE);
0058 sram_pool = gen_pool_create(ilog2(SRAM_GRANULARITY), -1);
0059 if (!sram_pool)
0060 status = -ENOMEM;
0061 }
0062
0063 if (sram_pool) {
0064 addr = ioremap(phys, len);
0065 if (!addr)
0066 return -ENOMEM;
0067 status = gen_pool_add_virt(sram_pool, (unsigned long) addr,
0068 phys, len, -1);
0069 if (status < 0)
0070 iounmap(addr);
0071 }
0072
0073 WARN_ON(status < 0);
0074 return status;
0075 }
0076 core_initcall(sram_init);
0077