xref: /openbmc/linux/sound/pci/ctxfi/ctvmem.h (revision 21956b61)
18cc72361SWai Yew CHAY /**
28cc72361SWai Yew CHAY  * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved.
38cc72361SWai Yew CHAY  *
48cc72361SWai Yew CHAY  * This source file is released under GPL v2 license (no other versions).
58cc72361SWai Yew CHAY  * See the COPYING file included in the main directory of this source
68cc72361SWai Yew CHAY  * distribution for the license terms and conditions.
78cc72361SWai Yew CHAY  *
88cc72361SWai Yew CHAY  * @File    ctvmem.h
98cc72361SWai Yew CHAY  *
108cc72361SWai Yew CHAY  * @Brief
118cc72361SWai Yew CHAY  * This file contains the definition of virtual memory management object
128cc72361SWai Yew CHAY  * for card device.
138cc72361SWai Yew CHAY  *
148cc72361SWai Yew CHAY  * @Author Liu Chun
158cc72361SWai Yew CHAY  * @Date Mar 28 2008
168cc72361SWai Yew CHAY  */
178cc72361SWai Yew CHAY 
188cc72361SWai Yew CHAY #ifndef CTVMEM_H
198cc72361SWai Yew CHAY #define CTVMEM_H
208cc72361SWai Yew CHAY 
218cc72361SWai Yew CHAY #define CT_PTP_NUM	1	/* num of device page table pages */
228cc72361SWai Yew CHAY 
238a4259bfSTakashi Iwai #include <linux/mutex.h>
248cc72361SWai Yew CHAY #include <linux/list.h>
2521956b61SJaroslav Kysela #include <linux/pci.h>
2621956b61SJaroslav Kysela #include <sound/memalloc.h>
278cc72361SWai Yew CHAY 
28cd391e20STakashi Iwai /* The chip can handle the page table of 4k pages
29cd391e20STakashi Iwai  * (emu20k1 can handle even 8k pages, but we don't use it right now)
30cd391e20STakashi Iwai  */
31cd391e20STakashi Iwai #define CT_PAGE_SIZE	4096
32cd391e20STakashi Iwai #define CT_PAGE_SHIFT	12
33cd391e20STakashi Iwai #define CT_PAGE_MASK	(~(PAGE_SIZE - 1))
34cd391e20STakashi Iwai #define CT_PAGE_ALIGN(addr)	ALIGN(addr, CT_PAGE_SIZE)
35cd391e20STakashi Iwai 
368cc72361SWai Yew CHAY struct ct_vm_block {
378cc72361SWai Yew CHAY 	unsigned int addr;	/* starting logical addr of this block */
388cc72361SWai Yew CHAY 	unsigned int size;	/* size of this device virtual mem block */
398cc72361SWai Yew CHAY 	struct list_head list;
408cc72361SWai Yew CHAY };
418cc72361SWai Yew CHAY 
42c76157d9STakashi Iwai struct snd_pcm_substream;
43c76157d9STakashi Iwai 
448cc72361SWai Yew CHAY /* Virtual memory management object for card device */
458cc72361SWai Yew CHAY struct ct_vm {
4621956b61SJaroslav Kysela 	struct snd_dma_buffer ptp[CT_PTP_NUM];	/* Device page table pages */
478cc72361SWai Yew CHAY 	unsigned int size;		/* Available addr space in bytes */
488cc72361SWai Yew CHAY 	struct list_head unused;	/* List of unused blocks */
498cc72361SWai Yew CHAY 	struct list_head used;		/* List of used blocks */
508a4259bfSTakashi Iwai 	struct mutex lock;
518cc72361SWai Yew CHAY 
528cc72361SWai Yew CHAY 	/* Map host addr (kmalloced/vmalloced) to device logical addr. */
53c76157d9STakashi Iwai 	struct ct_vm_block *(*map)(struct ct_vm *, struct snd_pcm_substream *,
54c76157d9STakashi Iwai 				   int size);
558cc72361SWai Yew CHAY 	/* Unmap device logical addr area. */
568cc72361SWai Yew CHAY 	void (*unmap)(struct ct_vm *, struct ct_vm_block *block);
5721956b61SJaroslav Kysela 	dma_addr_t (*get_ptp_phys)(struct ct_vm *vm, int index);
588cc72361SWai Yew CHAY };
598cc72361SWai Yew CHAY 
6021956b61SJaroslav Kysela int ct_vm_create(struct ct_vm **rvm, struct pci_dev *pci);
618cc72361SWai Yew CHAY void ct_vm_destroy(struct ct_vm *vm);
628cc72361SWai Yew CHAY 
638cc72361SWai Yew CHAY #endif /* CTVMEM_H */
64