Newbie: allocating aligned physically-contiguous memory? - Linux

This is a discussion on Newbie: allocating aligned physically-contiguous memory? - Linux ; My apologies for the dumb Linux question; I usually live in the comp.arch.fpga world. I'm using a custom architecture (2.4.26 kernel on PPC 405 inside an XC2VP30 FPGA) that can work with a framebuffer aligned on any multiple of 0x00200000. ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Newbie: allocating aligned physically-contiguous memory?

  1. Newbie: allocating aligned physically-contiguous memory?

    My apologies for the dumb Linux question; I usually live in the
    comp.arch.fpga world.

    I'm using a custom architecture (2.4.26 kernel on PPC 405 inside an
    XC2VP30 FPGA) that can work with a framebuffer aligned on any multiple
    of 0x00200000.

    Here's what I need to do:
    1. Allocate block of 0x00200000 physically contiguous bytes from memory.
    2. Guarantee the block is aligned on a physical 0x00200000 boundary.
    3. Make the block visible from user space, if possible.

    It would be nice to just kmalloc(0x00200000,GFP_USER), but that wouldn't
    give me any way to enforce the physical alignment requirement. I'm sure
    someone here has done this kind of thing a million times. Any ideas?
    Anything I should be reading up on?

  2. Re: Newbie: allocating aligned physically-contiguous memory?

    Neil Steiner wrote:
    > Here's what I need to do:
    > 1. Allocate block of 0x00200000 physically contiguous bytes from memory.
    > 2. Guarantee the block is aligned on a physical 0x00200000 boundary.
    > 3. Make the block visible from user space, if possible.


    > It would be nice to just kmalloc(0x00200000,GFP_USER), but that wouldn't
    > give me any way to enforce the physical alignment requirement. I'm sure
    > someone here has done this kind of thing a million times. Any ideas?
    > Anything I should be reading up on?


    I guess you should have a look at the __get_free_pages() function,
    it returns (if available) a number of physically contiguous pages
    (of course starting on a page bondary-. It's defined as

    __get_free_pages( unsigned int flags, unsigned int order )

    The 'flags' argument is the same as for kmalloc() and 'order'
    is the base-two logarithm of the number of pages you are re-
    questing (i.e. 21 in your case if I got the maths right;-).
    The function exists for both 2.4 and 2.6 kernels (include
    for the declaration).

    Regards, Jens
    --
    \ Jens Thoms Toerring ___ jt@toerring.de
    \__________________________ http://toerring.de

  3. Re: Newbie: allocating aligned physically-contiguous memory?

    > I guess you should have a look at the __get_free_pages() function,
    > it returns (if available) a number of physically contiguous pages
    > (of course starting on a page bondary-.


    Thanks for the thoughts, Jens. I ended up passing a mem= parameter to
    the kernel at startup to reserve the upper 4MB for two framebuffers, and
    then just ioremap'ing both of those blocks into virtual memory.

    As for making those blocks visible to user memory, do I have to use
    /dev/kmem, or is there a more transparent way?

  4. Re: Newbie: allocating aligned physically-contiguous memory?

    > As for making those blocks visible to user memory, do I have to use
    > /dev/kmem, or is there a more transparent way?


    Okay, I figured out how to use mmap, with the help of
    http://www.scs.ch/~frey/linux/memorymap.html.

+ Reply to Thread