I am writing a custom device driver for a USB device which is quite old. The driver is written on the basis on Sample code given by Apple for IOKit. I am able to do communication to the device and I have written the IOUserClient for application space as well.
I am having issue with retrieving data from the buffer to the IOUserClient from the Kernel space. The way this works is that I send a READ command to the device and in turn the device takes time to fill up the read buffer which is notified in the completionhandler. I am using IOCommandGate for the communication. The read function on the IOUserClient should ideally wait for the buffer to fill up from the device but it doesn't. I tried to add a IOLock so that IOUserClient side will wait for the buffer fill up but it waits infinitely without terminating. This might be because the commandgate only forks one thread.
Can Commandgate sleep/awake be used in this case? The Kernel panic happens when I do that. Is there another way?
I am relatively new in this area and would appreciate some direction or pointers on the same.
IOUserClientExternalMethods can either be async or synchronous. Async external methods should return immediately, then be notified of completion via the Mach port argument. For a sync/blocking externalmethod, if you want to use anIOCommandGate, you need to suspend the method code withcommandSleep(), and wake it up from the I/O completion usingcommandWakeup().