2
votes

I want to create a single kernel module driver for my application. It interfaces with an AXIS FIFO in Programmable logic and I need to send the physical addresses of allocated memory to this device to be used in programmable logic.

My platform driver recognises the AXIS FIFO device, and using mmap makes its registers available to my user space app. (previous post of mine)

I also want to allocate memory to be used by the programmable logic, and do this by using and IOCTL command which calls a kmalloc with the given size as argument. Since I want to use the physical address - I get the physical address using __pa(x).

If I want to access this allocated memory to verify that the correct info was stored in RAM, how do I do this? Through

fd = open("/dev/mem", ...)
va = mmap (phys_address, ....)

The problem I have with this is that I can still wrongfully access parts of memory that I shouldn't. Is there a better way to do this?

Thanks.

1

1 Answers

0
votes

I think the best way to do this is to create a /proc device file that maps to the allocated memory. Your kernel module kmalloc's the memory, creates the proc device, and services all the I/O calls to the device. Your userspace program reads and writes to this device, or possibly mmaps to it (if that will work, I'm not sure...).