attach() Entry Point
The syntax for attach(9E) is as follows:
int attach(dev_info_t *dip, ddi_attach_cmd_t cmd); |
When power is restored to the system, each device with a reg property or with a pm-hardware-state property of value needs-suspend-resume has its attach(9E) entry point called with a command value of DDI_RESUME. If the system shutdown was aborted for some reason, each driver that was suspended is called to resume, even though the power has not been shut off. Consequently, the resume code in attach(9E) must make no assumptions about the state of the hardware; it may or may not have lost power.
The power management framework considers the power level of the components to be unknown at DDI_RESUME time. Depending on the nature of the device, the driver writer has two choices:
If the driver can determine the actual power level of the components of the device without powering them up (by reading a register, for example), then the driver should notify the framework of the power level of each component by calling pm_power_has_changed(9F).
If it cannot determine the power levels of the components, then the driver should mark each component internally as unknown and call pm_raise_power(9F) before the first access to each one.
Example 9-7 shows an example of an attach(9E) routine with the DDI_RESUME command.
Example 9-7 attach(9E) Routine Implementing DDI_RESUME
Note - The detach(9E) and attach(9E) interfaces may also be used to resume a system that has been quiesced.
Power Management Device Access Example
If power management is supported, and detach(9E) and attach(9E) have code such as shown in the previous examples, the code fragment in Example 9-8 can be used where device access is about to be made to the device from user context (for example, in read(2), write(2), ioctl(2)).
The following example assumes that the operation about to be performed requires a component component that is operating at power level level.
Example 9-8 Device Access
The code fragment in Example 9-9 can be used when device operation completes (for example, in the device's interrupt handler).
Example 9-9 Device Operation Completion