Lines Matching +full:page +full:- +full:offset

1 // SPDX-License-Identifier: GPL-2.0-or-later
7 * Trident 4DWave-NX memory page allocation (TLB area)
19 /* page arguments of these two macros are Trident page (4096 bytes), not like
22 #define __set_tlb_bus(trident,page,addr) \ argument
23 (trident)->tlb.entries[page] = cpu_to_le32((addr) & ~(SNDRV_TRIDENT_PAGE_SIZE-1))
24 #define __tlb_to_addr(trident,page) \ argument
25 (dma_addr_t)le32_to_cpu((trident->tlb.entries[page]) & ~(SNDRV_TRIDENT_PAGE_SIZE - 1))
28 /* page size == SNDRV_TRIDENT_PAGE_SIZE */
29 #define ALIGN_PAGE_SIZE PAGE_SIZE /* minimum page size for allocation */
31 /* fill TLB entrie(s) corresponding to page with ptr */
32 #define set_tlb_bus(trident,page,addr) __set_tlb_bus(trident,page,addr) argument
33 /* fill TLB entrie(s) corresponding to page with silence pointer */
34 #define set_silent_tlb(trident,page) __set_tlb_bus(trident, page, trident->tlb.silent_page->addr) argument
35 /* get aligned page from offset address */
36 #define get_aligned_page(offset) ((offset) >> 12) argument
37 /* get offset address from aligned page */
38 #define aligned_page_offset(page) ((page) << 12) argument
39 /* get PCI physical address from aligned page */
40 #define page_to_addr(trident,page) __tlb_to_addr(trident, page) argument
43 /* page size == SNDRV_TRIDENT_PAGE_SIZE x 2*/
46 #define get_aligned_page(offset) ((offset) >> 13) argument
47 #define aligned_page_offset(page) ((page) << 13) argument
48 #define page_to_addr(trident,page) __tlb_to_addr(trident, (page) << 1) argument
50 /* fill TLB entries -- we need to fill two entries */
51 static inline void set_tlb_bus(struct snd_trident *trident, int page, in set_tlb_bus() argument
54 page <<= 1; in set_tlb_bus()
55 __set_tlb_bus(trident, page, addr); in set_tlb_bus()
56 __set_tlb_bus(trident, page+1, addr + SNDRV_TRIDENT_PAGE_SIZE); in set_tlb_bus()
58 static inline void set_silent_tlb(struct snd_trident *trident, int page) in set_silent_tlb() argument
60 page <<= 1; in set_silent_tlb()
61 __set_tlb_bus(trident, page, trident->tlb.silent_page->addr); in set_silent_tlb()
62 __set_tlb_bus(trident, page+1, trident->tlb.silent_page->addr); in set_silent_tlb()
72 * of accessing page in set_tlb_bus and set_silent_tlb. search_empty()
75 #define get_aligned_page(offset) ((offset) / ALIGN_PAGE_SIZE) argument
76 #define aligned_page_offset(page) ((page) * ALIGN_PAGE_SIZE) argument
77 #define page_to_addr(trident,page) __tlb_to_addr(trident, (page) * UNIT_PAGES) argument
79 /* fill TLB entries -- UNIT_PAGES entries must be filled */
80 static inline void set_tlb_bus(struct snd_trident *trident, int page, in set_tlb_bus() argument
84 page *= UNIT_PAGES; in set_tlb_bus()
85 for (i = 0; i < UNIT_PAGES; i++, page++) { in set_tlb_bus()
86 __set_tlb_bus(trident, page, addr); in set_tlb_bus()
90 static inline void set_silent_tlb(struct snd_trident *trident, int page) in set_silent_tlb() argument
93 page *= UNIT_PAGES; in set_silent_tlb()
94 for (i = 0; i < UNIT_PAGES; i++, page++) in set_silent_tlb()
95 __set_tlb_bus(trident, page, trident->tlb.silent_page->addr); in set_silent_tlb()
101 #define firstpg(blk) (((struct snd_trident_memblk_arg *)snd_util_memblk_argptr(blk))->first_page)
102 #define lastpg(blk) (((struct snd_trident_memblk_arg *)snd_util_memblk_argptr(blk))->last_page)
111 int page, psize; in search_empty() local
114 psize = get_aligned_page(size + ALIGN_PAGE_SIZE -1); in search_empty()
115 page = 0; in search_empty()
116 list_for_each(p, &hdr->block) { in search_empty()
118 if (page + psize <= firstpg(blk)) in search_empty()
120 page = lastpg(blk) + 1; in search_empty()
122 if (page + psize > MAX_ALIGN_PAGES) in search_empty()
127 blk = __snd_util_memblk_new(hdr, psize * ALIGN_PAGE_SIZE, p->prev); in search_empty()
130 blk->offset = aligned_page_offset(page); /* set aligned offset */ in search_empty()
131 firstpg(blk) = page; in search_empty()
132 lastpg(blk) = page + psize - 1; in search_empty()
143 dev_err(trident->card->dev, "max memory size is 1GB!!\n"); in is_valid_page()
146 if (ptr & (SNDRV_TRIDENT_PAGE_SIZE-1)) { in is_valid_page()
147 dev_err(trident->card->dev, "page is not aligned\n"); in is_valid_page()
154 * page allocation for DMA (Scatter-Gather version)
162 struct snd_pcm_runtime *runtime = substream->runtime; in snd_trident_alloc_sg_pages()
163 int idx, page; in snd_trident_alloc_sg_pages() local
165 if (snd_BUG_ON(runtime->dma_bytes <= 0 || in snd_trident_alloc_sg_pages()
166 runtime->dma_bytes > SNDRV_TRIDENT_MAX_PAGES * in snd_trident_alloc_sg_pages()
169 hdr = trident->tlb.memhdr; in snd_trident_alloc_sg_pages()
175 mutex_lock(&hdr->block_mutex); in snd_trident_alloc_sg_pages()
176 blk = search_empty(hdr, runtime->dma_bytes); in snd_trident_alloc_sg_pages()
178 mutex_unlock(&hdr->block_mutex); in snd_trident_alloc_sg_pages()
184 for (page = firstpg(blk); page <= lastpg(blk); page++, idx++) { in snd_trident_alloc_sg_pages()
189 mutex_unlock(&hdr->block_mutex); in snd_trident_alloc_sg_pages()
192 set_tlb_bus(trident, page, addr); in snd_trident_alloc_sg_pages()
194 mutex_unlock(&hdr->block_mutex); in snd_trident_alloc_sg_pages()
199 * page allocation for DMA (contiguous version)
207 int page; in snd_trident_alloc_cont_pages() local
208 struct snd_pcm_runtime *runtime = substream->runtime; in snd_trident_alloc_cont_pages()
211 if (snd_BUG_ON(runtime->dma_bytes <= 0 || in snd_trident_alloc_cont_pages()
212 runtime->dma_bytes > SNDRV_TRIDENT_MAX_PAGES * in snd_trident_alloc_cont_pages()
215 hdr = trident->tlb.memhdr; in snd_trident_alloc_cont_pages()
219 mutex_lock(&hdr->block_mutex); in snd_trident_alloc_cont_pages()
220 blk = search_empty(hdr, runtime->dma_bytes); in snd_trident_alloc_cont_pages()
222 mutex_unlock(&hdr->block_mutex); in snd_trident_alloc_cont_pages()
227 addr = runtime->dma_addr; in snd_trident_alloc_cont_pages()
228 for (page = firstpg(blk); page <= lastpg(blk); page++, in snd_trident_alloc_cont_pages()
232 mutex_unlock(&hdr->block_mutex); in snd_trident_alloc_cont_pages()
235 set_tlb_bus(trident, page, addr); in snd_trident_alloc_cont_pages()
237 mutex_unlock(&hdr->block_mutex); in snd_trident_alloc_cont_pages()
242 * page allocation for DMA
250 if (substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV_SG) in snd_trident_alloc_pages()
258 * release DMA buffer from page table
264 int page; in snd_trident_free_pages() local
267 return -EINVAL; in snd_trident_free_pages()
269 hdr = trident->tlb.memhdr; in snd_trident_free_pages()
270 mutex_lock(&hdr->block_mutex); in snd_trident_free_pages()
272 for (page = firstpg(blk); page <= lastpg(blk); page++) in snd_trident_free_pages()
273 set_silent_tlb(trident, page); in snd_trident_free_pages()
276 mutex_unlock(&hdr->block_mutex); in snd_trident_free_pages()