From: Takashi Iwai <tiwai@suse.de>
To: Bo Henriksen <bo.henriksen@nordicid.com>
Cc: alsa-devel@lists.sourceforge.net
Subject: Re: snd_pcm_lib_preallocate_pages_for_all
Date: Mon, 05 Jul 2004 13:10:08 +0200 [thread overview]
Message-ID: <s5hzn6e7lrj.wl@alsa2.suse.de> (raw)
In-Reply-To: <A6991F0FA073F34C94E97976CAC0323116F8E5@server2.nordicid.com>
[-- Attachment #1: Type: text/plain, Size: 772 bytes --]
At Mon, 5 Jul 2004 13:57:22 +0300,
Bo Henriksen wrote:
>
>
> From my understanding you are saying that I can get my driver working
> with the current ALSA by removing the _MMAP_ flags.
>
> runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP|SNDRV_PCM_INFO_MMAP_VALID);
>
> However, I do not have a pointer to the runtime or the substream at this
> stage. How do I change the HW permissions before I call
> snd_pcm_lib_preallocate_pages_for_all, where everything crashes, which
> is called in snd_mychip_new_pcm? I believe they are set only in the open
> callback in the example from the documentation.
Ah, of course, the crash in snd_pcm_lib_preallocate_pages_for_all has
nothing to do with mmap. I overlooked the point of crash.
The attached patch should fix it.
Takashi
[-- Attachment #2: Type: text/plain, Size: 3657 bytes --]
Index: alsa-kernel/core/memalloc.c
===================================================================
RCS file: /suse/tiwai/cvs/alsa/alsa-kernel/core/memalloc.c,v
retrieving revision 1.34
diff -u -r1.34 memalloc.c
--- alsa-kernel/core/memalloc.c 2 Jul 2004 13:17:39 -0000 1.34
+++ alsa-kernel/core/memalloc.c 5 Jul 2004 11:06:31 -0000
@@ -160,24 +160,6 @@
static long snd_allocated_pages; /* holding the number of allocated pages */
-static void mark_pages(void *res, 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;
-}
-
-static void unmark_pages(void *res, 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_malloc_pages - allocate pages with the given size
* @size: the size to allocate in bytes
@@ -190,15 +172,11 @@
void *snd_malloc_pages(size_t size, unsigned int gfp_flags)
{
int pg;
- void *res;
snd_assert(size > 0, return NULL);
snd_assert(gfp_flags != 0, return NULL);
- for (pg = 0; PAGE_SIZE * (1 << pg) < size; pg++);
- if ((res = (void *) __get_free_pages(gfp_flags, pg)) != NULL) {
- mark_pages(res, pg);
- }
- return res;
+ pg = get_order(size);
+ return (void *) __get_free_pages(gfp_flags, pg);
}
/**
@@ -243,8 +221,7 @@
if (ptr == NULL)
return;
- for (pg = 0; PAGE_SIZE * (1 << pg) < size; pg++);
- unmark_pages(ptr, pg);
+ pg = get_order(size);
free_pages((unsigned long) ptr, pg);
}
@@ -254,10 +231,10 @@
*
*/
+/* allocate the coherent DMA pages */
static void *snd_malloc_dev_pages(struct device *dev, size_t size, dma_addr_t *dma)
{
int pg;
- void *res;
unsigned int gfp_flags;
snd_assert(size > 0, return NULL);
@@ -266,11 +243,7 @@
gfp_flags = GFP_KERNEL;
if (pg > 0)
gfp_flags |= __GFP_NOWARN;
- res = dma_alloc_coherent(dev, PAGE_SIZE << pg, dma, gfp_flags);
- if (res != NULL)
- mark_pages(res, pg);
-
- return res;
+ return dma_alloc_coherent(dev, PAGE_SIZE << pg, dma, gfp_flags);
}
static void *snd_malloc_dev_pages_fallback(struct device *dev, size_t size,
@@ -289,6 +262,7 @@
return NULL;
}
+/* free the coherent DMA pages */
static void snd_free_dev_pages(struct device *dev, size_t size, void *ptr,
dma_addr_t dma)
{
@@ -297,7 +271,6 @@
if (ptr == NULL)
return;
pg = get_order(size);
- unmark_pages(ptr, pg);
dma_free_coherent(dev, PAGE_SIZE << pg, ptr, dma);
}
@@ -308,16 +281,11 @@
{
struct sbus_dev *sdev = (struct sbus_dev *)dev;
int pg;
- void *res;
snd_assert(size > 0, return NULL);
snd_assert(dma_addr != NULL, return NULL);
- for (pg = 0; PAGE_SIZE * (1 << pg) < size; pg++);
- res = sbus_alloc_consistent(sdev, PAGE_SIZE * (1 << pg), dma_addr);
- if (res != NULL) {
- mark_pages(res, pg);
- }
- return res;
+ pg = get_order(size);
+ return sbus_alloc_consistent(sdev, PAGE_SIZE * (1 << pg), dma_addr);
}
static void *snd_malloc_sbus_pages_fallback(struct device *dev, size_t size,
@@ -344,8 +312,7 @@
if (ptr == NULL)
return;
- for (pg = 0; PAGE_SIZE * (1 << pg) < size; pg++);
- unmark_pages(ptr, pg);
+ pg = get_order(size);
sbus_free_consistent(sdev, PAGE_SIZE * (1 << pg), ptr, dma_addr);
}
@@ -474,7 +441,7 @@
/**
* snd_dma_free_pages - release the allocated buffer
* @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().
*/
next prev parent reply other threads:[~2004-07-05 11:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-07-05 10:57 snd_pcm_lib_preallocate_pages_for_all Bo Henriksen
2004-07-05 11:10 ` Takashi Iwai [this message]
2004-07-06 8:34 ` snd_pcm_lib_preallocate_pages_for_all Jaroslav Kysela
-- strict thread matches above, loose matches on Subject: below --
2004-07-05 8:56 snd_pcm_lib_preallocate_pages_for_all Bo Henriksen
2004-07-05 9:00 ` snd_pcm_lib_preallocate_pages_for_all Russell King
2004-07-05 9:17 ` snd_pcm_lib_preallocate_pages_for_all Takashi Iwai
2004-07-05 7:03 snd_pcm_lib_preallocate_pages_for_all Bo Henriksen
2004-07-05 8:15 ` snd_pcm_lib_preallocate_pages_for_all Russell King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=s5hzn6e7lrj.wl@alsa2.suse.de \
--to=tiwai@suse.de \
--cc=alsa-devel@lists.sourceforge.net \
--cc=bo.henriksen@nordicid.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.