aboutsummaryrefslogtreecommitdiffstats
path: root/arch/blackfin/mm/blackfin_sram.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/blackfin/mm/blackfin_sram.c')
-rw-r--r--arch/blackfin/mm/blackfin_sram.c170
1 files changed, 137 insertions, 33 deletions
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