blob: 01e4fd0386a332193dfaa834516a79e25c10e970 [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
21#define CT_PTP_NUM 1 /* num of device page table pages */
22
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>
25
Takashi Iwaicd391e22009-06-02 15:04:29 +020026/* The chip can handle the page table of 4k pages
27 * (emu20k1 can handle even 8k pages, but we don't use it right now)
28 */
29#define CT_PAGE_SIZE 4096
30#define CT_PAGE_SHIFT 12
31#define CT_PAGE_MASK (~(PAGE_SIZE - 1))
32#define CT_PAGE_ALIGN(addr) ALIGN(addr, CT_PAGE_SIZE)
33
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020034struct ct_vm_block {
35 unsigned int addr; /* starting logical addr of this block */
36 unsigned int size; /* size of this device virtual mem block */
37 struct list_head list;
38};
39
Takashi Iwaic76157d2009-06-02 15:26:19 +020040struct snd_pcm_substream;
41
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020042/* Virtual memory management object for card device */
43struct ct_vm {
44 void *ptp[CT_PTP_NUM]; /* Device page table pages */
45 unsigned int size; /* Available addr space in bytes */
46 struct list_head unused; /* List of unused blocks */
47 struct list_head used; /* List of used blocks */
Takashi Iwai8a4259b2009-06-02 08:40:51 +020048 struct mutex lock;
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020049
50 /* Map host addr (kmalloced/vmalloced) to device logical addr. */
Takashi Iwaic76157d2009-06-02 15:26:19 +020051 struct ct_vm_block *(*map)(struct ct_vm *, struct snd_pcm_substream *,
52 int size);
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020053 /* Unmap device logical addr area. */
54 void (*unmap)(struct ct_vm *, struct ct_vm_block *block);
55 void *(*get_ptp_virt)(struct ct_vm *vm, int index);
56};
57
58int ct_vm_create(struct ct_vm **rvm);
59void ct_vm_destroy(struct ct_vm *vm);
60
61#endif /* CTVMEM_H */