mmap in kernel module - Embedded

This is a discussion on mmap in kernel module - Embedded ; Hi, i'm newby in kernel programming. I need to directly address a device in the memory, but i can't use open, mmap and munmap. What i actually need to do is the following (from application point of view): """ mem ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: mmap in kernel module

  1. mmap in kernel module

    Hi, i'm newby in kernel programming.

    I need to directly address a device in the memory, but i can't use
    open, mmap and munmap.


    What i actually need to do is the following (from application point of
    view):
    """
    mem = open("/dev/mem", O_RDWR | O_SYNC);
    base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, mem,
    EBI_BASE & ~MAP_MASK);
    munmap(base, MAP_SIZE);
    cs_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, mem,
    CS_BASE & ~MAP_MASK);
    """
    MAP_SIZE, MAP_SHARED, CS_BASE, EBI_BASE and MAP_MASK are predifinied
    consts which define addresses, masks and offsets.


    How can i do this in the device_open method?


    Please help.


    thanks in advance


  2. Re: mmap in kernel module

    pslana@gmail.com wrote:

    > MAP_SIZE, MAP_SHARED, CS_BASE, EBI_BASE and MAP_MASK are predifinied
    > consts which define addresses, masks and offsets.
    >
    >
    > How can i do this in the device_open method?


    ioremap ..

  3. Re: mmap in kernel module


    Geronimo W. Christ Esq wrote:
    > pslana@gmail.com wrote:
    >
    > > MAP_SIZE, MAP_SHARED, CS_BASE, EBI_BASE and MAP_MASK are predifinied
    > > consts which define addresses, masks and offsets.
    > >
    > >
    > > How can i do this in the device_open method?

    >
    > ioremap ..


    I still have problems.

    If i do the following:
    // mem = open("/dev/mem", O_RDWR | O_SYNC);
    //base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, mem,
    EBI_BASE & ~MAP_MASK);
    base = ioremap(EBI_BASE & ~MAP_MASK, MAP_SIZE);
    // === DO SOMETHIN' DIRECTLY ON IT
    *((unsigned long *) (base + (O_SMC_CSR3 & MAP_MASK))) = 0x4494;
    //munmap(base, MAP_SIZE);
    iounmap(base);
    //cs_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, mem,
    CS_BASE & ~MAP_MASK);
    cs_base = ioremap(CS_BASE & ~MAP_MASK, MAP_SIZE);
    // === DO SOMETHIN' DIRECTLY ON IT
    *((unsigned char *) (cs_base) +3) = 0x0001;


    It does actually nothin. If i print the address it is also funny:
    "c4854000" as the CS_BASE is "0x40000000UL".

    Please help ... urgent.


  4. Re: mmap in kernel module

    pslana@gmail.com wrote:
    > Geronimo W. Christ Esq wrote:
    >> pslana@gmail.com wrote:
    >>
    >>> MAP_SIZE, MAP_SHARED, CS_BASE, EBI_BASE and MAP_MASK are predifinied
    >>> consts which define addresses, masks and offsets.
    >>>
    >>>
    >>> How can i do this in the device_open method?

    >> ioremap ..

    >
    > I still have problems.
    >
    > If i do the following:
    > // mem = open("/dev/mem", O_RDWR | O_SYNC);
    > //base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, mem,
    > EBI_BASE & ~MAP_MASK);
    > base = ioremap(EBI_BASE & ~MAP_MASK, MAP_SIZE);
    > // === DO SOMETHIN' DIRECTLY ON IT
    > *((unsigned long *) (base + (O_SMC_CSR3 & MAP_MASK))) = 0x4494;
    > //munmap(base, MAP_SIZE);


    Depending on the arch, you may not be able to do this. You may need
    readb() and writeb() instead.

    Hey, hang on a minute. Why don't you read "Linux Device Drivers" ? It
    tells you all this stuff.

+ Reply to Thread