diff options
author | Mike Frysinger <michael.frysinger@analog.com> | 2007-06-14 01:21:08 -0400 |
---|---|---|
committer | Bryan Wu <bryan.wu@analog.com> | 2007-06-14 01:21:08 -0400 |
commit | bc61b4e69d26a1b9627d52ab45064eee9284aa72 (patch) | |
tree | 60c50e9bf22c5db4baa32fc098cf9ad8d2062872 /arch/blackfin/mm/blackfin_sram.c | |
parent | 321f6e0f5183e489448ae61af79cca1b7fe43e88 (diff) |
Blackfin arch: implement a basic /proc/sram file for L1 allocation visibility
implement a basic /proc/sram file for L1 allocation visibility until we can
rewrite the entire L1 allocator (which would include a proper mechanism)
Signed-off-by: Mike Frysinger <michael.frysinger@analog.com>
Signed-off-by: Bryan Wu <bryan.wu@analog.com>
Diffstat (limited to 'arch/blackfin/mm/blackfin_sram.c')
-rw-r--r-- | arch/blackfin/mm/blackfin_sram.c | 92 |
1 files changed, 80 insertions, 12 deletions
diff --git a/arch/blackfin/mm/blackfin_sram.c b/arch/blackfin/mm/blackfin_sram.c index 024176411473..dbb37b8854f5 100644 --- a/arch/blackfin/mm/blackfin_sram.c +++ b/arch/blackfin/mm/blackfin_sram.c | |||
@@ -63,6 +63,7 @@ struct l1_sram_piece { | |||
63 | void *paddr; | 63 | void *paddr; |
64 | int size; | 64 | int size; |
65 | int flag; | 65 | int flag; |
66 | pid_t pid; | ||
66 | }; | 67 | }; |
67 | 68 | ||
68 | static struct l1_sram_piece l1_ssram[CONFIG_L1_MAX_PIECE]; | 69 | static struct l1_sram_piece l1_ssram[CONFIG_L1_MAX_PIECE]; |
@@ -97,23 +98,23 @@ void __init l1sram_init(void) | |||
97 | void __init l1_data_sram_init(void) | 98 | void __init l1_data_sram_init(void) |
98 | { | 99 | { |
99 | #if L1_DATA_A_LENGTH != 0 | 100 | #if L1_DATA_A_LENGTH != 0 |
100 | printk(KERN_INFO "Blackfin DATA_A SRAM: %d KB\n", | ||
101 | L1_DATA_A_LENGTH >> 10); | ||
102 | |||
103 | memset(&l1_data_A_sram, 0x00, sizeof(l1_data_A_sram)); | 101 | memset(&l1_data_A_sram, 0x00, sizeof(l1_data_A_sram)); |
104 | l1_data_A_sram[0].paddr = (void*)L1_DATA_A_START + | 102 | l1_data_A_sram[0].paddr = (void *)L1_DATA_A_START + |
105 | (_ebss_l1 - _sdata_l1); | 103 | (_ebss_l1 - _sdata_l1); |
106 | l1_data_A_sram[0].size = L1_DATA_A_LENGTH - (_ebss_l1 - _sdata_l1); | 104 | l1_data_A_sram[0].size = L1_DATA_A_LENGTH - (_ebss_l1 - _sdata_l1); |
107 | l1_data_A_sram[0].flag = SRAM_SLT_FREE; | 105 | l1_data_A_sram[0].flag = SRAM_SLT_FREE; |
106 | |||
107 | printk(KERN_INFO "Blackfin Data A SRAM: %d KB (%d KB free)\n", | ||
108 | L1_DATA_A_LENGTH >> 10, l1_data_A_sram[0].size >> 10); | ||
108 | #endif | 109 | #endif |
109 | #if L1_DATA_B_LENGTH != 0 | 110 | #if L1_DATA_B_LENGTH != 0 |
110 | printk(KERN_INFO "Blackfin DATA_B SRAM: %d KB\n", | ||
111 | L1_DATA_B_LENGTH >> 10); | ||
112 | |||
113 | memset(&l1_data_B_sram, 0x00, sizeof(l1_data_B_sram)); | 111 | memset(&l1_data_B_sram, 0x00, sizeof(l1_data_B_sram)); |
114 | l1_data_B_sram[0].paddr = (void*)L1_DATA_B_START; | 112 | l1_data_B_sram[0].paddr = (void*)L1_DATA_B_START; |
115 | l1_data_B_sram[0].size = L1_DATA_B_LENGTH; | 113 | l1_data_B_sram[0].size = L1_DATA_B_LENGTH; |
116 | l1_data_B_sram[0].flag = SRAM_SLT_FREE; | 114 | l1_data_B_sram[0].flag = SRAM_SLT_FREE; |
115 | |||
116 | printk(KERN_INFO "Blackfin Data B SRAM: %d KB (%d KB free)\n", | ||
117 | L1_DATA_B_LENGTH >> 10, l1_data_B_sram[0].size >> 10); | ||
117 | #endif | 118 | #endif |
118 | 119 | ||
119 | /* mutex initialize */ | 120 | /* mutex initialize */ |
@@ -123,13 +124,13 @@ void __init l1_data_sram_init(void) | |||
123 | void __init l1_inst_sram_init(void) | 124 | void __init l1_inst_sram_init(void) |
124 | { | 125 | { |
125 | #if L1_CODE_LENGTH != 0 | 126 | #if L1_CODE_LENGTH != 0 |
126 | printk(KERN_INFO "Blackfin Instruction SRAM: %d KB\n", | ||
127 | L1_CODE_LENGTH >> 10); | ||
128 | |||
129 | memset(&l1_inst_sram, 0x00, sizeof(l1_inst_sram)); | 127 | memset(&l1_inst_sram, 0x00, sizeof(l1_inst_sram)); |
130 | l1_inst_sram[0].paddr = (void*)L1_CODE_START + (_etext_l1 - _stext_l1); | 128 | l1_inst_sram[0].paddr = (void*)L1_CODE_START + (_etext_l1 - _stext_l1); |
131 | l1_inst_sram[0].size = L1_CODE_LENGTH - (_etext_l1 - _stext_l1); | 129 | l1_inst_sram[0].size = L1_CODE_LENGTH - (_etext_l1 - _stext_l1); |
132 | l1_inst_sram[0].flag = SRAM_SLT_FREE; | 130 | l1_inst_sram[0].flag = SRAM_SLT_FREE; |
131 | |||
132 | printk(KERN_INFO "Blackfin Instruction SRAM: %d KB (%d KB free)\n", | ||
133 | L1_CODE_LENGTH >> 10, l1_inst_sram[0].size >> 10); | ||
133 | #endif | 134 | #endif |
134 | 135 | ||
135 | /* mutex initialize */ | 136 | /* mutex initialize */ |
@@ -155,6 +156,7 @@ static void *_l1_sram_alloc(size_t size, struct l1_sram_piece *pfree, int count) | |||
155 | && (pfree[i].size >= size)) { | 156 | && (pfree[i].size >= size)) { |
156 | addr = pfree[i].paddr; | 157 | addr = pfree[i].paddr; |
157 | pfree[i].flag = SRAM_SLT_ALLOCATED; | 158 | pfree[i].flag = SRAM_SLT_ALLOCATED; |
159 | pfree[i].pid = current->pid; | ||
158 | index = i; | 160 | index = i; |
159 | break; | 161 | break; |
160 | } | 162 | } |
@@ -166,6 +168,7 @@ static void *_l1_sram_alloc(size_t size, struct l1_sram_piece *pfree, int count) | |||
166 | if (pfree[i].size > size) { | 168 | if (pfree[i].size > size) { |
167 | for (i = 0; i < count; i++) { | 169 | for (i = 0; i < count; i++) { |
168 | if (pfree[i].flag == SRAM_SLT_NULL) { | 170 | if (pfree[i].flag == SRAM_SLT_NULL) { |
171 | pfree[i].pid = 0; | ||
169 | pfree[i].flag = SRAM_SLT_FREE; | 172 | pfree[i].flag = SRAM_SLT_FREE; |
170 | pfree[i].paddr = addr + size; | 173 | pfree[i].paddr = addr + size; |
171 | pfree[i].size = pfree[index].size - size; | 174 | pfree[i].size = pfree[index].size - size; |
@@ -198,13 +201,15 @@ static void *_l1_sram_alloc_max(struct l1_sram_piece *pfree, int count, | |||
198 | return NULL; | 201 | return NULL; |
199 | *psize = best; | 202 | *psize = best; |
200 | 203 | ||
204 | pfree[index].pid = current->pid; | ||
201 | pfree[index].flag = SRAM_SLT_ALLOCATED; | 205 | pfree[index].flag = SRAM_SLT_ALLOCATED; |
202 | return addr; | 206 | return addr; |
203 | } | 207 | } |
204 | 208 | ||
205 | /* L1 memory free function */ | 209 | /* L1 memory free function */ |
206 | static int _l1_sram_free(const void *addr, | 210 | static int _l1_sram_free(const void *addr, |
207 | struct l1_sram_piece *pfree, int count) | 211 | struct l1_sram_piece *pfree, |
212 | int count) | ||
208 | { | 213 | { |
209 | int i, index = 0; | 214 | int i, index = 0; |
210 | 215 | ||
@@ -222,12 +227,14 @@ static int _l1_sram_free(const void *addr, | |||
222 | if (i >= count) | 227 | if (i >= count) |
223 | return -1; | 228 | return -1; |
224 | 229 | ||
230 | pfree[index].pid = 0; | ||
225 | pfree[index].flag = SRAM_SLT_FREE; | 231 | pfree[index].flag = SRAM_SLT_FREE; |
226 | 232 | ||
227 | /* link the next address slot */ | 233 | /* link the next address slot */ |
228 | for (i = 0; i < count; i++) { | 234 | for (i = 0; i < count; i++) { |
229 | if (((pfree[index].paddr + pfree[index].size) == pfree[i].paddr) | 235 | if (((pfree[index].paddr + pfree[index].size) == pfree[i].paddr) |
230 | && (pfree[i].flag == SRAM_SLT_FREE)) { | 236 | && (pfree[i].flag == SRAM_SLT_FREE)) { |
237 | pfree[i].pid = 0; | ||
231 | pfree[i].flag = SRAM_SLT_NULL; | 238 | pfree[i].flag = SRAM_SLT_NULL; |
232 | pfree[index].size += pfree[i].size; | 239 | pfree[index].size += pfree[i].size; |
233 | pfree[index].flag = SRAM_SLT_FREE; | 240 | pfree[index].flag = SRAM_SLT_FREE; |
@@ -538,3 +545,64 @@ void *sram_alloc_with_lsl(size_t size, unsigned long flags) | |||
538 | return addr; | 545 | return addr; |
539 | } | 546 | } |
540 | EXPORT_SYMBOL(sram_alloc_with_lsl); | 547 | EXPORT_SYMBOL(sram_alloc_with_lsl); |
548 | |||
549 | #ifdef CONFIG_PROC_FS | ||
550 | /* Once we get a real allocator, we'll throw all of this away. | ||
551 | * Until then, we need some sort of visibility into the L1 alloc. | ||
552 | */ | ||
553 | static void _l1sram_proc_read(char *buf, int *len, const char *desc, | ||
554 | struct l1_sram_piece *pfree, const int array_size) | ||
555 | { | ||
556 | int i; | ||
557 | |||
558 | *len += sprintf(&buf[*len], "--- L1 %-14s Size PID State\n", desc); | ||
559 | for (i = 0; i < array_size; ++i) { | ||
560 | const char *alloc_type; | ||
561 | switch (pfree[i].flag) { | ||
562 | case SRAM_SLT_NULL: alloc_type = "NULL"; break; | ||
563 | case SRAM_SLT_FREE: alloc_type = "FREE"; break; | ||
564 | case SRAM_SLT_ALLOCATED: alloc_type = "ALLOCATED"; break; | ||
565 | default: alloc_type = "????"; break; | ||
566 | } | ||
567 | *len += sprintf(&buf[*len], "%p-%p %8i %4i %s\n", | ||
568 | pfree[i].paddr, pfree[i].paddr + pfree[i].size, | ||
569 | pfree[i].size, pfree[i].pid, alloc_type); | ||
570 | } | ||
571 | } | ||
572 | static int l1sram_proc_read(char *buf, char **start, off_t offset, int count, | ||
573 | int *eof, void *data) | ||
574 | { | ||
575 | int len = 0; | ||
576 | |||
577 | _l1sram_proc_read(buf, &len, "Scratchpad", | ||
578 | l1_ssram, ARRAY_SIZE(l1_ssram)); | ||
579 | #if L1_DATA_A_LENGTH != 0 | ||
580 | _l1sram_proc_read(buf, &len, "Data A", | ||
581 | l1_data_A_sram, ARRAY_SIZE(l1_data_A_sram)); | ||
582 | #endif | ||
583 | #if L1_DATA_B_LENGTH != 0 | ||
584 | _l1sram_proc_read(buf, &len, "Data B", | ||
585 | l1_data_B_sram, ARRAY_SIZE(l1_data_B_sram)); | ||
586 | #endif | ||
587 | #if L1_CODE_LENGTH != 0 | ||
588 | _l1sram_proc_read(buf, &len, "Instruction", | ||
589 | l1_inst_sram, ARRAY_SIZE(l1_inst_sram)); | ||
590 | #endif | ||
591 | |||
592 | return len; | ||
593 | } | ||
594 | |||
595 | static int __init l1sram_proc_init(void) | ||
596 | { | ||
597 | struct proc_dir_entry *ptr; | ||
598 | ptr = create_proc_entry("sram", S_IFREG | S_IRUGO, NULL); | ||
599 | if (!ptr) { | ||
600 | printk(KERN_WARNING "unable to create /proc/sram\n"); | ||
601 | return -1; | ||
602 | } | ||
603 | ptr->owner = THIS_MODULE; | ||
604 | ptr->read_proc = l1sram_proc_read; | ||
605 | return 0; | ||
606 | } | ||
607 | late_initcall(l1sram_proc_init); | ||
608 | #endif | ||