qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: BALATON Zoltan <balaton@eik.bme.hu>
To: Howard Spoelstra <hsp.cat7@gmail.com>
Cc: Programmingkid <programmingkidx@gmail.com>,
	QEMU devel list <qemu-devel@nongnu.org>,
	gerd@kraxel.org
Subject: Re: Mac OS real USB device support issue
Date: Wed, 7 Apr 2021 12:27:00 +0200 (CEST)	[thread overview]
Message-ID: <2ad99672-442b-a64b-dec-2fe3c027effd@eik.bme.hu> (raw)
In-Reply-To: <CABLmASEDhvb1Z3YhLoxF4D0BFrcxmE7tNafei0RJ5KwVM+rj9A@mail.gmail.com>

On Wed, 7 Apr 2021, Howard Spoelstra wrote:
> On Wed, Apr 7, 2021 at 7:26 AM Howard Spoelstra <hsp.cat7@gmail.com> wrote:
>> On Wed, Apr 7, 2021 at 3:53 AM Programmingkid <programmingkidx@gmail.com> wrote:
>>>> On Apr 6, 2021, at 7:18 PM, BALATON Zoltan <balaton@eik.bme.hu> 
>>>> wrote: 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.

I think drivers are managed by IOKit so QEMU should and probably could not 
call driver methods directly. There should be some upper management layer 
to control this that you should talk to instead.

>>>> guest and connect passed through devices to that. Did USB 2 cards 
>>>> exist for older G3/G4 Macs?
>>>
>>> Yes. I upgraded a friend's PowerMac G4 with such a card.
>>>
>>>> Some PowerBooks had USB 2 ports, what hardware did those use?
>>>
>>> I'm assuming it was the G4 PowerBooks.
>>>
>>>> Could those be emulated in QEMU?
>>>
>>> The PowerMac already is.

The PowerMacs don't have USB2, only USB1 I think and as Howard wrote MacOS 
does not have drivers either so you'd need to emulate the USB2 card and 
probably also need its driver from the FCode ROM on it or a new enough Mac 
OS X with USB2 drivers. Or pass through devices as USB1 but then you may 
need to somehow downgrade them to that level on the host for which using a 
USB1 only hub seems to work and as Howard found the hub in older Apple 
keyboards work for that.

>> This is what Gerd wrote about the USB 1.1 -> USB 2.0 issue:
>>
>> "Problem is when the device is plugged into a usb2 port you can't query
>> the usb1 descriptors.  So qemu presents the wrong descriptors to the
>> guest in case host and guest use different usb speeds.  That may or may
>> not work ...
>>
>> The other way around is less problematic, when plugging a usb2 device
>> into a usb3-capable (xhci) port I can tell the guest "this is a usb2
>> device".  But reporting "this is a usb2 device" via ohci isn't going to
>> fly for obvious reasons ..."
>>
>> So then I forced my device it into USB 1.1 mode by attaching it to a
>> real 1.1 hub. The qemu hub will not do this for you. Mac OS and Mac OS
>> X guests up to 10.2.8 do not have USB 2.0 support, but from 10.2.8
>> upwards you can use the ehci hub. This works for a simple usb storage
>> device that uses the usbstorage kext in macOS. Indeed, as Zoltan
>> wrote, unloading a kext for a device that has its class driver loaded,
>> one looses access to other devices that match too. Reboot time ;-)
>>
>> There used to be a solution by creating an empty kext that loaded with
>> higher priority compared to the standard kexts. I don't know whether
>> that solution could still work with Apple putting new requirements on
>> kext loading. I believe unloading a kext requires disabling SIP. Sudo
>> won't do anymore from Catalina upwards.
>>
>> I gather Qemu is currenty relying on libusb to do the heavy lifting.
>> For Linux that seems OK together with perhaps first unbinding a
>> driver, but for macOS and Windows hosts the unbinding does not work.
>>
>> Here is some discussion on how to create an empty kext:
>> https://github.com/libusb/libusb/issues/158#issuecomment-190582178
>>
>> Best,
>> Howard
>
> And this:
> https://github.com/libusb/libusb/issues/906

That sounds like it could be what's needed, I haven't read it in detail 
but somebody could try to make a patch based on this info and test it if 
it still works with latest macOS.

Regards,
BALATON Zoltan


  reply	other threads:[~2021-04-07 10:34 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-06 13:44 Mac OS real USB device support issue Programmingkid
2021-04-06 14:01 ` Howard Spoelstra
2021-04-06 14:20   ` BALATON Zoltan
2021-04-06 14:33     ` Programmingkid
2021-04-06 14:31   ` Programmingkid
2021-04-06 16:53     ` BALATON Zoltan
2021-04-06 19:28       ` Programmingkid
2021-04-06 23:18         ` BALATON Zoltan
2021-04-07  1:52           ` Programmingkid
2021-04-07  5:26             ` Howard Spoelstra
2021-04-07  5:28               ` Howard Spoelstra
2021-04-07 10:27                 ` BALATON Zoltan [this message]
2021-04-09 19:37                 ` Programmingkid
2021-04-10  7:28                   ` Howard Spoelstra
2021-04-10 11:29                     ` BALATON Zoltan
2021-05-16  0:33                       ` Programmingkid
2021-04-08 11:05             ` Gerd Hoffmann
2021-04-08 16:40               ` Howard Spoelstra
2021-04-08 19:50                 ` Programmingkid
2021-04-08 19:43               ` Programmingkid
2021-04-09  8:08                 ` Gerd Hoffmann
2021-04-14 14:03                   ` Programmingkid

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2ad99672-442b-a64b-dec-2fe3c027effd@eik.bme.hu \
    --to=balaton@eik.bme.hu \
    --cc=gerd@kraxel.org \
    --cc=hsp.cat7@gmail.com \
    --cc=programmingkidx@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).