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>
This commit is contained in:
Mike Frysinger 2007-06-14 13:21:08 +08:00 committed by Bryan Wu
parent 321f6e0f51
commit bc61b4e69d
1 changed files with 80 additions and 12 deletions

View File

@ -63,6 +63,7 @@ struct l1_sram_piece {
void *paddr;
int size;
int flag;
pid_t pid;
};
static struct l1_sram_piece l1_ssram[CONFIG_L1_MAX_PIECE];
@ -97,23 +98,23 @@ void __init l1sram_init(void)
void __init l1_data_sram_init(void)
{
#if L1_DATA_A_LENGTH != 0
printk(KERN_INFO "Blackfin DATA_A SRAM: %d KB\n",
L1_DATA_A_LENGTH >> 10);
memset(&l1_data_A_sram, 0x00, sizeof(l1_data_A_sram));
l1_data_A_sram[0].paddr = (void*)L1_DATA_A_START +
l1_data_A_sram[0].paddr = (void *)L1_DATA_A_START +
(_ebss_l1 - _sdata_l1);
l1_data_A_sram[0].size = L1_DATA_A_LENGTH - (_ebss_l1 - _sdata_l1);
l1_data_A_sram[0].flag = SRAM_SLT_FREE;
printk(KERN_INFO "Blackfin Data A SRAM: %d KB (%d KB free)\n",
L1_DATA_A_LENGTH >> 10, l1_data_A_sram[0].size >> 10);
#endif
#if L1_DATA_B_LENGTH != 0
printk(KERN_INFO "Blackfin DATA_B SRAM: %d KB\n",
L1_DATA_B_LENGTH >> 10);
memset(&l1_data_B_sram, 0x00, sizeof(l1_data_B_sram));
l1_data_B_sram[0].paddr = (void*)L1_DATA_B_START;
l1_data_B_sram[0].size = L1_DATA_B_LENGTH;
l1_data_B_sram[0].flag = SRAM_SLT_FREE;
printk(KERN_INFO "Blackfin Data B SRAM: %d KB (%d KB free)\n",
L1_DATA_B_LENGTH >> 10, l1_data_B_sram[0].size >> 10);
#endif
/* mutex initialize */
@ -123,13 +124,13 @@ void __init l1_data_sram_init(void)
void __init l1_inst_sram_init(void)
{
#if L1_CODE_LENGTH != 0
printk(KERN_INFO "Blackfin Instruction SRAM: %d KB\n",
L1_CODE_LENGTH >> 10);
memset(&l1_inst_sram, 0x00, sizeof(l1_inst_sram));
l1_inst_sram[0].paddr = (void*)L1_CODE_START + (_etext_l1 - _stext_l1);
l1_inst_sram[0].size = L1_CODE_LENGTH - (_etext_l1 - _stext_l1);
l1_inst_sram[0].flag = SRAM_SLT_FREE;
printk(KERN_INFO "Blackfin Instruction SRAM: %d KB (%d KB free)\n",
L1_CODE_LENGTH >> 10, l1_inst_sram[0].size >> 10);
#endif
/* mutex initialize */
@ -155,6 +156,7 @@ static void *_l1_sram_alloc(size_t size, struct l1_sram_piece *pfree, int count)
&& (pfree[i].size >= size)) {
addr = pfree[i].paddr;
pfree[i].flag = SRAM_SLT_ALLOCATED;
pfree[i].pid = current->pid;
index = i;
break;
}
@ -166,6 +168,7 @@ static void *_l1_sram_alloc(size_t size, struct l1_sram_piece *pfree, int count)
if (pfree[i].size > size) {
for (i = 0; i < count; i++) {
if (pfree[i].flag == SRAM_SLT_NULL) {
pfree[i].pid = 0;
pfree[i].flag = SRAM_SLT_FREE;
pfree[i].paddr = addr + size;
pfree[i].size = pfree[index].size - size;
@ -198,13 +201,15 @@ static void *_l1_sram_alloc_max(struct l1_sram_piece *pfree, int count,
return NULL;
*psize = best;
pfree[index].pid = current->pid;
pfree[index].flag = SRAM_SLT_ALLOCATED;
return addr;
}
/* L1 memory free function */
static int _l1_sram_free(const void *addr,
struct l1_sram_piece *pfree, int count)
struct l1_sram_piece *pfree,
int count)
{
int i, index = 0;
@ -222,12 +227,14 @@ static int _l1_sram_free(const void *addr,
if (i >= count)
return -1;
pfree[index].pid = 0;
pfree[index].flag = SRAM_SLT_FREE;
/* link the next address slot */
for (i = 0; i < count; i++) {
if (((pfree[index].paddr + pfree[index].size) == pfree[i].paddr)
&& (pfree[i].flag == SRAM_SLT_FREE)) {
pfree[i].pid = 0;
pfree[i].flag = SRAM_SLT_NULL;
pfree[index].size += pfree[i].size;
pfree[index].flag = SRAM_SLT_FREE;
@ -538,3 +545,64 @@ void *sram_alloc_with_lsl(size_t size, unsigned long flags)
return addr;
}
EXPORT_SYMBOL(sram_alloc_with_lsl);
#ifdef CONFIG_PROC_FS
/* Once we get a real allocator, we'll throw all of this away.
* Until then, we need some sort of visibility into the L1 alloc.
*/
static void _l1sram_proc_read(char *buf, int *len, const char *desc,
struct l1_sram_piece *pfree, const int array_size)
{
int i;
*len += sprintf(&buf[*len], "--- L1 %-14s Size PID State\n", desc);
for (i = 0; i < array_size; ++i) {
const char *alloc_type;
switch (pfree[i].flag) {
case SRAM_SLT_NULL: alloc_type = "NULL"; break;
case SRAM_SLT_FREE: alloc_type = "FREE"; break;
case SRAM_SLT_ALLOCATED: alloc_type = "ALLOCATED"; break;
default: alloc_type = "????"; break;
}
*len += sprintf(&buf[*len], "%p-%p %8i %4i %s\n",
pfree[i].paddr, pfree[i].paddr + pfree[i].size,
pfree[i].size, pfree[i].pid, alloc_type);
}
}
static int l1sram_proc_read(char *buf, char **start, off_t offset, int count,
int *eof, void *data)
{
int len = 0;
_l1sram_proc_read(buf, &len, "Scratchpad",
l1_ssram, ARRAY_SIZE(l1_ssram));
#if L1_DATA_A_LENGTH != 0
_l1sram_proc_read(buf, &len, "Data A",
l1_data_A_sram, ARRAY_SIZE(l1_data_A_sram));
#endif
#if L1_DATA_B_LENGTH != 0
_l1sram_proc_read(buf, &len, "Data B",
l1_data_B_sram, ARRAY_SIZE(l1_data_B_sram));
#endif
#if L1_CODE_LENGTH != 0
_l1sram_proc_read(buf, &len, "Instruction",
l1_inst_sram, ARRAY_SIZE(l1_inst_sram));
#endif
return len;
}
static int __init l1sram_proc_init(void)
{
struct proc_dir_entry *ptr;
ptr = create_proc_entry("sram", S_IFREG | S_IRUGO, NULL);
if (!ptr) {
printk(KERN_WARNING "unable to create /proc/sram\n");
return -1;
}
ptr->owner = THIS_MODULE;
ptr->read_proc = l1sram_proc_read;
return 0;
}
late_initcall(l1sram_proc_init);
#endif