flashburn
flashburn

Reputation: 4508

how to pass a pointer to physical memory from kernel space to user space and map it to virtual space

I'm working on a driver-like code for a PCI device which. The communication is done through a buffer, i.e. I write to a buffer and device grabs data from it. Device writes to a buffer and I grad data from it. Here is where the problem occurs. In order for a device to write to this buffer it needs to have its physical address (not virtual one). My boss told me it is possible to do it if I write a kernel module and allocate memory using kmalloc.

Here are my questions. How do I get access to this buffer from a user space, i.e. how do I pass a pointer to this buffer from a kernel space to a user space? Since all addresses in user space are virtual addresses, how do I convert a physical pointer to this buffer to a virtual one? As far as I understand I need to use ioctl but I don't how.

Any help is appreciated.

Upvotes: 2

Views: 1656

Answers (2)

Rujio
Rujio

Reputation: 11

If this is a PCI device then it already has a physical address than you need to map. Your device has a class and a subclass id. Spin through all of your pci devices until you get a match on your class and subclass id then pull the bus address from that.

You then map the physical address using mmap

C++ app to talk to an FPGA over PCI in userland using mmap

I hope this helps.

Upvotes: 1

lone_wolf
lone_wolf

Reputation: 1

Maybe you could use Netlink Socket API. This link could be of help to you How to use netlink socket to communicate with a kernel module?

Upvotes: 0

Related Questions