Question on using mmap to access physical memory - Embedded

This is a discussion on Question on using mmap to access physical memory - Embedded ; Hi, I am pretty new to linux and i have a few questions about an approach for an NVRAM driver. We have 4 segments of memory that are attached to our processor via TI's EMIF (external memory interface). I think ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Question on using mmap to access physical memory

  1. Question on using mmap to access physical memory

    Hi,

    I am pretty new to linux and i have a few questions about an approach
    for an NVRAM driver.

    We have 4 segments of memory that are attached to our processor via
    TI's EMIF (external memory interface).

    I think I know at high level what needs to be done, but am having
    trouble with the details.

    One of the areas is for an area of NonVolatile RAM. Once this is
    mapped you can read and write to the memory without any special needs.
    The chip handles the saving of data.

    So, what I think i would like to is write a driver to map that area of
    memory which starts at 0x06000000 and is 32M in length and then have
    my application use mmap() to access the memory. The actual amount of
    memory on this device is much smaller than the 32M, but that is the
    size of the EMIF partition.

    I found an example driver that implements something similar using a
    char driver, but it allocates new memory in the kernel and I don't
    quite get how to do this with existing memory.

    1) Do i need to be using the MTD subsystem to do this?
    2) How do you map the physical memory to an area that can be accessed
    by mmap?
    3) Does this approach sound reasonable?

    Thanks In Advance.

  2. Re: Question on using mmap to access physical memory

    On Jul 27, 10:56*pm, Gnu2Linux wrote:
    > Hi,
    >
    > I am pretty new to linux and i have a few questions about an approach
    > for an NVRAM driver.
    >
    > We have 4 segments of memory that are attached to our processor via
    > TI's EMIF (external memory interface).
    >
    > I think I know at high level what needs to be done, but am having
    > trouble with the details.
    >
    > One of the areas is for an area of NonVolatile RAM. Once this is
    > mapped you can read and write to the memory without any special needs.
    > The chip handles the saving of data.
    >
    > So, what I think i would like to is write a driver to map that area of
    > memory which starts at 0x06000000 and is 32M in length and then have
    > my application use mmap() to access the memory. The actual amount of
    > memory on this device is much smaller than the 32M, but that is the
    > size of the EMIF partition.
    >
    > I found an example driver that implements something similar using a
    > char driver, but it allocates new memory in the kernel and I don't
    > quite get how to do this with existing memory.
    >
    > 1) Do i need to be using the MTD subsystem to do this?
    > 2) How do you map the physical memory to an area that can be accessed
    > by mmap?
    > 3) Does this approach sound reasonable?
    >
    > Thanks In Advance.


    Are you trying to access your non-volatile memory from a Userspace
    program or a Kernel space driver/module ?
    Following comments assume that you already have mapped your NVmem to
    physical addresses by register punching on the CPU/memory subsystem.
    If it is a userspace program that you are trying to map your memory,
    "mmap()" by itself will be sufficient. Just put the physical address,
    size and attributes as specified in the mmap API.
    If you are trying to map physical addresses to kernel virtual
    addresses use "request_mem_region()" and "ioremap_nocache()".
    Cheers

  3. Re: Question on using mmap to access physical memory

    On Jul 27, 7:56 am, Gnu2Linux wrote:
    > Hi,
    >
    > I am pretty new to linux and i have a few questions about an approach
    > for an NVRAM driver.
    >
    > We have 4 segments of memory that are attached to our processor via
    > TI's EMIF (external memory interface).
    >
    > I think I know at high level what needs to be done, but am having
    > trouble with the details.
    >
    > One of the areas is for an area of NonVolatile RAM. Once this is
    > mapped you can read and write to the memory without any special needs.
    > The chip handles the saving of data.
    >
    > So, what I think i would like to is write a driver to map that area of
    > memory which starts at 0x06000000 and is 32M in length and then have
    > my application use mmap() to access the memory. The actual amount of
    > memory on this device is much smaller than the 32M, but that is the
    > size of the EMIF partition.
    >
    > I found an example driver that implements something similar using a
    > char driver, but it allocates new memory in the kernel and I don't
    > quite get how to do this with existing memory.
    >
    > 1) Do i need to be using the MTD subsystem to do this?
    > 2) How do you map the physical memory to an area that can be accessed
    > by mmap?
    > 3) Does this approach sound reasonable?
    >
    > Thanks In Advance.


    1) Depends on what you are atempting to do. But for the most part if
    you add it to a kernel build you would want to stick the config
    preambles in the MTD subsystem for make menuconfig.
    2) Something like this ..
    //======================
    static struct pci_dev *dev;
    .... some init stuff

    if (pci_enable_device( dev))
    {
    printk("Adapter failed to enable\n");
    return -EIO;
    }

    // Get information on PCI address so we can map the config memory
    // Use BAR_0 and not PCI_BASE_ADDRESS_0 which is the offset !!!
    mmio_start = pci_resource_start( dev, PCI_BAR_0);
    mmio_len = pci_resource_len( dev, PCI_BAR_0 );
    mmio_end = pci_resource_end( dev, PCI_BAR_0);
    mmio_flags = pci_resource_flags( dev, PCI_BAR_0);

    /* make sure above region is MMIO */
    if(!(mmio_flags & IORESOURCE_MEM)) {
    printk("Region not MMIO region\n");
    return -EIO;
    }

    /* get PCI memory space */
    if(pci_request_regions( dev, NAME)) {
    printk("Could not get PCI region\n");
    return -EIO;
    }

    // Remap the MMIO region into real memory from bus space
    iomem = ioremap_nocache(mmio_start, mmio_len);

    //===============

    3) Sure, if you follow the rules in building Linux device drivers.

    Glen

+ Reply to Thread