sysfs-pci.txt 4.5 KB

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