Commit d25201f5 authored by Jaroslav Kysela's avatar Jaroslav Kysela

ALSA CVS update

Memalloc module
- Don't mark pages from dma_alloc_coherent as reserved.
  The pages from __get_free_pages() are still marked as reserved, but this could
  be also unnecessary.
- Fixed a typo in comment.
- Fixed the pre-allocated buffer size for rme9652 & hdsp.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent e133a911
...@@ -160,21 +160,13 @@ static void *snd_dma_hack_alloc_coherent(struct device *dev, size_t size, ...@@ -160,21 +160,13 @@ static void *snd_dma_hack_alloc_coherent(struct device *dev, size_t size,
static long snd_allocated_pages; /* holding the number of allocated pages */ static long snd_allocated_pages; /* holding the number of allocated pages */
static void mark_pages(void *res, int order) static inline void inc_snd_pages(int order)
{ {
struct page *page = virt_to_page(res);
struct page *last_page = page + (1 << order);
while (page < last_page)
SetPageReserved(page++);
snd_allocated_pages += 1 << order; snd_allocated_pages += 1 << order;
} }
static void unmark_pages(void *res, int order) static inline void dec_snd_pages(int order)
{ {
struct page *page = virt_to_page(res);
struct page *last_page = page + (1 << order);
while (page < last_page)
ClearPageReserved(page++);
snd_allocated_pages -= 1 << order; snd_allocated_pages -= 1 << order;
} }
...@@ -194,9 +186,14 @@ void *snd_malloc_pages(size_t size, unsigned int gfp_flags) ...@@ -194,9 +186,14 @@ void *snd_malloc_pages(size_t size, unsigned int gfp_flags)
snd_assert(size > 0, return NULL); snd_assert(size > 0, return NULL);
snd_assert(gfp_flags != 0, return NULL); snd_assert(gfp_flags != 0, return NULL);
for (pg = 0; PAGE_SIZE * (1 << pg) < size; pg++); pg = get_order(size);
if ((res = (void *) __get_free_pages(gfp_flags, pg)) != NULL) { if ((res = (void *) __get_free_pages(gfp_flags, pg)) != NULL) {
mark_pages(res, pg); /* mark pages */
struct page *page = virt_to_page(res);
struct page *last_page = page + (1 << pg);
while (page < last_page)
SetPageReserved(page++);
inc_snd_pages(pg);
} }
return res; return res;
} }
...@@ -240,11 +237,17 @@ void *snd_malloc_pages_fallback(size_t size, unsigned int gfp_flags, size_t *res ...@@ -240,11 +237,17 @@ void *snd_malloc_pages_fallback(size_t size, unsigned int gfp_flags, size_t *res
void snd_free_pages(void *ptr, size_t size) void snd_free_pages(void *ptr, size_t size)
{ {
int pg; int pg;
struct page *page, *last_page;
if (ptr == NULL) if (ptr == NULL)
return; return;
for (pg = 0; PAGE_SIZE * (1 << pg) < size; pg++); pg = get_order(size);
unmark_pages(ptr, pg); dec_snd_pages(pg);
/* reset pages */
page = virt_to_page(ptr);
last_page = page + (1 << pg);
while (page < last_page)
ClearPageReserved(page++);
free_pages((unsigned long) ptr, pg); free_pages((unsigned long) ptr, pg);
} }
...@@ -254,6 +257,7 @@ void snd_free_pages(void *ptr, size_t size) ...@@ -254,6 +257,7 @@ void snd_free_pages(void *ptr, size_t size)
* *
*/ */
/* allocate the coherent DMA pages */
static void *snd_malloc_dev_pages(struct device *dev, size_t size, dma_addr_t *dma) static void *snd_malloc_dev_pages(struct device *dev, size_t size, dma_addr_t *dma)
{ {
int pg; int pg;
...@@ -268,7 +272,7 @@ static void *snd_malloc_dev_pages(struct device *dev, size_t size, dma_addr_t *d ...@@ -268,7 +272,7 @@ static void *snd_malloc_dev_pages(struct device *dev, size_t size, dma_addr_t *d
gfp_flags |= __GFP_NOWARN; gfp_flags |= __GFP_NOWARN;
res = dma_alloc_coherent(dev, PAGE_SIZE << pg, dma, gfp_flags); res = dma_alloc_coherent(dev, PAGE_SIZE << pg, dma, gfp_flags);
if (res != NULL) if (res != NULL)
mark_pages(res, pg); inc_snd_pages(pg);
return res; return res;
} }
...@@ -289,6 +293,7 @@ static void *snd_malloc_dev_pages_fallback(struct device *dev, size_t size, ...@@ -289,6 +293,7 @@ static void *snd_malloc_dev_pages_fallback(struct device *dev, size_t size,
return NULL; return NULL;
} }
/* free the coherent DMA pages */
static void snd_free_dev_pages(struct device *dev, size_t size, void *ptr, static void snd_free_dev_pages(struct device *dev, size_t size, void *ptr,
dma_addr_t dma) dma_addr_t dma)
{ {
...@@ -297,7 +302,7 @@ static void snd_free_dev_pages(struct device *dev, size_t size, void *ptr, ...@@ -297,7 +302,7 @@ static void snd_free_dev_pages(struct device *dev, size_t size, void *ptr,
if (ptr == NULL) if (ptr == NULL)
return; return;
pg = get_order(size); pg = get_order(size);
unmark_pages(ptr, pg); dec_snd_pages(pg);
dma_free_coherent(dev, PAGE_SIZE << pg, ptr, dma); dma_free_coherent(dev, PAGE_SIZE << pg, ptr, dma);
} }
...@@ -312,11 +317,10 @@ static void *snd_malloc_sbus_pages(struct device *dev, size_t size, ...@@ -312,11 +317,10 @@ static void *snd_malloc_sbus_pages(struct device *dev, size_t size,
snd_assert(size > 0, return NULL); snd_assert(size > 0, return NULL);
snd_assert(dma_addr != NULL, return NULL); snd_assert(dma_addr != NULL, return NULL);
for (pg = 0; PAGE_SIZE * (1 << pg) < size; pg++); pg = get_order(size);
res = sbus_alloc_consistent(sdev, PAGE_SIZE * (1 << pg), dma_addr); res = sbus_alloc_consistent(sdev, PAGE_SIZE * (1 << pg), dma_addr);
if (res != NULL) { if (res != NULL)
mark_pages(res, pg); inc_snd_pages(pg);
}
return res; return res;
} }
...@@ -344,8 +348,8 @@ static void snd_free_sbus_pages(struct device *dev, size_t size, ...@@ -344,8 +348,8 @@ static void snd_free_sbus_pages(struct device *dev, size_t size,
if (ptr == NULL) if (ptr == NULL)
return; return;
for (pg = 0; PAGE_SIZE * (1 << pg) < size; pg++); pg = get_order(size);
unmark_pages(ptr, pg); dec_snd_pages(pg);
sbus_free_consistent(sdev, PAGE_SIZE * (1 << pg), ptr, dma_addr); sbus_free_consistent(sdev, PAGE_SIZE * (1 << pg), ptr, dma_addr);
} }
...@@ -474,7 +478,7 @@ int snd_dma_alloc_pages_fallback(const struct snd_dma_device *dev, size_t size, ...@@ -474,7 +478,7 @@ int snd_dma_alloc_pages_fallback(const struct snd_dma_device *dev, size_t size,
/** /**
* snd_dma_free_pages - release the allocated buffer * snd_dma_free_pages - release the allocated buffer
* @dev: the buffer device info * @dev: the buffer device info
* @dmbab: the buffer allocation record to release * @dmab: the buffer allocation record to release
* *
* Releases the allocated buffer via snd_dma_alloc_pages(). * Releases the allocated buffer via snd_dma_alloc_pages().
*/ */
...@@ -658,7 +662,7 @@ struct prealloc_dev { ...@@ -658,7 +662,7 @@ struct prealloc_dev {
unsigned int buffers; unsigned int buffers;
}; };
#define HAMMERFALL_BUFFER_SIZE (16*1024*4*(26+1)) #define HAMMERFALL_BUFFER_SIZE (16*1024*4*(26+1)+0x10000)
static struct prealloc_dev prealloc_devices[] __initdata = { static struct prealloc_dev prealloc_devices[] __initdata = {
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment