But what will happen if memory which I try to remap are already in use ? Will kernel automatically free that memory ?Kernel will not free it because it is not allocated. Actually kernel will not even see it as normal memory. If the PCI device is programmed to exhibit the internal memory to the outside (i.e, In the BAR registers and prefetchable/non-prefetchable registers), then only this memory becomes visible to the kernel as PCI accessible memory. You will have to map this memory to some address space and have your own routines to allocate and deallocate memory from this pool.
I hope things are more clear.
I wouls strongly suggest reading the "pci system architecture" by shanley and anderson.
HTH, Om.
-- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/