2 * SRAM allocator for Blackfin on-chip memory
4 * Copyright 2004-2009 Analog Devices Inc.
6 * Licensed under the GPL-2 or later.
9 #include <linux/module.h>
10 #include <linux/kernel.h>
11 #include <linux/types.h>
12 #include <linux/miscdevice.h>
13 #include <linux/ioport.h>
14 #include <linux/fcntl.h>
15 #include <linux/init.h>
16 #include <linux/poll.h>
17 #include <linux/proc_fs.h>
18 #include <linux/seq_file.h>
19 #include <linux/spinlock.h>
20 #include <linux/rtc.h>
21 #include <linux/slab.h>
22 #include <asm/blackfin.h>
23 #include <asm/mem_map.h>
24 #include "blackfin_sram.h"
26 /* the data structure for L1 scratchpad and DATA SRAM */
31 struct sram_piece
*next
;
34 static DEFINE_PER_CPU_SHARED_ALIGNED(spinlock_t
, l1sram_lock
);
35 static DEFINE_PER_CPU(struct sram_piece
, free_l1_ssram_head
);
36 static DEFINE_PER_CPU(struct sram_piece
, used_l1_ssram_head
);
38 #if L1_DATA_A_LENGTH != 0
39 static DEFINE_PER_CPU(struct sram_piece
, free_l1_data_A_sram_head
);
40 static DEFINE_PER_CPU(struct sram_piece
, used_l1_data_A_sram_head
);
43 #if L1_DATA_B_LENGTH != 0
44 static DEFINE_PER_CPU(struct sram_piece
, free_l1_data_B_sram_head
);
45 static DEFINE_PER_CPU(struct sram_piece
, used_l1_data_B_sram_head
);
48 #if L1_DATA_A_LENGTH || L1_DATA_B_LENGTH
49 static DEFINE_PER_CPU_SHARED_ALIGNED(spinlock_t
, l1_data_sram_lock
);
52 #if L1_CODE_LENGTH != 0
53 static DEFINE_PER_CPU_SHARED_ALIGNED(spinlock_t
, l1_inst_sram_lock
);
54 static DEFINE_PER_CPU(struct sram_piece
, free_l1_inst_sram_head
);
55 static DEFINE_PER_CPU(struct sram_piece
, used_l1_inst_sram_head
);
59 static spinlock_t l2_sram_lock ____cacheline_aligned_in_smp
;
60 static struct sram_piece free_l2_sram_head
, used_l2_sram_head
;
63 static struct kmem_cache
*sram_piece_cache
;
65 /* L1 Scratchpad SRAM initialization function */
66 static void __init
l1sram_init(void)
69 unsigned long reserve
;
74 reserve
= sizeof(struct l1_scratch_task_info
);
77 for (cpu
= 0; cpu
< num_possible_cpus(); ++cpu
) {
78 per_cpu(free_l1_ssram_head
, cpu
).next
=
79 kmem_cache_alloc(sram_piece_cache
, GFP_KERNEL
);
80 if (!per_cpu(free_l1_ssram_head
, cpu
).next
) {
81 printk(KERN_INFO
"Fail to initialize Scratchpad data SRAM.\n");
85 per_cpu(free_l1_ssram_head
, cpu
).next
->paddr
= (void *)get_l1_scratch_start_cpu(cpu
) + reserve
;
86 per_cpu(free_l1_ssram_head
, cpu
).next
->size
= L1_SCRATCH_LENGTH
- reserve
;
87 per_cpu(free_l1_ssram_head
, cpu
).next
->pid
= 0;
88 per_cpu(free_l1_ssram_head
, cpu
).next
->next
= NULL
;
90 per_cpu(used_l1_ssram_head
, cpu
).next
= NULL
;
92 /* mutex initialize */
93 spin_lock_init(&per_cpu(l1sram_lock
, cpu
));
94 printk(KERN_INFO
"Blackfin Scratchpad data SRAM: %d KB\n",
95 L1_SCRATCH_LENGTH
>> 10);
99 static void __init
l1_data_sram_init(void)
101 #if L1_DATA_A_LENGTH != 0 || L1_DATA_B_LENGTH != 0
104 #if L1_DATA_A_LENGTH != 0
105 for (cpu
= 0; cpu
< num_possible_cpus(); ++cpu
) {
106 per_cpu(free_l1_data_A_sram_head
, cpu
).next
=
107 kmem_cache_alloc(sram_piece_cache
, GFP_KERNEL
);
108 if (!per_cpu(free_l1_data_A_sram_head
, cpu
).next
) {
109 printk(KERN_INFO
"Fail to initialize L1 Data A SRAM.\n");
113 per_cpu(free_l1_data_A_sram_head
, cpu
).next
->paddr
=
114 (void *)get_l1_data_a_start_cpu(cpu
) + (_ebss_l1
- _sdata_l1
);
115 per_cpu(free_l1_data_A_sram_head
, cpu
).next
->size
=
116 L1_DATA_A_LENGTH
- (_ebss_l1
- _sdata_l1
);
117 per_cpu(free_l1_data_A_sram_head
, cpu
).next
->pid
= 0;
118 per_cpu(free_l1_data_A_sram_head
, cpu
).next
->next
= NULL
;
120 per_cpu(used_l1_data_A_sram_head
, cpu
).next
= NULL
;
122 printk(KERN_INFO
"Blackfin L1 Data A SRAM: %d KB (%d KB free)\n",
123 L1_DATA_A_LENGTH
>> 10,
124 per_cpu(free_l1_data_A_sram_head
, cpu
).next
->size
>> 10);
127 #if L1_DATA_B_LENGTH != 0
128 for (cpu
= 0; cpu
< num_possible_cpus(); ++cpu
) {
129 per_cpu(free_l1_data_B_sram_head
, cpu
).next
=
130 kmem_cache_alloc(sram_piece_cache
, GFP_KERNEL
);
131 if (!per_cpu(free_l1_data_B_sram_head
, cpu
).next
) {
132 printk(KERN_INFO
"Fail to initialize L1 Data B SRAM.\n");
136 per_cpu(free_l1_data_B_sram_head
, cpu
).next
->paddr
=
137 (void *)get_l1_data_b_start_cpu(cpu
) + (_ebss_b_l1
- _sdata_b_l1
);
138 per_cpu(free_l1_data_B_sram_head
, cpu
).next
->size
=
139 L1_DATA_B_LENGTH
- (_ebss_b_l1
- _sdata_b_l1
);
140 per_cpu(free_l1_data_B_sram_head
, cpu
).next
->pid
= 0;
141 per_cpu(free_l1_data_B_sram_head
, cpu
).next
->next
= NULL
;
143 per_cpu(used_l1_data_B_sram_head
, cpu
).next
= NULL
;
145 printk(KERN_INFO
"Blackfin L1 Data B SRAM: %d KB (%d KB free)\n",
146 L1_DATA_B_LENGTH
>> 10,
147 per_cpu(free_l1_data_B_sram_head
, cpu
).next
->size
>> 10);
148 /* mutex initialize */
152 #if L1_DATA_A_LENGTH != 0 || L1_DATA_B_LENGTH != 0
153 for (cpu
= 0; cpu
< num_possible_cpus(); ++cpu
)
154 spin_lock_init(&per_cpu(l1_data_sram_lock
, cpu
));
158 static void __init
l1_inst_sram_init(void)
160 #if L1_CODE_LENGTH != 0
162 for (cpu
= 0; cpu
< num_possible_cpus(); ++cpu
) {
163 per_cpu(free_l1_inst_sram_head
, cpu
).next
=
164 kmem_cache_alloc(sram_piece_cache
, GFP_KERNEL
);
165 if (!per_cpu(free_l1_inst_sram_head
, cpu
).next
) {
166 printk(KERN_INFO
"Failed to initialize L1 Instruction SRAM\n");
170 per_cpu(free_l1_inst_sram_head
, cpu
).next
->paddr
=
171 (void *)get_l1_code_start_cpu(cpu
) + (_etext_l1
- _stext_l1
);
172 per_cpu(free_l1_inst_sram_head
, cpu
).next
->size
=
173 L1_CODE_LENGTH
- (_etext_l1
- _stext_l1
);
174 per_cpu(free_l1_inst_sram_head
, cpu
).next
->pid
= 0;
175 per_cpu(free_l1_inst_sram_head
, cpu
).next
->next
= NULL
;
177 per_cpu(used_l1_inst_sram_head
, cpu
).next
= NULL
;
179 printk(KERN_INFO
"Blackfin L1 Instruction SRAM: %d KB (%d KB free)\n",
180 L1_CODE_LENGTH
>> 10,
181 per_cpu(free_l1_inst_sram_head
, cpu
).next
->size
>> 10);
183 /* mutex initialize */
184 spin_lock_init(&per_cpu(l1_inst_sram_lock
, cpu
));
190 static irqreturn_t
l2_ecc_err(int irq
, void *dev_id
)
194 printk(KERN_ERR
"L2 ecc error happened\n");
195 status
= bfin_read32(L2CTL0_STAT
);
197 printk(KERN_ERR
"Core channel error type:0x%x, addr:0x%x\n",
198 bfin_read32(L2CTL0_ET0
), bfin_read32(L2CTL0_EADDR0
));
200 printk(KERN_ERR
"System channel error type:0x%x, addr:0x%x\n",
201 bfin_read32(L2CTL0_ET1
), bfin_read32(L2CTL0_EADDR1
));
203 status
= status
>> 8;
205 printk(KERN_ERR
"L2 Bank%d error, addr:0x%x\n",
206 status
, bfin_read32(L2CTL0_ERRADDR0
+ status
));
208 panic("L2 Ecc error");
213 static void __init
l2_sram_init(void)
220 ret
= request_irq(IRQ_L2CTL0_ECC_ERR
, l2_ecc_err
, 0, "l2-ecc-err",
222 if (unlikely(ret
< 0)) {
223 printk(KERN_INFO
"Fail to request l2 ecc error interrupt");
228 free_l2_sram_head
.next
=
229 kmem_cache_alloc(sram_piece_cache
, GFP_KERNEL
);
230 if (!free_l2_sram_head
.next
) {
231 printk(KERN_INFO
"Fail to initialize L2 SRAM.\n");
235 free_l2_sram_head
.next
->paddr
=
236 (void *)L2_START
+ (_ebss_l2
- _stext_l2
);
237 free_l2_sram_head
.next
->size
=
238 L2_LENGTH
- (_ebss_l2
- _stext_l2
);
239 free_l2_sram_head
.next
->pid
= 0;
240 free_l2_sram_head
.next
->next
= NULL
;
242 used_l2_sram_head
.next
= NULL
;
244 printk(KERN_INFO
"Blackfin L2 SRAM: %d KB (%d KB free)\n",
246 free_l2_sram_head
.next
->size
>> 10);
248 /* mutex initialize */
249 spin_lock_init(&l2_sram_lock
);
253 static int __init
bfin_sram_init(void)
255 sram_piece_cache
= kmem_cache_create("sram_piece_cache",
256 sizeof(struct sram_piece
),
257 0, SLAB_PANIC
, NULL
);
266 pure_initcall(bfin_sram_init
);
268 /* SRAM allocate function */
269 static void *_sram_alloc(size_t size
, struct sram_piece
*pfree_head
,
270 struct sram_piece
*pused_head
)
272 struct sram_piece
*pslot
, *plast
, *pavail
;
274 if (size
<= 0 || !pfree_head
|| !pused_head
)
278 size
= (size
+ 3) & ~3;
280 pslot
= pfree_head
->next
;
283 /* search an available piece slot */
284 while (pslot
!= NULL
&& size
> pslot
->size
) {
292 if (pslot
->size
== size
) {
293 plast
->next
= pslot
->next
;
296 /* use atomic so our L1 allocator can be used atomically */
297 pavail
= kmem_cache_alloc(sram_piece_cache
, GFP_ATOMIC
);
302 pavail
->paddr
= pslot
->paddr
;
304 pslot
->paddr
+= size
;
308 pavail
->pid
= current
->pid
;
310 pslot
= pused_head
->next
;
313 /* insert new piece into used piece list !!! */
314 while (pslot
!= NULL
&& pavail
->paddr
< pslot
->paddr
) {
319 pavail
->next
= pslot
;
320 plast
->next
= pavail
;
322 return pavail
->paddr
;
325 /* Allocate the largest available block. */
326 static void *_sram_alloc_max(struct sram_piece
*pfree_head
,
327 struct sram_piece
*pused_head
,
328 unsigned long *psize
)
330 struct sram_piece
*pslot
, *pmax
;
332 if (!pfree_head
|| !pused_head
)
335 pmax
= pslot
= pfree_head
->next
;
337 /* search an available piece slot */
338 while (pslot
!= NULL
) {
339 if (pslot
->size
> pmax
->size
)
349 return _sram_alloc(*psize
, pfree_head
, pused_head
);
352 /* SRAM free function */
353 static int _sram_free(const void *addr
,
354 struct sram_piece
*pfree_head
,
355 struct sram_piece
*pused_head
)
357 struct sram_piece
*pslot
, *plast
, *pavail
;
359 if (!pfree_head
|| !pused_head
)
362 /* search the relevant memory slot */
363 pslot
= pused_head
->next
;
366 /* search an available piece slot */
367 while (pslot
!= NULL
&& pslot
->paddr
!= addr
) {
375 plast
->next
= pslot
->next
;
379 /* insert free pieces back to the free list */
380 pslot
= pfree_head
->next
;
383 while (pslot
!= NULL
&& addr
> pslot
->paddr
) {
388 if (plast
!= pfree_head
&& plast
->paddr
+ plast
->size
== pavail
->paddr
) {
389 plast
->size
+= pavail
->size
;
390 kmem_cache_free(sram_piece_cache
, pavail
);
392 pavail
->next
= plast
->next
;
393 plast
->next
= pavail
;
397 if (pslot
&& plast
->paddr
+ plast
->size
== pslot
->paddr
) {
398 plast
->size
+= pslot
->size
;
399 plast
->next
= pslot
->next
;
400 kmem_cache_free(sram_piece_cache
, pslot
);
406 int sram_free(const void *addr
)
409 #if L1_CODE_LENGTH != 0
410 if (addr
>= (void *)get_l1_code_start()
411 && addr
< (void *)(get_l1_code_start() + L1_CODE_LENGTH
))
412 return l1_inst_sram_free(addr
);
415 #if L1_DATA_A_LENGTH != 0
416 if (addr
>= (void *)get_l1_data_a_start()
417 && addr
< (void *)(get_l1_data_a_start() + L1_DATA_A_LENGTH
))
418 return l1_data_A_sram_free(addr
);
421 #if L1_DATA_B_LENGTH != 0
422 if (addr
>= (void *)get_l1_data_b_start()
423 && addr
< (void *)(get_l1_data_b_start() + L1_DATA_B_LENGTH
))
424 return l1_data_B_sram_free(addr
);
428 if (addr
>= (void *)L2_START
429 && addr
< (void *)(L2_START
+ L2_LENGTH
))
430 return l2_sram_free(addr
);
435 EXPORT_SYMBOL(sram_free
);
437 void *l1_data_A_sram_alloc(size_t size
)
439 #if L1_DATA_A_LENGTH != 0
444 cpu
= smp_processor_id();
445 /* add mutex operation */
446 spin_lock_irqsave(&per_cpu(l1_data_sram_lock
, cpu
), flags
);
448 addr
= _sram_alloc(size
, &per_cpu(free_l1_data_A_sram_head
, cpu
),
449 &per_cpu(used_l1_data_A_sram_head
, cpu
));
451 /* add mutex operation */
452 spin_unlock_irqrestore(&per_cpu(l1_data_sram_lock
, cpu
), flags
);
454 pr_debug("Allocated address in l1_data_A_sram_alloc is 0x%lx+0x%lx\n",
455 (long unsigned int)addr
, size
);
462 EXPORT_SYMBOL(l1_data_A_sram_alloc
);
464 int l1_data_A_sram_free(const void *addr
)
466 #if L1_DATA_A_LENGTH != 0
471 cpu
= smp_processor_id();
472 /* add mutex operation */
473 spin_lock_irqsave(&per_cpu(l1_data_sram_lock
, cpu
), flags
);
475 ret
= _sram_free(addr
, &per_cpu(free_l1_data_A_sram_head
, cpu
),
476 &per_cpu(used_l1_data_A_sram_head
, cpu
));
478 /* add mutex operation */
479 spin_unlock_irqrestore(&per_cpu(l1_data_sram_lock
, cpu
), flags
);
486 EXPORT_SYMBOL(l1_data_A_sram_free
);
488 void *l1_data_B_sram_alloc(size_t size
)
490 #if L1_DATA_B_LENGTH != 0
495 cpu
= smp_processor_id();
496 /* add mutex operation */
497 spin_lock_irqsave(&per_cpu(l1_data_sram_lock
, cpu
), flags
);
499 addr
= _sram_alloc(size
, &per_cpu(free_l1_data_B_sram_head
, cpu
),
500 &per_cpu(used_l1_data_B_sram_head
, cpu
));
502 /* add mutex operation */
503 spin_unlock_irqrestore(&per_cpu(l1_data_sram_lock
, cpu
), flags
);
505 pr_debug("Allocated address in l1_data_B_sram_alloc is 0x%lx+0x%lx\n",
506 (long unsigned int)addr
, size
);
513 EXPORT_SYMBOL(l1_data_B_sram_alloc
);
515 int l1_data_B_sram_free(const void *addr
)
517 #if L1_DATA_B_LENGTH != 0
522 cpu
= smp_processor_id();
523 /* add mutex operation */
524 spin_lock_irqsave(&per_cpu(l1_data_sram_lock
, cpu
), flags
);
526 ret
= _sram_free(addr
, &per_cpu(free_l1_data_B_sram_head
, cpu
),
527 &per_cpu(used_l1_data_B_sram_head
, cpu
));
529 /* add mutex operation */
530 spin_unlock_irqrestore(&per_cpu(l1_data_sram_lock
, cpu
), flags
);
537 EXPORT_SYMBOL(l1_data_B_sram_free
);
539 void *l1_data_sram_alloc(size_t size
)
541 void *addr
= l1_data_A_sram_alloc(size
);
544 addr
= l1_data_B_sram_alloc(size
);
548 EXPORT_SYMBOL(l1_data_sram_alloc
);
550 void *l1_data_sram_zalloc(size_t size
)
552 void *addr
= l1_data_sram_alloc(size
);
555 memset(addr
, 0x00, size
);
559 EXPORT_SYMBOL(l1_data_sram_zalloc
);
561 int l1_data_sram_free(const void *addr
)
564 ret
= l1_data_A_sram_free(addr
);
566 ret
= l1_data_B_sram_free(addr
);
569 EXPORT_SYMBOL(l1_data_sram_free
);
571 void *l1_inst_sram_alloc(size_t size
)
573 #if L1_CODE_LENGTH != 0
578 cpu
= smp_processor_id();
579 /* add mutex operation */
580 spin_lock_irqsave(&per_cpu(l1_inst_sram_lock
, cpu
), flags
);
582 addr
= _sram_alloc(size
, &per_cpu(free_l1_inst_sram_head
, cpu
),
583 &per_cpu(used_l1_inst_sram_head
, cpu
));
585 /* add mutex operation */
586 spin_unlock_irqrestore(&per_cpu(l1_inst_sram_lock
, cpu
), flags
);
588 pr_debug("Allocated address in l1_inst_sram_alloc is 0x%lx+0x%lx\n",
589 (long unsigned int)addr
, size
);
596 EXPORT_SYMBOL(l1_inst_sram_alloc
);
598 int l1_inst_sram_free(const void *addr
)
600 #if L1_CODE_LENGTH != 0
605 cpu
= smp_processor_id();
606 /* add mutex operation */
607 spin_lock_irqsave(&per_cpu(l1_inst_sram_lock
, cpu
), flags
);
609 ret
= _sram_free(addr
, &per_cpu(free_l1_inst_sram_head
, cpu
),
610 &per_cpu(used_l1_inst_sram_head
, cpu
));
612 /* add mutex operation */
613 spin_unlock_irqrestore(&per_cpu(l1_inst_sram_lock
, cpu
), flags
);
620 EXPORT_SYMBOL(l1_inst_sram_free
);
622 /* L1 Scratchpad memory allocate function */
623 void *l1sram_alloc(size_t size
)
629 cpu
= smp_processor_id();
630 /* add mutex operation */
631 spin_lock_irqsave(&per_cpu(l1sram_lock
, cpu
), flags
);
633 addr
= _sram_alloc(size
, &per_cpu(free_l1_ssram_head
, cpu
),
634 &per_cpu(used_l1_ssram_head
, cpu
));
636 /* add mutex operation */
637 spin_unlock_irqrestore(&per_cpu(l1sram_lock
, cpu
), flags
);
642 /* L1 Scratchpad memory allocate function */
643 void *l1sram_alloc_max(size_t *psize
)
649 cpu
= smp_processor_id();
650 /* add mutex operation */
651 spin_lock_irqsave(&per_cpu(l1sram_lock
, cpu
), flags
);
653 addr
= _sram_alloc_max(&per_cpu(free_l1_ssram_head
, cpu
),
654 &per_cpu(used_l1_ssram_head
, cpu
), psize
);
656 /* add mutex operation */
657 spin_unlock_irqrestore(&per_cpu(l1sram_lock
, cpu
), flags
);
662 /* L1 Scratchpad memory free function */
663 int l1sram_free(const void *addr
)
669 cpu
= smp_processor_id();
670 /* add mutex operation */
671 spin_lock_irqsave(&per_cpu(l1sram_lock
, cpu
), flags
);
673 ret
= _sram_free(addr
, &per_cpu(free_l1_ssram_head
, cpu
),
674 &per_cpu(used_l1_ssram_head
, cpu
));
676 /* add mutex operation */
677 spin_unlock_irqrestore(&per_cpu(l1sram_lock
, cpu
), flags
);
682 void *l2_sram_alloc(size_t size
)
688 /* add mutex operation */
689 spin_lock_irqsave(&l2_sram_lock
, flags
);
691 addr
= _sram_alloc(size
, &free_l2_sram_head
,
694 /* add mutex operation */
695 spin_unlock_irqrestore(&l2_sram_lock
, flags
);
697 pr_debug("Allocated address in l2_sram_alloc is 0x%lx+0x%lx\n",
698 (long unsigned int)addr
, size
);
705 EXPORT_SYMBOL(l2_sram_alloc
);
707 void *l2_sram_zalloc(size_t size
)
709 void *addr
= l2_sram_alloc(size
);
712 memset(addr
, 0x00, size
);
716 EXPORT_SYMBOL(l2_sram_zalloc
);
718 int l2_sram_free(const void *addr
)
724 /* add mutex operation */
725 spin_lock_irqsave(&l2_sram_lock
, flags
);
727 ret
= _sram_free(addr
, &free_l2_sram_head
,
730 /* add mutex operation */
731 spin_unlock_irqrestore(&l2_sram_lock
, flags
);
738 EXPORT_SYMBOL(l2_sram_free
);
740 int sram_free_with_lsl(const void *addr
)
742 struct sram_list_struct
*lsl
, **tmp
;
743 struct mm_struct
*mm
= current
->mm
;
746 for (tmp
= &mm
->context
.sram_list
; *tmp
; tmp
= &(*tmp
)->next
)
747 if ((*tmp
)->addr
== addr
) {
749 ret
= sram_free(addr
);
757 EXPORT_SYMBOL(sram_free_with_lsl
);
759 /* Allocate memory and keep in L1 SRAM List (lsl) so that the resources are
760 * tracked. These are designed for userspace so that when a process exits,
761 * we can safely reap their resources.
763 void *sram_alloc_with_lsl(size_t size
, unsigned long flags
)
766 struct sram_list_struct
*lsl
= NULL
;
767 struct mm_struct
*mm
= current
->mm
;
769 lsl
= kzalloc(sizeof(struct sram_list_struct
), GFP_KERNEL
);
773 if (flags
& L1_INST_SRAM
)
774 addr
= l1_inst_sram_alloc(size
);
776 if (addr
== NULL
&& (flags
& L1_DATA_A_SRAM
))
777 addr
= l1_data_A_sram_alloc(size
);
779 if (addr
== NULL
&& (flags
& L1_DATA_B_SRAM
))
780 addr
= l1_data_B_sram_alloc(size
);
782 if (addr
== NULL
&& (flags
& L2_SRAM
))
783 addr
= l2_sram_alloc(size
);
791 lsl
->next
= mm
->context
.sram_list
;
792 mm
->context
.sram_list
= lsl
;
795 EXPORT_SYMBOL(sram_alloc_with_lsl
);
797 #ifdef CONFIG_PROC_FS
798 /* Once we get a real allocator, we'll throw all of this away.
799 * Until then, we need some sort of visibility into the L1 alloc.
801 /* Need to keep line of output the same. Currently, that is 44 bytes
802 * (including newline).
804 static int _sram_proc_show(struct seq_file
*m
, const char *desc
,
805 struct sram_piece
*pfree_head
,
806 struct sram_piece
*pused_head
)
808 struct sram_piece
*pslot
;
810 if (!pfree_head
|| !pused_head
)
813 seq_printf(m
, "--- SRAM %-14s Size PID State \n", desc
);
815 /* search the relevant memory slot */
816 pslot
= pused_head
->next
;
818 while (pslot
!= NULL
) {
819 seq_printf(m
, "%p-%p %10i %5i %-10s\n",
820 pslot
->paddr
, pslot
->paddr
+ pslot
->size
,
821 pslot
->size
, pslot
->pid
, "ALLOCATED");
826 pslot
= pfree_head
->next
;
828 while (pslot
!= NULL
) {
829 seq_printf(m
, "%p-%p %10i %5i %-10s\n",
830 pslot
->paddr
, pslot
->paddr
+ pslot
->size
,
831 pslot
->size
, pslot
->pid
, "FREE");
838 static int sram_proc_show(struct seq_file
*m
, void *v
)
842 for (cpu
= 0; cpu
< num_possible_cpus(); ++cpu
) {
843 if (_sram_proc_show(m
, "Scratchpad",
844 &per_cpu(free_l1_ssram_head
, cpu
), &per_cpu(used_l1_ssram_head
, cpu
)))
846 #if L1_DATA_A_LENGTH != 0
847 if (_sram_proc_show(m
, "L1 Data A",
848 &per_cpu(free_l1_data_A_sram_head
, cpu
),
849 &per_cpu(used_l1_data_A_sram_head
, cpu
)))
852 #if L1_DATA_B_LENGTH != 0
853 if (_sram_proc_show(m
, "L1 Data B",
854 &per_cpu(free_l1_data_B_sram_head
, cpu
),
855 &per_cpu(used_l1_data_B_sram_head
, cpu
)))
858 #if L1_CODE_LENGTH != 0
859 if (_sram_proc_show(m
, "L1 Instruction",
860 &per_cpu(free_l1_inst_sram_head
, cpu
),
861 &per_cpu(used_l1_inst_sram_head
, cpu
)))
866 if (_sram_proc_show(m
, "L2", &free_l2_sram_head
, &used_l2_sram_head
))
873 static int sram_proc_open(struct inode
*inode
, struct file
*file
)
875 return single_open(file
, sram_proc_show
, NULL
);
878 static const struct file_operations sram_proc_ops
= {
879 .open
= sram_proc_open
,
882 .release
= single_release
,
885 static int __init
sram_proc_init(void)
887 struct proc_dir_entry
*ptr
;
889 ptr
= proc_create("sram", S_IRUGO
, NULL
, &sram_proc_ops
);
891 printk(KERN_WARNING
"unable to create /proc/sram\n");
896 late_initcall(sram_proc_init
);