================================== これは、 linux-2.6.13-rc5/Documentation/filesystems/sysfs-pci.txt の和訳 です。 翻訳団体: JF プロジェクト < http://www.linux.or.jp/JF/ > 更新日 : 2005/8/28 翻訳者 : Hiroshi.Suzuki < setter at reset dot jp > 校正者 : Chie Nakatani さん Seiji Kaneko さん ================================== Accessing PCI device resources through sysfs sysfs 経由で PCI デバイス資源にアクセスする。 sysfs, usually mounted at /sys, provides access to PCI resources on platforms that support it. For example, a given bus might look like this: sysfs は 通常 /sys にマウントされ、プラットフォームがサポートする PCI 資源へのアクセ スを提供します。たとえば、与えられたバスは、次に示すようになるでしょう: /sys/devices/pci0000:17 |-- 0000:17:00.0 | |-- class | |-- config | |-- device | |-- irq | |-- local_cpus | |-- resource | |-- resource0 | |-- resource1 | |-- resource2 | |-- rom | |-- subsystem_device | |-- subsystem_vendor | `-- vendor `-- ... The topmost element describes the PCI domain and bus number. In this case, the domain number is 0000 and the bus number is 17 (both values are in hex). This bus contains a single function device in slot 0. The domain and bus numbers are reproduced for convenience. Under the device directory are several files, each with their own function. 一番上の行は、PCI ドメインと、バス番号を表わしています。 ここで示したものは、ドメイン番号が 0000 で、バス番号が 17 (それぞれの値は 16進数) です。このバスには、スロット 0 内の単機能デバイスがあります。ドメインとバス番号は、 便宜上、再度表示しています。デバイスディレクトリ内にはいくつかのファイルがあり、 それぞれが、機能を持っています。 file function ---- -------- class PCI class (ascii, ro) config PCI config space (binary, rw) device PCI device (ascii, ro) irq IRQ number (ascii, ro) local_cpus nearby CPU mask (cpumask, ro) resource PCI resource host addresses (ascii, ro) resource0..N PCI resource N, if present (binary, mmap) rom PCI ROM resource, if present (binary, ro) subsystem_device PCI subsystem device (ascii, ro) subsystem_vendor PCI subsystem vendor (ascii, ro) vendor PCI vendor (ascii, ro) ro - read only file rw - file is readable and writable mmap - file is mmapable ascii - file contains ascii text binary - file contains binary data cpumask - file contains a cpumask type ファイル 機能 ---- -------- class PCI クラス (ascii, ro) config PCI 設定空間 (binary, rw) device PCI デバイス (ascii, ro) irq IRQ 番号 (ascii, ro) local_cpus ローカルの CPU マスク (cpumask, ro) resource PCI 資源のホストアドレス (ascii, ro) resource0..N 存在するなら、PCI 資源 N (binary, mmap) rom 存在するなら、PCI ROM 資源 (binary, ro) subsystem_device PCI サブシステムデバイス (ascii, ro) subsystem_vendor PCI サブシステムベンダ (ascii, ro) vendor PCI ベンダ (ascii, ro) ro - 読み込み専用ファイル rw - 読み書きできるファイル mmap - ファイルは mmap できます ascii - アスキーテキストを保持するファイル binary - バイナリデータを保持するファイル cpumask - cpumask タイプを保持するファイル The read only files are informational, writes to them will be ignored. Writable files can be used to perform actions on the device (e.g. changing config space, detaching a device). mmapable files are available via an mmap of the file at offset 0 and can be used to do actual device programming from userspace. Note that some platforms don't support mmapping of certain resources, so be sure to check the return value from any attempted mmap. 読み込み専用ファイルは情報を提供し、書き込みは無視されます。 書き込みできるファイルは、デバイス上の処理 (例えば、設定空間を変更したり、デバイスを取り除く) を実行するのに使えます。mmap できるファイルは、そのファイルを mmap したものを オフセット 0 からアクセスすることで利用でき、また、ユーザ空間から実際のデバイス プログラミングをするのに使えます。いくつかのプラットフォームでは、特定の資源の mmap が サポートされていないので、試みられたどのような mmap からの戻り値も検査しなければなら ないことに注意してください。 Accessing legacy resources through sysfs sysfs 経由で古い (レガシー) 資源にアクセスする。 Legacy I/O port and ISA memory resources are also provided in sysfs if the underlying platform supports them. They're located in the PCI class heirarchy, e.g. 構成しているプラットフォームがサポートしているなら、古い入出力ポートと、ISA メモリ 資源も、sysfs で提供します。 それらは、次に示すように、PCI クラス階層に配置されます。 /sys/class/pci_bus/0000:17/ |-- bridge -> ../../../devices/pci0000:17 |-- cpuaffinity |-- legacy_io `-- legacy_mem The legacy_io file is a read/write file that can be used by applications to do legacy port I/O. The application should open the file, seek to the desired port (e.g. 0x3e8) and do a read or a write of 1, 2 or 4 bytes. The legacy_mem file should be mmapped with an offset corresponding to the memory offset desired, e.g. 0xa0000 for the VGA frame buffer. The application can then simply dereference the returned pointer (after checking for errors of course) to access legacy memory space. legacy_io ファイルは、読み書きできるファイルで、アプリケーションが古いポートの入出力 をするのに使えます。アプリケーションは、ファイルを開き、目的のポート (例えば、0x3e8) を探し、1、または、2 または、4バイトを読み込むか、書き込まなければなりません。 legacy_mem ファイルは、目的のメモリオフセット (例えば、VGA フレームバッファ用の 0xa0000) に対応したオフセットに mmap しなければなりません。 アプリケーションは、単に、返されたポインタ (もちろんエラー検査の後で) を間接参照 ('*' 演算子を使って参照)することで、古いメモリ空間にアクセスできます。 Supporting PCI access on new platforms 新しいプラットフォーム上での PCI アクセスサポート In order to support PCI resource mapping as described above, Linux platform code must define HAVE_PCI_MMAP and provide a pci_mmap_page_range function. Platforms are free to only support subsets of the mmap functionality, but useful return codes should be provided. 上述した PCI 資源のマッピングを行うためには、Linux プラットフォームコードは、 HAVE_PCI_MMAP の定義と、pci_mmap_page_range 機能の提供をしなければなりません。 プラットフォームで mmap の機能のサブセットをサポートするようにしてもよいですが、 有効なリターンコードは提供しなければなりません。 Legacy resources are protected by the HAVE_PCI_LEGACY define. Platforms wishing to support legacy functionality should define it and provide pci_legacy_read, pci_legacy_write and pci_mmap_legacy_page_range functions. 古い (レガシー) 資源は HAVE_PCI_LEGACY 定義で保護されています。 プラットフォームが古い機能をサポートしたいとき、HAVE_PCI_LEGACY を定義し、 pci_legacy_read, pci_legacy_write, pci_mmap_legacy_page_range 機能を 提供しなければなりません。