Commit 983c42ba3465d4a80edfd318de24f8ffb2bf71ca
Committed by
Sekhar Nori
1 parent
c94472d4ad
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
ARM: davinci: add platform hook to fetch the SRAM pool
Adds sram_get_gen_pool() which allows platform code to get the machine's SRAM gen_pool. The gen_pool may be passed in platform data for driver genalloc use. Signed-off-by: Matt Porter <mporter@ti.com> Signed-off-by: Sekhar Nori <nsekhar@ti.com>
Showing 2 changed files with 8 additions and 0 deletions Inline Diff
arch/arm/mach-davinci/include/mach/sram.h
1 | /* | 1 | /* |
2 | * mach/sram.h - DaVinci simple SRAM allocator | 2 | * mach/sram.h - DaVinci simple SRAM allocator |
3 | * | 3 | * |
4 | * Copyright (C) 2009 David Brownell | 4 | * Copyright (C) 2009 David Brownell |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or modify | 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 | 7 | * it under the terms of the GNU General Public License version 2 as |
8 | * published by the Free Software Foundation. | 8 | * published by the Free Software Foundation. |
9 | */ | 9 | */ |
10 | #ifndef __MACH_SRAM_H | 10 | #ifndef __MACH_SRAM_H |
11 | #define __MACH_SRAM_H | 11 | #define __MACH_SRAM_H |
12 | 12 | ||
13 | /* ARBITRARY: SRAM allocations are multiples of this 2^N size */ | 13 | /* ARBITRARY: SRAM allocations are multiples of this 2^N size */ |
14 | #define SRAM_GRANULARITY 512 | 14 | #define SRAM_GRANULARITY 512 |
15 | 15 | ||
16 | /* | 16 | /* |
17 | * SRAM allocations return a CPU virtual address, or NULL on error. | 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 | 18 | * If a DMA address is requested and the SRAM supports DMA, its |
19 | * mapped address is also returned. | 19 | * mapped address is also returned. |
20 | * | 20 | * |
21 | * Errors include SRAM memory not being available, and requesting | 21 | * Errors include SRAM memory not being available, and requesting |
22 | * DMA mapped SRAM on systems which don't allow that. | 22 | * DMA mapped SRAM on systems which don't allow that. |
23 | */ | 23 | */ |
24 | extern void *sram_alloc(size_t len, dma_addr_t *dma); | 24 | extern void *sram_alloc(size_t len, dma_addr_t *dma); |
25 | extern void sram_free(void *addr, size_t len); | 25 | extern void sram_free(void *addr, size_t len); |
26 | 26 | ||
27 | /* Get the struct gen_pool * for use in platform data */ | ||
28 | extern struct gen_pool *sram_get_gen_pool(void); | ||
29 | |||
27 | #endif /* __MACH_SRAM_H */ | 30 | #endif /* __MACH_SRAM_H */ |
28 | 31 |
arch/arm/mach-davinci/sram.c
1 | /* | 1 | /* |
2 | * mach-davinci/sram.c - DaVinci simple SRAM allocator | 2 | * mach-davinci/sram.c - DaVinci simple SRAM allocator |
3 | * | 3 | * |
4 | * Copyright (C) 2009 David Brownell | 4 | * Copyright (C) 2009 David Brownell |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or modify | 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 | 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 | 8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. | 9 | * (at your option) any later version. |
10 | */ | 10 | */ |
11 | #include <linux/module.h> | 11 | #include <linux/module.h> |
12 | #include <linux/init.h> | 12 | #include <linux/init.h> |
13 | #include <linux/io.h> | 13 | #include <linux/io.h> |
14 | #include <linux/genalloc.h> | 14 | #include <linux/genalloc.h> |
15 | 15 | ||
16 | #include <mach/common.h> | 16 | #include <mach/common.h> |
17 | #include <mach/sram.h> | 17 | #include <mach/sram.h> |
18 | 18 | ||
19 | static struct gen_pool *sram_pool; | 19 | static struct gen_pool *sram_pool; |
20 | 20 | ||
21 | struct gen_pool *sram_get_gen_pool(void) | ||
22 | { | ||
23 | return sram_pool; | ||
24 | } | ||
25 | |||
21 | void *sram_alloc(size_t len, dma_addr_t *dma) | 26 | void *sram_alloc(size_t len, dma_addr_t *dma) |
22 | { | 27 | { |
23 | unsigned long vaddr; | 28 | unsigned long vaddr; |
24 | dma_addr_t dma_base = davinci_soc_info.sram_dma; | 29 | dma_addr_t dma_base = davinci_soc_info.sram_dma; |
25 | 30 | ||
26 | if (dma) | 31 | if (dma) |
27 | *dma = 0; | 32 | *dma = 0; |
28 | if (!sram_pool || (dma && !dma_base)) | 33 | if (!sram_pool || (dma && !dma_base)) |
29 | return NULL; | 34 | return NULL; |
30 | 35 | ||
31 | vaddr = gen_pool_alloc(sram_pool, len); | 36 | vaddr = gen_pool_alloc(sram_pool, len); |
32 | if (!vaddr) | 37 | if (!vaddr) |
33 | return NULL; | 38 | return NULL; |
34 | 39 | ||
35 | if (dma) | 40 | if (dma) |
36 | *dma = gen_pool_virt_to_phys(sram_pool, vaddr); | 41 | *dma = gen_pool_virt_to_phys(sram_pool, vaddr); |
37 | return (void *)vaddr; | 42 | return (void *)vaddr; |
38 | 43 | ||
39 | } | 44 | } |
40 | EXPORT_SYMBOL(sram_alloc); | 45 | EXPORT_SYMBOL(sram_alloc); |
41 | 46 | ||
42 | void sram_free(void *addr, size_t len) | 47 | void sram_free(void *addr, size_t len) |
43 | { | 48 | { |
44 | gen_pool_free(sram_pool, (unsigned long) addr, len); | 49 | gen_pool_free(sram_pool, (unsigned long) addr, len); |
45 | } | 50 | } |
46 | EXPORT_SYMBOL(sram_free); | 51 | EXPORT_SYMBOL(sram_free); |
47 | 52 | ||
48 | 53 | ||
49 | /* | 54 | /* |
50 | * REVISIT This supports CPU and DMA access to/from SRAM, but it | 55 | * REVISIT This supports CPU and DMA access to/from SRAM, but it |
51 | * doesn't (yet?) support some other notable uses of SRAM: as TCM | 56 | * doesn't (yet?) support some other notable uses of SRAM: as TCM |
52 | * for data and/or instructions; and holding code needed to enter | 57 | * for data and/or instructions; and holding code needed to enter |
53 | * and exit suspend states (while DRAM can't be used). | 58 | * and exit suspend states (while DRAM can't be used). |
54 | */ | 59 | */ |
55 | static int __init sram_init(void) | 60 | static int __init sram_init(void) |
56 | { | 61 | { |
57 | phys_addr_t phys = davinci_soc_info.sram_dma; | 62 | phys_addr_t phys = davinci_soc_info.sram_dma; |
58 | unsigned len = davinci_soc_info.sram_len; | 63 | unsigned len = davinci_soc_info.sram_len; |
59 | int status = 0; | 64 | int status = 0; |
60 | void *addr; | 65 | void *addr; |
61 | 66 | ||
62 | if (len) { | 67 | if (len) { |
63 | len = min_t(unsigned, len, SRAM_SIZE); | 68 | len = min_t(unsigned, len, SRAM_SIZE); |
64 | sram_pool = gen_pool_create(ilog2(SRAM_GRANULARITY), -1); | 69 | sram_pool = gen_pool_create(ilog2(SRAM_GRANULARITY), -1); |
65 | if (!sram_pool) | 70 | if (!sram_pool) |
66 | status = -ENOMEM; | 71 | status = -ENOMEM; |
67 | } | 72 | } |
68 | 73 | ||
69 | if (sram_pool) { | 74 | if (sram_pool) { |
70 | addr = ioremap(phys, len); | 75 | addr = ioremap(phys, len); |
71 | if (!addr) | 76 | if (!addr) |
72 | return -ENOMEM; | 77 | return -ENOMEM; |
73 | status = gen_pool_add_virt(sram_pool, (unsigned)addr, | 78 | status = gen_pool_add_virt(sram_pool, (unsigned)addr, |
74 | phys, len, -1); | 79 | phys, len, -1); |
75 | if (status < 0) | 80 | if (status < 0) |
76 | iounmap(addr); | 81 | iounmap(addr); |
77 | } | 82 | } |
78 | 83 | ||
79 | WARN_ON(status < 0); | 84 | WARN_ON(status < 0); |
80 | return status; | 85 | return status; |
81 | } | 86 | } |
82 | core_initcall(sram_init); | 87 | core_initcall(sram_init); |
83 | 88 | ||
84 | 89 |