From mboxrd@z Thu Jan 1 00:00:00 1970 From: Takashi Iwai Subject: Re: snd_pcm_lib_preallocate_pages_for_all Date: Mon, 05 Jul 2004 13:10:08 +0200 Sender: alsa-devel-admin@lists.sourceforge.net Message-ID: References: Mime-Version: 1.0 (generated by SEMI 1.14.5 - "Awara-Onsen") Content-Type: multipart/mixed; boundary="Multipart_Mon_Jul__5_13:10:08_2004-1" Return-path: In-Reply-To: Errors-To: alsa-devel-admin@lists.sourceforge.net List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , List-Archive: To: Bo Henriksen Cc: alsa-devel@lists.sourceforge.net List-Id: alsa-devel@alsa-project.org --Multipart_Mon_Jul__5_13:10:08_2004-1 Content-Type: text/plain; charset=US-ASCII 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 --Multipart_Mon_Jul__5_13:10:08_2004-1 Content-Type: text/plain; charset=US-ASCII 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(). */ --Multipart_Mon_Jul__5_13:10:08_2004-1-- ------------------------------------------------------- This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com