2

So I was wondering: Since libusb provides userspace access to USB, is it possible to port already existing kernel drivers to libusb?

I do understand it might need rewriting of the driver, but do you think it is possible to write a "virtual kernel" that relies on libusb for access to devices and link already existing drivers to that? Essentially writing a layer between libusb and kernel modules that translates kernel USB commands to libusb commands.

Why bother? If you want to run a kernel driver on Android for example, you need to make sure it was compiled for a particular kernel version/device model. So an app will not be able to run on all devices. On the other hand libusb is fully compatible with most of the latest Android devcices.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Martin Marinov
  • 1,167
  • 3
  • 15
  • 25

1 Answers1

0

AFAIK, libusb is a library that communicates with the higher level of the USB layer of the kernel. The lowest parts of the USB subsystem have to be written in kernel space, because they need to have access to the physical address space of the USB host controller and uses interrupts, and other low-level functions that are not possible to implement in user space.

So I don't think that it is possible to port low-level parts of the USB subsystem in user-space.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user2699113
  • 4,262
  • 3
  • 25
  • 43
  • Only host controller drivers need that low-level access. – CL. Mar 12 '14 at 10:40
  • So - is it possible to write usb-device driver only in user space? Well, I've written usb-device driver but I needed to use interrupts and bus (physical) addresses and some locking methods. So how to write such a driver in userspace? – user2699113 Mar 12 '14 at 11:34
  • 3
    No USB device driver handles interrupts or DMA mapping directly; all this is done by the HCD. Userspace drivers use the libusb API (which wraps the usbfs API). – CL. Mar 12 '14 at 12:02