ARM: tegra: fix compilation error due to mach/hardware.h removal
[linux-btrfs-devel.git] / arch / arm / mach-davinci / sram.c
blobdb0f7787faf17d2d64ca650c1af6d9ecf2d7e628
1 /*
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/init.h>
13 #include <linux/genalloc.h>
15 #include <mach/common.h>
16 #include <mach/sram.h>
18 static struct gen_pool *sram_pool;
20 void *sram_alloc(size_t len, dma_addr_t *dma)
22 unsigned long vaddr;
23 dma_addr_t dma_base = davinci_soc_info.sram_dma;
25 if (dma)
26 *dma = 0;
27 if (!sram_pool || (dma && !dma_base))
28 return NULL;
30 vaddr = gen_pool_alloc(sram_pool, len);
31 if (!vaddr)
32 return NULL;
34 if (dma)
35 *dma = dma_base + (vaddr - SRAM_VIRT);
36 return (void *)vaddr;
39 EXPORT_SYMBOL(sram_alloc);
41 void sram_free(void *addr, size_t len)
43 gen_pool_free(sram_pool, (unsigned long) addr, len);
45 EXPORT_SYMBOL(sram_free);
49 * REVISIT This supports CPU and DMA access to/from SRAM, but it
50 * doesn't (yet?) support some other notable uses of SRAM: as TCM
51 * for data and/or instructions; and holding code needed to enter
52 * and exit suspend states (while DRAM can't be used).
54 static int __init sram_init(void)
56 unsigned len = davinci_soc_info.sram_len;
57 int status = 0;
59 if (len) {
60 len = min_t(unsigned, len, SRAM_SIZE);
61 sram_pool = gen_pool_create(ilog2(SRAM_GRANULARITY), -1);
62 if (!sram_pool)
63 status = -ENOMEM;
65 if (sram_pool)
66 status = gen_pool_add(sram_pool, SRAM_VIRT, len, -1);
67 WARN_ON(status < 0);
68 return status;
70 core_initcall(sram_init);