blob: e6da60eb19ceb76d64ce92fbcbd62f2bb144b6c3 [file] [log] [blame]
Wai Yew CHAY8cc72362009-05-14 08:05:58 +02001/**
2 * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved.
3 *
4 * This source file is released under GPL v2 license (no other versions).
5 * See the COPYING file included in the main directory of this source
6 * distribution for the license terms and conditions.
7 *
8 * @File ctvmem.h
9 *
10 * @Brief
11 * This file contains the definition of virtual memory management object
12 * for card device.
13 *
14 * @Author Liu Chun
15 * @Date Mar 28 2008
16 */
17
18#ifndef CTVMEM_H
19#define CTVMEM_H
20
Maarten Lankhorst391e6912011-08-24 00:48:59 +020021#define CT_PTP_NUM 4 /* num of device page table pages */
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020022
Takashi Iwai8a4259b2009-06-02 08:40:51 +020023#include <linux/mutex.h>
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020024#include <linux/list.h>
Jaroslav Kysela21956b62010-02-02 19:58:25 +010025#include <linux/pci.h>
26#include <sound/memalloc.h>
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020027
Takashi Iwaicd391e22009-06-02 15:04:29 +020028/* The chip can handle the page table of 4k pages
29 * (emu20k1 can handle even 8k pages, but we don't use it right now)
30 */
31#define CT_PAGE_SIZE 4096
32#define CT_PAGE_SHIFT 12
33#define CT_PAGE_MASK (~(PAGE_SIZE - 1))
34#define CT_PAGE_ALIGN(addr) ALIGN(addr, CT_PAGE_SIZE)
35
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020036struct ct_vm_block {
37 unsigned int addr; /* starting logical addr of this block */
38 unsigned int size; /* size of this device virtual mem block */
39 struct list_head list;
40};
41
Takashi Iwaic76157d2009-06-02 15:26:19 +020042struct snd_pcm_substream;
43
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020044/* Virtual memory management object for card device */
45struct ct_vm {
Jaroslav Kysela21956b62010-02-02 19:58:25 +010046 struct snd_dma_buffer ptp[CT_PTP_NUM]; /* Device page table pages */
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020047 unsigned int size; /* Available addr space in bytes */
48 struct list_head unused; /* List of unused blocks */
49 struct list_head used; /* List of used blocks */
Takashi Iwai8a4259b2009-06-02 08:40:51 +020050 struct mutex lock;
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020051
52 /* Map host addr (kmalloced/vmalloced) to device logical addr. */
Takashi Iwaic76157d2009-06-02 15:26:19 +020053 struct ct_vm_block *(*map)(struct ct_vm *, struct snd_pcm_substream *,
54 int size);
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020055 /* Unmap device logical addr area. */
56 void (*unmap)(struct ct_vm *, struct ct_vm_block *block);
Jaroslav Kysela21956b62010-02-02 19:58:25 +010057 dma_addr_t (*get_ptp_phys)(struct ct_vm *vm, int index);
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020058};
59
Jaroslav Kysela21956b62010-02-02 19:58:25 +010060int ct_vm_create(struct ct_vm **rvm, struct pci_dev *pci);
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020061void ct_vm_destroy(struct ct_vm *vm);
62
63#endif /* CTVMEM_H */