diff options
-rw-r--r-- | arch/arm/Kconfig | 1 | ||||
-rw-r--r-- | arch/arm/mach-davinci/Makefile | 2 | ||||
-rw-r--r-- | arch/arm/mach-davinci/include/mach/sram.h | 27 | ||||
-rw-r--r-- | arch/arm/mach-davinci/sram.c | 74 |
4 files changed, 103 insertions, 1 deletions
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 9d02cdb15b23..915b39382e65 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig | |||
@@ -587,6 +587,7 @@ config ARCH_DAVINCI | |||
587 | select ZONE_DMA | 587 | select ZONE_DMA |
588 | select HAVE_IDE | 588 | select HAVE_IDE |
589 | select COMMON_CLKDEV | 589 | select COMMON_CLKDEV |
590 | select GENERIC_ALLOCATOR | ||
590 | help | 591 | help |
591 | Support for TI's DaVinci platform. | 592 | Support for TI's DaVinci platform. |
592 | 593 | ||
diff --git a/arch/arm/mach-davinci/Makefile b/arch/arm/mach-davinci/Makefile index 5b62d8a4b180..059ab78084ba 100644 --- a/arch/arm/mach-davinci/Makefile +++ b/arch/arm/mach-davinci/Makefile | |||
@@ -5,7 +5,7 @@ | |||
5 | 5 | ||
6 | # Common objects | 6 | # Common objects |
7 | obj-y := time.o clock.o serial.o io.o psc.o \ | 7 | obj-y := time.o clock.o serial.o io.o psc.o \ |
8 | gpio.o devices.o dma.o usb.o common.o | 8 | gpio.o devices.o dma.o usb.o common.o sram.o |
9 | 9 | ||
10 | obj-$(CONFIG_DAVINCI_MUX) += mux.o | 10 | obj-$(CONFIG_DAVINCI_MUX) += mux.o |
11 | 11 | ||
diff --git a/arch/arm/mach-davinci/include/mach/sram.h b/arch/arm/mach-davinci/include/mach/sram.h new file mode 100644 index 000000000000..111f7cc71e07 --- /dev/null +++ b/arch/arm/mach-davinci/include/mach/sram.h | |||
@@ -0,0 +1,27 @@ | |||
1 | /* | ||
2 | * mach/sram.h - DaVinci simple SRAM allocator | ||
3 | * | ||
4 | * Copyright (C) 2009 David Brownell | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | */ | ||
10 | #ifndef __MACH_SRAM_H | ||
11 | #define __MACH_SRAM_H | ||
12 | |||
13 | /* ARBITRARY: SRAM allocations are multiples of this 2^N size */ | ||
14 | #define SRAM_GRANULARITY 512 | ||
15 | |||
16 | /* | ||
17 | * SRAM allocations return a CPU virtual address, or NULL on error. | ||
18 | * If a DMA address is requested and the SRAM supports DMA, its | ||
19 | * mapped address is also returned. | ||
20 | * | ||
21 | * Errors include SRAM memory not being available, and requesting | ||
22 | * DMA mapped SRAM on systems which don't allow that. | ||
23 | */ | ||
24 | extern void *sram_alloc(size_t len, dma_addr_t *dma); | ||
25 | extern void sram_free(void *addr, size_t len); | ||
26 | |||
27 | #endif /* __MACH_SRAM_H */ | ||
diff --git a/arch/arm/mach-davinci/sram.c b/arch/arm/mach-davinci/sram.c new file mode 100644 index 000000000000..db54b2a66b4d --- /dev/null +++ b/arch/arm/mach-davinci/sram.c | |||
@@ -0,0 +1,74 @@ | |||
1 | /* | ||
2 | * mach-davinci/sram.c - DaVinci simple SRAM allocator | ||
3 | * | ||
4 | * Copyright (C) 2009 David Brownell | ||
5 | * | ||
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. | ||
10 | */ | ||
11 | #include <linux/module.h> | ||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/genalloc.h> | ||
15 | |||
16 | #include <mach/common.h> | ||
17 | #include <mach/memory.h> | ||
18 | #include <mach/sram.h> | ||
19 | |||
20 | |||
21 | static struct gen_pool *sram_pool; | ||
22 | |||
23 | void *sram_alloc(size_t len, dma_addr_t *dma) | ||
24 | { | ||
25 | unsigned long vaddr; | ||
26 | dma_addr_t dma_base = davinci_soc_info.sram_dma; | ||
27 | |||
28 | if (dma) | ||
29 | *dma = 0; | ||
30 | if (!sram_pool || (dma && !dma_base)) | ||
31 | return NULL; | ||
32 | |||
33 | vaddr = gen_pool_alloc(sram_pool, len); | ||
34 | if (!vaddr) | ||
35 | return NULL; | ||
36 | |||
37 | if (dma) | ||
38 | *dma = dma_base + (vaddr - SRAM_VIRT); | ||
39 | return (void *)vaddr; | ||
40 | |||
41 | } | ||
42 | EXPORT_SYMBOL(sram_alloc); | ||
43 | |||
44 | void sram_free(void *addr, size_t len) | ||
45 | { | ||
46 | gen_pool_free(sram_pool, (unsigned long) addr, len); | ||
47 | } | ||
48 | EXPORT_SYMBOL(sram_free); | ||
49 | |||
50 | |||
51 | /* | ||
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). | ||
56 | */ | ||
57 | static int __init sram_init(void) | ||
58 | { | ||
59 | unsigned len = davinci_soc_info.sram_len; | ||
60 | int status = 0; | ||
61 | |||
62 | if (len) { | ||
63 | len = min(len, SRAM_SIZE); | ||
64 | sram_pool = gen_pool_create(ilog2(SRAM_GRANULARITY), -1); | ||
65 | if (!sram_pool) | ||
66 | status = -ENOMEM; | ||
67 | } | ||
68 | if (sram_pool) | ||
69 | status = gen_pool_add(sram_pool, SRAM_VIRT, len, -1); | ||
70 | WARN_ON(status < 0); | ||
71 | return status; | ||
72 | } | ||
73 | core_initcall(sram_init); | ||
74 | |||