電源管理がサポートされており、使用例 53 および使用例 54 のように detach(9E) およびattach(9E) が使用されている場合、read(2)、write(2)、ioctl(2) などのユーザーコンテキストからデバイスへのアクセスを実行できます。
次の例はこのアプローチを示しています。この例の前提として、操作を実行するためには、部品 component が電源レベル level で動作している必要があります。
使用例 55 デバイスアクセスmutex_enter(&xsp->mu);
/*
* Block command while device is suspended by DDI_SUSPEND
*/
while (xsp->xx_suspended)
cv_wait(&xsp->xx_suspend_cv, &xsp->mu);
/*
* Mark component busy so xx_power() will reject attempt to lower power
*/
xsp->xx_busy[component]++;
if (pm_busy_component(dip, component) != DDI_SUCCESS) {
xsp->xx_busy[component]--;
/*
* Log error and abort
*/
}
if (xsp->xx_power_level[component] < level) {
mutex_exit(&xsp->mu);
if (pm_raise_power(dip, component, level) != DDI_SUCCESS) {
/*
* Log error and abort
*/
}
mutex_enter(&xsp->mu);
}
デバイス操作が完了したら、デバイスの割り込みハンドラなどで次の例のコードフラグメントを使用できます。
使用例 56 デバイス操作完了/*
* For each command completion, decrement the busy count and unstack
* the pm_busy_component() call by calling pm_idle_component(). This
* will allow device power to be lowered when all commands complete
* (all pm_busy_component() counts are unstacked)
*/
xsp->xx_busy[component]--;
if (pm_idle_component(dip, component) != DDI_SUCCESS) {
xsp->xx_busy[component]++;
/*
* Log error and abort
*/
}
/*
* If no more outstanding commands, wake up anyone (like DDI_SUSPEND)
* waiting for all commands to be completed
*/