LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* alloc_bootmem - Kernel panic
@ 2007-02-07 13:41 Martyn Welch
  0 siblings, 0 replies; 3+ messages in thread
From: Martyn Welch @ 2007-02-07 13:41 UTC (permalink / raw)
  To: linux-kernel

Hi Everyone,

First I'd like to appologise if my query is glaringly obvious. I'm
reasonable new to this, but every that I have read (including the Linux
Device Drivers book) seems to suggest that what I am doing should
work...

I am attempting to allocate a large buffer for DMA transfers in a driver
I am working on. I understand that the kernel normally will not allocate
block of coherent memory larger than 128KB, the suggested solution seems
to be to compile the driver into the kernel and allocate memory at boot
using alloc_bootmem. When attempting this I receive a kernel panic:

=========================================

Loading driver.
bootmem alloc of 4096 bytes failed!
Kernel panic - not syncing: Out of memory

=========================================
This is using:

kernel version 2.6.20
gcc version 4.1.1 20070105 (Red Hat 4.1.1-51)

The config is based on the default i386 config + one extra option to
cause my driver to be compiled in.

The offending code is listed below,

Thank you for any help in advance,

Martyn

=========================================

#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/bootmem.h>

void *buffer;

static int __init universeII_init(void)
{
        printk(KERN_INFO "Loading driver.\n");

        buffer = alloc_bootmem(PAGE_SIZE);

        return 0;

}


static void __exit universeII_exit(void)
{
        if (buffer != NULL) {
                free_bootmem((unsigned long)buffer, PAGE_SIZE);
        }
        printk(KERN_INFO "Driver removed.\n");
}


MODULE_DESCRIPTION("alloc_bootmem_x Test");
MODULE_AUTHOR("Martyn Welch <martyn.welch@radstone.co.uk>");
MODULE_LICENSE("GPL");

/** Register initilisation function */
module_init(universeII_init);
/** Register cleanup function */
module_exit(universeII_exit);


________________________________________________________________________
This e-mail has been scanned for all viruses by Star.The service is powered by MessageLabs. 
________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread
* RE: alloc_bootmem - Kernel panic
@ 2007-02-07 16:47 Martyn Welch
  2007-02-07 18:24 ` Asgard
  0 siblings, 1 reply; 3+ messages in thread
From: Martyn Welch @ 2007-02-07 16:47 UTC (permalink / raw)
  To: Asgard, linux-kernel

Hi Asgard,

Thank you for your reply.
	
> I don't sure, that linux performs to allocate bootmem after kernel already booted.
> As I know, bootmem allocator "destroyed" when kernel initializes buddy allocator.
> Indeed you can look at arch/i385/mm/init.c, mem_init routine.
> kernel passes all bootmem pages to buddy system, so bootmem allocator can't be used after it. 
	
That explains why I can't use alloc_bootmem. It'd assumed that do_initcalls and hence functions labelled with module_init() were called early enough, mainly because LDD3 suggests using alloc_bootmem. It seems the vt driver uses console_init() instead, which is called much earlier.

Which leads me to the question: what is the best method to reserve a large (~4MB) coherent buffer for DMA transfers?

Is there any way of using alloc_bootmem from a driver (compiled into the kernel) without delving further into kernel code?

Martyn

________________________________________________________________________
This e-mail has been scanned for all viruses by Star.The service is powered by MessageLabs. 
________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-02-07 18:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-07 13:41 alloc_bootmem - Kernel panic Martyn Welch
2007-02-07 16:47 Martyn Welch
2007-02-07 18:24 ` Asgard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).