include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / arch / blackfin / mm / sram-alloc.c
index 0f1ca69..49b2ff2 100644 (file)
@@ -1,30 +1,9 @@
 /*
- * File:         arch/blackfin/mm/sram-alloc.c
- * Based on:
- * Author:
+ * SRAM allocator for Blackfin on-chip memory
  *
- * Created:
- * Description:  SRAM allocator for Blackfin L1 and L2 memory
+ * Copyright 2004-2009 Analog Devices Inc.
  *
- * Modified:
- *               Copyright 2004-2008 Analog Devices Inc.
- *
- * Bugs:         Enter bugs at http://blackfin.uclinux.org/
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see the file COPYING, or write
- * to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ * Licensed under the GPL-2 or later.
  */
 
 #include <linux/module.h>
 #include <linux/proc_fs.h>
 #include <linux/spinlock.h>
 #include <linux/rtc.h>
+#include <linux/slab.h>
 #include <asm/blackfin.h>
+#include <asm/mem_map.h>
 #include "blackfin_sram.h"
 
-static spinlock_t l1sram_lock, l1_data_sram_lock, l1_inst_sram_lock;
-static spinlock_t l2_sram_lock;
-
 /* the data structure for L1 scratchpad and DATA SRAM */
 struct sram_piece {
        void *paddr;
@@ -52,21 +30,32 @@ struct sram_piece {
        struct sram_piece *next;
 };
 
-static struct sram_piece free_l1_ssram_head, used_l1_ssram_head;
+static DEFINE_PER_CPU_SHARED_ALIGNED(spinlock_t, l1sram_lock);
+static DEFINE_PER_CPU(struct sram_piece, free_l1_ssram_head);
+static DEFINE_PER_CPU(struct sram_piece, used_l1_ssram_head);
 
 #if L1_DATA_A_LENGTH != 0
-static struct sram_piece free_l1_data_A_sram_head, used_l1_data_A_sram_head;
+static DEFINE_PER_CPU(struct sram_piece, free_l1_data_A_sram_head);
+static DEFINE_PER_CPU(struct sram_piece, used_l1_data_A_sram_head);
 #endif
 
 #if L1_DATA_B_LENGTH != 0
-static struct sram_piece free_l1_data_B_sram_head, used_l1_data_B_sram_head;
+static DEFINE_PER_CPU(struct sram_piece, free_l1_data_B_sram_head);
+static DEFINE_PER_CPU(struct sram_piece, used_l1_data_B_sram_head);
+#endif
+
+#if L1_DATA_A_LENGTH || L1_DATA_B_LENGTH
+static DEFINE_PER_CPU_SHARED_ALIGNED(spinlock_t, l1_data_sram_lock);
 #endif
 
 #if L1_CODE_LENGTH != 0
-static struct sram_piece free_l1_inst_sram_head, used_l1_inst_sram_head;
+static DEFINE_PER_CPU_SHARED_ALIGNED(spinlock_t, l1_inst_sram_lock);
+static DEFINE_PER_CPU(struct sram_piece, free_l1_inst_sram_head);
+static DEFINE_PER_CPU(struct sram_piece, used_l1_inst_sram_head);
 #endif
 
 #if L2_LENGTH != 0
+static spinlock_t l2_sram_lock ____cacheline_aligned_in_smp;
 static struct sram_piece free_l2_sram_head, used_l2_sram_head;
 #endif
 
@@ -75,102 +64,125 @@ static struct kmem_cache *sram_piece_cache;
 /* L1 Scratchpad SRAM initialization function */
 static void __init l1sram_init(void)
 {
-       free_l1_ssram_head.next =
-               kmem_cache_alloc(sram_piece_cache, GFP_KERNEL);
-       if (!free_l1_ssram_head.next) {
-               printk(KERN_INFO "Failed to initialize Scratchpad data SRAM\n");
-               return;
-       }
-
-       free_l1_ssram_head.next->paddr = (void *)L1_SCRATCH_START;
-       free_l1_ssram_head.next->size = L1_SCRATCH_LENGTH;
-       free_l1_ssram_head.next->pid = 0;
-       free_l1_ssram_head.next->next = NULL;
-
-       used_l1_ssram_head.next = NULL;
+       unsigned int cpu;
+       unsigned long reserve;
 
-       /* mutex initialize */
-       spin_lock_init(&l1sram_lock);
+#ifdef CONFIG_SMP
+       reserve = 0;
+#else
+       reserve = sizeof(struct l1_scratch_task_info);
+#endif
 
-       printk(KERN_INFO "Blackfin Scratchpad data SRAM: %d KB\n",
-              L1_SCRATCH_LENGTH >> 10);
+       for (cpu = 0; cpu < num_possible_cpus(); ++cpu) {
+               per_cpu(free_l1_ssram_head, cpu).next =
+                       kmem_cache_alloc(sram_piece_cache, GFP_KERNEL);
+               if (!per_cpu(free_l1_ssram_head, cpu).next) {
+                       printk(KERN_INFO "Fail to initialize Scratchpad data SRAM.\n");
+                       return;
+               }
+
+               per_cpu(free_l1_ssram_head, cpu).next->paddr = (void *)get_l1_scratch_start_cpu(cpu) + reserve;
+               per_cpu(free_l1_ssram_head, cpu).next->size = L1_SCRATCH_LENGTH - reserve;
+               per_cpu(free_l1_ssram_head, cpu).next->pid = 0;
+               per_cpu(free_l1_ssram_head, cpu).next->next = NULL;
+
+               per_cpu(used_l1_ssram_head, cpu).next = NULL;
+
+               /* mutex initialize */
+               spin_lock_init(&per_cpu(l1sram_lock, cpu));
+               printk(KERN_INFO "Blackfin Scratchpad data SRAM: %d KB\n",
+                       L1_SCRATCH_LENGTH >> 10);
+       }
 }
 
 static void __init l1_data_sram_init(void)
 {
+#if L1_DATA_A_LENGTH != 0 || L1_DATA_B_LENGTH != 0
+       unsigned int cpu;
+#endif
 #if L1_DATA_A_LENGTH != 0
-       free_l1_data_A_sram_head.next =
-               kmem_cache_alloc(sram_piece_cache, GFP_KERNEL);
-       if (!free_l1_data_A_sram_head.next) {
-               printk(KERN_INFO "Failed to initialize L1 Data A SRAM\n");
-               return;
+       for (cpu = 0; cpu < num_possible_cpus(); ++cpu) {
+               per_cpu(free_l1_data_A_sram_head, cpu).next =
+                       kmem_cache_alloc(sram_piece_cache, GFP_KERNEL);
+               if (!per_cpu(free_l1_data_A_sram_head, cpu).next) {
+                       printk(KERN_INFO "Fail to initialize L1 Data A SRAM.\n");
+                       return;
+               }
+
+               per_cpu(free_l1_data_A_sram_head, cpu).next->paddr =
+                       (void *)get_l1_data_a_start_cpu(cpu) + (_ebss_l1 - _sdata_l1);
+               per_cpu(free_l1_data_A_sram_head, cpu).next->size =
+                       L1_DATA_A_LENGTH - (_ebss_l1 - _sdata_l1);
+               per_cpu(free_l1_data_A_sram_head, cpu).next->pid = 0;
+               per_cpu(free_l1_data_A_sram_head, cpu).next->next = NULL;
+
+               per_cpu(used_l1_data_A_sram_head, cpu).next = NULL;
+
+               printk(KERN_INFO "Blackfin L1 Data A SRAM: %d KB (%d KB free)\n",
+                       L1_DATA_A_LENGTH >> 10,
+                       per_cpu(free_l1_data_A_sram_head, cpu).next->size >> 10);
        }
-
-       free_l1_data_A_sram_head.next->paddr =
-               (void *)L1_DATA_A_START + (_ebss_l1 - _sdata_l1);
-       free_l1_data_A_sram_head.next->size =
-               L1_DATA_A_LENGTH - (_ebss_l1 - _sdata_l1);
-       free_l1_data_A_sram_head.next->pid = 0;
-       free_l1_data_A_sram_head.next->next = NULL;
-
-       used_l1_data_A_sram_head.next = NULL;
-
-       printk(KERN_INFO "Blackfin L1 Data A SRAM: %d KB (%d KB free)\n",
-               L1_DATA_A_LENGTH >> 10,
-               free_l1_data_A_sram_head.next->size >> 10);
 #endif
 #if L1_DATA_B_LENGTH != 0
-       free_l1_data_B_sram_head.next =
-               kmem_cache_alloc(sram_piece_cache, GFP_KERNEL);
-       if (!free_l1_data_B_sram_head.next) {
-               printk(KERN_INFO "Failed to initialize L1 Data B SRAM\n");
-               return;
+       for (cpu = 0; cpu < num_possible_cpus(); ++cpu) {
+               per_cpu(free_l1_data_B_sram_head, cpu).next =
+                       kmem_cache_alloc(sram_piece_cache, GFP_KERNEL);
+               if (!per_cpu(free_l1_data_B_sram_head, cpu).next) {
+                       printk(KERN_INFO "Fail to initialize L1 Data B SRAM.\n");
+                       return;
+               }
+
+               per_cpu(free_l1_data_B_sram_head, cpu).next->paddr =
+                       (void *)get_l1_data_b_start_cpu(cpu) + (_ebss_b_l1 - _sdata_b_l1);
+               per_cpu(free_l1_data_B_sram_head, cpu).next->size =
+                       L1_DATA_B_LENGTH - (_ebss_b_l1 - _sdata_b_l1);
+               per_cpu(free_l1_data_B_sram_head, cpu).next->pid = 0;
+               per_cpu(free_l1_data_B_sram_head, cpu).next->next = NULL;
+
+               per_cpu(used_l1_data_B_sram_head, cpu).next = NULL;
+
+               printk(KERN_INFO "Blackfin L1 Data B SRAM: %d KB (%d KB free)\n",
+                       L1_DATA_B_LENGTH >> 10,
+                       per_cpu(free_l1_data_B_sram_head, cpu).next->size >> 10);
+               /* mutex initialize */
        }
-
-       free_l1_data_B_sram_head.next->paddr =
-               (void *)L1_DATA_B_START + (_ebss_b_l1 - _sdata_b_l1);
-       free_l1_data_B_sram_head.next->size =
-               L1_DATA_B_LENGTH - (_ebss_b_l1 - _sdata_b_l1);
-       free_l1_data_B_sram_head.next->pid = 0;
-       free_l1_data_B_sram_head.next->next = NULL;
-
-       used_l1_data_B_sram_head.next = NULL;
-
-       printk(KERN_INFO "Blackfin L1 Data B SRAM: %d KB (%d KB free)\n",
-               L1_DATA_B_LENGTH >> 10,
-               free_l1_data_B_sram_head.next->size >> 10);
 #endif
 
-       /* mutex initialize */
-       spin_lock_init(&l1_data_sram_lock);
+#if L1_DATA_A_LENGTH != 0 || L1_DATA_B_LENGTH != 0
+       for (cpu = 0; cpu < num_possible_cpus(); ++cpu)
+               spin_lock_init(&per_cpu(l1_data_sram_lock, cpu));
+#endif
 }
 
 static void __init l1_inst_sram_init(void)
 {
 #if L1_CODE_LENGTH != 0
-       free_l1_inst_sram_head.next =
-               kmem_cache_alloc(sram_piece_cache, GFP_KERNEL);
-       if (!free_l1_inst_sram_head.next) {
-               printk(KERN_INFO "Failed to initialize L1 Instruction SRAM\n");
-               return;
+       unsigned int cpu;
+       for (cpu = 0; cpu < num_possible_cpus(); ++cpu) {
+               per_cpu(free_l1_inst_sram_head, cpu).next =
+                       kmem_cache_alloc(sram_piece_cache, GFP_KERNEL);
+               if (!per_cpu(free_l1_inst_sram_head, cpu).next) {
+                       printk(KERN_INFO "Failed to initialize L1 Instruction SRAM\n");
+                       return;
+               }
+
+               per_cpu(free_l1_inst_sram_head, cpu).next->paddr =
+                       (void *)get_l1_code_start_cpu(cpu) + (_etext_l1 - _stext_l1);
+               per_cpu(free_l1_inst_sram_head, cpu).next->size =
+                       L1_CODE_LENGTH - (_etext_l1 - _stext_l1);
+               per_cpu(free_l1_inst_sram_head, cpu).next->pid = 0;
+               per_cpu(free_l1_inst_sram_head, cpu).next->next = NULL;
+
+               per_cpu(used_l1_inst_sram_head, cpu).next = NULL;
+
+               printk(KERN_INFO "Blackfin L1 Instruction SRAM: %d KB (%d KB free)\n",
+                       L1_CODE_LENGTH >> 10,
+                       per_cpu(free_l1_inst_sram_head, cpu).next->size >> 10);
+
+               /* mutex initialize */
+               spin_lock_init(&per_cpu(l1_inst_sram_lock, cpu));
        }
-
-       free_l1_inst_sram_head.next->paddr =
-               (void *)L1_CODE_START + (_etext_l1 - _stext_l1);
-       free_l1_inst_sram_head.next->size =
-               L1_CODE_LENGTH - (_etext_l1 - _stext_l1);
-       free_l1_inst_sram_head.next->pid = 0;
-       free_l1_inst_sram_head.next->next = NULL;
-
-       used_l1_inst_sram_head.next = NULL;
-
-       printk(KERN_INFO "Blackfin L1 Instruction SRAM: %d KB (%d KB free)\n",
-               L1_CODE_LENGTH >> 10,
-               free_l1_inst_sram_head.next->size >> 10);
 #endif
-
-       /* mutex initialize */
-       spin_lock_init(&l1_inst_sram_lock);
 }
 
 static void __init l2_sram_init(void)
@@ -179,14 +191,14 @@ static void __init l2_sram_init(void)
        free_l2_sram_head.next =
                kmem_cache_alloc(sram_piece_cache, GFP_KERNEL);
        if (!free_l2_sram_head.next) {
-               printk(KERN_INFO "Failed to initialize L2 SRAM\n");
+               printk(KERN_INFO "Fail to initialize L2 SRAM.\n");
                return;
        }
 
-       free_l2_sram_head.next->paddr = (void *)L2_START +
-               (_etext_l2 - _stext_l2) + (_edata_l2 - _sdata_l2);
-       free_l2_sram_head.next->size = L2_LENGTH -
-               (_etext_l2 - _stext_l2) + (_edata_l2 - _sdata_l2);
+       free_l2_sram_head.next->paddr =
+               (void *)L2_START + (_ebss_l2 - _stext_l2);
+       free_l2_sram_head.next->size =
+               L2_LENGTH - (_ebss_l2 - _stext_l2);
        free_l2_sram_head.next->pid = 0;
        free_l2_sram_head.next->next = NULL;
 
@@ -195,12 +207,13 @@ static void __init l2_sram_init(void)
        printk(KERN_INFO "Blackfin L2 SRAM: %d KB (%d KB free)\n",
                L2_LENGTH >> 10,
                free_l2_sram_head.next->size >> 10);
-#endif
 
        /* mutex initialize */
        spin_lock_init(&l2_sram_lock);
+#endif
 }
-void __init bfin_sram_init(void)
+
+static int __init bfin_sram_init(void)
 {
        sram_piece_cache = kmem_cache_create("sram_piece_cache",
                                sizeof(struct sram_piece),
@@ -210,7 +223,10 @@ void __init bfin_sram_init(void)
        l1_data_sram_init();
        l1_inst_sram_init();
        l2_sram_init();
+
+       return 0;
 }
+pure_initcall(bfin_sram_init);
 
 /* SRAM allocate function */
 static void *_sram_alloc(size_t size, struct sram_piece *pfree_head,
@@ -353,20 +369,20 @@ int sram_free(const void *addr)
 {
 
 #if L1_CODE_LENGTH != 0
-       if (addr >= (void *)L1_CODE_START
-                && addr < (void *)(L1_CODE_START + L1_CODE_LENGTH))
+       if (addr >= (void *)get_l1_code_start()
+                && addr < (void *)(get_l1_code_start() + L1_CODE_LENGTH))
                return l1_inst_sram_free(addr);
        else
 #endif
 #if L1_DATA_A_LENGTH != 0
-       if (addr >= (void *)L1_DATA_A_START
-                && addr < (void *)(L1_DATA_A_START + L1_DATA_A_LENGTH))
+       if (addr >= (void *)get_l1_data_a_start()
+                && addr < (void *)(get_l1_data_a_start() + L1_DATA_A_LENGTH))
                return l1_data_A_sram_free(addr);
        else
 #endif
 #if L1_DATA_B_LENGTH != 0
-       if (addr >= (void *)L1_DATA_B_START
-                && addr < (void *)(L1_DATA_B_START + L1_DATA_B_LENGTH))
+       if (addr >= (void *)get_l1_data_b_start()
+                && addr < (void *)(get_l1_data_b_start() + L1_DATA_B_LENGTH))
                return l1_data_B_sram_free(addr);
        else
 #endif
@@ -382,46 +398,52 @@ EXPORT_SYMBOL(sram_free);
 
 void *l1_data_A_sram_alloc(size_t size)
 {
+#if L1_DATA_A_LENGTH != 0
        unsigned long flags;
-       void *addr = NULL;
+       void *addr;
+       unsigned int cpu;
 
+       cpu = smp_processor_id();
        /* add mutex operation */
-       spin_lock_irqsave(&l1_data_sram_lock, flags);
+       spin_lock_irqsave(&per_cpu(l1_data_sram_lock, cpu), flags);
 
-#if L1_DATA_A_LENGTH != 0
-       addr = _sram_alloc(size, &free_l1_data_A_sram_head,
-                       &used_l1_data_A_sram_head);
-#endif
+       addr = _sram_alloc(size, &per_cpu(free_l1_data_A_sram_head, cpu),
+                       &per_cpu(used_l1_data_A_sram_head, cpu));
 
        /* add mutex operation */
-       spin_unlock_irqrestore(&l1_data_sram_lock, flags);
+       spin_unlock_irqrestore(&per_cpu(l1_data_sram_lock, cpu), flags);
 
        pr_debug("Allocated address in l1_data_A_sram_alloc is 0x%lx+0x%lx\n",
                 (long unsigned int)addr, size);
 
        return addr;
+#else
+       return NULL;
+#endif
 }
 EXPORT_SYMBOL(l1_data_A_sram_alloc);
 
 int l1_data_A_sram_free(const void *addr)
 {
+#if L1_DATA_A_LENGTH != 0
        unsigned long flags;
        int ret;
+       unsigned int cpu;
 
+       cpu = smp_processor_id();
        /* add mutex operation */
-       spin_lock_irqsave(&l1_data_sram_lock, flags);
+       spin_lock_irqsave(&per_cpu(l1_data_sram_lock, cpu), flags);
 
-#if L1_DATA_A_LENGTH != 0
-       ret = _sram_free(addr, &free_l1_data_A_sram_head,
-                       &used_l1_data_A_sram_head);
-#else
-       ret = -1;
-#endif
+       ret = _sram_free(addr, &per_cpu(free_l1_data_A_sram_head, cpu),
+                       &per_cpu(used_l1_data_A_sram_head, cpu));
 
        /* add mutex operation */
-       spin_unlock_irqrestore(&l1_data_sram_lock, flags);
+       spin_unlock_irqrestore(&per_cpu(l1_data_sram_lock, cpu), flags);
 
        return ret;
+#else
+       return -1;
+#endif
 }
 EXPORT_SYMBOL(l1_data_A_sram_free);
 
@@ -430,15 +452,17 @@ void *l1_data_B_sram_alloc(size_t size)
 #if L1_DATA_B_LENGTH != 0
        unsigned long flags;
        void *addr;
+       unsigned int cpu;
 
+       cpu = smp_processor_id();
        /* add mutex operation */
-       spin_lock_irqsave(&l1_data_sram_lock, flags);
+       spin_lock_irqsave(&per_cpu(l1_data_sram_lock, cpu), flags);
 
-       addr = _sram_alloc(size, &free_l1_data_B_sram_head,
-                       &used_l1_data_B_sram_head);
+       addr = _sram_alloc(size, &per_cpu(free_l1_data_B_sram_head, cpu),
+                       &per_cpu(used_l1_data_B_sram_head, cpu));
 
        /* add mutex operation */
-       spin_unlock_irqrestore(&l1_data_sram_lock, flags);
+       spin_unlock_irqrestore(&per_cpu(l1_data_sram_lock, cpu), flags);
 
        pr_debug("Allocated address in l1_data_B_sram_alloc is 0x%lx+0x%lx\n",
                 (long unsigned int)addr, size);
@@ -455,15 +479,17 @@ int l1_data_B_sram_free(const void *addr)
 #if L1_DATA_B_LENGTH != 0
        unsigned long flags;
        int ret;
+       unsigned int cpu;
 
+       cpu = smp_processor_id();
        /* add mutex operation */
-       spin_lock_irqsave(&l1_data_sram_lock, flags);
+       spin_lock_irqsave(&per_cpu(l1_data_sram_lock, cpu), flags);
 
-       ret = _sram_free(addr, &free_l1_data_B_sram_head,
-                       &used_l1_data_B_sram_head);
+       ret = _sram_free(addr, &per_cpu(free_l1_data_B_sram_head, cpu),
+                       &per_cpu(used_l1_data_B_sram_head, cpu));
 
        /* add mutex operation */
-       spin_unlock_irqrestore(&l1_data_sram_lock, flags);
+       spin_unlock_irqrestore(&per_cpu(l1_data_sram_lock, cpu), flags);
 
        return ret;
 #else
@@ -509,15 +535,17 @@ void *l1_inst_sram_alloc(size_t size)
 #if L1_CODE_LENGTH != 0
        unsigned long flags;
        void *addr;
+       unsigned int cpu;
 
+       cpu = smp_processor_id();
        /* add mutex operation */
-       spin_lock_irqsave(&l1_inst_sram_lock, flags);
+       spin_lock_irqsave(&per_cpu(l1_inst_sram_lock, cpu), flags);
 
-       addr = _sram_alloc(size, &free_l1_inst_sram_head,
-                       &used_l1_inst_sram_head);
+       addr = _sram_alloc(size, &per_cpu(free_l1_inst_sram_head, cpu),
+                       &per_cpu(used_l1_inst_sram_head, cpu));
 
        /* add mutex operation */
-       spin_unlock_irqrestore(&l1_inst_sram_lock, flags);
+       spin_unlock_irqrestore(&per_cpu(l1_inst_sram_lock, cpu), flags);
 
        pr_debug("Allocated address in l1_inst_sram_alloc is 0x%lx+0x%lx\n",
                 (long unsigned int)addr, size);
@@ -534,15 +562,17 @@ int l1_inst_sram_free(const void *addr)
 #if L1_CODE_LENGTH != 0
        unsigned long flags;
        int ret;
+       unsigned int cpu;
 
+       cpu = smp_processor_id();
        /* add mutex operation */
-       spin_lock_irqsave(&l1_inst_sram_lock, flags);
+       spin_lock_irqsave(&per_cpu(l1_inst_sram_lock, cpu), flags);
 
-       ret = _sram_free(addr, &free_l1_inst_sram_head,
-                       &used_l1_inst_sram_head);
+       ret = _sram_free(addr, &per_cpu(free_l1_inst_sram_head, cpu),
+                       &per_cpu(used_l1_inst_sram_head, cpu));
 
        /* add mutex operation */
-       spin_unlock_irqrestore(&l1_inst_sram_lock, flags);
+       spin_unlock_irqrestore(&per_cpu(l1_inst_sram_lock, cpu), flags);
 
        return ret;
 #else
@@ -556,15 +586,17 @@ void *l1sram_alloc(size_t size)
 {
        unsigned long flags;
        void *addr;
+       unsigned int cpu;
 
+       cpu = smp_processor_id();
        /* add mutex operation */
-       spin_lock_irqsave(&l1sram_lock, flags);
+       spin_lock_irqsave(&per_cpu(l1sram_lock, cpu), flags);
 
-       addr = _sram_alloc(size, &free_l1_ssram_head,
-                       &used_l1_ssram_head);
+       addr = _sram_alloc(size, &per_cpu(free_l1_ssram_head, cpu),
+                       &per_cpu(used_l1_ssram_head, cpu));
 
        /* add mutex operation */
-       spin_unlock_irqrestore(&l1sram_lock, flags);
+       spin_unlock_irqrestore(&per_cpu(l1sram_lock, cpu), flags);
 
        return addr;
 }
@@ -574,15 +606,17 @@ void *l1sram_alloc_max(size_t *psize)
 {
        unsigned long flags;
        void *addr;
+       unsigned int cpu;
 
+       cpu = smp_processor_id();
        /* add mutex operation */
-       spin_lock_irqsave(&l1sram_lock, flags);
+       spin_lock_irqsave(&per_cpu(l1sram_lock, cpu), flags);
 
-       addr = _sram_alloc_max(&free_l1_ssram_head,
-                       &used_l1_ssram_head, psize);
+       addr = _sram_alloc_max(&per_cpu(free_l1_ssram_head, cpu),
+                       &per_cpu(used_l1_ssram_head, cpu), psize);
 
        /* add mutex operation */
-       spin_unlock_irqrestore(&l1sram_lock, flags);
+       spin_unlock_irqrestore(&per_cpu(l1sram_lock, cpu), flags);
 
        return addr;
 }
@@ -592,15 +626,17 @@ int l1sram_free(const void *addr)
 {
        unsigned long flags;
        int ret;
+       unsigned int cpu;
 
+       cpu = smp_processor_id();
        /* add mutex operation */
-       spin_lock_irqsave(&l1sram_lock, flags);
+       spin_lock_irqsave(&per_cpu(l1sram_lock, cpu), flags);
 
-       ret = _sram_free(addr, &free_l1_ssram_head,
-                       &used_l1_ssram_head);
+       ret = _sram_free(addr, &per_cpu(free_l1_ssram_head, cpu),
+                       &per_cpu(used_l1_ssram_head, cpu));
 
        /* add mutex operation */
-       spin_unlock_irqrestore(&l1sram_lock, flags);
+       spin_unlock_irqrestore(&per_cpu(l1sram_lock, cpu), flags);
 
        return ret;
 }
@@ -682,6 +718,10 @@ found:
 }
 EXPORT_SYMBOL(sram_free_with_lsl);
 
+/* Allocate memory and keep in L1 SRAM List (lsl) so that the resources are
+ * tracked.  These are designed for userspace so that when a process exits,
+ * we can safely reap their resources.
+ */
 void *sram_alloc_with_lsl(size_t size, unsigned long flags)
 {
        void *addr = NULL;
@@ -761,33 +801,36 @@ static int sram_proc_read(char *buf, char **start, off_t offset, int count,
                int *eof, void *data)
 {
        int len = 0;
+       unsigned int cpu;
 
-       if (_sram_proc_read(buf, &len, count, "Scratchpad",
-                       &free_l1_ssram_head, &used_l1_ssram_head))
-               goto not_done;
+       for (cpu = 0; cpu < num_possible_cpus(); ++cpu) {
+               if (_sram_proc_read(buf, &len, count, "Scratchpad",
+                       &per_cpu(free_l1_ssram_head, cpu), &per_cpu(used_l1_ssram_head, cpu)))
+                       goto not_done;
 #if L1_DATA_A_LENGTH != 0
-       if (_sram_proc_read(buf, &len, count, "L1 Data A",
-                       &free_l1_data_A_sram_head,
-                       &used_l1_data_A_sram_head))
-               goto not_done;
+               if (_sram_proc_read(buf, &len, count, "L1 Data A",
+                       &per_cpu(free_l1_data_A_sram_head, cpu),
+                       &per_cpu(used_l1_data_A_sram_head, cpu)))
+                       goto not_done;
 #endif
 #if L1_DATA_B_LENGTH != 0
-       if (_sram_proc_read(buf, &len, count, "L1 Data B",
-                       &free_l1_data_B_sram_head,
-                       &used_l1_data_B_sram_head))
-               goto not_done;
+               if (_sram_proc_read(buf, &len, count, "L1 Data B",
+                       &per_cpu(free_l1_data_B_sram_head, cpu),
+                       &per_cpu(used_l1_data_B_sram_head, cpu)))
+                       goto not_done;
 #endif
 #if L1_CODE_LENGTH != 0
-       if (_sram_proc_read(buf, &len, count, "L1 Instruction",
-                       &free_l1_inst_sram_head, &used_l1_inst_sram_head))
-               goto not_done;
+               if (_sram_proc_read(buf, &len, count, "L1 Instruction",
+                       &per_cpu(free_l1_inst_sram_head, cpu),
+                       &per_cpu(used_l1_inst_sram_head, cpu)))
+                       goto not_done;
 #endif
+       }
 #if L2_LENGTH != 0
-       if (_sram_proc_read(buf, &len, count, "L2",
-                       &free_l2_sram_head, &used_l2_sram_head))
+       if (_sram_proc_read(buf, &len, count, "L2", &free_l2_sram_head,
+               &used_l2_sram_head))
                goto not_done;
 #endif
-
        *eof = 1;
  not_done:
        return len;
@@ -801,7 +844,6 @@ static int __init sram_proc_init(void)
                printk(KERN_WARNING "unable to create /proc/sram\n");
                return -1;
        }
-       ptr->owner = THIS_MODULE;
        ptr->read_proc = sram_proc_read;
        return 0;
 }