Release 4.13 arch/blackfin/mm/sram-alloc.c
  
  
  
/*
 * SRAM allocator for Blackfin on-chip memory
 *
 * Copyright 2004-2009 Analog Devices Inc.
 *
 * Licensed under the GPL-2 or later.
 */
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/miscdevice.h>
#include <linux/ioport.h>
#include <linux/fcntl.h>
#include <linux/init.h>
#include <linux/poll.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/spinlock.h>
#include <linux/rtc.h>
#include <linux/slab.h>
#include <linux/mm_types.h>
#include <asm/blackfin.h>
#include <asm/mem_map.h>
#include "blackfin_sram.h"
/* the data structure for L1 scratchpad and DATA SRAM */
struct sram_piece {
	
void *paddr;
	
int size;
	
pid_t pid;
	
struct sram_piece *next;
};
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 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 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 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
static struct kmem_cache *sram_piece_cache;
/* L1 Scratchpad SRAM initialization function */
static void __init l1sram_init(void)
{
	unsigned int cpu;
	unsigned long reserve;
#ifdef CONFIG_SMP
	reserve = 0;
#else
	reserve = sizeof(struct l1_scratch_task_info);
#endif
	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);
	}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Graf Yang | 92 | 49.73% | 2 | 40.00% | 
| Sonic Zhang | 54 | 29.19% | 1 | 20.00% | 
| Bryan Wu | 38 | 20.54% | 1 | 20.00% | 
| Mike Frysinger | 1 | 0.54% | 1 | 20.00% | 
| Total | 185 | 100.00% | 5 | 100.00% | 
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
	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);
	}
#endif
#if L1_DATA_B_LENGTH != 0
	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 */
	}
#endif
#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
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Graf Yang | 157 | 40.15% | 1 | 12.50% | 
| Sonic Zhang | 99 | 25.32% | 2 | 25.00% | 
| Bryan Wu | 84 | 21.48% | 1 | 12.50% | 
| Mike Frysinger | 51 | 13.04% | 4 | 50.00% | 
| Total | 391 | 100.00% | 8 | 100.00% | 
static void __init l1_inst_sram_init(void)
{
#if L1_CODE_LENGTH != 0
	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));
	}
#endif
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Graf Yang | 71 | 37.37% | 1 | 14.29% | 
| Bryan Wu | 53 | 27.89% | 1 | 14.29% | 
| Sonic Zhang | 50 | 26.32% | 2 | 28.57% | 
| Mike Frysinger | 15 | 7.89% | 2 | 28.57% | 
| Robin Getz | 1 | 0.53% | 1 | 14.29% | 
| Total | 190 | 100.00% | 7 | 100.00% | 
#ifdef __ADSPBF60x__
static irqreturn_t l2_ecc_err(int irq, void *dev_id)
{
	int status;
	printk(KERN_ERR "L2 ecc error happened\n");
	status = bfin_read32(L2CTL0_STAT);
	if (status & 0x1)
		printk(KERN_ERR "Core channel error type:0x%x, addr:0x%x\n",
			bfin_read32(L2CTL0_ET0), bfin_read32(L2CTL0_EADDR0));
	if (status & 0x2)
		printk(KERN_ERR "System channel error type:0x%x, addr:0x%x\n",
			bfin_read32(L2CTL0_ET1), bfin_read32(L2CTL0_EADDR1));
	status = status >> 8;
	if (status)
		printk(KERN_ERR "L2 Bank%d error, addr:0x%x\n",
			status, bfin_read32(L2CTL0_ERRADDR0 + status));
	panic("L2 Ecc error");
	return IRQ_HANDLED;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Bob Liu | 105 | 99.06% | 1 | 50.00% | 
| Masanari Iida | 1 | 0.94% | 1 | 50.00% | 
| Total | 106 | 100.00% | 2 | 100.00% | 
#endif
static void __init l2_sram_init(void)
{
#if L2_LENGTH != 0
#ifdef __ADSPBF60x__
	int ret;
	ret = request_irq(IRQ_L2CTL0_ECC_ERR, l2_ecc_err, 0, "l2-ecc-err",
			NULL);
	if (unlikely(ret < 0)) {
		printk(KERN_INFO "Fail to request l2 ecc error interrupt");
		return;
	}
#endif
	free_l2_sram_head.next =
		kmem_cache_alloc(sram_piece_cache, GFP_KERNEL);
	if (!free_l2_sram_head.next) {
		printk(KERN_INFO "Fail to initialize L2 SRAM.\n");
		return;
	}
	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;
	used_l2_sram_head.next = NULL;
	printk(KERN_INFO "Blackfin L2 SRAM: %d KB (%d KB free)\n",
		L2_LENGTH >> 10,
		free_l2_sram_head.next->size >> 10);
	/* mutex initialize */
	spin_lock_init(&l2_sram_lock);
#endif
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Sonic Zhang | 113 | 69.33% | 1 | 16.67% | 
| Bob Liu | 41 | 25.15% | 1 | 16.67% | 
| Mike Frysinger | 6 | 3.68% | 2 | 33.33% | 
| Jie Zhang | 2 | 1.23% | 1 | 16.67% | 
| Graf Yang | 1 | 0.61% | 1 | 16.67% | 
| Total | 163 | 100.00% | 6 | 100.00% | 
static int __init bfin_sram_init(void)
{
	sram_piece_cache = kmem_cache_create("sram_piece_cache",
				sizeof(struct sram_piece),
				0, SLAB_PANIC, NULL);
	l1sram_init();
	l1_data_sram_init();
	l1_inst_sram_init();
	l2_sram_init();
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Sonic Zhang | 38 | 88.37% | 2 | 66.67% | 
| Graf Yang | 5 | 11.63% | 1 | 33.33% | 
| Total | 43 | 100.00% | 3 | 100.00% | 
pure_initcall(bfin_sram_init);
/* SRAM allocate function */
static void *_sram_alloc(size_t size, struct sram_piece *pfree_head,
		struct sram_piece *pused_head)
{
	struct sram_piece *pslot, *plast, *pavail;
	if (size <= 0 || !pfree_head || !pused_head)
		return NULL;
	/* Align the size */
	size = (size + 3) & ~3;
	pslot = pfree_head->next;
	plast = pfree_head;
	/* search an available piece slot */
	while (pslot != NULL && size > pslot->size) {
		plast = pslot;
		pslot = pslot->next;
	}
	if (!pslot)
		return NULL;
	if (pslot->size == size) {
		plast->next = pslot->next;
		pavail = pslot;
	} else {
		/* use atomic so our L1 allocator can be used atomically */
		pavail = kmem_cache_alloc(sram_piece_cache, GFP_ATOMIC);
		if (!pavail)
			return NULL;
		pavail->paddr = pslot->paddr;
		pavail->size = size;
		pslot->paddr += size;
		pslot->size -= size;
	}
	pavail->pid = current->pid;
	pslot = pused_head->next;
	plast = pused_head;
	/* insert new piece into used piece list !!! */
	while (pslot != NULL && pavail->paddr < pslot->paddr) {
		plast = pslot;
		pslot = pslot->next;
	}
	pavail->next = pslot;
	plast->next = pavail;
	return pavail->paddr;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Sonic Zhang | 148 | 63.79% | 2 | 40.00% | 
| Bryan Wu | 78 | 33.62% | 1 | 20.00% | 
| Mike Frysinger | 6 | 2.59% | 2 | 40.00% | 
| Total | 232 | 100.00% | 5 | 100.00% | 
/* Allocate the largest available block.  */
static void *_sram_alloc_max(struct sram_piece *pfree_head,
				struct sram_piece *pused_head,
				unsigned long *psize)
{
	struct sram_piece *pslot, *pmax;
	if (!pfree_head || !pused_head)
		return NULL;
	pmax = pslot = pfree_head->next;
	/* search an available piece slot */
	while (pslot != NULL) {
		if (pslot->size > pmax->size)
			pmax = pslot;
		pslot = pslot->next;
	}
	if (!pmax)
		return NULL;
	*psize = pmax->size;
	return _sram_alloc(*psize, pfree_head, pused_head);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Sonic Zhang | 61 | 58.65% | 2 | 50.00% | 
| Bryan Wu | 42 | 40.38% | 1 | 25.00% | 
| Mike Frysinger | 1 | 0.96% | 1 | 25.00% | 
| Total | 104 | 100.00% | 4 | 100.00% | 
/* SRAM free function */
static int _sram_free(const void *addr,
			struct sram_piece *pfree_head,
			struct sram_piece *pused_head)
{
	struct sram_piece *pslot, *plast, *pavail;
	if (!pfree_head || !pused_head)
		return -1;
	/* search the relevant memory slot */
	pslot = pused_head->next;
	plast = pused_head;
	/* search an available piece slot */
	while (pslot != NULL && pslot->paddr != addr) {
		plast = pslot;
		pslot = pslot->next;
	}
	if (!pslot)
		return -1;
	plast->next = pslot->next;
	pavail = pslot;
	pavail->pid = 0;
	/* insert free pieces back to the free list */
	pslot = pfree_head->next;
	plast = pfree_head;
	while (pslot != NULL && addr > pslot->paddr) {
		plast = pslot;
		pslot = pslot->next;
	}
	if (plast != pfree_head && plast->paddr + plast->size == pavail->paddr) {
		plast->size += pavail->size;
		kmem_cache_free(sram_piece_cache, pavail);
	} else {
		pavail->next = plast->next;
		plast->next = pavail;
		plast = pavail;
	}
	if (pslot && plast->paddr + plast->size == pslot->paddr) {
		plast->size += pslot->size;
		plast->next = pslot->next;
		kmem_cache_free(sram_piece_cache, pslot);
	}
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Sonic Zhang | 168 | 69.42% | 3 | 60.00% | 
| Bryan Wu | 68 | 28.10% | 1 | 20.00% | 
| Mike Frysinger | 6 | 2.48% | 1 | 20.00% | 
| Total | 242 | 100.00% | 5 | 100.00% | 
int sram_free(const void *addr)
{
#if L1_CODE_LENGTH != 0
	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 *)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 *)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
#if L2_LENGTH != 0
	if (addr >= (void *)L2_START
		 && addr < (void *)(L2_START + L2_LENGTH))
		return l2_sram_free(addr);
	else
#endif
		return -1;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Bryan Wu | 113 | 68.90% | 1 | 20.00% | 
| Sonic Zhang | 31 | 18.90% | 1 | 20.00% | 
| Graf Yang | 12 | 7.32% | 1 | 20.00% | 
| Robin Getz | 4 | 2.44% | 1 | 20.00% | 
| Mike Frysinger | 4 | 2.44% | 1 | 20.00% | 
| Total | 164 | 100.00% | 5 | 100.00% | 
EXPORT_SYMBOL(sram_free);
void *l1_data_A_sram_alloc(size_t size)
{
#if L1_DATA_A_LENGTH != 0
	unsigned long flags;
	void *addr;
	unsigned int cpu;
	cpu = smp_processor_id();
	/* add mutex operation */
	spin_lock_irqsave(&per_cpu(l1_data_sram_lock, cpu), flags);
	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(&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
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Bryan Wu | 59 | 55.66% | 1 | 14.29% | 
| Graf Yang | 28 | 26.42% | 1 | 14.29% | 
| Mike Frysinger | 12 | 11.32% | 1 | 14.29% | 
| Sonic Zhang | 5 | 4.72% | 2 | 28.57% | 
| Vegard Nossum | 1 | 0.94% | 1 | 14.29% | 
| Yi Li | 1 | 0.94% | 1 | 14.29% | 
| Total | 106 | 100.00% | 7 | 100.00% | 
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(&per_cpu(l1_data_sram_lock, cpu), flags);
	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(&per_cpu(l1_data_sram_lock, cpu), flags);
	return ret;
#else
	return -1;
#endif
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Bryan Wu | 45 | 48.39% | 1 | 14.29% | 
| Graf Yang | 28 | 30.11% | 1 | 14.29% | 
| Mike Frysinger | 13 | 13.98% | 1 | 14.29% | 
| Sonic Zhang | 5 | 5.38% | 2 | 28.57% | 
| Vegard Nossum | 1 | 1.08% | 1 | 14.29% | 
| Yi Li | 1 | 1.08% | 1 | 14.29% | 
| Total | 93 | 100.00% | 7 | 100.00% | 
EXPORT_SYMBOL(l1_data_A_sram_free);
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(&per_cpu(l1_data_sram_lock, cpu), flags);
	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(&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);
	return addr;
#else
	return NULL;
#endif
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Bryan Wu | 71 | 66.98% | 1 | 16.67% | 
| Graf Yang | 28 | 26.42% | 1 | 16.67% | 
| Sonic Zhang | 5 | 4.72% | 2 | 33.33% | 
| Vegard Nossum | 1 | 0.94% | 1 | 16.67% | 
| Yi Li | 1 | 0.94% | 1 | 16.67% | 
| Total | 106 | 100.00% | 6 | 100.00% | 
EXPORT_SYMBOL(l1_data_B_sram_alloc);
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(&per_cpu(l1_data_sram_lock, cpu), flags);
	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(&per_cpu(l1_data_sram_lock, cpu), flags);
	return ret;
#else
	return -1;
#endif
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Bryan Wu | 58 | 62.37% | 1 | 16.67% | 
| Graf Yang | 28 | 30.11% | 1 | 16.67% | 
| Sonic Zhang | 5 | 5.38% | 2 | 33.33% | 
| Yi Li | 1 | 1.08% | 1 | 16.67% | 
| Vegard Nossum | 1 | 1.08% | 1 | 16.67% | 
| Total | 93 | 100.00% | 6 | 100.00% | 
EXPORT_SYMBOL(l1_data_B_sram_free);
void *l1_data_sram_alloc(size_t size)
{
	void *addr = l1_data_A_sram_alloc(size);
	if (!addr)
		addr = l1_data_B_sram_alloc(size);
	return addr;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Bryan Wu | 33 | 100.00% | 1 | 100.00% | 
| Total | 33 | 100.00% | 1 | 100.00% | 
EXPORT_SYMBOL(l1_data_sram_alloc);
void *l1_data_sram_zalloc(size_t size)
{
	void *addr = l1_data_sram_alloc(size);
	if (addr)
		memset(addr, 0x00, size);
	return addr;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Bryan Wu | 34 | 100.00% | 1 | 100.00% | 
| Total | 34 | 100.00% | 1 | 100.00% | 
EXPORT_SYMBOL(l1_data_sram_zalloc);
int l1_data_sram_free(const void *addr)
{
	int ret;
	ret = l1_data_A_sram_free(addr);
	if (ret == -1)
		ret = l1_data_B_sram_free(addr);
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Bryan Wu | 37 | 100.00% | 1 | 100.00% | 
| Total | 37 | 100.00% | 1 | 100.00% | 
EXPORT_SYMBOL(l1_data_sram_free);
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(&per_cpu(l1_inst_sram_lock, cpu), flags);
	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(&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);
	return addr;
#else
	return NULL;
#endif
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Bryan Wu | 70 | 66.04% | 1 | 14.29% | 
| Graf Yang | 28 | 26.42% | 1 | 14.29% | 
| Sonic Zhang | 5 | 4.72% | 2 | 28.57% | 
| Meihui Fan | 1 | 0.94% | 1 | 14.29% | 
| Yi Li | 1 | 0.94% | 1 | 14.29% | 
| Vegard Nossum | 1 | 0.94% | 1 | 14.29% | 
| Total | 106 | 100.00% | 7 | 100.00% | 
EXPORT_SYMBOL(l1_inst_sram_alloc);
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(&per_cpu(l1_inst_sram_lock, cpu), flags);
	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(&per_cpu(l1_inst_sram_lock, cpu), flags);
	return ret;
#else
	return -1;
#endif
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Bryan Wu | 58 | 62.37% | 1 | 16.67% | 
| Graf Yang | 28 | 30.11% | 1 | 16.67% | 
| Sonic Zhang | 5 | 5.38% | 2 | 33.33% | 
| Vegard Nossum | 1 | 1.08% | 1 | 16.67% | 
| Yi Li | 1 | 1.08% | 1 | 16.67% | 
| Total | 93 | 100.00% | 6 | 100.00% | 
EXPORT_SYMBOL(l1_inst_sram_free);
/* L1 Scratchpad memory allocate function */
void *l1sram_alloc(size_t size)
{
	unsigned long flags;
	void *addr;
	unsigned int cpu;
	cpu = smp_processor_id();
	/* add mutex operation */
	spin_lock_irqsave(&per_cpu(l1sram_lock, cpu), flags);
	addr = _sram_alloc(size, &per_cpu(free_l1_ssram_head, cpu),
			&per_cpu(used_l1_ssram_head, cpu));
	/* add mutex operation */
	spin_unlock_irqrestore(&per_cpu(l1sram_lock, cpu), flags);
	return addr;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Bryan Wu | 45 | 56.25% | 1 | 16.67% | 
| Graf Yang | 28 | 35.00% | 1 | 16.67% | 
| Sonic Zhang | 5 | 6.25% | 2 | 33.33% | 
| Yi Li | 1 | 1.25% | 1 | 16.67% | 
| Vegard Nossum | 1 | 1.25% | 1 | 16.67% | 
| Total | 80 | 100.00% | 6 | 100.00% | 
/* L1 Scratchpad memory allocate function */
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(&per_cpu(l1sram_lock, cpu), flags);
	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(&per_cpu(l1sram_lock, cpu), flags);
	return addr;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Bryan Wu | 46 | 56.79% | 1 | 16.67% | 
| Graf Yang | 28 | 34.57% | 1 | 16.67% | 
| Sonic Zhang | 5 | 6.17% | 2 | 33.33% | 
| Yi Li | 1 | 1.23% | 1 | 16.67% | 
| Vegard Nossum | 1 | 1.23% | 1 | 16.67% | 
| Total | 81 | 100.00% | 6 | 100.00% | 
/* L1 Scratchpad memory free function */
int l1sram_free(const void *addr)
{
	unsigned long flags;
	int ret;
	unsigned int cpu;
	cpu = smp_processor_id();
	/* add mutex operation */
	spin_lock_irqsave(&per_cpu(l1sram_lock, cpu), flags);
	ret = _sram_free(addr, &per_cpu(free_l1_ssram_head, cpu),
			&per_cpu(used_l1_ssram_head, cpu));
	/* add mutex operation */
	spin_unlock_irqrestore(&per_cpu(l1sram_lock, cpu), flags);
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Bryan Wu | 45 | 56.25% | 1 | 16.67% | 
| Graf Yang | 28 | 35.00% | 1 | 16.67% | 
| Sonic Zhang | 5 | 6.25% | 2 | 33.33% | 
| Vegard Nossum | 1 | 1.25% | 1 | 16.67% | 
| Yi Li | 1 | 1.25% | 1 | 16.67% | 
| Total | 80 | 100.00% | 6 | 100.00% | 
void *l2_sram_alloc(size_t size)
{
#if L2_LENGTH != 0
	unsigned long flags;
	void *addr;
	/* add mutex operation */
	spin_lock_irqsave(&l2_sram_lock, flags);
	addr = _sram_alloc(size, &free_l2_sram_head,
			&used_l2_sram_head);
	/* add mutex operation */
	spin_unlock_irqrestore(&l2_sram_lock, flags);
	pr_debug("Allocated address in l2_sram_alloc is 0x%lx+0x%lx\n",
		 (long unsigned int)addr, size);
	return addr;
#else
	return NULL;
#endif
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Sonic Zhang | 72 | 93.51% | 1 | 33.33% | 
| Mike Frysinger | 4 | 5.19% | 1 | 33.33% | 
| Vegard Nossum | 1 | 1.30% | 1 | 33.33% | 
| Total | 77 | 100.00% | 3 | 100.00% | 
EXPORT_SYMBOL(l2_sram_alloc);
void *l2_sram_zalloc(size_t size)
{
	void *addr = l2_sram_alloc(size);
	if (addr)
		memset(addr, 0x00, size);
	return addr;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Sonic Zhang | 34 | 100.00% | 1 | 100.00% | 
| Total | 34 | 100.00% | 1 | 100.00% | 
EXPORT_SYMBOL(l2_sram_zalloc);
int l2_sram_free(const void *addr)
{
#if L2_LENGTH != 0
	unsigned long flags;
	int ret;
	/* add mutex operation */
	spin_lock_irqsave(&l2_sram_lock, flags);
	ret = _sram_free(addr, &free_l2_sram_head,
			&used_l2_sram_head);
	/* add mutex operation */
	spin_unlock_irqrestore(&l2_sram_lock, flags);
	return ret;
#else
	return -1;
#endif
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Sonic Zhang | 59 | 92.19% | 1 | 33.33% | 
| Mike Frysinger | 4 | 6.25% | 1 | 33.33% | 
| Vegard Nossum | 1 | 1.56% | 1 | 33.33% | 
| Total | 64 | 100.00% | 3 | 100.00% | 
EXPORT_SYMBOL(l2_sram_free);
int sram_free_with_lsl(const void *addr)
{
	struct sram_list_struct *lsl, **tmp;
	struct mm_struct *mm = current->mm;
	int ret = -1;
	for (tmp = &mm->context.sram_list; *tmp; tmp = &(*tmp)->next)
		if ((*tmp)->addr == addr) {
			lsl = *tmp;
			ret = sram_free(addr);
			*tmp = lsl->next;
			kfree(lsl);
			break;
		}
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Bryan Wu | 87 | 87.88% | 1 | 50.00% | 
| Mike Frysinger | 12 | 12.12% | 1 | 50.00% | 
| Total | 99 | 100.00% | 2 | 100.00% | 
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;
	struct sram_list_struct *lsl = NULL;
	struct mm_struct *mm = current->mm;
	lsl = kzalloc(sizeof(struct sram_list_struct), GFP_KERNEL);
	if (!lsl)
		return NULL;
	if (flags & L1_INST_SRAM)
		addr = l1_inst_sram_alloc(size);
	if (addr == NULL && (flags & L1_DATA_A_SRAM))
		addr = l1_data_A_sram_alloc(size);
	if (addr == NULL && (flags & L1_DATA_B_SRAM))
		addr = l1_data_B_sram_alloc(size);
	if (addr == NULL && (flags & L2_SRAM))
		addr = l2_sram_alloc(size);
	if (addr == NULL) {
		kfree(lsl);
		return NULL;
	}
	lsl->addr = addr;
	lsl->length = size;
	lsl->next = mm->context.sram_list;
	mm->context.sram_list = lsl;
	return addr;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Bryan Wu | 155 | 88.57% | 1 | 33.33% | 
| Sonic Zhang | 19 | 10.86% | 1 | 33.33% | 
| Yoann Padioleau | 1 | 0.57% | 1 | 33.33% | 
| Total | 175 | 100.00% | 3 | 100.00% | 
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.
 */
/* Need to keep line of output the same.  Currently, that is 44 bytes
 * (including newline).
 */
static int _sram_proc_show(struct seq_file *m, const char *desc,
		struct sram_piece *pfree_head,
		struct sram_piece *pused_head)
{
	struct sram_piece *pslot;
	if (!pfree_head || !pused_head)
		return -1;
	seq_printf(m, "--- SRAM %-14s Size   PID State     \n", desc);
	/* search the relevant memory slot */
	pslot = pused_head->next;
	while (pslot != NULL) {
		seq_printf(m, "%p-%p %10i %5i %-10s\n",
			pslot->paddr, pslot->paddr + pslot->size,
			pslot->size, pslot->pid, "ALLOCATED");
		pslot = pslot->next;
	}
	pslot = pfree_head->next;
	while (pslot != NULL) {
		seq_printf(m, "%p-%p %10i %5i %-10s\n",
			pslot->paddr, pslot->paddr + pslot->size,
			pslot->size, pslot->pid, "FREE");
		pslot = pslot->next;
	}
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Sonic Zhang | 95 | 61.69% | 2 | 40.00% | 
| Mike Frysinger | 49 | 31.82% | 2 | 40.00% | 
| Alexey Dobriyan | 10 | 6.49% | 1 | 20.00% | 
| Total | 154 | 100.00% | 5 | 100.00% | 
static int sram_proc_show(struct seq_file *m, void *v)
{
	unsigned int cpu;
	for (cpu = 0; cpu < num_possible_cpus(); ++cpu) {
		if (_sram_proc_show(m, "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_show(m, "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_show(m, "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_show(m, "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_show(m, "L2", &free_l2_sram_head, &used_l2_sram_head))
		goto not_done;
#endif
 not_done:
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Mike Frysinger | 82 | 41.41% | 3 | 42.86% | 
| Graf Yang | 60 | 30.30% | 1 | 14.29% | 
| Sonic Zhang | 38 | 19.19% | 2 | 28.57% | 
| Alexey Dobriyan | 18 | 9.09% | 1 | 14.29% | 
| Total | 198 | 100.00% | 7 | 100.00% | 
static int sram_proc_open(struct inode *inode, struct file *file)
{
	return single_open(file, sram_proc_show, NULL);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Alexey Dobriyan | 24 | 92.31% | 1 | 50.00% | 
| Mike Frysinger | 2 | 7.69% | 1 | 50.00% | 
| Total | 26 | 100.00% | 2 | 100.00% | 
static const struct file_operations sram_proc_ops = {
	.open		= sram_proc_open,
	.read		= seq_read,
	.llseek		= seq_lseek,
	.release	= single_release,
};
static int __init sram_proc_init(void)
{
	struct proc_dir_entry *ptr;
	ptr = proc_create("sram", S_IRUGO, NULL, &sram_proc_ops);
	if (!ptr) {
		printk(KERN_WARNING "unable to create /proc/sram\n");
		return -1;
	}
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Mike Frysinger | 43 | 89.58% | 1 | 33.33% | 
| Alexey Dobriyan | 4 | 8.33% | 1 | 33.33% | 
| Sonic Zhang | 1 | 2.08% | 1 | 33.33% | 
| Total | 48 | 100.00% | 3 | 100.00% | 
late_initcall(sram_proc_init);
#endif
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Bryan Wu | 1460 | 36.57% | 1 | 3.33% | 
| Sonic Zhang | 1177 | 29.48% | 3 | 10.00% | 
| Graf Yang | 714 | 17.89% | 4 | 13.33% | 
| Mike Frysinger | 366 | 9.17% | 10 | 33.33% | 
| Bob Liu | 151 | 3.78% | 1 | 3.33% | 
| Alexey Dobriyan | 87 | 2.18% | 1 | 3.33% | 
| Vegard Nossum | 11 | 0.28% | 1 | 3.33% | 
| Yi Li | 9 | 0.23% | 1 | 3.33% | 
| Robin Getz | 6 | 0.15% | 2 | 6.67% | 
| Ingo Molnar | 3 | 0.08% | 1 | 3.33% | 
| Tejun Heo | 3 | 0.08% | 1 | 3.33% | 
| Jie Zhang | 2 | 0.05% | 1 | 3.33% | 
| Yoann Padioleau | 1 | 0.03% | 1 | 3.33% | 
| Meihui Fan | 1 | 0.03% | 1 | 3.33% | 
| Masanari Iida | 1 | 0.03% | 1 | 3.33% | 
| Total | 3992 | 100.00% | 30 | 100.00% | 
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.