^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * @File ctvmem.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * @Brief
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * This file contains the definition of virtual memory management object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * for card device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * @Author Liu Chun
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * @Date Mar 28 2008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #ifndef CTVMEM_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define CTVMEM_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define CT_PTP_NUM 4 /* num of device page table pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <sound/memalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /* The chip can handle the page table of 4k pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * (emu20k1 can handle even 8k pages, but we don't use it right now)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define CT_PAGE_SIZE 4096
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define CT_PAGE_SHIFT 12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define CT_PAGE_MASK (~(PAGE_SIZE - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define CT_PAGE_ALIGN(addr) ALIGN(addr, CT_PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct ct_vm_block {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) unsigned int addr; /* starting logical addr of this block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) unsigned int size; /* size of this device virtual mem block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct snd_pcm_substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /* Virtual memory management object for card device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct ct_vm {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct snd_dma_buffer ptp[CT_PTP_NUM]; /* Device page table pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) unsigned int size; /* Available addr space in bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct list_head unused; /* List of unused blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct list_head used; /* List of used blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct mutex lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /* Map host addr (kmalloced/vmalloced) to device logical addr. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct ct_vm_block *(*map)(struct ct_vm *, struct snd_pcm_substream *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) int size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /* Unmap device logical addr area. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) void (*unmap)(struct ct_vm *, struct ct_vm_block *block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) dma_addr_t (*get_ptp_phys)(struct ct_vm *vm, int index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) int ct_vm_create(struct ct_vm **rvm, struct pci_dev *pci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) void ct_vm_destroy(struct ct_vm *vm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #endif /* CTVMEM_H */