]> err.no Git - linux-2.6/blobdiff - arch/blackfin/mm/blackfin_sram.c
[ARM] 4652/1: pxa: fix a typo of pxa27x usb host clk definition
[linux-2.6] / arch / blackfin / mm / blackfin_sram.c
index dd0c6501c42448180bff438e0736a47669e22e40..b99ea883cd22bdafa38377d1e8d4d66c9a55da93 100644 (file)
@@ -7,7 +7,7 @@
  * Description:  SRAM driver for Blackfin ADSP-BF5xx
  *
  * Modified:
- *               Copyright 2004-2006 Analog Devices Inc.
+ *               Copyright 2004-2007 Analog Devices Inc.
  *
  * Bugs:         Enter bugs at http://blackfin.uclinux.org/
  *
@@ -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];
@@ -80,13 +81,13 @@ static struct l1_sram_piece l1_inst_sram[CONFIG_L1_MAX_PIECE];
 #endif
 
 /* L1 Scratchpad SRAM initialization function */
-void l1sram_init(void)
+void __init l1sram_init(void)
 {
        printk(KERN_INFO "Blackfin Scratchpad data SRAM: %d KB\n",
               L1_SCRATCH_LENGTH >> 10);
 
        memset(&l1_ssram, 0x00, sizeof(l1_ssram));
-       l1_ssram[0].paddr = (void*)L1_SCRATCH_START;
+       l1_ssram[0].paddr = (void *)L1_SCRATCH_START;
        l1_ssram[0].size = L1_SCRATCH_LENGTH;
        l1_ssram[0].flag = SRAM_SLT_FREE;
 
@@ -94,42 +95,43 @@ void l1sram_init(void)
        spin_lock_init(&l1sram_lock);
 }
 
-void l1_data_sram_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 +
-               (_ebss_l1 - _sdata_l1);
+       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].paddr = (void *)L1_DATA_B_START +
+                               (_ebss_b_l1 - _sdata_b_l1);
+       l1_data_B_sram[0].size = L1_DATA_B_LENGTH - (_ebss_b_l1 - _sdata_b_l1);
        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 */
        spin_lock_init(&l1_data_sram_lock);
 }
 
-void l1_inst_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].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 */
@@ -149,12 +151,13 @@ static void *_l1_sram_alloc(size_t size, struct l1_sram_piece *pfree, int count)
        size = (size + 3) & ~3;
 
        /* not use the good method to match the best slot !!! */
-       /* search an available memeory slot */
+       /* search an available memory slot */
        for (i = 0; i < count; i++) {
                if ((pfree[i].flag == SRAM_SLT_FREE)
                    && (pfree[i].size >= size)) {
                        addr = pfree[i].paddr;
                        pfree[i].flag = SRAM_SLT_ALLOCATED;
+                       pfree[i].pid = current->pid;
                        index = i;
                        break;
                }
@@ -162,10 +165,11 @@ static void *_l1_sram_alloc(size_t size, struct l1_sram_piece *pfree, int count)
        if (i >= count)
                return NULL;
 
-       /* updated the NULL memeory slot !!! */
+       /* updated the NULL memory slot !!! */
        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;
@@ -186,7 +190,7 @@ static void *_l1_sram_alloc_max(struct l1_sram_piece *pfree, int count,
        int i, index = -1;
        void *addr = NULL;
 
-       /* search an available memeory slot */
+       /* search an available memory slot */
        for (i = 0; i < count; i++) {
                if (pfree[i].flag == SRAM_SLT_FREE && pfree[i].size > best) {
                        addr = pfree[i].paddr;
@@ -198,13 +202,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 +228,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;
@@ -513,10 +521,9 @@ void *sram_alloc_with_lsl(size_t size, unsigned long flags)
        struct sram_list_struct *lsl = NULL;
        struct mm_struct *mm = current->mm;
 
-       lsl = kmalloc(sizeof(struct sram_list_struct), GFP_KERNEL);
+       lsl = kzalloc(sizeof(struct sram_list_struct), GFP_KERNEL);
        if (!lsl)
                return NULL;
-       memset(lsl, 0, sizeof(*lsl));
 
        if (flags & L1_INST_SRAM)
                addr = l1_inst_sram_alloc(size);
@@ -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