1
2
3
4
5
6
7
8
9
10
11#include <linux/module.h>
12#include <linux/init.h>
13#include <linux/io.h>
14#include <linux/genalloc.h>
15
16#include <mach/common.h>
17#include <mach/sram.h>
18
19static struct gen_pool *sram_pool;
20
21struct gen_pool *sram_get_gen_pool(void)
22{
23 return sram_pool;
24}
25
26void *sram_alloc(size_t len, dma_addr_t *dma)
27{
28 unsigned long vaddr;
29 dma_addr_t dma_base = davinci_soc_info.sram_dma;
30
31 if (dma)
32 *dma = 0;
33 if (!sram_pool || (dma && !dma_base))
34 return NULL;
35
36 vaddr = gen_pool_alloc(sram_pool, len);
37 if (!vaddr)
38 return NULL;
39
40 if (dma)
41 *dma = gen_pool_virt_to_phys(sram_pool, vaddr);
42 return (void *)vaddr;
43
44}
45EXPORT_SYMBOL(sram_alloc);
46
47void sram_free(void *addr, size_t len)
48{
49 gen_pool_free(sram_pool, (unsigned long) addr, len);
50}
51EXPORT_SYMBOL(sram_free);
52
53
54
55
56
57
58
59
60static int __init sram_init(void)
61{
62 phys_addr_t phys = davinci_soc_info.sram_dma;
63 unsigned len = davinci_soc_info.sram_len;
64 int status = 0;
65 void __iomem *addr;
66
67 if (len) {
68 len = min_t(unsigned, len, SRAM_SIZE);
69 sram_pool = gen_pool_create(ilog2(SRAM_GRANULARITY), -1);
70 if (!sram_pool)
71 status = -ENOMEM;
72 }
73
74 if (sram_pool) {
75 addr = ioremap(phys, len);
76 if (!addr)
77 return -ENOMEM;
78 status = gen_pool_add_virt(sram_pool, (unsigned long) addr,
79 phys, len, -1);
80 if (status < 0)
81 iounmap(addr);
82 }
83
84 WARN_ON(status < 0);
85 return status;
86}
87core_initcall(sram_init);
88
89