linux/sound/pci/trident/trident_memory.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 *  Copyright (c) by Jaroslav Kysela <[email protected]>
 *  Copyright (c) by Takashi Iwai <[email protected]>
 *  Copyright (c) by Scott McNab <[email protected]>
 *
 *  Trident 4DWave-NX memory page allocation (TLB area)
 *  Trident chip can handle only 16MByte of the memory at the same time.
 */

#include <linux/io.h>
#include <linux/pci.h>
#include <linux/time.h>
#include <linux/mutex.h>

#include <sound/core.h>
#include "trident.h"

/* page arguments of these two macros are Trident page (4096 bytes), not like
 * aligned pages in others
 */
#define __set_tlb_bus(trident,page,addr)
#define __tlb_to_addr(trident,page)

#if PAGE_SIZE == 4096
/* page size == SNDRV_TRIDENT_PAGE_SIZE */
#define ALIGN_PAGE_SIZE
#define MAX_ALIGN_PAGES
/* fill TLB entrie(s) corresponding to page with ptr */
#define set_tlb_bus(trident,page,addr)
/* fill TLB entrie(s) corresponding to page with silence pointer */
#define set_silent_tlb(trident,page)
/* get aligned page from offset address */
#define get_aligned_page(offset)
/* get offset address from aligned page */
#define aligned_page_offset(page)
/* get PCI physical address from aligned page */
#define page_to_addr(trident,page)

#elif PAGE_SIZE == 8192
/* page size == SNDRV_TRIDENT_PAGE_SIZE x 2*/
#define ALIGN_PAGE_SIZE
#define MAX_ALIGN_PAGES
#define get_aligned_page
#define aligned_page_offset
#define page_to_addr

/* fill TLB entries -- we need to fill two entries */
static inline void set_tlb_bus(struct snd_trident *trident, int page,
			       dma_addr_t addr)
{
	page <<= 1;
	__set_tlb_bus(trident, page, addr);
	__set_tlb_bus(trident, page+1, addr + SNDRV_TRIDENT_PAGE_SIZE);
}
static inline void set_silent_tlb(struct snd_trident *trident, int page)
{
	page <<= 1;
	__set_tlb_bus(trident, page, trident->tlb.silent_page->addr);
	__set_tlb_bus(trident, page+1, trident->tlb.silent_page->addr);
}

#else
/* arbitrary size */
#define UNIT_PAGES
#define ALIGN_PAGE_SIZE
#define MAX_ALIGN_PAGES
/* Note: if alignment doesn't match to the maximum size, the last few blocks
 * become unusable.  To use such blocks, you'll need to check the validity
 * of accessing page in set_tlb_bus and set_silent_tlb.  search_empty()
 * should also check it, too.
 */
#define get_aligned_page
#define aligned_page_offset
#define page_to_addr

/* fill TLB entries -- UNIT_PAGES entries must be filled */
static inline void set_tlb_bus(struct snd_trident *trident, int page,
			       dma_addr_t addr)
{
	int i;
	page *= UNIT_PAGES;
	for (i = 0; i < UNIT_PAGES; i++, page++) {
		__set_tlb_bus(trident, page, addr);
		addr += SNDRV_TRIDENT_PAGE_SIZE;
	}
}
static inline void set_silent_tlb(struct snd_trident *trident, int page)
{
	int i;
	page *= UNIT_PAGES;
	for (i = 0; i < UNIT_PAGES; i++, page++)
		__set_tlb_bus(trident, page, trident->tlb.silent_page->addr);
}

#endif /* PAGE_SIZE */

/* first and last (aligned) pages of memory block */
#define firstpg(blk)
#define lastpg(blk)

/*
 * search empty pages which may contain given size
 */
static struct snd_util_memblk *
search_empty(struct snd_util_memhdr *hdr, int size)
{}


/*
 * check if the given pointer is valid for pages
 */
static int is_valid_page(unsigned long ptr)
{}

/*
 * page allocation for DMA (Scatter-Gather version)
 */
static struct snd_util_memblk *
snd_trident_alloc_sg_pages(struct snd_trident *trident,
			   struct snd_pcm_substream *substream)
{}

/*
 * page allocation for DMA (contiguous version)
 */
static struct snd_util_memblk *
snd_trident_alloc_cont_pages(struct snd_trident *trident,
			     struct snd_pcm_substream *substream)
{}

/*
 * page allocation for DMA
 */
struct snd_util_memblk *
snd_trident_alloc_pages(struct snd_trident *trident,
			struct snd_pcm_substream *substream)
{}


/*
 * release DMA buffer from page table
 */
int snd_trident_free_pages(struct snd_trident *trident,
			   struct snd_util_memblk *blk)
{}