x86/mm/pat: Don't report PAT on CPUs that don't support it
[linux/fpc-iii.git] / arch / arm / mach-davinci / sram.c
blob668b6e74976801862e4d100e2da2434603b8ae04
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/io.h>
14 #include <linux/genalloc.h>
16 #include <mach/common.h>
17 #include "sram.h"
19 static struct gen_pool *sram_pool;
21 struct gen_pool *sram_get_gen_pool(void)
23 return sram_pool;
26 void *sram_alloc(size_t len, dma_addr_t *dma)
28 dma_addr_t dma_base = davinci_soc_info.sram_dma;
30 if (dma)
31 *dma = 0;
32 if (!sram_pool || (dma && !dma_base))
33 return NULL;
35 return gen_pool_dma_alloc(sram_pool, len, dma);
38 EXPORT_SYMBOL(sram_alloc);
40 void sram_free(void *addr, size_t len)
42 gen_pool_free(sram_pool, (unsigned long) addr, len);
44 EXPORT_SYMBOL(sram_free);
48 * REVISIT This supports CPU and DMA access to/from SRAM, but it
49 * doesn't (yet?) support some other notable uses of SRAM: as TCM
50 * for data and/or instructions; and holding code needed to enter
51 * and exit suspend states (while DRAM can't be used).
53 static int __init sram_init(void)
55 phys_addr_t phys = davinci_soc_info.sram_dma;
56 unsigned len = davinci_soc_info.sram_len;
57 int status = 0;
58 void __iomem *addr;
60 if (len) {
61 len = min_t(unsigned, len, SRAM_SIZE);
62 sram_pool = gen_pool_create(ilog2(SRAM_GRANULARITY), -1);
63 if (!sram_pool)
64 status = -ENOMEM;
67 if (sram_pool) {
68 addr = ioremap(phys, len);
69 if (!addr)
70 return -ENOMEM;
71 status = gen_pool_add_virt(sram_pool, (unsigned long) addr,
72 phys, len, -1);
73 if (status < 0)
74 iounmap(addr);
77 WARN_ON(status < 0);
78 return status;
80 core_initcall(sram_init);