X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sound%2Fpci%2Femu10k1%2Fmemory.c;h=e7ec98649f044fa858740dc6a4678bf2b9f7c734;hb=43bc926fffd92024b46cafaf7350d669ba9ca884;hp=90e69535a751a60613495d917485e49cee363a16;hpb=5273a3df6485dc2ad6aa7ddd441b9a21970f003b;p=linux-2.6.git diff --git a/sound/pci/emu10k1/memory.c b/sound/pci/emu10k1/memory.c index 90e69535a..e7ec98649 100644 --- a/sound/pci/emu10k1/memory.c +++ b/sound/pci/emu10k1/memory.c @@ -22,7 +22,10 @@ */ #include +#include #include +#include + #include #include @@ -47,7 +50,7 @@ #define set_silent_ptb(emu,page) __set_ptb_entry(emu,page,emu->silent_page.addr) #else /* fill PTB entries -- we need to fill UNIT_PAGES entries */ -static inline void set_ptb_entry(emu10k1_t *emu, int page, dma_addr_t addr) +static inline void set_ptb_entry(struct snd_emu10k1 *emu, int page, dma_addr_t addr) { int i; page *= UNIT_PAGES; @@ -56,7 +59,7 @@ static inline void set_ptb_entry(emu10k1_t *emu, int page, dma_addr_t addr) addr += EMUPAGESIZE; } } -static inline void set_silent_ptb(emu10k1_t *emu, int page) +static inline void set_silent_ptb(struct snd_emu10k1 *emu, int page) { int i; page *= UNIT_PAGES; @@ -69,14 +72,14 @@ static inline void set_silent_ptb(emu10k1_t *emu, int page) /* */ -static int synth_alloc_pages(emu10k1_t *hw, emu10k1_memblk_t *blk); -static int synth_free_pages(emu10k1_t *hw, emu10k1_memblk_t *blk); +static int synth_alloc_pages(struct snd_emu10k1 *hw, struct snd_emu10k1_memblk *blk); +static int synth_free_pages(struct snd_emu10k1 *hw, struct snd_emu10k1_memblk *blk); -#define get_emu10k1_memblk(l,member) list_entry(l, emu10k1_memblk_t, member) +#define get_emu10k1_memblk(l,member) list_entry(l, struct snd_emu10k1_memblk, member) /* initialize emu10k1 part */ -static void emu10k1_memblk_init(emu10k1_memblk_t *blk) +static void emu10k1_memblk_init(struct snd_emu10k1_memblk *blk) { blk->mapped_page = -1; INIT_LIST_HEAD(&blk->mapped_link); @@ -95,7 +98,7 @@ static void emu10k1_memblk_init(emu10k1_memblk_t *blk) * in nextp * if not found, return a negative error code. */ -static int search_empty_map_area(emu10k1_t *emu, int npages, struct list_head **nextp) +static int search_empty_map_area(struct snd_emu10k1 *emu, int npages, struct list_head **nextp) { int page = 0, found_page = -ENOMEM; int max_size = npages; @@ -104,7 +107,7 @@ static int search_empty_map_area(emu10k1_t *emu, int npages, struct list_head ** struct list_head *pos; list_for_each (pos, &emu->mapped_link_head) { - emu10k1_memblk_t *blk = get_emu10k1_memblk(pos, mapped_link); + struct snd_emu10k1_memblk *blk = get_emu10k1_memblk(pos, mapped_link); snd_assert(blk->mapped_page >= 0, continue); size = blk->mapped_page - page; if (size == npages) { @@ -133,7 +136,7 @@ static int search_empty_map_area(emu10k1_t *emu, int npages, struct list_head ** * * call with memblk_lock held */ -static int map_memblk(emu10k1_t *emu, emu10k1_memblk_t *blk) +static int map_memblk(struct snd_emu10k1 *emu, struct snd_emu10k1_memblk *blk) { int page, pg; struct list_head *next; @@ -160,11 +163,11 @@ static int map_memblk(emu10k1_t *emu, emu10k1_memblk_t *blk) * * call with memblk_lock held */ -static int unmap_memblk(emu10k1_t *emu, emu10k1_memblk_t *blk) +static int unmap_memblk(struct snd_emu10k1 *emu, struct snd_emu10k1_memblk *blk) { int start_page, end_page, mpage, pg; struct list_head *p; - emu10k1_memblk_t *q; + struct snd_emu10k1_memblk *q; /* calculate the expected size of empty region */ if ((p = blk->mapped_link.prev) != &emu->mapped_link_head) { @@ -196,11 +199,11 @@ static int unmap_memblk(emu10k1_t *emu, emu10k1_memblk_t *blk) * * unlike synth_alloc the memory block is aligned to the page start */ -static emu10k1_memblk_t * -search_empty(emu10k1_t *emu, int size) +static struct snd_emu10k1_memblk * +search_empty(struct snd_emu10k1 *emu, int size) { struct list_head *p; - emu10k1_memblk_t *blk; + struct snd_emu10k1_memblk *blk; int page, psize; psize = get_aligned_page(size + PAGE_SIZE -1); @@ -216,7 +219,7 @@ search_empty(emu10k1_t *emu, int size) __found_pages: /* create a new memory block */ - blk = (emu10k1_memblk_t *)__snd_util_memblk_new(emu->memhdr, psize << PAGE_SHIFT, p->prev); + blk = (struct snd_emu10k1_memblk *)__snd_util_memblk_new(emu->memhdr, psize << PAGE_SHIFT, p->prev); if (blk == NULL) return NULL; blk->mem.offset = aligned_page_offset(page); /* set aligned offset */ @@ -228,14 +231,14 @@ __found_pages: /* * check if the given pointer is valid for pages */ -static int is_valid_page(emu10k1_t *emu, dma_addr_t addr) +static int is_valid_page(struct snd_emu10k1 *emu, dma_addr_t addr) { if (addr & ~emu->dma_mask) { - snd_printk("max memory size is 0x%lx (addr = 0x%lx)!!\n", emu->dma_mask, (unsigned long)addr); + snd_printk(KERN_ERR "max memory size is 0x%lx (addr = 0x%lx)!!\n", emu->dma_mask, (unsigned long)addr); return 0; } if (addr & (EMUPAGESIZE-1)) { - snd_printk("page is not aligned\n"); + snd_printk(KERN_ERR "page is not aligned\n"); return 0; } return 1; @@ -247,12 +250,12 @@ static int is_valid_page(emu10k1_t *emu, dma_addr_t addr) * if no empty pages are found, tries to release unsed memory blocks * and retry the mapping. */ -int snd_emu10k1_memblk_map(emu10k1_t *emu, emu10k1_memblk_t *blk) +int snd_emu10k1_memblk_map(struct snd_emu10k1 *emu, struct snd_emu10k1_memblk *blk) { int err; int size; struct list_head *p, *nextp; - emu10k1_memblk_t *deleted; + struct snd_emu10k1_memblk *deleted; unsigned long flags; spin_lock_irqsave(&emu->memblk_lock, flags); @@ -287,13 +290,13 @@ int snd_emu10k1_memblk_map(emu10k1_t *emu, emu10k1_memblk_t *blk) /* * page allocation for DMA */ -snd_util_memblk_t * -snd_emu10k1_alloc_pages(emu10k1_t *emu, snd_pcm_substream_t *substream) +struct snd_util_memblk * +snd_emu10k1_alloc_pages(struct snd_emu10k1 *emu, struct snd_pcm_substream *substream) { - snd_pcm_runtime_t *runtime = substream->runtime; - struct snd_sg_buf *sgbuf = runtime->dma_private; - snd_util_memhdr_t *hdr; - emu10k1_memblk_t *blk; + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream); + struct snd_util_memhdr *hdr; + struct snd_emu10k1_memblk *blk; int page, err, idx; snd_assert(emu, return NULL); @@ -301,10 +304,10 @@ snd_emu10k1_alloc_pages(emu10k1_t *emu, snd_pcm_substream_t *substream) hdr = emu->memhdr; snd_assert(hdr, return NULL); - down(&hdr->block_mutex); + mutex_lock(&hdr->block_mutex); blk = search_empty(emu, runtime->dma_bytes); if (blk == NULL) { - up(&hdr->block_mutex); + mutex_unlock(&hdr->block_mutex); return NULL; } /* fill buffer addresses but pointers are not stored so that @@ -317,14 +320,14 @@ snd_emu10k1_alloc_pages(emu10k1_t *emu, snd_pcm_substream_t *substream) if (idx >= sgbuf->pages) { printk(KERN_ERR "emu: pages overflow! (%d-%d) for %d\n", blk->first_page, blk->last_page, sgbuf->pages); - up(&hdr->block_mutex); + mutex_unlock(&hdr->block_mutex); return NULL; } #endif addr = sgbuf->table[idx].addr; if (! is_valid_page(emu, addr)) { printk(KERN_ERR "emu: failure page = %d\n", idx); - up(&hdr->block_mutex); + mutex_unlock(&hdr->block_mutex); return NULL; } emu->page_addr_table[page] = addr; @@ -335,19 +338,19 @@ snd_emu10k1_alloc_pages(emu10k1_t *emu, snd_pcm_substream_t *substream) blk->map_locked = 1; /* do not unmap this block! */ err = snd_emu10k1_memblk_map(emu, blk); if (err < 0) { - __snd_util_mem_free(hdr, (snd_util_memblk_t *)blk); - up(&hdr->block_mutex); + __snd_util_mem_free(hdr, (struct snd_util_memblk *)blk); + mutex_unlock(&hdr->block_mutex); return NULL; } - up(&hdr->block_mutex); - return (snd_util_memblk_t *)blk; + mutex_unlock(&hdr->block_mutex); + return (struct snd_util_memblk *)blk; } /* * release DMA buffer from page table */ -int snd_emu10k1_free_pages(emu10k1_t *emu, snd_util_memblk_t *blk) +int snd_emu10k1_free_pages(struct snd_emu10k1 *emu, struct snd_util_memblk *blk) { snd_assert(emu && blk, return -EINVAL); return snd_emu10k1_synth_free(emu, blk); @@ -362,26 +365,26 @@ int snd_emu10k1_free_pages(emu10k1_t *emu, snd_util_memblk_t *blk) /* * allocate a synth sample area */ -snd_util_memblk_t * -snd_emu10k1_synth_alloc(emu10k1_t *hw, unsigned int size) +struct snd_util_memblk * +snd_emu10k1_synth_alloc(struct snd_emu10k1 *hw, unsigned int size) { - emu10k1_memblk_t *blk; - snd_util_memhdr_t *hdr = hw->memhdr; + struct snd_emu10k1_memblk *blk; + struct snd_util_memhdr *hdr = hw->memhdr; - down(&hdr->block_mutex); - blk = (emu10k1_memblk_t *)__snd_util_mem_alloc(hdr, size); + mutex_lock(&hdr->block_mutex); + blk = (struct snd_emu10k1_memblk *)__snd_util_mem_alloc(hdr, size); if (blk == NULL) { - up(&hdr->block_mutex); + mutex_unlock(&hdr->block_mutex); return NULL; } if (synth_alloc_pages(hw, blk)) { - __snd_util_mem_free(hdr, (snd_util_memblk_t *)blk); - up(&hdr->block_mutex); + __snd_util_mem_free(hdr, (struct snd_util_memblk *)blk); + mutex_unlock(&hdr->block_mutex); return NULL; } snd_emu10k1_memblk_map(hw, blk); - up(&hdr->block_mutex); - return (snd_util_memblk_t *)blk; + mutex_unlock(&hdr->block_mutex); + return (struct snd_util_memblk *)blk; } @@ -389,29 +392,31 @@ snd_emu10k1_synth_alloc(emu10k1_t *hw, unsigned int size) * free a synth sample area */ int -snd_emu10k1_synth_free(emu10k1_t *emu, snd_util_memblk_t *memblk) +snd_emu10k1_synth_free(struct snd_emu10k1 *emu, struct snd_util_memblk *memblk) { - snd_util_memhdr_t *hdr = emu->memhdr; - emu10k1_memblk_t *blk = (emu10k1_memblk_t *)memblk; + struct snd_util_memhdr *hdr = emu->memhdr; + struct snd_emu10k1_memblk *blk = (struct snd_emu10k1_memblk *)memblk; unsigned long flags; - down(&hdr->block_mutex); + mutex_lock(&hdr->block_mutex); spin_lock_irqsave(&emu->memblk_lock, flags); if (blk->mapped_page >= 0) unmap_memblk(emu, blk); spin_unlock_irqrestore(&emu->memblk_lock, flags); synth_free_pages(emu, blk); __snd_util_mem_free(hdr, memblk); - up(&hdr->block_mutex); + mutex_unlock(&hdr->block_mutex); return 0; } /* check new allocation range */ -static void get_single_page_range(snd_util_memhdr_t *hdr, emu10k1_memblk_t *blk, int *first_page_ret, int *last_page_ret) +static void get_single_page_range(struct snd_util_memhdr *hdr, + struct snd_emu10k1_memblk *blk, + int *first_page_ret, int *last_page_ret) { struct list_head *p; - emu10k1_memblk_t *q; + struct snd_emu10k1_memblk *q; int first_page, last_page; first_page = blk->first_page; if ((p = blk->mem.list.prev) != &hdr->block) { @@ -432,7 +437,7 @@ static void get_single_page_range(snd_util_memhdr_t *hdr, emu10k1_memblk_t *blk, /* * allocate kernel pages */ -static int synth_alloc_pages(emu10k1_t *emu, emu10k1_memblk_t *blk) +static int synth_alloc_pages(struct snd_emu10k1 *emu, struct snd_emu10k1_memblk *blk) { int page, first_page, last_page; struct snd_dma_buffer dmab; @@ -441,10 +446,11 @@ static int synth_alloc_pages(emu10k1_t *emu, emu10k1_memblk_t *blk) get_single_page_range(emu->memhdr, blk, &first_page, &last_page); /* allocate kernel pages */ for (page = first_page; page <= last_page; page++) { - if (snd_dma_alloc_pages(&emu->dma_dev, PAGE_SIZE, &dmab) < 0) + if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(emu->pci), + PAGE_SIZE, &dmab) < 0) goto __fail; if (! is_valid_page(emu, dmab.addr)) { - snd_dma_free_pages(&emu->dma_dev, &dmab); + snd_dma_free_pages(&dmab); goto __fail; } emu->page_addr_table[page] = dmab.addr; @@ -459,7 +465,7 @@ __fail: dmab.area = emu->page_ptr_table[page]; dmab.addr = emu->page_addr_table[page]; dmab.bytes = PAGE_SIZE; - snd_dma_free_pages(&emu->dma_dev, &dmab); + snd_dma_free_pages(&dmab); emu->page_addr_table[page] = 0; emu->page_ptr_table[page] = NULL; } @@ -470,19 +476,21 @@ __fail: /* * free pages */ -static int synth_free_pages(emu10k1_t *emu, emu10k1_memblk_t *blk) +static int synth_free_pages(struct snd_emu10k1 *emu, struct snd_emu10k1_memblk *blk) { int page, first_page, last_page; struct snd_dma_buffer dmab; get_single_page_range(emu->memhdr, blk, &first_page, &last_page); + dmab.dev.type = SNDRV_DMA_TYPE_DEV; + dmab.dev.dev = snd_dma_pci_data(emu->pci); for (page = first_page; page <= last_page; page++) { if (emu->page_ptr_table[page] == NULL) continue; dmab.area = emu->page_ptr_table[page]; dmab.addr = emu->page_addr_table[page]; dmab.bytes = PAGE_SIZE; - snd_dma_free_pages(&emu->dma_dev, &dmab); + snd_dma_free_pages(&dmab); emu->page_addr_table[page] = 0; emu->page_ptr_table[page] = NULL; } @@ -491,13 +499,13 @@ static int synth_free_pages(emu10k1_t *emu, emu10k1_memblk_t *blk) } /* calculate buffer pointer from offset address */ -inline static void *offset_ptr(emu10k1_t *emu, int page, int offset) +static inline void *offset_ptr(struct snd_emu10k1 *emu, int page, int offset) { char *ptr; snd_assert(page >= 0 && page < emu->max_cache_pages, return NULL); ptr = emu->page_ptr_table[page]; if (! ptr) { - printk("emu10k1: access to NULL ptr: page = %d\n", page); + printk(KERN_ERR "emu10k1: access to NULL ptr: page = %d\n", page); return NULL; } ptr += offset & (PAGE_SIZE - 1); @@ -507,11 +515,12 @@ inline static void *offset_ptr(emu10k1_t *emu, int page, int offset) /* * bzero(blk + offset, size) */ -int snd_emu10k1_synth_bzero(emu10k1_t *emu, snd_util_memblk_t *blk, int offset, int size) +int snd_emu10k1_synth_bzero(struct snd_emu10k1 *emu, struct snd_util_memblk *blk, + int offset, int size) { int page, nextofs, end_offset, temp, temp1; void *ptr; - emu10k1_memblk_t *p = (emu10k1_memblk_t *)blk; + struct snd_emu10k1_memblk *p = (struct snd_emu10k1_memblk *)blk; offset += blk->offset & (PAGE_SIZE - 1); end_offset = offset + size; @@ -534,11 +543,12 @@ int snd_emu10k1_synth_bzero(emu10k1_t *emu, snd_util_memblk_t *blk, int offset, /* * copy_from_user(blk + offset, data, size) */ -int snd_emu10k1_synth_copy_from_user(emu10k1_t *emu, snd_util_memblk_t *blk, int offset, const char __user *data, int size) +int snd_emu10k1_synth_copy_from_user(struct snd_emu10k1 *emu, struct snd_util_memblk *blk, + int offset, const char __user *data, int size) { int page, nextofs, end_offset, temp, temp1; void *ptr; - emu10k1_memblk_t *p = (emu10k1_memblk_t *)blk; + struct snd_emu10k1_memblk *p = (struct snd_emu10k1_memblk *)blk; offset += blk->offset & (PAGE_SIZE - 1); end_offset = offset + size;