Release 4.14 arch/cris/arch-v32/mm/intmem.c
// SPDX-License-Identifier: GPL-2.0
/*
* Simple allocator for internal RAM in ETRAX FS
*
* Copyright (c) 2004 Axis Communications AB.
*/
#include <linux/list.h>
#include <linux/slab.h>
#include <asm/io.h>
#include <memmap.h>
#define STATUS_FREE 0
#define STATUS_ALLOCATED 1
#ifdef CONFIG_ETRAX_L2CACHE
#define RESERVED_SIZE 66*1024
#else
#define RESERVED_SIZE 0
#endif
struct intmem_allocation {
struct list_head entry;
unsigned int size;
unsigned offset;
char status;
};
static struct list_head intmem_allocations;
static void* intmem_virtual;
static void crisv32_intmem_init(void)
{
static int initiated = 0;
if (!initiated) {
struct intmem_allocation* alloc;
alloc = kmalloc(sizeof *alloc, GFP_KERNEL);
INIT_LIST_HEAD(&intmem_allocations);
intmem_virtual = ioremap(MEM_INTMEM_START + RESERVED_SIZE,
MEM_INTMEM_SIZE - RESERVED_SIZE);
initiated = 1;
alloc->size = MEM_INTMEM_SIZE - RESERVED_SIZE;
alloc->offset = 0;
alloc->status = STATUS_FREE;
list_add_tail(&alloc->entry, &intmem_allocations);
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mikael Starvik | 81 | 89.01% | 1 | 33.33% |
Jesper Nilsson | 6 | 6.59% | 1 | 33.33% |
Joe Perches | 4 | 4.40% | 1 | 33.33% |
Total | 91 | 100.00% | 3 | 100.00% |
void* crisv32_intmem_alloc(unsigned size, unsigned align)
{
struct intmem_allocation* allocation;
struct intmem_allocation* tmp;
void* ret = NULL;
preempt_disable();
crisv32_intmem_init();
list_for_each_entry_safe(allocation, tmp, &intmem_allocations, entry) {
int alignment = allocation->offset % align;
alignment = alignment ? align - alignment : alignment;
if (allocation->status == STATUS_FREE &&
allocation->size >= size + alignment) {
if (allocation->size > size + alignment) {
struct intmem_allocation* alloc;
alloc = kmalloc(sizeof *alloc, GFP_ATOMIC);
alloc->status = STATUS_FREE;
alloc->size = allocation->size - size -
alignment;
alloc->offset = allocation->offset + size +
alignment;
list_add(&alloc->entry, &allocation->entry);
if (alignment) {
struct intmem_allocation *tmp;
tmp = kmalloc(sizeof *tmp, GFP_ATOMIC);
tmp->offset = allocation->offset;
tmp->size = alignment;
tmp->status = STATUS_FREE;
allocation->offset += alignment;
list_add_tail(&tmp->entry,
&allocation->entry);
}
}
allocation->status = STATUS_ALLOCATED;
allocation->size = size;
ret = (void*)((int)intmem_virtual + allocation->offset);
}
}
preempt_enable();
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mikael Starvik | 244 | 97.60% | 1 | 33.33% |
Joe Perches | 4 | 1.60% | 1 | 33.33% |
Jesper Nilsson | 2 | 0.80% | 1 | 33.33% |
Total | 250 | 100.00% | 3 | 100.00% |
void crisv32_intmem_free(void* addr)
{
struct intmem_allocation* allocation;
struct intmem_allocation* tmp;
if (addr == NULL)
return;
preempt_disable();
crisv32_intmem_init();
list_for_each_entry_safe(allocation, tmp, &intmem_allocations, entry) {
if (allocation->offset == (int)(addr - intmem_virtual)) {
struct intmem_allocation *prev =
list_entry(allocation->entry.prev,
struct intmem_allocation, entry);
struct intmem_allocation *next =
list_entry(allocation->entry.next,
struct intmem_allocation, entry);
allocation->status = STATUS_FREE;
/* Join with prev and/or next if also free */
if ((&prev->entry != &intmem_allocations) &&
(prev->status == STATUS_FREE)) {
prev->size += allocation->size;
list_del(&allocation->entry);
kfree(allocation);
allocation = prev;
}
if ((&next->entry != &intmem_allocations) &&
(next->status == STATUS_FREE)) {
allocation->size += next->size;
list_del(&next->entry);
kfree(next);
}
preempt_enable();
return;
}
}
preempt_enable();
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mikael Starvik | 179 | 88.18% | 1 | 33.33% |
Jesper Nilsson | 18 | 8.87% | 1 | 33.33% |
Niklas Svensson (Niklas Cassel) | 6 | 2.96% | 1 | 33.33% |
Total | 203 | 100.00% | 3 | 100.00% |
void* crisv32_intmem_phys_to_virt(unsigned long addr)
{
return (void *)(addr - (MEM_INTMEM_START + RESERVED_SIZE) +
(unsigned long)intmem_virtual);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mikael Starvik | 27 | 87.10% | 1 | 50.00% |
Jesper Nilsson | 4 | 12.90% | 1 | 50.00% |
Total | 31 | 100.00% | 2 | 100.00% |
unsigned long crisv32_intmem_virt_to_phys(void* addr)
{
return (unsigned long)((unsigned long )addr -
(unsigned long)intmem_virtual + MEM_INTMEM_START +
RESERVED_SIZE);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mikael Starvik | 31 | 93.94% | 1 | 50.00% |
Jesper Nilsson | 2 | 6.06% | 1 | 50.00% |
Total | 33 | 100.00% | 2 | 100.00% |
static int __init crisv32_intmem_setup(void)
{
crisv32_intmem_init();
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jesper Nilsson | 15 | 100.00% | 1 | 100.00% |
Total | 15 | 100.00% | 1 | 100.00% |
device_initcall(crisv32_intmem_setup);
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mikael Starvik | 611 | 88.04% | 1 | 14.29% |
Jesper Nilsson | 67 | 9.65% | 2 | 28.57% |
Joe Perches | 8 | 1.15% | 1 | 14.29% |
Niklas Svensson (Niklas Cassel) | 6 | 0.86% | 1 | 14.29% |
Greg Kroah-Hartman | 1 | 0.14% | 1 | 14.29% |
Paul Gortmaker | 1 | 0.14% | 1 | 14.29% |
Total | 694 | 100.00% | 7 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.