sysfs-pci.txt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. Accessing PCI device resources through sysfs
  2. --------------------------------------------
  3. sysfs, usually mounted at /sys, provides access to PCI resources on platforms
  4. that support it. For example, a given bus might look like this:
  5. /sys/devices/pci0000:17
  6. |-- 0000:17:00.0
  7. | |-- class
  8. | |-- config
  9. | |-- device
  10. | |-- irq
  11. | |-- local_cpus
  12. | |-- resource
  13. | |-- resource0
  14. | |-- resource1
  15. | |-- resource2
  16. | |-- rom
  17. | |-- subsystem_device
  18. | |-- subsystem_vendor
  19. | `-- vendor
  20. `-- ...
  21. The topmost element describes the PCI domain and bus number. In this case,
  22. the domain number is 0000 and the bus number is 17 (both values are in hex).
  23. This bus contains a single function device in slot 0. The domain and bus
  24. numbers are reproduced for convenience. Under the device directory are several
  25. files, each with their own function.
  26. file function
  27. ---- --------
  28. class PCI class (ascii, ro)
  29. config PCI config space (binary, rw)
  30. device PCI device (ascii, ro)
  31. irq IRQ number (ascii, ro)
  32. local_cpus nearby CPU mask (cpumask, ro)
  33. resource PCI resource host addresses (ascii, ro)
  34. resource0..N PCI resource N, if present (binary, mmap)
  35. resource0_wc..N_wc PCI WC map resource N, if prefetchable (binary, mmap)
  36. rom PCI ROM resource, if present (binary, ro)
  37. subsystem_device PCI subsystem device (ascii, ro)
  38. subsystem_vendor PCI subsystem vendor (ascii, ro)
  39. vendor PCI vendor (ascii, ro)
  40. ro - read only file
  41. rw - file is readable and writable
  42. mmap - file is mmapable
  43. ascii - file contains ascii text
  44. binary - file contains binary data
  45. cpumask - file contains a cpumask type
  46. The read only files are informational, writes to them will be ignored, with
  47. the exception of the 'rom' file. Writable files can be used to perform
  48. actions on the device (e.g. changing config space, detaching a device).
  49. mmapable files are available via an mmap of the file at offset 0 and can be
  50. used to do actual device programming from userspace. Note that some platforms
  51. don't support mmapping of certain resources, so be sure to check the return
  52. value from any attempted mmap.
  53. The 'rom' file is special in that it provides read-only access to the device's
  54. ROM file, if available. It's disabled by default, however, so applications
  55. should write the string "1" to the file to enable it before attempting a read
  56. call, and disable it following the access by writing "0" to the file.
  57. Accessing legacy resources through sysfs
  58. ----------------------------------------
  59. Legacy I/O port and ISA memory resources are also provided in sysfs if the
  60. underlying platform supports them. They're located in the PCI class hierarchy,
  61. e.g.
  62. /sys/class/pci_bus/0000:17/
  63. |-- bridge -> ../../../devices/pci0000:17
  64. |-- cpuaffinity
  65. |-- legacy_io
  66. `-- legacy_mem
  67. The legacy_io file is a read/write file that can be used by applications to
  68. do legacy port I/O. The application should open the file, seek to the desired
  69. port (e.g. 0x3e8) and do a read or a write of 1, 2 or 4 bytes. The legacy_mem
  70. file should be mmapped with an offset corresponding to the memory offset
  71. desired, e.g. 0xa0000 for the VGA frame buffer. The application can then
  72. simply dereference the returned pointer (after checking for errors of course)
  73. to access legacy memory space.
  74. Supporting PCI access on new platforms
  75. --------------------------------------
  76. In order to support PCI resource mapping as described above, Linux platform
  77. code must define HAVE_PCI_MMAP and provide a pci_mmap_page_range function.
  78. Platforms are free to only support subsets of the mmap functionality, but
  79. useful return codes should be provided.
  80. Legacy resources are protected by the HAVE_PCI_LEGACY define. Platforms
  81. wishing to support legacy functionality should define it and provide
  82. pci_legacy_read, pci_legacy_write and pci_mmap_legacy_page_range functions.