2 * mach-davinci/sram.c - DaVinci simple SRAM allocator
4 * Copyright (C) 2009 David Brownell
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 #include <linux/module.h>
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/genalloc.h>
16 #include <mach/common.h>
17 #include <mach/memory.h>
18 #include <mach/sram.h>
21 static struct gen_pool
*sram_pool
;
23 void *sram_alloc(size_t len
, dma_addr_t
*dma
)
26 dma_addr_t dma_base
= davinci_soc_info
.sram_dma
;
30 if (!sram_pool
|| (dma
&& !dma_base
))
33 vaddr
= gen_pool_alloc(sram_pool
, len
);
38 *dma
= dma_base
+ (vaddr
- SRAM_VIRT
);
42 EXPORT_SYMBOL(sram_alloc
);
44 void sram_free(void *addr
, size_t len
)
46 gen_pool_free(sram_pool
, (unsigned long) addr
, len
);
48 EXPORT_SYMBOL(sram_free
);
52 * REVISIT This supports CPU and DMA access to/from SRAM, but it
53 * doesn't (yet?) support some other notable uses of SRAM: as TCM
54 * for data and/or instructions; and holding code needed to enter
55 * and exit suspend states (while DRAM can't be used).
57 static int __init
sram_init(void)
59 unsigned len
= davinci_soc_info
.sram_len
;
63 len
= min_t(unsigned, len
, SRAM_SIZE
);
64 sram_pool
= gen_pool_create(ilog2(SRAM_GRANULARITY
), -1);
69 status
= gen_pool_add(sram_pool
, SRAM_VIRT
, len
, -1);
73 core_initcall(sram_init
);