ctvmem.h 1.7 KB

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