~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/sound/memalloc.h

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0-or-later */
  2 /*
  3  *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  4  *                   Takashi Iwai <tiwai@suse.de>
  5  * 
  6  *  Generic memory allocators
  7  */
  8 
  9 #ifndef __SOUND_MEMALLOC_H
 10 #define __SOUND_MEMALLOC_H
 11 
 12 #include <linux/dma-direction.h>
 13 #include <asm/page.h>
 14 
 15 struct device;
 16 struct vm_area_struct;
 17 struct sg_table;
 18 
 19 /*
 20  * buffer device info
 21  */
 22 struct snd_dma_device {
 23         int type;                       /* SNDRV_DMA_TYPE_XXX */
 24         enum dma_data_direction dir;    /* DMA direction */
 25         bool need_sync;                 /* explicit sync needed? */
 26         struct device *dev;             /* generic device */
 27 };
 28 
 29 /*
 30  * buffer types
 31  */
 32 #define SNDRV_DMA_TYPE_UNKNOWN          0       /* not defined */
 33 #define SNDRV_DMA_TYPE_CONTINUOUS       1       /* continuous no-DMA memory */
 34 #define SNDRV_DMA_TYPE_DEV              2       /* generic device continuous */
 35 #define SNDRV_DMA_TYPE_DEV_WC           5       /* continuous write-combined */
 36 #ifdef CONFIG_GENERIC_ALLOCATOR
 37 #define SNDRV_DMA_TYPE_DEV_IRAM         4       /* generic device iram-buffer */
 38 #else
 39 #define SNDRV_DMA_TYPE_DEV_IRAM SNDRV_DMA_TYPE_DEV
 40 #endif
 41 #define SNDRV_DMA_TYPE_VMALLOC          7       /* vmalloc'ed buffer */
 42 #define SNDRV_DMA_TYPE_NONCONTIG        8       /* non-coherent SG buffer */
 43 #define SNDRV_DMA_TYPE_NONCOHERENT      9       /* non-coherent buffer */
 44 #ifdef CONFIG_SND_DMA_SGBUF
 45 #define SNDRV_DMA_TYPE_DEV_SG           3       /* S/G pages */
 46 #define SNDRV_DMA_TYPE_DEV_WC_SG        6       /* SG write-combined */
 47 #else
 48 #define SNDRV_DMA_TYPE_DEV_SG   SNDRV_DMA_TYPE_DEV /* no SG-buf support */
 49 #define SNDRV_DMA_TYPE_DEV_WC_SG        SNDRV_DMA_TYPE_DEV_WC
 50 #endif
 51 
 52 /*
 53  * info for buffer allocation
 54  */
 55 struct snd_dma_buffer {
 56         struct snd_dma_device dev;      /* device type */
 57         unsigned char *area;    /* virtual pointer */
 58         dma_addr_t addr;        /* physical address */
 59         size_t bytes;           /* buffer size in bytes */
 60         void *private_data;     /* private for allocator; don't touch */
 61 };
 62 
 63 /*
 64  * return the pages matching with the given byte size
 65  */
 66 static inline unsigned int snd_sgbuf_aligned_pages(size_t size)
 67 {
 68         return (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
 69 }
 70 
 71 /* allocate/release a buffer */
 72 int snd_dma_alloc_dir_pages(int type, struct device *dev,
 73                             enum dma_data_direction dir, size_t size,
 74                             struct snd_dma_buffer *dmab);
 75 
 76 static inline int snd_dma_alloc_pages(int type, struct device *dev,
 77                                       size_t size, struct snd_dma_buffer *dmab)
 78 {
 79         return snd_dma_alloc_dir_pages(type, dev, DMA_BIDIRECTIONAL, size, dmab);
 80 }
 81 
 82 int snd_dma_alloc_pages_fallback(int type, struct device *dev, size_t size,
 83                                  struct snd_dma_buffer *dmab);
 84 void snd_dma_free_pages(struct snd_dma_buffer *dmab);
 85 int snd_dma_buffer_mmap(struct snd_dma_buffer *dmab,
 86                         struct vm_area_struct *area);
 87 
 88 enum snd_dma_sync_mode { SNDRV_DMA_SYNC_CPU, SNDRV_DMA_SYNC_DEVICE };
 89 #ifdef CONFIG_HAS_DMA
 90 void snd_dma_buffer_sync(struct snd_dma_buffer *dmab,
 91                          enum snd_dma_sync_mode mode);
 92 #else
 93 static inline void snd_dma_buffer_sync(struct snd_dma_buffer *dmab,
 94                                        enum snd_dma_sync_mode mode) {}
 95 #endif
 96 
 97 dma_addr_t snd_sgbuf_get_addr(struct snd_dma_buffer *dmab, size_t offset);
 98 struct page *snd_sgbuf_get_page(struct snd_dma_buffer *dmab, size_t offset);
 99 unsigned int snd_sgbuf_get_chunk_size(struct snd_dma_buffer *dmab,
100                                       unsigned int ofs, unsigned int size);
101 
102 /* device-managed memory allocator */
103 struct snd_dma_buffer *snd_devm_alloc_dir_pages(struct device *dev, int type,
104                                                 enum dma_data_direction dir,
105                                                 size_t size);
106 
107 static inline struct snd_dma_buffer *
108 snd_devm_alloc_pages(struct device *dev, int type, size_t size)
109 {
110         return snd_devm_alloc_dir_pages(dev, type, DMA_BIDIRECTIONAL, size);
111 }
112 
113 static inline struct sg_table *
114 snd_dma_noncontig_sg_table(struct snd_dma_buffer *dmab)
115 {
116         return dmab->private_data;
117 }
118 
119 #endif /* __SOUND_MEMALLOC_H */
120 
121 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php