Kernel Newbies
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Kernel Newbies Japan

  • Webリソース

  • Mailing List

Wiki bits

  • Site Editors

  • Navigation Menu

  • WikiWall Terms of Service

  • Hosted by WikiWall

Navigation

  • RecentChanges
  • FindPage
  • HelpContents

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment

Revision 3 as of 2017-12-30 08:13:16
KernelNewbiesJP:
  • AccessingPciMemory

このページはWritingPortableDriversセクションの一部です。

PCIメモリアクセス

原文: AccessingPciMemory

デバイスのPCIメモリにアクセスする場合も、メモリに直接アクセスしようとしないで、汎用関数を使用してください。 PCIバスにアクセスする方法には、ハードウェアの種類によりさまざまな方法があるからです。汎用関数を使用すれば、 あなたのPCIドライバはPCIバスを持つどのようなLinuxシステム上でも動作させることができるでしょう。

PCIバスからデータを読み込むには、次の関数を使用してください。

   1 int pci_read_config_byte(struct pci_dev *dev, int where, u8 *val);
   2 int pci_read_config_word(struct pci_dev *dev, int where, u16 *val);
   3 int pci_read_config_dword(struct pci_dev *dev, int where, u32 *val);

データを書き込むには、次の関数を使用してください。

   1 int pci_write_config_byte(struct pci_dev *dev, int where, u8 val);
   2 int pci_write_config_word(struct pci_dev *dev, int where, u16 val);
   3 int pci_write_config_dword(struct pci_dev *dev, int where, u32 val);

これらの関数を使用することで、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 }
  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01