Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1 | /** |
| 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 Lankhorst | 391e691 | 2011-08-24 00:48:59 +0200 | [diff] [blame] | 21 | #define CT_PTP_NUM 4 /* num of device page table pages */ |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 22 | |
Takashi Iwai | 8a4259b | 2009-06-02 08:40:51 +0200 | [diff] [blame] | 23 | #include <linux/mutex.h> |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 24 | #include <linux/list.h> |
Jaroslav Kysela | 21956b6 | 2010-02-02 19:58:25 +0100 | [diff] [blame] | 25 | #include <linux/pci.h> |
| 26 | #include <sound/memalloc.h> |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 27 | |
Takashi Iwai | cd391e2 | 2009-06-02 15:04:29 +0200 | [diff] [blame] | 28 | /* 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 CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 36 | struct 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 Iwai | c76157d | 2009-06-02 15:26:19 +0200 | [diff] [blame] | 42 | struct snd_pcm_substream; |
| 43 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 44 | /* Virtual memory management object for card device */ |
| 45 | struct ct_vm { |
Jaroslav Kysela | 21956b6 | 2010-02-02 19:58:25 +0100 | [diff] [blame] | 46 | struct snd_dma_buffer ptp[CT_PTP_NUM]; /* Device page table pages */ |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 47 | 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 Iwai | 8a4259b | 2009-06-02 08:40:51 +0200 | [diff] [blame] | 50 | struct mutex lock; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 51 | |
| 52 | /* Map host addr (kmalloced/vmalloced) to device logical addr. */ |
Takashi Iwai | c76157d | 2009-06-02 15:26:19 +0200 | [diff] [blame] | 53 | struct ct_vm_block *(*map)(struct ct_vm *, struct snd_pcm_substream *, |
| 54 | int size); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 55 | /* Unmap device logical addr area. */ |
| 56 | void (*unmap)(struct ct_vm *, struct ct_vm_block *block); |
Jaroslav Kysela | 21956b6 | 2010-02-02 19:58:25 +0100 | [diff] [blame] | 57 | dma_addr_t (*get_ptp_phys)(struct ct_vm *vm, int index); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 58 | }; |
| 59 | |
Jaroslav Kysela | 21956b6 | 2010-02-02 19:58:25 +0100 | [diff] [blame] | 60 | int ct_vm_create(struct ct_vm **rvm, struct pci_dev *pci); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 61 | void ct_vm_destroy(struct ct_vm *vm); |
| 62 | |
| 63 | #endif /* CTVMEM_H */ |