このページはWritingPortableDriversセクションの一部です。
PCIメモリアクセス
デバイスのPCIメモリにアクセスする場合も、メモリに直接アクセスしようとしないで、汎用関数を使用してください。 PCIバスにアクセスする方法には、ハードウェアの種類によりさまざまな方法があるからです。汎用関数を使用すれば、 あなたのPCIドライバはPCIバスを持つどのようなLinuxシステム上でも動作させることができるでしょう。
PCIバスからデータを読み込むには、次の関数を使用してください。
データを書き込むには、次の関数を使用してください。
これらの関数を使用することで、PCIデバイスに割り当てられた特定のメモリ位置に8ビット、16ビット、32ビットの データを書き込むことができます。Linux PCIコアによりまだ初期化されていないPCIデバイスのメモリにアクセスしたい ときは、pci_hotplugコアのコードにある次の関数を使用することができます。
1 int pci_read_config_byte_nodev(struct pci_ops *ops, u8 bus, u8 device,
2 u8 function, int where, u8 *val);
3 int pci_read_config_word_nodev(struct pci_ops *ops, u8 bus, u8 device,
4 u8 function, int where, u16 *val);
5 int pci_read_config_dword_nodev(struct pci_ops *ops, u8 bus, u8 device,
6 u8 function, int where, u32 *val);
7
8 int pci_write_config_byte_nodev(struct pci_ops *ops, u8 bus, u8 device,
9 u8 function, int where, u8 val);
10 int pci_write_config_word_nodev(struct pci_ops *ops, u8 bus, u8 device,
11 u8 function, int where, u16 val);
12 int pci_write_config_dword_nodev(struct pci_ops *ops, u8 bus, u8 device,
13 u8 function, int where, u32 val);
ドライバからPCIメモリを読み書きする例は、drivers/usb/host/usb-ohci.cのUSB OHCIドライバに見ることができます。
1 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &latency);
2 if (latency) {
3 pci_read_config_byte(dev, PCI_MAX_LAT, &limit);
4 if (limit && limit < latency) {
5 dbg("PCI latency reduced to max %d", limit);
6 pci_write_config_byte(dev, PCI_LATENCY_TIMER, limit);
7 ohci->pci_latency = limit;
8 } else {
9 /* it might already have been reduced */
10 ohci->pci_latency = latency;
11 }
12 }