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.

Reply to
Gnu2Linux
Loading thread data ...

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

Reply to
Janaka

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
glenfine

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.