简体   繁体   中英

Mac M1 get IOMobileFramebufferUserClient interface

I am trying to get access to framebuffer interface for a M1 Mac. I know it's quite different from other Mac, because these new Mac use IOMobileFrameBuffer (which comes from OS) instead of classical IOFrameBuffer.

So I tried to use this code to access this framebuffer with no luck.

func makeIterator() -> io_iterator_t {
    var port: mach_port_t = 0
    var status = IOMasterPort(mach_port_t(MACH_PORT_NULL), &port)
    guard status == KERN_SUCCESS else { return 0 }
    guard let match = IOBSDNameMatching(port, 0, "AppleMobileCLCD") else { return 0 }
    var iterator: io_iterator_t = 0
    status = IOServiceGetMatchingServices(port, match, &iterator)
    guard status == KERN_SUCCESS else { return 0 }
    return iterator
}

I also tried with "IOMobileFramebuffer", "AppleCLCD" and "IOMobileFramebufferUserClient" strings but the matching does not seem to be ok.

I tried also to display ioreg command which told me:

+-o IOMobileFramebufferUserClient <class IOMobileFramebufferUserClient, id 0x1000007fb, ,registered, ,matched, active, busy 0, retain 5>

Do you know how I can find the string to access this user client? Or maybe I am totally wrong with this code... I am trying to search for setting up some luminosity in this interface. I think it won't work well, but I want to try...

Thanks!

The reason your matching ( IOServiceGetMatchingServices ) call is not returning the object you're looking for is because your matching dictionary is incorrect.

First of all, let's look at the ioreg output (command line: ioreg -w0 -irc IOMobileFramebuffer ) for the objects you're interested in. On my Mac Mini, they look like this:

+-o AppleCLCD2  <class IORegistryEntry:IOService:IOMobileFramebuffer:IOMobileFramebufferService:IOMobileFramebufferAP:UnifiedPipeline2:AppleCLCD2, id 0x100000300, registered, matched, active, busy 0 (0 ms), retain 15>
[…]
+-o AppleCLCD2  <class IORegistryEntry:IOService:IOMobileFramebuffer:IOMobileFramebufferService:IOMobileFramebufferAP:UnifiedPipeline2:AppleCLCD2, id 0x1000002bc, registered, matched, active, busy 0 (0 ms), retain 14>

First of all, IOBSDNameMatching is for matching devices which have equivalents in the BSD subsystem (essentially, they appear under /dev/ ) which is only the case a few kinds of device on macOS, for example block storage devices and serial ports. (If it was the correct function for this purpose, you would also need to pass kIOMasterPortDefault as the first argument as the documentation instructs.)

I'm not sure where you're getting "AppleMobileCLCD" from, perhaps that's the entry's name on your system (instead of AppleCLCD2 on the Mac Mini).

If that's the case, you need to use IOServiceNameMatching to create the matching dictionary.

However, matching by name is usually not a great idea unless you have a very good reason; instead, match by class name, using IOServiceMatching() . So, for example:

    guard let match = IOServiceMatching("IOMobileFramebuffer") else { return 0 }

This should work.

You will usually not be able to match existing user client objects, such as the one whose ioreg line you quote, as they are typically not registered for matching. (they show as !registered ) They generally also don't have any usable interface, as they are the interface for their provider object.

There is no documented interface for IOMobileFramebuffer but perhaps you can find something useful to do with it nevertheless.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM