3

I'm developing a kernel driver for a USB device on OS X. After adding the setPowerState handler, I'm noticing that it's called for a wake event immediately after the start method is called. This happens on OS X 10.6 when I load the driver, and when I plug the USB device in.

The kernel.log shows the iolog entries I'm making on each method call:

...(attach device)
MyDriver: Initializing
MyDriver: Probing
MyDriver: Starting
MyDriver: Waking
...(detach device)
MyDriver: Stopping
MyDriver: Freeing

Can I expect wakeup to occur after start every time?

If so is it reasonable to put most of my initialization code into the setPowerState handler, knowing it will be called after start?

Is this true for OS X 10.4 and 10.5 as well?

Adam Davis
  • 91,931
  • 60
  • 264
  • 330
  • 3
    This concerns programming a kernel driver, so it should be on topic for Stack Overflow. If you disagree, please consider adding a comment when you cast your close vote so I can revise my question to make this more clear. – Adam Davis Apr 21 '11 at 18:13

1 Answers1

1

Yes you can, provide your have your driver is correctly connected to the Power Plane and has correctly initialised Power Managment (see the link below under the Implementing Basic Power Management heading.

It is not only reasonable but it is expected. Note that the only initialization code that make not be in setPowerState and that is in start or elsewhere is stuff that is only loaded the once and has power state handling code for sleep and wake events in start.

For more information see here.

The only difference between setPowerState in Mac OS X versions is that in Mac OS X 10.5 and newer, setPowerState is called in its own thread, whilst 10.4 it is called as part of the existing thread.

Appleman1234
  • 15,946
  • 45
  • 67