9 #include <linux/module.h>
10 #include <linux/kernel.h>
11 #include <linux/types.h>
14 #include <linux/fcntl.h>
16 #include <linux/poll.h>
20 #include <linux/rtc.h>
21 #include <linux/slab.h>
38 #if L1_DATA_A_LENGTH != 0
43 #if L1_DATA_B_LENGTH != 0
48 #if L1_DATA_A_LENGTH || L1_DATA_B_LENGTH
52 #if L1_CODE_LENGTH != 0
60 static struct sram_piece free_l2_sram_head, used_l2_sram_head;
66 static void __init l1sram_init(
void)
78 per_cpu(free_l1_ssram_head, cpu).next =
85 per_cpu(free_l1_ssram_head, cpu).next->paddr = (
void *)get_l1_scratch_start_cpu(cpu) +
reserve;
87 per_cpu(free_l1_ssram_head, cpu).next->pid = 0;
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
106 per_cpu(free_l1_data_A_sram_head, cpu).next =
108 if (!
per_cpu(free_l1_data_A_sram_head, cpu).next) {
113 per_cpu(free_l1_data_A_sram_head, cpu).next->paddr =
115 per_cpu(free_l1_data_A_sram_head, cpu).next->size =
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;
124 per_cpu(free_l1_data_A_sram_head, cpu).next->size >> 10);
127 #if L1_DATA_B_LENGTH != 0
129 per_cpu(free_l1_data_B_sram_head, cpu).next =
131 if (!
per_cpu(free_l1_data_B_sram_head, cpu).next) {
136 per_cpu(free_l1_data_B_sram_head, cpu).next->paddr =
138 per_cpu(free_l1_data_B_sram_head, cpu).next->size =
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;
147 per_cpu(free_l1_data_B_sram_head, cpu).next->size >> 10);
152 #if L1_DATA_A_LENGTH != 0 || L1_DATA_B_LENGTH != 0
158 static void __init l1_inst_sram_init(
void)
160 #if L1_CODE_LENGTH != 0
163 per_cpu(free_l1_inst_sram_head, cpu).next =
165 if (!
per_cpu(free_l1_inst_sram_head, cpu).next) {
170 per_cpu(free_l1_inst_sram_head, cpu).next->paddr =
172 per_cpu(free_l1_inst_sram_head, cpu).next->size =
174 per_cpu(free_l1_inst_sram_head, cpu).next->pid = 0;
175 per_cpu(free_l1_inst_sram_head, cpu).next->next =
NULL;
181 per_cpu(free_l1_inst_sram_head, cpu).next->size >> 10);
203 status = status >> 8;
208 panic(
"L2 Ecc error");
213 static void __init l2_sram_init(
void)
228 free_l2_sram_head.next =
230 if (!free_l2_sram_head.next) {
235 free_l2_sram_head.next->paddr =
236 (
void *)
L2_START + (_ebss_l2 - _stext_l2);
237 free_l2_sram_head.next->size =
239 free_l2_sram_head.next->pid = 0;
240 free_l2_sram_head.next->next =
NULL;
242 used_l2_sram_head.next =
NULL;
246 free_l2_sram_head.next->size >> 10);
253 static int __init bfin_sram_init(
void)
269 static void *_sram_alloc(
size_t size,
struct sram_piece *pfree_head,
274 if (size <= 0 || !pfree_head || !pused_head)
278 size = (size + 3) & ~3;
280 pslot = pfree_head->
next;
284 while (pslot !=
NULL && size > pslot->
size) {
292 if (pslot->
size == size) {
310 pslot = pused_head->
next;
319 pavail->
next = pslot;
320 plast->
next = pavail;
322 return pavail->
paddr;
326 static void *_sram_alloc_max(
struct sram_piece *pfree_head,
328 unsigned long *psize)
332 if (!pfree_head || !pused_head)
335 pmax = pslot = pfree_head->
next;
338 while (pslot !=
NULL) {
349 return _sram_alloc(*psize, pfree_head, pused_head);
353 static int _sram_free(
const void *
addr,
359 if (!pfree_head || !pused_head)
363 pslot = pused_head->
next;
367 while (pslot !=
NULL && pslot->
paddr != addr) {
380 pslot = pfree_head->
next;
383 while (pslot !=
NULL && addr > pslot->
paddr) {
388 if (plast != pfree_head && plast->
paddr + plast->
size == pavail->
paddr) {
393 plast->
next = pavail;
409 #if L1_CODE_LENGTH != 0
410 if (addr >= (
void *)get_l1_code_start()
415 #if L1_DATA_A_LENGTH != 0
416 if (addr >= (
void *)get_l1_data_a_start()
421 #if L1_DATA_B_LENGTH != 0
422 if (addr >= (
void *)get_l1_data_b_start()
439 #if L1_DATA_A_LENGTH != 0
448 addr = _sram_alloc(size, &
per_cpu(free_l1_data_A_sram_head, cpu),
449 &
per_cpu(used_l1_data_A_sram_head, cpu));
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);
466 #if L1_DATA_A_LENGTH != 0
475 ret = _sram_free(addr, &
per_cpu(free_l1_data_A_sram_head, cpu),
476 &
per_cpu(used_l1_data_A_sram_head, cpu));
479 spin_unlock_irqrestore(&
per_cpu(l1_data_sram_lock, cpu), flags);
490 #if L1_DATA_B_LENGTH != 0
499 addr = _sram_alloc(size, &
per_cpu(free_l1_data_B_sram_head, cpu),
500 &
per_cpu(used_l1_data_B_sram_head, cpu));
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);
517 #if L1_DATA_B_LENGTH != 0
526 ret = _sram_free(addr, &
per_cpu(free_l1_data_B_sram_head, cpu),
527 &
per_cpu(used_l1_data_B_sram_head, cpu));
530 spin_unlock_irqrestore(&
per_cpu(l1_data_sram_lock, cpu), flags);
573 #if L1_CODE_LENGTH != 0
582 addr = _sram_alloc(size, &
per_cpu(free_l1_inst_sram_head, cpu),
583 &
per_cpu(used_l1_inst_sram_head, cpu));
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);
600 #if L1_CODE_LENGTH != 0
609 ret = _sram_free(addr, &
per_cpu(free_l1_inst_sram_head, cpu),
610 &
per_cpu(used_l1_inst_sram_head, cpu));
613 spin_unlock_irqrestore(&
per_cpu(l1_inst_sram_lock, cpu), flags);
633 addr = _sram_alloc(size, &
per_cpu(free_l1_ssram_head, cpu),
634 &
per_cpu(used_l1_ssram_head, cpu));
637 spin_unlock_irqrestore(&
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);
657 spin_unlock_irqrestore(&
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));
677 spin_unlock_irqrestore(&
per_cpu(l1sram_lock, cpu), flags);
691 addr = _sram_alloc(size, &free_l2_sram_head,
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);
727 ret = _sram_free(addr, &free_l2_sram_head,
731 spin_unlock_irqrestore(&l2_sram_lock, flags);
747 if ((*tmp)->addr == addr) {
797 #ifdef CONFIG_PROC_FS
804 static int _sram_proc_show(
struct seq_file *
m,
const char *
desc,
810 if (!pfree_head || !pused_head)
813 seq_printf(m,
"--- SRAM %-14s Size PID State \n", desc);
816 pslot = pused_head->
next;
818 while (pslot !=
NULL) {
821 pslot->
size, pslot->
pid,
"ALLOCATED");
826 pslot = pfree_head->
next;
828 while (pslot !=
NULL) {
831 pslot->
size, pslot->
pid,
"FREE");
838 static int sram_proc_show(
struct seq_file *m,
void *
v)
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))
879 .
open = sram_proc_open,
885 static int __init sram_proc_init(
void)
889 ptr = proc_create(
"sram",
S_IRUGO,
NULL, &sram_proc_ops);