X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sound%2Fpci%2Ftrident%2Ftrident_memory.c;h=46c6982c9e88b88162c76ae0de8ba76e089b5116;hb=43bc926fffd92024b46cafaf7350d669ba9ca884;hp=6cc282681e096c9883874f9114de0fa40c6899a3;hpb=cee37fe97739d85991964371c1f3a745c00dd236;p=linux-2.6.git diff --git a/sound/pci/trident/trident_memory.c b/sound/pci/trident/trident_memory.c index 6cc282681..46c6982c9 100644 --- a/sound/pci/trident/trident_memory.c +++ b/sound/pci/trident/trident_memory.c @@ -27,6 +27,8 @@ #include #include #include +#include + #include #include @@ -68,13 +70,14 @@ #define page_to_addr(trident,page) __tlb_to_addr(trident, (page) << 1) /* fill TLB entries -- we need to fill two entries */ -static inline void set_tlb_bus(trident_t *trident, int page, unsigned long ptr, dma_addr_t addr) +static inline void set_tlb_bus(struct snd_trident *trident, int page, + unsigned long ptr, dma_addr_t addr) { page <<= 1; __set_tlb_bus(trident, page, ptr, addr); __set_tlb_bus(trident, page+1, ptr + SNDRV_TRIDENT_PAGE_SIZE, addr + SNDRV_TRIDENT_PAGE_SIZE); } -static inline void set_silent_tlb(trident_t *trident, int page) +static inline void set_silent_tlb(struct snd_trident *trident, int page) { page <<= 1; __set_tlb_bus(trident, page, (unsigned long)trident->tlb.silent_page.area, trident->tlb.silent_page.addr); @@ -97,7 +100,8 @@ static inline void set_silent_tlb(trident_t *trident, int page) #define page_to_addr(trident,page) __tlb_to_addr(trident, (page) * UNIT_PAGES) /* fill TLB entries -- UNIT_PAGES entries must be filled */ -static inline void set_tlb_bus(trident_t *trident, int page, unsigned long ptr, dma_addr_t addr) +static inline void set_tlb_bus(struct snd_trident *trident, int page, + unsigned long ptr, dma_addr_t addr) { int i; page *= UNIT_PAGES; @@ -107,7 +111,7 @@ static inline void set_tlb_bus(trident_t *trident, int page, unsigned long ptr, addr += SNDRV_TRIDENT_PAGE_SIZE; } } -static inline void set_silent_tlb(trident_t *trident, int page) +static inline void set_silent_tlb(struct snd_trident *trident, int page) { int i; page *= UNIT_PAGES; @@ -118,7 +122,7 @@ static inline void set_silent_tlb(trident_t *trident, int page) #endif /* PAGE_SIZE */ /* calculate buffer pointer from offset address */ -inline static void *offset_ptr(trident_t *trident, int offset) +static inline void *offset_ptr(struct snd_trident *trident, int offset) { char *ptr; ptr = page_to_ptr(trident, get_aligned_page(offset)); @@ -127,16 +131,16 @@ inline static void *offset_ptr(trident_t *trident, int offset) } /* first and last (aligned) pages of memory block */ -#define firstpg(blk) (((snd_trident_memblk_arg_t*)snd_util_memblk_argptr(blk))->first_page) -#define lastpg(blk) (((snd_trident_memblk_arg_t*)snd_util_memblk_argptr(blk))->last_page) +#define firstpg(blk) (((struct snd_trident_memblk_arg *)snd_util_memblk_argptr(blk))->first_page) +#define lastpg(blk) (((struct snd_trident_memblk_arg *)snd_util_memblk_argptr(blk))->last_page) /* * search empty pages which may contain given size */ -static snd_util_memblk_t * -search_empty(snd_util_memhdr_t *hdr, int size) +static struct snd_util_memblk * +search_empty(struct snd_util_memhdr *hdr, int size) { - snd_util_memblk_t *blk, *prev; + struct snd_util_memblk *blk, *prev; int page, psize; struct list_head *p; @@ -144,7 +148,7 @@ search_empty(snd_util_memhdr_t *hdr, int size) prev = NULL; page = 0; list_for_each(p, &hdr->block) { - blk = list_entry(p, snd_util_memblk_t, list); + blk = list_entry(p, struct snd_util_memblk, list); if (page + psize <= firstpg(blk)) goto __found_pages; page = lastpg(blk) + 1; @@ -170,11 +174,11 @@ __found_pages: static int is_valid_page(unsigned long ptr) { if (ptr & ~0x3fffffffUL) { - snd_printk("max memory size is 1GB!!\n"); + snd_printk(KERN_ERR "max memory size is 1GB!!\n"); return 0; } if (ptr & (SNDRV_TRIDENT_PAGE_SIZE-1)) { - snd_printk("page is not aligned\n"); + snd_printk(KERN_ERR "page is not aligned\n"); return 0; } return 1; @@ -183,12 +187,13 @@ static int is_valid_page(unsigned long ptr) /* * page allocation for DMA (Scatter-Gather version) */ -static snd_util_memblk_t * -snd_trident_alloc_sg_pages(trident_t *trident, snd_pcm_substream_t *substream) +static struct snd_util_memblk * +snd_trident_alloc_sg_pages(struct snd_trident *trident, + struct snd_pcm_substream *substream) { - snd_util_memhdr_t *hdr; - snd_util_memblk_t *blk; - snd_pcm_runtime_t *runtime = substream->runtime; + struct snd_util_memhdr *hdr; + struct snd_util_memblk *blk; + struct snd_pcm_runtime *runtime = substream->runtime; int idx, page; struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream); @@ -198,16 +203,16 @@ snd_trident_alloc_sg_pages(trident_t *trident, snd_pcm_substream_t *substream) - down(&hdr->block_mutex); + mutex_lock(&hdr->block_mutex); blk = search_empty(hdr, runtime->dma_bytes); if (blk == NULL) { - up(&hdr->block_mutex); + mutex_unlock(&hdr->block_mutex); return NULL; } if (lastpg(blk) - firstpg(blk) >= sgbuf->pages) { snd_printk(KERN_ERR "page calculation doesn't match: allocated pages = %d, trident = %d/%d\n", sgbuf->pages, firstpg(blk), lastpg(blk)); __snd_util_mem_free(hdr, blk); - up(&hdr->block_mutex); + mutex_unlock(&hdr->block_mutex); return NULL; } @@ -218,25 +223,26 @@ snd_trident_alloc_sg_pages(trident_t *trident, snd_pcm_substream_t *substream) unsigned long ptr = (unsigned long)sgbuf->table[idx].buf; if (! is_valid_page(addr)) { __snd_util_mem_free(hdr, blk); - up(&hdr->block_mutex); + mutex_unlock(&hdr->block_mutex); return NULL; } set_tlb_bus(trident, page, ptr, addr); } - up(&hdr->block_mutex); + mutex_unlock(&hdr->block_mutex); return blk; } /* * page allocation for DMA (contiguous version) */ -static snd_util_memblk_t * -snd_trident_alloc_cont_pages(trident_t *trident, snd_pcm_substream_t *substream) +static struct snd_util_memblk * +snd_trident_alloc_cont_pages(struct snd_trident *trident, + struct snd_pcm_substream *substream) { - snd_util_memhdr_t *hdr; - snd_util_memblk_t *blk; + struct snd_util_memhdr *hdr; + struct snd_util_memblk *blk; int page; - snd_pcm_runtime_t *runtime = substream->runtime; + struct snd_pcm_runtime *runtime = substream->runtime; dma_addr_t addr; unsigned long ptr; @@ -244,10 +250,10 @@ snd_trident_alloc_cont_pages(trident_t *trident, snd_pcm_substream_t *substream) hdr = trident->tlb.memhdr; snd_assert(hdr != NULL, return NULL); - down(&hdr->block_mutex); + mutex_lock(&hdr->block_mutex); blk = search_empty(hdr, runtime->dma_bytes); if (blk == NULL) { - up(&hdr->block_mutex); + mutex_unlock(&hdr->block_mutex); return NULL; } @@ -258,20 +264,21 @@ snd_trident_alloc_cont_pages(trident_t *trident, snd_pcm_substream_t *substream) ptr += SNDRV_TRIDENT_PAGE_SIZE, addr += SNDRV_TRIDENT_PAGE_SIZE) { if (! is_valid_page(addr)) { __snd_util_mem_free(hdr, blk); - up(&hdr->block_mutex); + mutex_unlock(&hdr->block_mutex); return NULL; } set_tlb_bus(trident, page, ptr, addr); } - up(&hdr->block_mutex); + mutex_unlock(&hdr->block_mutex); return blk; } /* * page allocation for DMA */ -snd_util_memblk_t * -snd_trident_alloc_pages(trident_t *trident, snd_pcm_substream_t *substream) +struct snd_util_memblk * +snd_trident_alloc_pages(struct snd_trident *trident, + struct snd_pcm_substream *substream) { snd_assert(trident != NULL, return NULL); snd_assert(substream != NULL, return NULL); @@ -285,22 +292,23 @@ snd_trident_alloc_pages(trident_t *trident, snd_pcm_substream_t *substream) /* * release DMA buffer from page table */ -int snd_trident_free_pages(trident_t *trident, snd_util_memblk_t *blk) +int snd_trident_free_pages(struct snd_trident *trident, + struct snd_util_memblk *blk) { - snd_util_memhdr_t *hdr; + struct snd_util_memhdr *hdr; int page; snd_assert(trident != NULL, return -EINVAL); snd_assert(blk != NULL, return -EINVAL); hdr = trident->tlb.memhdr; - down(&hdr->block_mutex); + mutex_lock(&hdr->block_mutex); /* reset TLB entries */ for (page = firstpg(blk); page <= lastpg(blk); page++) set_silent_tlb(trident, page); /* free memory block */ __snd_util_mem_free(hdr, blk); - up(&hdr->block_mutex); + mutex_unlock(&hdr->block_mutex); return 0; } @@ -314,30 +322,30 @@ int snd_trident_free_pages(trident_t *trident, snd_util_memblk_t *blk) /* */ -static int synth_alloc_pages(trident_t *hw, snd_util_memblk_t *blk); -static int synth_free_pages(trident_t *hw, snd_util_memblk_t *blk); +static int synth_alloc_pages(struct snd_trident *hw, struct snd_util_memblk *blk); +static int synth_free_pages(struct snd_trident *hw, struct snd_util_memblk *blk); /* * allocate a synth sample area */ -snd_util_memblk_t * -snd_trident_synth_alloc(trident_t *hw, unsigned int size) +struct snd_util_memblk * +snd_trident_synth_alloc(struct snd_trident *hw, unsigned int size) { - snd_util_memblk_t *blk; - snd_util_memhdr_t *hdr = hw->tlb.memhdr; + struct snd_util_memblk *blk; + struct snd_util_memhdr *hdr = hw->tlb.memhdr; - down(&hdr->block_mutex); + mutex_lock(&hdr->block_mutex); blk = __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, blk); - up(&hdr->block_mutex); + mutex_unlock(&hdr->block_mutex); return NULL; } - up(&hdr->block_mutex); + mutex_unlock(&hdr->block_mutex); return blk; } @@ -346,14 +354,14 @@ snd_trident_synth_alloc(trident_t *hw, unsigned int size) * free a synth sample area */ int -snd_trident_synth_free(trident_t *hw, snd_util_memblk_t *blk) +snd_trident_synth_free(struct snd_trident *hw, struct snd_util_memblk *blk) { - snd_util_memhdr_t *hdr = hw->tlb.memhdr; + struct snd_util_memhdr *hdr = hw->tlb.memhdr; - down(&hdr->block_mutex); + mutex_lock(&hdr->block_mutex); synth_free_pages(hw, blk); __snd_util_mem_free(hdr, blk); - up(&hdr->block_mutex); + mutex_unlock(&hdr->block_mutex); return 0; } @@ -361,7 +369,7 @@ snd_trident_synth_free(trident_t *hw, snd_util_memblk_t *blk) /* * reset TLB entry and free kernel page */ -static void clear_tlb(trident_t *trident, int page) +static void clear_tlb(struct snd_trident *trident, int page) { void *ptr = page_to_ptr(trident, page); dma_addr_t addr = page_to_addr(trident, page); @@ -378,20 +386,22 @@ static void clear_tlb(trident_t *trident, int page) } /* check new allocation range */ -static void get_single_page_range(snd_util_memhdr_t *hdr, snd_util_memblk_t *blk, int *first_page_ret, int *last_page_ret) +static void get_single_page_range(struct snd_util_memhdr *hdr, + struct snd_util_memblk *blk, + int *first_page_ret, int *last_page_ret) { struct list_head *p; - snd_util_memblk_t *q; + struct snd_util_memblk *q; int first_page, last_page; first_page = firstpg(blk); if ((p = blk->list.prev) != &hdr->block) { - q = list_entry(p, snd_util_memblk_t, list); + q = list_entry(p, struct snd_util_memblk, list); if (lastpg(q) == first_page) first_page++; /* first page was already allocated */ } last_page = lastpg(blk); if ((p = blk->list.next) != &hdr->block) { - q = list_entry(p, snd_util_memblk_t, list); + q = list_entry(p, struct snd_util_memblk, list); if (firstpg(q) == last_page) last_page--; /* last page was already allocated */ } @@ -402,7 +412,7 @@ static void get_single_page_range(snd_util_memhdr_t *hdr, snd_util_memblk_t *blk /* * allocate kernel pages and assign them to TLB */ -static int synth_alloc_pages(trident_t *hw, snd_util_memblk_t *blk) +static int synth_alloc_pages(struct snd_trident *hw, struct snd_util_memblk *blk) { int page, first_page, last_page; struct snd_dma_buffer dmab; @@ -438,7 +448,7 @@ __fail: /* * free pages */ -static int synth_free_pages(trident_t *trident, snd_util_memblk_t *blk) +static int synth_free_pages(struct snd_trident *trident, struct snd_util_memblk *blk) { int page, first_page, last_page; @@ -452,7 +462,9 @@ static int synth_free_pages(trident_t *trident, snd_util_memblk_t *blk) /* * copy_from_user(blk + offset, data, size) */ -int snd_trident_synth_copy_from_user(trident_t *trident, snd_util_memblk_t *blk, int offset, const char __user *data, int size) +int snd_trident_synth_copy_from_user(struct snd_trident *trident, + struct snd_util_memblk *blk, + int offset, const char __user *data, int size) { int page, nextofs, end_offset, temp, temp1;