> On Apr 8, 2021, at 7:05 AM, Gerd Hoffmann <g...@kraxel.org> wrote:
>
> Hi,
>
>>> Those might be a good place to start. IOKit provides the drivers and
>>> also the io registry which is probably where you can get if a driver
>>> is bound to a device and which one is it. How to dissociate the
>>> driver from the device though I don't know.
>
>> https://developer.apple.com/library/archive/documentation/DeviceDrivers/Conceptual/IOKitFundamentals/DeviceRemoval/DeviceRemoval.html
>
>> According to this article a driver has a stop() and detach() method
>> that is called by the IOKit to remove a device. I'm thinking QEMU can
>> be the one that calls these methods for a certain device.
>
> libusb should do that. Interfaces exist already (see
> libusb_detach_kernel_driver & friends) because we have the very same
> problem on linux.
>
> take care,
> Gerd
>
The questions that come to mind are:
- Does libusb_detach_kernel_driver() work on Mac OS?
- Is libusb_detach_kernel_driver() called on Mac OS in QEMU?
The only mention of this function in QEMU comes from host-libusb.c.
After some tests I found out the function
host-libusb.c:usb_host_detach_kernel() is being called on Mac OS 11.1. It never
reaches the libusb_detach_kernel_driver() function. It stops at the continue
statement. Here is the full function:
static void usb_host_detach_kernel(USBHostDevice *s)
{
printf("usb_host_detach_kernel() called\n");
struct libusb_config_descriptor *conf;
int rc, i;
rc = libusb_get_active_config_descriptor(s->dev, &conf);
if (rc != 0) {
printf("rc != 0 => %d\n", rc);
return;
}
for (i = 0; i < USB_MAX_INTERFACES; i++) {
rc = libusb_kernel_driver_active(s->dh, i);
usb_host_libusb_error("libusb_kernel_driver_active", rc);
if (rc != 1) {
if (rc == 0) {
s->ifs[i].detached = true;
}
printf("rc != 1 => %d\n", rc);
continue;
}
trace_usb_host_detach_kernel(s->bus_num, s->addr, i);
rc = libusb_detach_kernel_driver(s->dh, i);
printf("libusb_detach_kernel_driver() called\n");
usb_host_libusb_error("libusb_detach_kernel_driver", rc);
s->ifs[i].detached = true;
}
libusb_free_config_descriptor(conf);
}
Next to the continue statement in the loop is where my printf function says
that rc is equal to 0. So it looks like libusb_kernel_driver_active() may have
an issue since it sets the rc variable. Later on I will try to figure out what
is happening here.