Commit 74fb9831 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: trident: Drop shadow TLB pointer table

The shadow TLB pointer table is allocated and set up, but never really
used any longer by the driver.  Let's drop it.

Since this is the only user of snd_pcm_sgbuf_get_ptr(), we can clean
up the API after this change.

Link: https://lore.kernel.org/r/20210609162551.7842-2-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 25c794cd
...@@ -251,7 +251,6 @@ struct snd_trident_memblk_arg { ...@@ -251,7 +251,6 @@ struct snd_trident_memblk_arg {
struct snd_trident_tlb { struct snd_trident_tlb {
__le32 *entries; /* 16k-aligned TLB table */ __le32 *entries; /* 16k-aligned TLB table */
dma_addr_t entries_dmaaddr; /* 16k-aligned PCI address to TLB table */ dma_addr_t entries_dmaaddr; /* 16k-aligned PCI address to TLB table */
unsigned long * shadow_entries; /* shadow entries with virtual addresses */
struct snd_dma_buffer buffer; struct snd_dma_buffer buffer;
struct snd_util_memhdr * memhdr; /* page allocation list */ struct snd_util_memhdr * memhdr; /* page allocation list */
struct snd_dma_buffer silent_page; struct snd_dma_buffer silent_page;
......
...@@ -3331,12 +3331,6 @@ static int snd_trident_tlb_alloc(struct snd_trident *trident) ...@@ -3331,12 +3331,6 @@ static int snd_trident_tlb_alloc(struct snd_trident *trident)
} }
trident->tlb.entries = (__le32 *)ALIGN((unsigned long)trident->tlb.buffer.area, SNDRV_TRIDENT_MAX_PAGES * 4); trident->tlb.entries = (__le32 *)ALIGN((unsigned long)trident->tlb.buffer.area, SNDRV_TRIDENT_MAX_PAGES * 4);
trident->tlb.entries_dmaaddr = ALIGN(trident->tlb.buffer.addr, SNDRV_TRIDENT_MAX_PAGES * 4); trident->tlb.entries_dmaaddr = ALIGN(trident->tlb.buffer.addr, SNDRV_TRIDENT_MAX_PAGES * 4);
/* allocate shadow TLB page table (virtual addresses) */
trident->tlb.shadow_entries =
vmalloc(array_size(SNDRV_TRIDENT_MAX_PAGES,
sizeof(unsigned long)));
if (!trident->tlb.shadow_entries)
return -ENOMEM;
/* allocate and setup silent page and initialise TLB entries */ /* allocate and setup silent page and initialise TLB entries */
if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &trident->pci->dev, if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &trident->pci->dev,
...@@ -3345,10 +3339,8 @@ static int snd_trident_tlb_alloc(struct snd_trident *trident) ...@@ -3345,10 +3339,8 @@ static int snd_trident_tlb_alloc(struct snd_trident *trident)
return -ENOMEM; return -ENOMEM;
} }
memset(trident->tlb.silent_page.area, 0, SNDRV_TRIDENT_PAGE_SIZE); memset(trident->tlb.silent_page.area, 0, SNDRV_TRIDENT_PAGE_SIZE);
for (i = 0; i < SNDRV_TRIDENT_MAX_PAGES; i++) { for (i = 0; i < SNDRV_TRIDENT_MAX_PAGES; i++)
trident->tlb.entries[i] = cpu_to_le32(trident->tlb.silent_page.addr & ~(SNDRV_TRIDENT_PAGE_SIZE-1)); trident->tlb.entries[i] = cpu_to_le32(trident->tlb.silent_page.addr & ~(SNDRV_TRIDENT_PAGE_SIZE-1));
trident->tlb.shadow_entries[i] = (unsigned long)trident->tlb.silent_page.area;
}
/* use emu memory block manager code to manage tlb page allocation */ /* use emu memory block manager code to manage tlb page allocation */
trident->tlb.memhdr = snd_util_memhdr_new(SNDRV_TRIDENT_PAGE_SIZE * SNDRV_TRIDENT_MAX_PAGES); trident->tlb.memhdr = snd_util_memhdr_new(SNDRV_TRIDENT_PAGE_SIZE * SNDRV_TRIDENT_MAX_PAGES);
...@@ -3665,7 +3657,6 @@ static int snd_trident_free(struct snd_trident *trident) ...@@ -3665,7 +3657,6 @@ static int snd_trident_free(struct snd_trident *trident)
snd_util_memhdr_free(trident->tlb.memhdr); snd_util_memhdr_free(trident->tlb.memhdr);
if (trident->tlb.silent_page.area) if (trident->tlb.silent_page.area)
snd_dma_free_pages(&trident->tlb.silent_page); snd_dma_free_pages(&trident->tlb.silent_page);
vfree(trident->tlb.shadow_entries);
snd_dma_free_pages(&trident->tlb.buffer); snd_dma_free_pages(&trident->tlb.buffer);
} }
pci_release_regions(trident->pci); pci_release_regions(trident->pci);
......
...@@ -19,11 +19,8 @@ ...@@ -19,11 +19,8 @@
/* page arguments of these two macros are Trident page (4096 bytes), not like /* page arguments of these two macros are Trident page (4096 bytes), not like
* aligned pages in others * aligned pages in others
*/ */
#define __set_tlb_bus(trident,page,ptr,addr) \ #define __set_tlb_bus(trident,page,addr) \
do { (trident)->tlb.entries[page] = cpu_to_le32((addr) & ~(SNDRV_TRIDENT_PAGE_SIZE-1)); \ (trident)->tlb.entries[page] = cpu_to_le32((addr) & ~(SNDRV_TRIDENT_PAGE_SIZE-1))
(trident)->tlb.shadow_entries[page] = (ptr); } while (0)
#define __tlb_to_ptr(trident,page) \
(void*)((trident)->tlb.shadow_entries[page])
#define __tlb_to_addr(trident,page) \ #define __tlb_to_addr(trident,page) \
(dma_addr_t)le32_to_cpu((trident->tlb.entries[page]) & ~(SNDRV_TRIDENT_PAGE_SIZE - 1)) (dma_addr_t)le32_to_cpu((trident->tlb.entries[page]) & ~(SNDRV_TRIDENT_PAGE_SIZE - 1))
...@@ -32,15 +29,13 @@ ...@@ -32,15 +29,13 @@
#define ALIGN_PAGE_SIZE PAGE_SIZE /* minimum page size for allocation */ #define ALIGN_PAGE_SIZE PAGE_SIZE /* minimum page size for allocation */
#define MAX_ALIGN_PAGES SNDRV_TRIDENT_MAX_PAGES /* maxmium aligned pages */ #define MAX_ALIGN_PAGES SNDRV_TRIDENT_MAX_PAGES /* maxmium aligned pages */
/* fill TLB entrie(s) corresponding to page with ptr */ /* fill TLB entrie(s) corresponding to page with ptr */
#define set_tlb_bus(trident,page,ptr,addr) __set_tlb_bus(trident,page,ptr,addr) #define set_tlb_bus(trident,page,addr) __set_tlb_bus(trident,page,addr)
/* fill TLB entrie(s) corresponding to page with silence pointer */ /* fill TLB entrie(s) corresponding to page with silence pointer */
#define set_silent_tlb(trident,page) __set_tlb_bus(trident, page, (unsigned long)trident->tlb.silent_page.area, trident->tlb.silent_page.addr) #define set_silent_tlb(trident,page) __set_tlb_bus(trident, page, trident->tlb.silent_page.addr)
/* get aligned page from offset address */ /* get aligned page from offset address */
#define get_aligned_page(offset) ((offset) >> 12) #define get_aligned_page(offset) ((offset) >> 12)
/* get offset address from aligned page */ /* get offset address from aligned page */
#define aligned_page_offset(page) ((page) << 12) #define aligned_page_offset(page) ((page) << 12)
/* get buffer address from aligned page */
#define page_to_ptr(trident,page) __tlb_to_ptr(trident, page)
/* get PCI physical address from aligned page */ /* get PCI physical address from aligned page */
#define page_to_addr(trident,page) __tlb_to_addr(trident, page) #define page_to_addr(trident,page) __tlb_to_addr(trident, page)
...@@ -50,22 +45,21 @@ ...@@ -50,22 +45,21 @@
#define MAX_ALIGN_PAGES (SNDRV_TRIDENT_MAX_PAGES / 2) #define MAX_ALIGN_PAGES (SNDRV_TRIDENT_MAX_PAGES / 2)
#define get_aligned_page(offset) ((offset) >> 13) #define get_aligned_page(offset) ((offset) >> 13)
#define aligned_page_offset(page) ((page) << 13) #define aligned_page_offset(page) ((page) << 13)
#define page_to_ptr(trident,page) __tlb_to_ptr(trident, (page) << 1)
#define page_to_addr(trident,page) __tlb_to_addr(trident, (page) << 1) #define page_to_addr(trident,page) __tlb_to_addr(trident, (page) << 1)
/* fill TLB entries -- we need to fill two entries */ /* fill TLB entries -- we need to fill two entries */
static inline void set_tlb_bus(struct snd_trident *trident, int page, static inline void set_tlb_bus(struct snd_trident *trident, int page,
unsigned long ptr, dma_addr_t addr) dma_addr_t addr)
{ {
page <<= 1; page <<= 1;
__set_tlb_bus(trident, page, ptr, addr); __set_tlb_bus(trident, page, addr);
__set_tlb_bus(trident, page+1, ptr + SNDRV_TRIDENT_PAGE_SIZE, addr + SNDRV_TRIDENT_PAGE_SIZE); __set_tlb_bus(trident, page+1, addr + SNDRV_TRIDENT_PAGE_SIZE);
} }
static inline void set_silent_tlb(struct snd_trident *trident, int page) static inline void set_silent_tlb(struct snd_trident *trident, int page)
{ {
page <<= 1; page <<= 1;
__set_tlb_bus(trident, page, (unsigned long)trident->tlb.silent_page.area, trident->tlb.silent_page.addr); __set_tlb_bus(trident, page, trident->tlb.silent_page.addr);
__set_tlb_bus(trident, page+1, (unsigned long)trident->tlb.silent_page.area, trident->tlb.silent_page.addr); __set_tlb_bus(trident, page+1, trident->tlb.silent_page.addr);
} }
#else #else
...@@ -80,18 +74,16 @@ static inline void set_silent_tlb(struct snd_trident *trident, int page) ...@@ -80,18 +74,16 @@ static inline void set_silent_tlb(struct snd_trident *trident, int page)
*/ */
#define get_aligned_page(offset) ((offset) / ALIGN_PAGE_SIZE) #define get_aligned_page(offset) ((offset) / ALIGN_PAGE_SIZE)
#define aligned_page_offset(page) ((page) * ALIGN_PAGE_SIZE) #define aligned_page_offset(page) ((page) * ALIGN_PAGE_SIZE)
#define page_to_ptr(trident,page) __tlb_to_ptr(trident, (page) * UNIT_PAGES)
#define page_to_addr(trident,page) __tlb_to_addr(trident, (page) * UNIT_PAGES) #define page_to_addr(trident,page) __tlb_to_addr(trident, (page) * UNIT_PAGES)
/* fill TLB entries -- UNIT_PAGES entries must be filled */ /* fill TLB entries -- UNIT_PAGES entries must be filled */
static inline void set_tlb_bus(struct snd_trident *trident, int page, static inline void set_tlb_bus(struct snd_trident *trident, int page,
unsigned long ptr, dma_addr_t addr) dma_addr_t addr)
{ {
int i; int i;
page *= UNIT_PAGES; page *= UNIT_PAGES;
for (i = 0; i < UNIT_PAGES; i++, page++) { for (i = 0; i < UNIT_PAGES; i++, pagetr++) {
__set_tlb_bus(trident, page, ptr, addr); __set_tlb_bus(trident, page, addr);
ptr += SNDRV_TRIDENT_PAGE_SIZE;
addr += SNDRV_TRIDENT_PAGE_SIZE; addr += SNDRV_TRIDENT_PAGE_SIZE;
} }
} }
...@@ -100,20 +92,11 @@ static inline void set_silent_tlb(struct snd_trident *trident, int page) ...@@ -100,20 +92,11 @@ static inline void set_silent_tlb(struct snd_trident *trident, int page)
int i; int i;
page *= UNIT_PAGES; page *= UNIT_PAGES;
for (i = 0; i < UNIT_PAGES; i++, page++) for (i = 0; i < UNIT_PAGES; i++, page++)
__set_tlb_bus(trident, page, (unsigned long)trident->tlb.silent_page.area, trident->tlb.silent_page.addr); __set_tlb_bus(trident, page, trident->tlb.silent_page.addr);
} }
#endif /* PAGE_SIZE */ #endif /* PAGE_SIZE */
/* calculate buffer pointer from offset address */
static inline void *offset_ptr(struct snd_trident *trident, int offset)
{
char *ptr;
ptr = page_to_ptr(trident, get_aligned_page(offset));
ptr += offset % ALIGN_PAGE_SIZE;
return (void*)ptr;
}
/* first and last (aligned) pages of memory block */ /* first and last (aligned) pages of memory block */
#define firstpg(blk) (((struct snd_trident_memblk_arg *)snd_util_memblk_argptr(blk))->first_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) #define lastpg(blk) (((struct snd_trident_memblk_arg *)snd_util_memblk_argptr(blk))->last_page)
...@@ -201,14 +184,12 @@ snd_trident_alloc_sg_pages(struct snd_trident *trident, ...@@ -201,14 +184,12 @@ snd_trident_alloc_sg_pages(struct snd_trident *trident,
for (page = firstpg(blk); page <= lastpg(blk); page++, idx++) { for (page = firstpg(blk); page <= lastpg(blk); page++, idx++) {
unsigned long ofs = idx << PAGE_SHIFT; unsigned long ofs = idx << PAGE_SHIFT;
dma_addr_t addr = snd_pcm_sgbuf_get_addr(substream, ofs); dma_addr_t addr = snd_pcm_sgbuf_get_addr(substream, ofs);
unsigned long ptr = (unsigned long)
snd_pcm_sgbuf_get_ptr(substream, ofs);
if (! is_valid_page(addr)) { if (! is_valid_page(addr)) {
__snd_util_mem_free(hdr, blk); __snd_util_mem_free(hdr, blk);
mutex_unlock(&hdr->block_mutex); mutex_unlock(&hdr->block_mutex);
return NULL; return NULL;
} }
set_tlb_bus(trident, page, ptr, addr); set_tlb_bus(trident, page, addr);
} }
mutex_unlock(&hdr->block_mutex); mutex_unlock(&hdr->block_mutex);
return blk; return blk;
...@@ -226,7 +207,6 @@ snd_trident_alloc_cont_pages(struct snd_trident *trident, ...@@ -226,7 +207,6 @@ snd_trident_alloc_cont_pages(struct snd_trident *trident,
int page; int page;
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_runtime *runtime = substream->runtime;
dma_addr_t addr; dma_addr_t addr;
unsigned long ptr;
if (snd_BUG_ON(runtime->dma_bytes <= 0 || if (snd_BUG_ON(runtime->dma_bytes <= 0 ||
runtime->dma_bytes > SNDRV_TRIDENT_MAX_PAGES * runtime->dma_bytes > SNDRV_TRIDENT_MAX_PAGES *
...@@ -245,15 +225,14 @@ snd_trident_alloc_cont_pages(struct snd_trident *trident, ...@@ -245,15 +225,14 @@ snd_trident_alloc_cont_pages(struct snd_trident *trident,
/* set TLB entries */ /* set TLB entries */
addr = runtime->dma_addr; addr = runtime->dma_addr;
ptr = (unsigned long)runtime->dma_area;
for (page = firstpg(blk); page <= lastpg(blk); page++, for (page = firstpg(blk); page <= lastpg(blk); page++,
ptr += SNDRV_TRIDENT_PAGE_SIZE, addr += SNDRV_TRIDENT_PAGE_SIZE) { addr += SNDRV_TRIDENT_PAGE_SIZE) {
if (! is_valid_page(addr)) { if (! is_valid_page(addr)) {
__snd_util_mem_free(hdr, blk); __snd_util_mem_free(hdr, blk);
mutex_unlock(&hdr->block_mutex); mutex_unlock(&hdr->block_mutex);
return NULL; return NULL;
} }
set_tlb_bus(trident, page, ptr, addr); set_tlb_bus(trident, page, addr);
} }
mutex_unlock(&hdr->block_mutex); mutex_unlock(&hdr->block_mutex);
return blk; return blk;
......
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