| ナビゲーションリンクをスキップ | |
| 印刷ビューの終了 | |
|
デバイスドライバの記述 Oracle Solaris 11.1 Information Library (日本語) |
パート I Oracle Solaris プラットフォーム用デバイスドライバの設計
2. Oracle Solaris カーネルとデバイスツリー
22. ドライバのコンパイル、ロード、パッケージ化、およびテスト
23. デバイスドライバのデバッグ、テスト、およびチューニング
電源管理がサポートされており、例 12-6 および例 12-7 のように detach(9E) および attach(9E) が使用されている場合、read(2)、write(2)、ioctl(2) などのユーザーコンテキストからデバイスへのアクセスを実行できます。
次の例はこのアプローチを示しています。この例の前提として、操作を実行するためには、部品 component が電源レベル level で動作している必要があります。
例 12-8 デバイスアクセス
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);
}
デバイス操作が完了したら、デバイスの割り込みハンドラなどで次の例のコードフラグメントを使用できます。
例 12-9 デバイス操作完了
/*
* 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
*/