mirror of
https://github.com/adulau/aha.git
synced 2024-12-28 11:46:19 +00:00
ALSA: ctxfi - Support SG-buffers
Use SG-buffers instead of contiguous pages. Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
cd391e206f
commit
c76157d928
4 changed files with 30 additions and 37 deletions
|
@ -128,7 +128,7 @@ static int ct_map_audio_buffer(struct ct_atc *atc, struct ct_atc_pcm *apcm)
|
||||||
runtime = apcm->substream->runtime;
|
runtime = apcm->substream->runtime;
|
||||||
vm = atc->vm;
|
vm = atc->vm;
|
||||||
|
|
||||||
apcm->vm_block = vm->map(vm, runtime->dma_area, runtime->dma_bytes);
|
apcm->vm_block = vm->map(vm, apcm->substream, runtime->dma_bytes);
|
||||||
|
|
||||||
if (NULL == apcm->vm_block)
|
if (NULL == apcm->vm_block)
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
|
|
@ -442,6 +442,7 @@ static struct snd_pcm_ops ct_pcm_playback_ops = {
|
||||||
.prepare = ct_pcm_playback_prepare,
|
.prepare = ct_pcm_playback_prepare,
|
||||||
.trigger = ct_pcm_playback_trigger,
|
.trigger = ct_pcm_playback_trigger,
|
||||||
.pointer = ct_pcm_playback_pointer,
|
.pointer = ct_pcm_playback_pointer,
|
||||||
|
.page = snd_pcm_sgbuf_ops_page,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* PCM operators for capture */
|
/* PCM operators for capture */
|
||||||
|
@ -454,6 +455,7 @@ static struct snd_pcm_ops ct_pcm_capture_ops = {
|
||||||
.prepare = ct_pcm_capture_prepare,
|
.prepare = ct_pcm_capture_prepare,
|
||||||
.trigger = ct_pcm_capture_trigger,
|
.trigger = ct_pcm_capture_trigger,
|
||||||
.pointer = ct_pcm_capture_pointer,
|
.pointer = ct_pcm_capture_pointer,
|
||||||
|
.page = snd_pcm_sgbuf_ops_page,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Create ALSA pcm device */
|
/* Create ALSA pcm device */
|
||||||
|
@ -485,7 +487,7 @@ int ct_alsa_pcm_create(struct ct_atc *atc,
|
||||||
snd_pcm_set_ops(pcm,
|
snd_pcm_set_ops(pcm,
|
||||||
SNDRV_PCM_STREAM_CAPTURE, &ct_pcm_capture_ops);
|
SNDRV_PCM_STREAM_CAPTURE, &ct_pcm_capture_ops);
|
||||||
|
|
||||||
snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
|
snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
|
||||||
snd_dma_pci_data(atc->pci), 128*1024, 128*1024);
|
snd_dma_pci_data(atc->pci), 128*1024, 128*1024);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/mm.h>
|
#include <linux/mm.h>
|
||||||
#include <linux/io.h>
|
#include <linux/io.h>
|
||||||
#include <asm/pgtable.h>
|
#include <sound/pcm.h>
|
||||||
|
|
||||||
#define CT_PTES_PER_PAGE (CT_PAGE_SIZE / sizeof(void *))
|
#define CT_PTES_PER_PAGE (CT_PAGE_SIZE / sizeof(void *))
|
||||||
#define CT_ADDRS_PER_PAGE (CT_PTES_PER_PAGE * CT_PAGE_SIZE)
|
#define CT_ADDRS_PER_PAGE (CT_PTES_PER_PAGE * CT_PAGE_SIZE)
|
||||||
|
@ -34,6 +34,13 @@ get_vm_block(struct ct_vm *vm, unsigned int size)
|
||||||
struct ct_vm_block *block = NULL, *entry = NULL;
|
struct ct_vm_block *block = NULL, *entry = NULL;
|
||||||
struct list_head *pos = NULL;
|
struct list_head *pos = NULL;
|
||||||
|
|
||||||
|
size = CT_PAGE_ALIGN(size);
|
||||||
|
if (size > vm->size) {
|
||||||
|
printk(KERN_ERR "ctxfi: Fail! No sufficient device virtural "
|
||||||
|
"memory space available!\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
mutex_lock(&vm->lock);
|
mutex_lock(&vm->lock);
|
||||||
list_for_each(pos, &vm->unused) {
|
list_for_each(pos, &vm->unused) {
|
||||||
entry = list_entry(pos, struct ct_vm_block, list);
|
entry = list_entry(pos, struct ct_vm_block, list);
|
||||||
|
@ -73,6 +80,8 @@ static void put_vm_block(struct ct_vm *vm, struct ct_vm_block *block)
|
||||||
struct ct_vm_block *entry = NULL, *pre_ent = NULL;
|
struct ct_vm_block *entry = NULL, *pre_ent = NULL;
|
||||||
struct list_head *pos = NULL, *pre = NULL;
|
struct list_head *pos = NULL, *pre = NULL;
|
||||||
|
|
||||||
|
block->size = CT_PAGE_ALIGN(block->size);
|
||||||
|
|
||||||
mutex_lock(&vm->lock);
|
mutex_lock(&vm->lock);
|
||||||
list_del(&block->list);
|
list_del(&block->list);
|
||||||
vm->size += block->size;
|
vm->size += block->size;
|
||||||
|
@ -115,57 +124,36 @@ static void put_vm_block(struct ct_vm *vm, struct ct_vm_block *block)
|
||||||
|
|
||||||
/* Map host addr (kmalloced/vmalloced) to device logical addr. */
|
/* Map host addr (kmalloced/vmalloced) to device logical addr. */
|
||||||
static struct ct_vm_block *
|
static struct ct_vm_block *
|
||||||
ct_vm_map(struct ct_vm *vm, void *host_addr, int size)
|
ct_vm_map(struct ct_vm *vm, struct snd_pcm_substream *substream, int size)
|
||||||
{
|
{
|
||||||
struct ct_vm_block *block = NULL;
|
struct ct_vm_block *block;
|
||||||
unsigned long pte_start;
|
unsigned int pte_start;
|
||||||
unsigned long i;
|
unsigned i, pages;
|
||||||
unsigned long pages;
|
|
||||||
unsigned long start_phys;
|
|
||||||
unsigned long *ptp;
|
unsigned long *ptp;
|
||||||
|
|
||||||
/* do mapping */
|
block = get_vm_block(vm, size);
|
||||||
if ((unsigned long)host_addr >= VMALLOC_START) {
|
|
||||||
printk(KERN_ERR "ctxfi: "
|
|
||||||
"Fail! Not support vmalloced addr now!\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (size > vm->size) {
|
|
||||||
printk(KERN_ERR "ctxfi: Fail! No sufficient device virtural "
|
|
||||||
"memory space available!\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
start_phys = (virt_to_phys(host_addr) & CT_PAGE_MASK);
|
|
||||||
pages = (CT_PAGE_ALIGN(virt_to_phys(host_addr) + size)
|
|
||||||
- start_phys) >> CT_PAGE_SHIFT;
|
|
||||||
|
|
||||||
ptp = vm->ptp[0];
|
|
||||||
|
|
||||||
block = get_vm_block(vm, (pages << CT_PAGE_SHIFT));
|
|
||||||
if (block == NULL) {
|
if (block == NULL) {
|
||||||
printk(KERN_ERR "ctxfi: No virtual memory block that is big "
|
printk(KERN_ERR "ctxfi: No virtual memory block that is big "
|
||||||
"enough to allocate!\n");
|
"enough to allocate!\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ptp = vm->ptp[0];
|
||||||
pte_start = (block->addr >> CT_PAGE_SHIFT);
|
pte_start = (block->addr >> CT_PAGE_SHIFT);
|
||||||
for (i = 0; i < pages; i++)
|
pages = block->size >> CT_PAGE_SHIFT;
|
||||||
ptp[pte_start+i] = start_phys + (i << CT_PAGE_SHIFT);
|
for (i = 0; i < pages; i++) {
|
||||||
|
unsigned long addr;
|
||||||
|
addr = snd_pcm_sgbuf_get_addr(substream, i << CT_PAGE_SHIFT);
|
||||||
|
ptp[pte_start + i] = addr;
|
||||||
|
}
|
||||||
|
|
||||||
block->addr += (virt_to_phys(host_addr) & (~CT_PAGE_MASK));
|
|
||||||
block->size = size;
|
block->size = size;
|
||||||
|
|
||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ct_vm_unmap(struct ct_vm *vm, struct ct_vm_block *block)
|
static void ct_vm_unmap(struct ct_vm *vm, struct ct_vm_block *block)
|
||||||
{
|
{
|
||||||
/* do unmapping */
|
/* do unmapping */
|
||||||
block->size = ((block->addr + block->size + CT_PAGE_SIZE - 1)
|
|
||||||
& CT_PAGE_MASK) - (block->addr & CT_PAGE_MASK);
|
|
||||||
block->addr &= CT_PAGE_MASK;
|
|
||||||
put_vm_block(vm, block);
|
put_vm_block(vm, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,8 @@ struct ct_vm_block {
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct snd_pcm_substream;
|
||||||
|
|
||||||
/* Virtual memory management object for card device */
|
/* Virtual memory management object for card device */
|
||||||
struct ct_vm {
|
struct ct_vm {
|
||||||
void *ptp[CT_PTP_NUM]; /* Device page table pages */
|
void *ptp[CT_PTP_NUM]; /* Device page table pages */
|
||||||
|
@ -46,7 +48,8 @@ struct ct_vm {
|
||||||
struct mutex lock;
|
struct mutex lock;
|
||||||
|
|
||||||
/* Map host addr (kmalloced/vmalloced) to device logical addr. */
|
/* Map host addr (kmalloced/vmalloced) to device logical addr. */
|
||||||
struct ct_vm_block *(*map)(struct ct_vm *, void *host_addr, int size);
|
struct ct_vm_block *(*map)(struct ct_vm *, struct snd_pcm_substream *,
|
||||||
|
int size);
|
||||||
/* Unmap device logical addr area. */
|
/* Unmap device logical addr area. */
|
||||||
void (*unmap)(struct ct_vm *, struct ct_vm_block *block);
|
void (*unmap)(struct ct_vm *, struct ct_vm_block *block);
|
||||||
void *(*get_ptp_virt)(struct ct_vm *vm, int index);
|
void *(*get_ptp_virt)(struct ct_vm *vm, int index);
|
||||||
|
|
Loading…
Reference in a new issue