Commit 79bc5bfe authored by Troy Kisky's avatar Troy Kisky Committed by Kevin Hilman

ARM: DaVinci: IRAM alloc/free routines

This adds IRAM allocation and free routines which
will be used to fix audio underrun/overrun problems.
Signed-off-by: default avatarTroy Kisky <troy.kisky@boundarydevices.com>
parent 615a0842
......@@ -5,7 +5,7 @@
# Common objects
obj-y := time.o irq.o clock.o serial.o io.o id.o psc.o \
gpio.o mux.o devices.o usb.o dma.o common.o
gpio.o mux.o devices.o usb.o dma.o common.o iram.o
# Board specific
obj-$(CONFIG_MACH_DAVINCI_EVM) += board-evm.o
......
......@@ -560,4 +560,7 @@ void davinci_free_dma(int lch);
* DMA channel
**/
void davinci_dma_getposition(int lch, dma_addr_t *src, dma_addr_t *dst);
int davinci_alloc_iram(unsigned size);
void davinci_free_iram(unsigned addr, unsigned size);
#endif
/*
* linux/arch/arm/mach-davinci/iram.c
*
* DaVinci iram allocation/free
* Copyright (C) 2008 Boundary Devices.
*
* 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.
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <mach/memory.h>
/*
* 2**14 (16K) / 2**5 (32) = 2**9 (512 bytes per bit)
*/
static atomic_t iram_mask;
int davinci_alloc_iram(unsigned size)
{
unsigned int mask;
unsigned int mask_prior;
unsigned addr;
unsigned cnt;
cnt = (size + 511) >> 9;
if (cnt >= 32)
return 0;
mask = atomic_read(&iram_mask);
do {
unsigned int need_mask = (1 << cnt) - 1;
addr = DAVINCI_IRAM_BASE;
while (mask & need_mask) {
if (need_mask & (1<<31))
return -ENOMEM;
need_mask <<= 1;
addr += 512;
}
mask_prior = mask;
mask = atomic_cmpxchg(&iram_mask, mask, mask | need_mask);
} while (mask != mask_prior);
return addr;
}
EXPORT_SYMBOL(davinci_alloc_iram);
void davinci_free_iram(unsigned addr, unsigned size)
{
unsigned mask;
addr -= DAVINCI_IRAM_BASE;
addr >>= 9;
size = (size + 511) >> 9;
if ((size + addr) >= 32)
return;
mask = ((1 << size) - 1) << addr;
atomic_clear_mask(mask, (unsigned long *)&iram_mask.counter);
}
EXPORT_SYMBOL(davinci_free_iram);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment