aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorSonic Zhang <sonic.zhang@analog.com>2008-07-19 03:42:41 -0400
committerBryan Wu <cooloney@kernel.org>2008-07-19 03:42:41 -0400
commit262c3825a9f3eb0f4f30ebb4b1ee57397bcb3ffc (patch)
treefb5402f0de002d3e7a6671820228a2b9808d831f /arch
parentbafcc1b97323261a42d47960db99947bcc1be133 (diff)
Blackfin arch: Extend sram malloc to handle L2 SRAM.
Extend system call to alloc L2 SRAM in application. Automatically move following sections to L2 SRAM: 1. kernel built-in l2 attribute section 2. kernel module l2 attribute section 3. elf-fdpic application l2 attribute section Signed-off-by: Sonic Zhang <sonic.zhang@analog.com> Signed-off-by: Bryan Wu <cooloney@kernel.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/blackfin/kernel/module.c74
-rw-r--r--arch/blackfin/kernel/setup.c10
-rw-r--r--arch/blackfin/kernel/vmlinux.lds.S40
-rw-r--r--arch/blackfin/mm/blackfin_sram.c170
4 files changed, 241 insertions, 53 deletions
diff --git a/arch/blackfin/kernel/module.c b/arch/blackfin/kernel/module.c
index 14a42848f37f..e1bebc80a5bf 100644
--- a/arch/blackfin/kernel/module.c
+++ b/arch/blackfin/kernel/module.c
@@ -173,7 +173,7 @@ module_frob_arch_sections(Elf_Ehdr * hdr, Elf_Shdr * sechdrs,
173 for (s = sechdrs; s < sechdrs_end; ++s) { 173 for (s = sechdrs; s < sechdrs_end; ++s) {
174 if ((strcmp(".l1.text", secstrings + s->sh_name) == 0) || 174 if ((strcmp(".l1.text", secstrings + s->sh_name) == 0) ||
175 ((strcmp(".text", secstrings + s->sh_name) == 0) && 175 ((strcmp(".text", secstrings + s->sh_name) == 0) &&
176 (hdr->e_flags & FLG_CODE_IN_L1) && (s->sh_size > 0))) { 176 (hdr->e_flags & EF_BFIN_CODE_IN_L1) && (s->sh_size > 0))) {
177 dest = l1_inst_sram_alloc(s->sh_size); 177 dest = l1_inst_sram_alloc(s->sh_size);
178 mod->arch.text_l1 = dest; 178 mod->arch.text_l1 = dest;
179 if (dest == NULL) { 179 if (dest == NULL) {
@@ -188,7 +188,7 @@ module_frob_arch_sections(Elf_Ehdr * hdr, Elf_Shdr * sechdrs,
188 } 188 }
189 if ((strcmp(".l1.data", secstrings + s->sh_name) == 0) || 189 if ((strcmp(".l1.data", secstrings + s->sh_name) == 0) ||
190 ((strcmp(".data", secstrings + s->sh_name) == 0) && 190 ((strcmp(".data", secstrings + s->sh_name) == 0) &&
191 (hdr->e_flags & FLG_DATA_IN_L1) && (s->sh_size > 0))) { 191 (hdr->e_flags & EF_BFIN_DATA_IN_L1) && (s->sh_size > 0))) {
192 dest = l1_data_sram_alloc(s->sh_size); 192 dest = l1_data_sram_alloc(s->sh_size);
193 mod->arch.data_a_l1 = dest; 193 mod->arch.data_a_l1 = dest;
194 if (dest == NULL) { 194 if (dest == NULL) {
@@ -203,7 +203,7 @@ module_frob_arch_sections(Elf_Ehdr * hdr, Elf_Shdr * sechdrs,
203 } 203 }
204 if (strcmp(".l1.bss", secstrings + s->sh_name) == 0 || 204 if (strcmp(".l1.bss", secstrings + s->sh_name) == 0 ||
205 ((strcmp(".bss", secstrings + s->sh_name) == 0) && 205 ((strcmp(".bss", secstrings + s->sh_name) == 0) &&
206 (hdr->e_flags & FLG_DATA_IN_L1) && (s->sh_size > 0))) { 206 (hdr->e_flags & EF_BFIN_DATA_IN_L1) && (s->sh_size > 0))) {
207 dest = l1_data_sram_alloc(s->sh_size); 207 dest = l1_data_sram_alloc(s->sh_size);
208 mod->arch.bss_a_l1 = dest; 208 mod->arch.bss_a_l1 = dest;
209 if (dest == NULL) { 209 if (dest == NULL) {
@@ -242,6 +242,51 @@ module_frob_arch_sections(Elf_Ehdr * hdr, Elf_Shdr * sechdrs,
242 s->sh_flags &= ~SHF_ALLOC; 242 s->sh_flags &= ~SHF_ALLOC;
243 s->sh_addr = (unsigned long)dest; 243 s->sh_addr = (unsigned long)dest;
244 } 244 }
245 if ((strcmp(".l2.text", secstrings + s->sh_name) == 0) ||
246 ((strcmp(".text", secstrings + s->sh_name) == 0) &&
247 (hdr->e_flags & EF_BFIN_CODE_IN_L2) && (s->sh_size > 0))) {
248 dest = l2_sram_alloc(s->sh_size);
249 mod->arch.text_l2 = dest;
250 if (dest == NULL) {
251 printk(KERN_ERR
252 "module %s: L2 SRAM allocation failed\n",
253 mod->name);
254 return -1;
255 }
256 memcpy(dest, (void *)s->sh_addr, s->sh_size);
257 s->sh_flags &= ~SHF_ALLOC;
258 s->sh_addr = (unsigned long)dest;
259 }
260 if ((strcmp(".l2.data", secstrings + s->sh_name) == 0) ||
261 ((strcmp(".data", secstrings + s->sh_name) == 0) &&
262 (hdr->e_flags & EF_BFIN_DATA_IN_L2) && (s->sh_size > 0))) {
263 dest = l2_sram_alloc(s->sh_size);
264 mod->arch.data_l2 = dest;
265 if (dest == NULL) {
266 printk(KERN_ERR
267 "module %s: L2 SRAM allocation failed\n",
268 mod->name);
269 return -1;
270 }
271 memcpy(dest, (void *)s->sh_addr, s->sh_size);
272 s->sh_flags &= ~SHF_ALLOC;
273 s->sh_addr = (unsigned long)dest;
274 }
275 if (strcmp(".l2.bss", secstrings + s->sh_name) == 0 ||
276 ((strcmp(".bss", secstrings + s->sh_name) == 0) &&
277 (hdr->e_flags & EF_BFIN_DATA_IN_L2) && (s->sh_size > 0))) {
278 dest = l2_sram_alloc(s->sh_size);
279 mod->arch.bss_l2 = dest;
280 if (dest == NULL) {
281 printk(KERN_ERR
282 "module %s: L2 SRAM allocation failed\n",
283 mod->name);
284 return -1;
285 }
286 memset(dest, 0, s->sh_size);
287 s->sh_flags &= ~SHF_ALLOC;
288 s->sh_addr = (unsigned long)dest;
289 }
245 } 290 }
246 return 0; 291 return 0;
247} 292}
@@ -411,9 +456,10 @@ module_finalize(const Elf_Ehdr * hdr,
411 continue; 456 continue;
412 457
413 if ((sechdrs[i].sh_type == SHT_RELA) && 458 if ((sechdrs[i].sh_type == SHT_RELA) &&
414 ((strcmp(".rela.l1.text", secstrings + sechdrs[i].sh_name) == 0) || 459 ((strcmp(".rela.l2.text", secstrings + sechdrs[i].sh_name) == 0) ||
460 (strcmp(".rela.l1.text", secstrings + sechdrs[i].sh_name) == 0) ||
415 ((strcmp(".rela.text", secstrings + sechdrs[i].sh_name) == 0) && 461 ((strcmp(".rela.text", secstrings + sechdrs[i].sh_name) == 0) &&
416 (hdr->e_flags & FLG_CODE_IN_L1)))) { 462 (hdr->e_flags & (EF_BFIN_CODE_IN_L1|EF_BFIN_CODE_IN_L2))))) {
417 apply_relocate_add((Elf_Shdr *) sechdrs, strtab, 463 apply_relocate_add((Elf_Shdr *) sechdrs, strtab,
418 symindex, i, mod); 464 symindex, i, mod);
419 } 465 }
@@ -423,14 +469,12 @@ module_finalize(const Elf_Ehdr * hdr,
423 469
424void module_arch_cleanup(struct module *mod) 470void module_arch_cleanup(struct module *mod)
425{ 471{
426 if (mod->arch.text_l1) 472 l1_inst_sram_free(mod->arch.text_l1);
427 l1_inst_sram_free((void *)mod->arch.text_l1); 473 l1_data_A_sram_free(mod->arch.data_a_l1);
428 if (mod->arch.data_a_l1) 474 l1_data_A_sram_free(mod->arch.bss_a_l1);
429 l1_data_sram_free((void *)mod->arch.data_a_l1); 475 l1_data_B_sram_free(mod->arch.data_b_l1);
430 if (mod->arch.bss_a_l1) 476 l1_data_B_sram_free(mod->arch.bss_b_l1);
431 l1_data_sram_free((void *)mod->arch.bss_a_l1); 477 l2_sram_free(mod->arch.text_l2);
432 if (mod->arch.data_b_l1) 478 l2_sram_free(mod->arch.data_l2);
433 l1_data_B_sram_free((void *)mod->arch.data_b_l1); 479 l2_sram_free(mod->arch.bss_l2);
434 if (mod->arch.bss_b_l1)
435 l1_data_B_sram_free((void *)mod->arch.bss_b_l1);
436} 480}
diff --git a/arch/blackfin/kernel/setup.c b/arch/blackfin/kernel/setup.c
index 861a1db74df8..8671d1db1f99 100644
--- a/arch/blackfin/kernel/setup.c
+++ b/arch/blackfin/kernel/setup.c
@@ -104,6 +104,7 @@ void __init bf53x_relocate_l1_mem(void)
104 unsigned long l1_code_length; 104 unsigned long l1_code_length;
105 unsigned long l1_data_a_length; 105 unsigned long l1_data_a_length;
106 unsigned long l1_data_b_length; 106 unsigned long l1_data_b_length;
107 unsigned long l2_length;
107 108
108 l1_code_length = _etext_l1 - _stext_l1; 109 l1_code_length = _etext_l1 - _stext_l1;
109 if (l1_code_length > L1_CODE_LENGTH) 110 if (l1_code_length > L1_CODE_LENGTH)
@@ -129,6 +130,15 @@ void __init bf53x_relocate_l1_mem(void)
129 /* Copy _sdata_b_l1 to _ebss_b_l1 to L1 data bank B SRAM */ 130 /* Copy _sdata_b_l1 to _ebss_b_l1 to L1 data bank B SRAM */
130 dma_memcpy(_sdata_b_l1, _l1_lma_start + l1_code_length + 131 dma_memcpy(_sdata_b_l1, _l1_lma_start + l1_code_length +
131 l1_data_a_length, l1_data_b_length); 132 l1_data_a_length, l1_data_b_length);
133
134#ifdef L2_LENGTH
135 l2_length = _ebss_l2 - _stext_l2;
136 if (l2_length > L2_LENGTH)
137 panic("L2 SRAM Overflow\n");
138
139 /* Copy _stext_l2 to _edata_l2 to L2 SRAM */
140 dma_memcpy(_stext_l2, _l2_lma_start, l2_length);
141#endif
132} 142}
133 143
134/* add_memory_region to memmap */ 144/* add_memory_region to memmap */
diff --git a/arch/blackfin/kernel/vmlinux.lds.S b/arch/blackfin/kernel/vmlinux.lds.S
index 3ecc64cab3be..0896e38d6108 100644
--- a/arch/blackfin/kernel/vmlinux.lds.S
+++ b/arch/blackfin/kernel/vmlinux.lds.S
@@ -101,6 +101,11 @@ SECTIONS
101#if !L1_DATA_B_LENGTH 101#if !L1_DATA_B_LENGTH
102 *(.l1.data.B) 102 *(.l1.data.B)
103#endif 103#endif
104#ifndef L2_LENGTH
105 . = ALIGN(32);
106 *(.data_l2.cacheline_aligned)
107 *(.l2.data)
108#endif
104 109
105 DATA_DATA 110 DATA_DATA
106 *(.data.*) 111 *(.data.*)
@@ -182,14 +187,13 @@ SECTIONS
182 *(.l1.data) 187 *(.l1.data)
183 __edata_l1 = .; 188 __edata_l1 = .;
184 189
185 . = ALIGN(4);
186 __sbss_l1 = .;
187 *(.l1.bss)
188
189 . = ALIGN(32); 190 . = ALIGN(32);
190 *(.data_l1.cacheline_aligned) 191 *(.data_l1.cacheline_aligned)
191 192
192 . = ALIGN(4); 193 . = ALIGN(4);
194 __sbss_l1 = .;
195 *(.l1.bss)
196 . = ALIGN(4);
193 __ebss_l1 = .; 197 __ebss_l1 = .;
194 } 198 }
195 199
@@ -203,11 +207,37 @@ SECTIONS
203 . = ALIGN(4); 207 . = ALIGN(4);
204 __sbss_b_l1 = .; 208 __sbss_b_l1 = .;
205 *(.l1.bss.B) 209 *(.l1.bss.B)
206
207 . = ALIGN(4); 210 . = ALIGN(4);
208 __ebss_b_l1 = .; 211 __ebss_b_l1 = .;
209 } 212 }
210 213
214#ifdef L2_LENGTH
215 __l2_lma_start = .;
216
217 .text_data_l2 L2_START : AT(LOADADDR(.data_b_l1) + SIZEOF(.data_b_l1))
218 {
219 . = ALIGN(4);
220 __stext_l2 = .;
221 *(.l1.text)
222 . = ALIGN(4);
223 __etext_l2 = .;
224
225 . = ALIGN(4);
226 __sdata_l2 = .;
227 *(.l1.data)
228 __edata_l2 = .;
229
230 . = ALIGN(32);
231 *(.data_l2.cacheline_aligned)
232
233 . = ALIGN(4);
234 __sbss_l2 = .;
235 *(.l1.bss)
236 . = ALIGN(4);
237 __ebss_l2 = .;
238 }
239#endif
240
211 /* Force trailing alignment of our init section so that when we 241 /* Force trailing alignment of our init section so that when we
212 * free our init memory, we don't leave behind a partial page. 242 * free our init memory, we don't leave behind a partial page.
213 */ 243 */
diff --git a/arch/blackfin/mm/blackfin_sram.c b/arch/blackfin/mm/blackfin_sram.c
index b58cf196d7cc..5af3c31c9365 100644
--- a/arch/blackfin/mm/blackfin_sram.c
+++ b/arch/blackfin/mm/blackfin_sram.c
@@ -42,6 +42,7 @@
42#include "blackfin_sram.h" 42#include "blackfin_sram.h"
43 43
44static spinlock_t l1sram_lock, l1_data_sram_lock, l1_inst_sram_lock; 44static spinlock_t l1sram_lock, l1_data_sram_lock, l1_inst_sram_lock;
45static spinlock_t l2_sram_lock;
45 46
46/* the data structure for L1 scratchpad and DATA SRAM */ 47/* the data structure for L1 scratchpad and DATA SRAM */
47struct sram_piece { 48struct sram_piece {
@@ -65,6 +66,10 @@ static struct sram_piece free_l1_data_B_sram_head, used_l1_data_B_sram_head;
65static struct sram_piece free_l1_inst_sram_head, used_l1_inst_sram_head; 66static struct sram_piece free_l1_inst_sram_head, used_l1_inst_sram_head;
66#endif 67#endif
67 68
69#ifdef L2_LENGTH
70static struct sram_piece free_l2_sram_head, used_l2_sram_head;
71#endif
72
68static struct kmem_cache *sram_piece_cache; 73static struct kmem_cache *sram_piece_cache;
69 74
70/* L1 Scratchpad SRAM initialization function */ 75/* L1 Scratchpad SRAM initialization function */
@@ -97,7 +102,7 @@ static void __init l1_data_sram_init(void)
97 free_l1_data_A_sram_head.next = 102 free_l1_data_A_sram_head.next =
98 kmem_cache_alloc(sram_piece_cache, GFP_KERNEL); 103 kmem_cache_alloc(sram_piece_cache, GFP_KERNEL);
99 if (!free_l1_data_A_sram_head.next) { 104 if (!free_l1_data_A_sram_head.next) {
100 printk(KERN_INFO"Fail to initialize Data A SRAM.\n"); 105 printk(KERN_INFO"Fail to initialize L1 Data A SRAM.\n");
101 return; 106 return;
102 } 107 }
103 108
@@ -110,7 +115,7 @@ static void __init l1_data_sram_init(void)
110 115
111 used_l1_data_A_sram_head.next = NULL; 116 used_l1_data_A_sram_head.next = NULL;
112 117
113 printk(KERN_INFO "Blackfin Data A SRAM: %d KB (%d KB free)\n", 118 printk(KERN_INFO "Blackfin L1 Data A SRAM: %d KB (%d KB free)\n",
114 L1_DATA_A_LENGTH >> 10, 119 L1_DATA_A_LENGTH >> 10,
115 free_l1_data_A_sram_head.next->size >> 10); 120 free_l1_data_A_sram_head.next->size >> 10);
116#endif 121#endif
@@ -118,7 +123,7 @@ static void __init l1_data_sram_init(void)
118 free_l1_data_B_sram_head.next = 123 free_l1_data_B_sram_head.next =
119 kmem_cache_alloc(sram_piece_cache, GFP_KERNEL); 124 kmem_cache_alloc(sram_piece_cache, GFP_KERNEL);
120 if (!free_l1_data_B_sram_head.next) { 125 if (!free_l1_data_B_sram_head.next) {
121 printk(KERN_INFO"Fail to initialize Data B SRAM.\n"); 126 printk(KERN_INFO"Fail to initialize L1 Data B SRAM.\n");
122 return; 127 return;
123 } 128 }
124 129
@@ -131,7 +136,7 @@ static void __init l1_data_sram_init(void)
131 136
132 used_l1_data_B_sram_head.next = NULL; 137 used_l1_data_B_sram_head.next = NULL;
133 138
134 printk(KERN_INFO "Blackfin Data B SRAM: %d KB (%d KB free)\n", 139 printk(KERN_INFO "Blackfin L1 Data B SRAM: %d KB (%d KB free)\n",
135 L1_DATA_B_LENGTH >> 10, 140 L1_DATA_B_LENGTH >> 10,
136 free_l1_data_B_sram_head.next->size >> 10); 141 free_l1_data_B_sram_head.next->size >> 10);
137#endif 142#endif
@@ -146,7 +151,7 @@ static void __init l1_inst_sram_init(void)
146 free_l1_inst_sram_head.next = 151 free_l1_inst_sram_head.next =
147 kmem_cache_alloc(sram_piece_cache, GFP_KERNEL); 152 kmem_cache_alloc(sram_piece_cache, GFP_KERNEL);
148 if (!free_l1_inst_sram_head.next) { 153 if (!free_l1_inst_sram_head.next) {
149 printk(KERN_INFO"Fail to initialize Instruction SRAM.\n"); 154 printk(KERN_INFO"Fail to initialize L1 Instruction SRAM.\n");
150 return; 155 return;
151 } 156 }
152 157
@@ -159,7 +164,7 @@ static void __init l1_inst_sram_init(void)
159 164
160 used_l1_inst_sram_head.next = NULL; 165 used_l1_inst_sram_head.next = NULL;
161 166
162 printk(KERN_INFO "Blackfin Instruction SRAM: %d KB (%d KB free)\n", 167 printk(KERN_INFO "Blackfin L1 Instruction SRAM: %d KB (%d KB free)\n",
163 L1_CODE_LENGTH >> 10, 168 L1_CODE_LENGTH >> 10,
164 free_l1_inst_sram_head.next->size >> 10); 169 free_l1_inst_sram_head.next->size >> 10);
165#endif 170#endif
@@ -168,6 +173,33 @@ static void __init l1_inst_sram_init(void)
168 spin_lock_init(&l1_inst_sram_lock); 173 spin_lock_init(&l1_inst_sram_lock);
169} 174}
170 175
176static void __init l2_sram_init(void)
177{
178#ifdef L2_LENGTH
179 free_l2_sram_head.next =
180 kmem_cache_alloc(sram_piece_cache, GFP_KERNEL);
181 if (!free_l2_sram_head.next) {
182 printk(KERN_INFO"Fail to initialize L2 SRAM.\n");
183 return;
184 }
185
186 free_l2_sram_head.next->paddr = (void *)L2_START +
187 (_etext_l2 - _stext_l2) + (_edata_l2 - _sdata_l2);
188 free_l2_sram_head.next->size = L2_LENGTH -
189 (_etext_l2 - _stext_l2) + (_edata_l2 - _sdata_l2);
190 free_l2_sram_head.next->pid = 0;
191 free_l2_sram_head.next->next = NULL;
192
193 used_l2_sram_head.next = NULL;
194
195 printk(KERN_INFO "Blackfin L2 SRAM: %d KB (%d KB free)\n",
196 L2_LENGTH >> 10,
197 free_l2_sram_head.next->size >> 10);
198#endif
199
200 /* mutex initialize */
201 spin_lock_init(&l2_sram_lock);
202}
171void __init bfin_sram_init(void) 203void __init bfin_sram_init(void)
172{ 204{
173 sram_piece_cache = kmem_cache_create("sram_piece_cache", 205 sram_piece_cache = kmem_cache_create("sram_piece_cache",
@@ -177,10 +209,11 @@ void __init bfin_sram_init(void)
177 l1sram_init(); 209 l1sram_init();
178 l1_data_sram_init(); 210 l1_data_sram_init();
179 l1_inst_sram_init(); 211 l1_inst_sram_init();
212 l2_sram_init();
180} 213}
181 214
182/* L1 memory allocate function */ 215/* SRAM allocate function */
183static void *_l1_sram_alloc(size_t size, struct sram_piece *pfree_head, 216static void *_sram_alloc(size_t size, struct sram_piece *pfree_head,
184 struct sram_piece *pused_head) 217 struct sram_piece *pused_head)
185{ 218{
186 struct sram_piece *pslot, *plast, *pavail; 219 struct sram_piece *pslot, *plast, *pavail;
@@ -236,7 +269,7 @@ static void *_l1_sram_alloc(size_t size, struct sram_piece *pfree_head,
236} 269}
237 270
238/* Allocate the largest available block. */ 271/* Allocate the largest available block. */
239static void *_l1_sram_alloc_max(struct sram_piece *pfree_head, 272static void *_sram_alloc_max(struct sram_piece *pfree_head,
240 struct sram_piece *pused_head, 273 struct sram_piece *pused_head,
241 unsigned long *psize) 274 unsigned long *psize)
242{ 275{
@@ -259,11 +292,11 @@ static void *_l1_sram_alloc_max(struct sram_piece *pfree_head,
259 292
260 *psize = pmax->size; 293 *psize = pmax->size;
261 294
262 return _l1_sram_alloc(*psize, pfree_head, pused_head); 295 return _sram_alloc(*psize, pfree_head, pused_head);
263} 296}
264 297
265/* L1 memory free function */ 298/* SRAM free function */
266static int _l1_sram_free(const void *addr, 299static int _sram_free(const void *addr,
267 struct sram_piece *pfree_head, 300 struct sram_piece *pfree_head,
268 struct sram_piece *pused_head) 301 struct sram_piece *pused_head)
269{ 302{
@@ -334,6 +367,11 @@ int sram_free(const void *addr)
334 && addr < (void *)(L1_DATA_B_START + L1_DATA_B_LENGTH)) 367 && addr < (void *)(L1_DATA_B_START + L1_DATA_B_LENGTH))
335 return l1_data_B_sram_free(addr); 368 return l1_data_B_sram_free(addr);
336#endif 369#endif
370#ifdef L2_LENGTH
371 else if (addr >= (void *)L2_START
372 && addr < (void *)(L2_START + L2_LENGTH))
373 return l2_sram_free(addr);
374#endif
337 else 375 else
338 return -1; 376 return -1;
339} 377}
@@ -348,7 +386,7 @@ void *l1_data_A_sram_alloc(size_t size)
348 spin_lock_irqsave(&l1_data_sram_lock, flags); 386 spin_lock_irqsave(&l1_data_sram_lock, flags);
349 387
350#if L1_DATA_A_LENGTH != 0 388#if L1_DATA_A_LENGTH != 0
351 addr = _l1_sram_alloc(size, &free_l1_data_A_sram_head, 389 addr = _sram_alloc(size, &free_l1_data_A_sram_head,
352 &used_l1_data_A_sram_head); 390 &used_l1_data_A_sram_head);
353#endif 391#endif
354 392
@@ -371,7 +409,7 @@ int l1_data_A_sram_free(const void *addr)
371 spin_lock_irqsave(&l1_data_sram_lock, flags); 409 spin_lock_irqsave(&l1_data_sram_lock, flags);
372 410
373#if L1_DATA_A_LENGTH != 0 411#if L1_DATA_A_LENGTH != 0
374 ret = _l1_sram_free(addr, &free_l1_data_A_sram_head, 412 ret = _sram_free(addr, &free_l1_data_A_sram_head,
375 &used_l1_data_A_sram_head); 413 &used_l1_data_A_sram_head);
376#else 414#else
377 ret = -1; 415 ret = -1;
@@ -393,7 +431,7 @@ void *l1_data_B_sram_alloc(size_t size)
393 /* add mutex operation */ 431 /* add mutex operation */
394 spin_lock_irqsave(&l1_data_sram_lock, flags); 432 spin_lock_irqsave(&l1_data_sram_lock, flags);
395 433
396 addr = _l1_sram_alloc(size, &free_l1_data_B_sram_head, 434 addr = _sram_alloc(size, &free_l1_data_B_sram_head,
397 &used_l1_data_B_sram_head); 435 &used_l1_data_B_sram_head);
398 436
399 /* add mutex operation */ 437 /* add mutex operation */
@@ -418,7 +456,7 @@ int l1_data_B_sram_free(const void *addr)
418 /* add mutex operation */ 456 /* add mutex operation */
419 spin_lock_irqsave(&l1_data_sram_lock, flags); 457 spin_lock_irqsave(&l1_data_sram_lock, flags);
420 458
421 ret = _l1_sram_free(addr, &free_l1_data_B_sram_head, 459 ret = _sram_free(addr, &free_l1_data_B_sram_head,
422 &used_l1_data_B_sram_head); 460 &used_l1_data_B_sram_head);
423 461
424 /* add mutex operation */ 462 /* add mutex operation */
@@ -472,7 +510,7 @@ void *l1_inst_sram_alloc(size_t size)
472 /* add mutex operation */ 510 /* add mutex operation */
473 spin_lock_irqsave(&l1_inst_sram_lock, flags); 511 spin_lock_irqsave(&l1_inst_sram_lock, flags);
474 512
475 addr = _l1_sram_alloc(size, &free_l1_inst_sram_head, 513 addr = _sram_alloc(size, &free_l1_inst_sram_head,
476 &used_l1_inst_sram_head); 514 &used_l1_inst_sram_head);
477 515
478 /* add mutex operation */ 516 /* add mutex operation */
@@ -497,7 +535,7 @@ int l1_inst_sram_free(const void *addr)
497 /* add mutex operation */ 535 /* add mutex operation */
498 spin_lock_irqsave(&l1_inst_sram_lock, flags); 536 spin_lock_irqsave(&l1_inst_sram_lock, flags);
499 537
500 ret = _l1_sram_free(addr, &free_l1_inst_sram_head, 538 ret = _sram_free(addr, &free_l1_inst_sram_head,
501 &used_l1_inst_sram_head); 539 &used_l1_inst_sram_head);
502 540
503 /* add mutex operation */ 541 /* add mutex operation */
@@ -519,7 +557,7 @@ void *l1sram_alloc(size_t size)
519 /* add mutex operation */ 557 /* add mutex operation */
520 spin_lock_irqsave(&l1sram_lock, flags); 558 spin_lock_irqsave(&l1sram_lock, flags);
521 559
522 addr = _l1_sram_alloc(size, &free_l1_ssram_head, 560 addr = _sram_alloc(size, &free_l1_ssram_head,
523 &used_l1_ssram_head); 561 &used_l1_ssram_head);
524 562
525 /* add mutex operation */ 563 /* add mutex operation */
@@ -537,7 +575,7 @@ void *l1sram_alloc_max(size_t *psize)
537 /* add mutex operation */ 575 /* add mutex operation */
538 spin_lock_irqsave(&l1sram_lock, flags); 576 spin_lock_irqsave(&l1sram_lock, flags);
539 577
540 addr = _l1_sram_alloc_max(&free_l1_ssram_head, 578 addr = _sram_alloc_max(&free_l1_ssram_head,
541 &used_l1_ssram_head, psize); 579 &used_l1_ssram_head, psize);
542 580
543 /* add mutex operation */ 581 /* add mutex operation */
@@ -555,7 +593,7 @@ int l1sram_free(const void *addr)
555 /* add mutex operation */ 593 /* add mutex operation */
556 spin_lock_irqsave(&l1sram_lock, flags); 594 spin_lock_irqsave(&l1sram_lock, flags);
557 595
558 ret = _l1_sram_free(addr, &free_l1_ssram_head, 596 ret = _sram_free(addr, &free_l1_ssram_head,
559 &used_l1_ssram_head); 597 &used_l1_ssram_head);
560 598
561 /* add mutex operation */ 599 /* add mutex operation */
@@ -564,6 +602,64 @@ int l1sram_free(const void *addr)
564 return ret; 602 return ret;
565} 603}
566 604
605void *l2_sram_alloc(size_t size)
606{
607#ifdef L2_LENGTH
608 unsigned flags;
609 void *addr;
610
611 /* add mutex operation */
612 spin_lock_irqsave(&l2_sram_lock, flags);
613
614 addr = _sram_alloc(size, &free_l2_sram_head,
615 &used_l2_sram_head);
616
617 /* add mutex operation */
618 spin_unlock_irqrestore(&l2_sram_lock, flags);
619
620 pr_debug("Allocated address in l2_sram_alloc is 0x%lx+0x%lx\n",
621 (long unsigned int)addr, size);
622
623 return addr;
624#else
625 return NULL;
626#endif
627}
628EXPORT_SYMBOL(l2_sram_alloc);
629
630void *l2_sram_zalloc(size_t size)
631{
632 void *addr = l2_sram_alloc(size);
633
634 if (addr)
635 memset(addr, 0x00, size);
636
637 return addr;
638}
639EXPORT_SYMBOL(l2_sram_zalloc);
640
641int l2_sram_free(const void *addr)
642{
643#ifdef L2_LENGTH
644 unsigned flags;
645 int ret;
646
647 /* add mutex operation */
648 spin_lock_irqsave(&l2_sram_lock, flags);
649
650 ret = _sram_free(addr, &free_l2_sram_head,
651 &used_l2_sram_head);
652
653 /* add mutex operation */
654 spin_unlock_irqrestore(&l2_sram_lock, flags);
655
656 return ret;
657#else
658 return -1;
659#endif
660}
661EXPORT_SYMBOL(l2_sram_free);
662
567int sram_free_with_lsl(const void *addr) 663int sram_free_with_lsl(const void *addr)
568{ 664{
569 struct sram_list_struct *lsl, **tmp; 665 struct sram_list_struct *lsl, **tmp;
@@ -602,6 +698,9 @@ void *sram_alloc_with_lsl(size_t size, unsigned long flags)
602 if (addr == NULL && (flags & L1_DATA_B_SRAM)) 698 if (addr == NULL && (flags & L1_DATA_B_SRAM))
603 addr = l1_data_B_sram_alloc(size); 699 addr = l1_data_B_sram_alloc(size);
604 700
701 if (addr == NULL && (flags & L2_SRAM))
702 addr = l2_sram_alloc(size);
703
605 if (addr == NULL) { 704 if (addr == NULL) {
606 kfree(lsl); 705 kfree(lsl);
607 return NULL; 706 return NULL;
@@ -621,7 +720,7 @@ EXPORT_SYMBOL(sram_alloc_with_lsl);
621/* Need to keep line of output the same. Currently, that is 44 bytes 720/* Need to keep line of output the same. Currently, that is 44 bytes
622 * (including newline). 721 * (including newline).
623 */ 722 */
624static int _l1sram_proc_read(char *buf, int *len, int count, const char *desc, 723static int _sram_proc_read(char *buf, int *len, int count, const char *desc,
625 struct sram_piece *pfree_head, 724 struct sram_piece *pfree_head,
626 struct sram_piece *pused_head) 725 struct sram_piece *pused_head)
627{ 726{
@@ -630,13 +729,13 @@ static int _l1sram_proc_read(char *buf, int *len, int count, const char *desc,
630 if (!pfree_head || !pused_head) 729 if (!pfree_head || !pused_head)
631 return -1; 730 return -1;
632 731
633 *len += sprintf(&buf[*len], "--- L1 %-14s Size PID State \n", desc); 732 *len += sprintf(&buf[*len], "--- SRAM %-14s Size PID State \n", desc);
634 733
635 /* search the relevant memory slot */ 734 /* search the relevant memory slot */
636 pslot = pused_head->next; 735 pslot = pused_head->next;
637 736
638 while (pslot != NULL) { 737 while (pslot != NULL) {
639 *len += sprintf(&buf[*len], "%p-%p %8i %5i %-10s\n", 738 *len += sprintf(&buf[*len], "%p-%p %10i %5i %-10s\n",
640 pslot->paddr, pslot->paddr + pslot->size, 739 pslot->paddr, pslot->paddr + pslot->size,
641 pslot->size, pslot->pid, "ALLOCATED"); 740 pslot->size, pslot->pid, "ALLOCATED");
642 741
@@ -646,7 +745,7 @@ static int _l1sram_proc_read(char *buf, int *len, int count, const char *desc,
646 pslot = pfree_head->next; 745 pslot = pfree_head->next;
647 746
648 while (pslot != NULL) { 747 while (pslot != NULL) {
649 *len += sprintf(&buf[*len], "%p-%p %8i %5i %-10s\n", 748 *len += sprintf(&buf[*len], "%p-%p %10i %5i %-10s\n",
650 pslot->paddr, pslot->paddr + pslot->size, 749 pslot->paddr, pslot->paddr + pslot->size,
651 pslot->size, pslot->pid, "FREE"); 750 pslot->size, pslot->pid, "FREE");
652 751
@@ -655,38 +754,43 @@ static int _l1sram_proc_read(char *buf, int *len, int count, const char *desc,
655 754
656 return 0; 755 return 0;
657} 756}
658static int l1sram_proc_read(char *buf, char **start, off_t offset, int count, 757static int sram_proc_read(char *buf, char **start, off_t offset, int count,
659 int *eof, void *data) 758 int *eof, void *data)
660{ 759{
661 int len = 0; 760 int len = 0;
662 761
663 if (_l1sram_proc_read(buf, &len, count, "Scratchpad", 762 if (_sram_proc_read(buf, &len, count, "Scratchpad",
664 &free_l1_ssram_head, &used_l1_ssram_head)) 763 &free_l1_ssram_head, &used_l1_ssram_head))
665 goto not_done; 764 goto not_done;
666#if L1_DATA_A_LENGTH != 0 765#if L1_DATA_A_LENGTH != 0
667 if (_l1sram_proc_read(buf, &len, count, "Data A", 766 if (_sram_proc_read(buf, &len, count, "L1 Data A",
668 &free_l1_data_A_sram_head, 767 &free_l1_data_A_sram_head,
669 &used_l1_data_A_sram_head)) 768 &used_l1_data_A_sram_head))
670 goto not_done; 769 goto not_done;
671#endif 770#endif
672#if L1_DATA_B_LENGTH != 0 771#if L1_DATA_B_LENGTH != 0
673 if (_l1sram_proc_read(buf, &len, count, "Data B", 772 if (_sram_proc_read(buf, &len, count, "L1 Data B",
674 &free_l1_data_B_sram_head, 773 &free_l1_data_B_sram_head,
675 &used_l1_data_B_sram_head)) 774 &used_l1_data_B_sram_head))
676 goto not_done; 775 goto not_done;
677#endif 776#endif
678#if L1_CODE_LENGTH != 0 777#if L1_CODE_LENGTH != 0
679 if (_l1sram_proc_read(buf, &len, count, "Instruction", 778 if (_sram_proc_read(buf, &len, count, "L1 Instruction",
680 &free_l1_inst_sram_head, &used_l1_inst_sram_head)) 779 &free_l1_inst_sram_head, &used_l1_inst_sram_head))
681 goto not_done; 780 goto not_done;
682#endif 781#endif
782#ifdef L2_LENGTH
783 if (_sram_proc_read(buf, &len, count, "L2",
784 &free_l2_sram_head, &used_l2_sram_head))
785 goto not_done;
786#endif
683 787
684 *eof = 1; 788 *eof = 1;
685 not_done: 789 not_done:
686 return len; 790 return len;
687} 791}
688 792
689static int __init l1sram_proc_init(void) 793static int __init sram_proc_init(void)
690{ 794{
691 struct proc_dir_entry *ptr; 795 struct proc_dir_entry *ptr;
692 ptr = create_proc_entry("sram", S_IFREG | S_IRUGO, NULL); 796 ptr = create_proc_entry("sram", S_IFREG | S_IRUGO, NULL);
@@ -695,8 +799,8 @@ static int __init l1sram_proc_init(void)
695 return -1; 799 return -1;
696 } 800 }
697 ptr->owner = THIS_MODULE; 801 ptr->owner = THIS_MODULE;
698 ptr->read_proc = l1sram_proc_read; 802 ptr->read_proc = sram_proc_read;
699 return 0; 803 return 0;
700} 804}
701late_initcall(l1sram_proc_init); 805late_initcall(sram_proc_init);
702#endif 806#endif