diff options
Diffstat (limited to 'sound/core/memalloc.c')
| -rw-r--r-- | sound/core/memalloc.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c index bdf826f4fe0c..9d93f02c6285 100644 --- a/sound/core/memalloc.c +++ b/sound/core/memalloc.c | |||
| @@ -30,6 +30,7 @@ | |||
| 30 | #include <linux/seq_file.h> | 30 | #include <linux/seq_file.h> |
| 31 | #include <asm/uaccess.h> | 31 | #include <asm/uaccess.h> |
| 32 | #include <linux/dma-mapping.h> | 32 | #include <linux/dma-mapping.h> |
| 33 | #include <linux/genalloc.h> | ||
| 33 | #include <linux/moduleparam.h> | 34 | #include <linux/moduleparam.h> |
| 34 | #include <linux/mutex.h> | 35 | #include <linux/mutex.h> |
| 35 | #include <sound/memalloc.h> | 36 | #include <sound/memalloc.h> |
| @@ -157,6 +158,51 @@ static void snd_free_dev_pages(struct device *dev, size_t size, void *ptr, | |||
| 157 | dec_snd_pages(pg); | 158 | dec_snd_pages(pg); |
| 158 | dma_free_coherent(dev, PAGE_SIZE << pg, ptr, dma); | 159 | dma_free_coherent(dev, PAGE_SIZE << pg, ptr, dma); |
| 159 | } | 160 | } |
| 161 | |||
| 162 | #ifdef CONFIG_GENERIC_ALLOCATOR | ||
| 163 | /** | ||
| 164 | * snd_malloc_dev_iram - allocate memory from on-chip internal ram | ||
| 165 | * @dmab: buffer allocation record to store the allocated data | ||
| 166 | * @size: number of bytes to allocate from the iram | ||
| 167 | * | ||
| 168 | * This function requires iram phandle provided via of_node | ||
| 169 | */ | ||
| 170 | static void snd_malloc_dev_iram(struct snd_dma_buffer *dmab, size_t size) | ||
| 171 | { | ||
| 172 | struct device *dev = dmab->dev.dev; | ||
| 173 | struct gen_pool *pool = NULL; | ||
| 174 | |||
| 175 | dmab->area = NULL; | ||
| 176 | dmab->addr = 0; | ||
| 177 | |||
| 178 | if (dev->of_node) | ||
| 179 | pool = of_get_named_gen_pool(dev->of_node, "iram", 0); | ||
| 180 | |||
| 181 | if (!pool) | ||
| 182 | return; | ||
| 183 | |||
| 184 | /* Assign the pool into private_data field */ | ||
| 185 | dmab->private_data = pool; | ||
| 186 | |||
| 187 | dmab->area = (void *)gen_pool_alloc(pool, size); | ||
| 188 | if (!dmab->area) | ||
| 189 | return; | ||
| 190 | |||
| 191 | dmab->addr = gen_pool_virt_to_phys(pool, (unsigned long)dmab->area); | ||
| 192 | } | ||
| 193 | |||
| 194 | /** | ||
| 195 | * snd_free_dev_iram - free allocated specific memory from on-chip internal ram | ||
| 196 | * @dmab: buffer allocation record to store the allocated data | ||
| 197 | */ | ||
| 198 | static void snd_free_dev_iram(struct snd_dma_buffer *dmab) | ||
| 199 | { | ||
| 200 | struct gen_pool *pool = dmab->private_data; | ||
| 201 | |||
| 202 | if (pool && dmab->area) | ||
| 203 | gen_pool_free(pool, (unsigned long)dmab->area, dmab->bytes); | ||
| 204 | } | ||
| 205 | #endif /* CONFIG_GENERIC_ALLOCATOR */ | ||
| 160 | #endif /* CONFIG_HAS_DMA */ | 206 | #endif /* CONFIG_HAS_DMA */ |
| 161 | 207 | ||
| 162 | /* | 208 | /* |
| @@ -197,6 +243,16 @@ int snd_dma_alloc_pages(int type, struct device *device, size_t size, | |||
| 197 | dmab->addr = 0; | 243 | dmab->addr = 0; |
| 198 | break; | 244 | break; |
| 199 | #ifdef CONFIG_HAS_DMA | 245 | #ifdef CONFIG_HAS_DMA |
| 246 | #ifdef CONFIG_GENERIC_ALLOCATOR | ||
| 247 | case SNDRV_DMA_TYPE_DEV_IRAM: | ||
| 248 | snd_malloc_dev_iram(dmab, size); | ||
| 249 | if (dmab->area) | ||
| 250 | break; | ||
| 251 | /* Internal memory might have limited size and no enough space, | ||
| 252 | * so if we fail to malloc, try to fetch memory traditionally. | ||
| 253 | */ | ||
| 254 | dmab->dev.type = SNDRV_DMA_TYPE_DEV; | ||
| 255 | #endif /* CONFIG_GENERIC_ALLOCATOR */ | ||
| 200 | case SNDRV_DMA_TYPE_DEV: | 256 | case SNDRV_DMA_TYPE_DEV: |
| 201 | dmab->area = snd_malloc_dev_pages(device, size, &dmab->addr); | 257 | dmab->area = snd_malloc_dev_pages(device, size, &dmab->addr); |
| 202 | break; | 258 | break; |
| @@ -269,6 +325,11 @@ void snd_dma_free_pages(struct snd_dma_buffer *dmab) | |||
| 269 | snd_free_pages(dmab->area, dmab->bytes); | 325 | snd_free_pages(dmab->area, dmab->bytes); |
| 270 | break; | 326 | break; |
| 271 | #ifdef CONFIG_HAS_DMA | 327 | #ifdef CONFIG_HAS_DMA |
| 328 | #ifdef CONFIG_GENERIC_ALLOCATOR | ||
| 329 | case SNDRV_DMA_TYPE_DEV_IRAM: | ||
| 330 | snd_free_dev_iram(dmab); | ||
| 331 | break; | ||
| 332 | #endif /* CONFIG_GENERIC_ALLOCATOR */ | ||
| 272 | case SNDRV_DMA_TYPE_DEV: | 333 | case SNDRV_DMA_TYPE_DEV: |
| 273 | snd_free_dev_pages(dmab->dev.dev, dmab->bytes, dmab->area, dmab->addr); | 334 | snd_free_dev_pages(dmab->dev.dev, dmab->bytes, dmab->area, dmab->addr); |
| 274 | break; | 335 | break; |
