1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * mach-davinci/sram.c - DaVinci simple SRAM allocator
5 * Copyright (C) 2009 David Brownell
7 #include <linux/module.h>
8 #include <linux/init.h>
10 #include <linux/genalloc.h>
15 static struct gen_pool *sram_pool;
17 struct gen_pool *sram_get_gen_pool(void)
22 void *sram_alloc(size_t len, dma_addr_t *dma)
24 dma_addr_t dma_base = davinci_soc_info.sram_dma;
28 if (!sram_pool || (dma && !dma_base))
31 return gen_pool_dma_alloc(sram_pool, len, dma);
34 EXPORT_SYMBOL(sram_alloc);
36 void sram_free(void *addr, size_t len)
38 gen_pool_free(sram_pool, (unsigned long) addr, len);
40 EXPORT_SYMBOL(sram_free);
44 * REVISIT This supports CPU and DMA access to/from SRAM, but it
45 * doesn't (yet?) support some other notable uses of SRAM: as TCM
46 * for data and/or instructions; and holding code needed to enter
47 * and exit suspend states (while DRAM can't be used).
49 static int __init sram_init(void)
51 phys_addr_t phys = davinci_soc_info.sram_dma;
52 unsigned len = davinci_soc_info.sram_len;
57 len = min_t(unsigned, len, SRAM_SIZE);
58 sram_pool = gen_pool_create(ilog2(SRAM_GRANULARITY), -1);
64 addr = ioremap(phys, len);
67 status = gen_pool_add_virt(sram_pool, (unsigned long) addr,
76 core_initcall(sram_init);