1

I understand the basics behind a UIO driver, as described in the documentation. The part I'm missing is how to write data from the user space program back to the device driver. My guess is that you'd write this data to the mmap region, but then how to do you let the device driver know it should read said memory?

Ultimately I'm trying to write a block device that can be implemented by a user space program. I've got the block device code stubbed out and working: https://github.com/wspeirs/usbd. My thought was that UIO was the most efficient way to transfer blocks/sectors between the block device and the user space program. Is this the wrong way to go about communicating with the block device driver from user space? Should I be using sysfs or some other communication mechanism?

wspeirs
  • 1,321
  • 2
  • 11
  • 22
  • How is your code related to a UIO driver when it does not even call **uio_register_device()** or define a **uio_info** structure? There is already framework for block devices. Since you're not using that framework, then you can't fully utilize your block device, e.g. install a filesystem on it. BTW your code does not conform to kernel coding style. – sawdust Sep 18 '18 at 09:33
  • @sawdust I have not yet added the uio portions as I do not understand how to get data from the user space program to the kernel driver. What is the block device framework you're referring to that I'm not using? Thanks! – wspeirs Sep 18 '18 at 13:12
  • See https://stackoverflow.com/questions/12917198/linux-device-driver-program-where-the-program-starts/12923107#12923107 – sawdust Sep 18 '18 at 22:44
  • @sawdust [I'm using](https://github.com/wspeirs/usbd/blob/12307abc4e99b83c0028a4c502dadfe878348011/usbd.c#L116) the `block_device_operations` struct you mention in that post... is that the "framework" you're talking about? – wspeirs Sep 19 '18 at 15:05
  • You have *defined* a `struct block_device_operations` but you're not using it effectively. If you want *"the most efficient way to transfer blocks/sectors between the block device and the user space program"* then consider implementing a [`direct_access` block device operation](https://www.kernel.org/doc/Documentation/filesystems/dax.txt). Your implication of also using UIO with this driver is irrational. – sawdust Sep 20 '18 at 01:55
  • 1
    minus 1 nasty answer. You might consider that somebody asking a question is looking for information, not insults. – stu Sep 20 '18 at 16:25
  • A filesystem in user space is called FUSE. Efficient way to transfer large amounts of data between app and physical device is DMA. So, is your device physical or not? – ddbug Sep 26 '18 at 01:38
  • @ddbug no, this is all virtual. The map solution given below seems to work very well. – wspeirs Sep 27 '18 at 02:15

1 Answers1

2

UIO is designed so that user space bypasses the kernel to communicate with a hardware device. That does not seem to fit your needs.

In a standard Linux block device, you can use mmap() to write data to your block and msync() to indicate to the driver which regions you have written.

Jamey Hicks
  • 2,340
  • 1
  • 14
  • 20