sysfs-pci.txt 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. | |-- enable
  11. | |-- irq
  12. | |-- local_cpus
  13. | |-- remove
  14. | |-- resource
  15. | |-- resource0
  16. | |-- resource1
  17. | |-- resource2
  18. | |-- revision
  19. | |-- rom
  20. | |-- subsystem_device
  21. | |-- subsystem_vendor
  22. | `-- vendor
  23. `-- ...
  24. The topmost element describes the PCI domain and bus number. In this case,
  25. the domain number is 0000 and the bus number is 17 (both values are in hex).
  26. This bus contains a single function device in slot 0. The domain and bus
  27. numbers are reproduced for convenience. Under the device directory are several
  28. files, each with their own function.
  29. file function
  30. ---- --------
  31. class PCI class (ascii, ro)
  32. config PCI config space (binary, rw)
  33. device PCI device (ascii, ro)
  34. enable Whether the device is enabled (ascii, rw)
  35. irq IRQ number (ascii, ro)
  36. local_cpus nearby CPU mask (cpumask, ro)
  37. remove remove device from kernel's list (ascii, wo)
  38. resource PCI resource host addresses (ascii, ro)
  39. resource0..N PCI resource N, if present (binary, mmap, rw[1])
  40. resource0_wc..N_wc PCI WC map resource N, if prefetchable (binary, mmap)
  41. revision PCI revision (ascii, ro)
  42. rom PCI ROM resource, if present (binary, ro)
  43. subsystem_device PCI subsystem device (ascii, ro)
  44. subsystem_vendor PCI subsystem vendor (ascii, ro)
  45. vendor PCI vendor (ascii, ro)
  46. ro - read only file
  47. rw - file is readable and writable
  48. wo - write only file
  49. mmap - file is mmapable
  50. ascii - file contains ascii text
  51. binary - file contains binary data
  52. cpumask - file contains a cpumask type
  53. [1] rw for RESOURCE_IO (I/O port) regions only
  54. The read only files are informational, writes to them will be ignored, with
  55. the exception of the 'rom' file. Writable files can be used to perform
  56. actions on the device (e.g. changing config space, detaching a device).
  57. mmapable files are available via an mmap of the file at offset 0 and can be
  58. used to do actual device programming from userspace. Note that some platforms
  59. don't support mmapping of certain resources, so be sure to check the return
  60. value from any attempted mmap. The most notable of these are I/O port
  61. resources, which also provide read/write access.
  62. The 'enable' file provides a counter that indicates how many times the device
  63. has been enabled. If the 'enable' file currently returns '4', and a '1' is
  64. echoed into it, it will then return '5'. Echoing a '0' into it will decrease
  65. the count. Even when it returns to 0, though, some of the initialisation
  66. may not be reversed.
  67. The 'rom' file is special in that it provides read-only access to the device's
  68. ROM file, if available. It's disabled by default, however, so applications
  69. should write the string "1" to the file to enable it before attempting a read
  70. call, and disable it following the access by writing "0" to the file. Note
  71. that the device must be enabled for a rom read to return data successfully.
  72. In the event a driver is not bound to the device, it can be enabled using the
  73. 'enable' file, documented above.
  74. The 'remove' file is used to remove the PCI device, by writing a non-zero
  75. integer to the file. This does not involve any kind of hot-plug functionality,
  76. e.g. powering off the device. The device is removed from the kernel's list of
  77. PCI devices, the sysfs directory for it is removed, and the device will be
  78. removed from any drivers attached to it. Removal of PCI root buses is
  79. disallowed.
  80. Accessing legacy resources through sysfs
  81. ----------------------------------------
  82. Legacy I/O port and ISA memory resources are also provided in sysfs if the
  83. underlying platform supports them. They're located in the PCI class hierarchy,
  84. e.g.
  85. /sys/class/pci_bus/0000:17/
  86. |-- bridge -> ../../../devices/pci0000:17
  87. |-- cpuaffinity
  88. |-- legacy_io
  89. `-- legacy_mem
  90. The legacy_io file is a read/write file that can be used by applications to
  91. do legacy port I/O. The application should open the file, seek to the desired
  92. port (e.g. 0x3e8) and do a read or a write of 1, 2 or 4 bytes. The legacy_mem
  93. file should be mmapped with an offset corresponding to the memory offset
  94. desired, e.g. 0xa0000 for the VGA frame buffer. The application can then
  95. simply dereference the returned pointer (after checking for errors of course)
  96. to access legacy memory space.
  97. Supporting PCI access on new platforms
  98. --------------------------------------
  99. In order to support PCI resource mapping as described above, Linux platform
  100. code should ideally define ARCH_GENERIC_PCI_MMAP_RESOURCE and use the generic
  101. implementation of that functionality. To support the historical interface of
  102. mmap() through files in /proc/bus/pci, platforms may also set HAVE_PCI_MMAP.
  103. Alternatively, platforms which set HAVE_PCI_MMAP may provide their own
  104. implementation of pci_mmap_page_range() instead of defining
  105. ARCH_GENERIC_PCI_MMAP_RESOURCE.
  106. Platforms which support write-combining maps of PCI resources must define
  107. arch_can_pci_mmap_wc() which shall evaluate to non-zero at runtime when
  108. write-combining is permitted. Platforms which support maps of I/O resources
  109. define arch_can_pci_mmap_io() similarly.
  110. Legacy resources are protected by the HAVE_PCI_LEGACY define. Platforms
  111. wishing to support legacy functionality should define it and provide
  112. pci_legacy_read, pci_legacy_write and pci_mmap_legacy_page_range functions.