sysfs-pci.txt 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. Accessing PCI device resources through sysfs
  2. sysfs, usually mounted at /sys, provides access to PCI resources on platforms
  3. that support it. For example, a given bus might look like this:
  4. /sys/devices/pci0000:17
  5. |-- 0000:17:00.0
  6. | |-- class
  7. | |-- config
  8. | |-- detach_state
  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. `-- detach_state
  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. detach_state connection status (bool, rw)
  31. device PCI device (ascii, ro)
  32. irq IRQ number (ascii, ro)
  33. local_cpus nearby CPU mask (cpumask, ro)
  34. resource PCI resource host addresses (ascii, ro)
  35. resource0..N PCI resource N, if present (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.
  47. Writable files can be used to perform actions on the device (e.g. changing
  48. config space, detaching a device). mmapable files are available via an
  49. mmap of the file at offset 0 and can be used to do actual device programming
  50. from userspace. Note that some platforms don't support mmapping of certain
  51. resources, so be sure to check the return value from any attempted mmap.
  52. Accessing legacy resources through sysfs
  53. Legacy I/O port and ISA memory resources are also provided in sysfs if the
  54. underlying platform supports them. They're located in the PCI class heirarchy,
  55. e.g.
  56. /sys/class/pci_bus/0000:17/
  57. |-- bridge -> ../../../devices/pci0000:17
  58. |-- cpuaffinity
  59. |-- legacy_io
  60. `-- legacy_mem
  61. The legacy_io file is a read/write file that can be used by applications to
  62. do legacy port I/O. The application should open the file, seek to the desired
  63. port (e.g. 0x3e8) and do a read or a write of 1, 2 or 4 bytes. The legacy_mem
  64. file should be mmapped with an offset corresponding to the memory offset
  65. desired, e.g. 0xa0000 for the VGA frame buffer. The application can then
  66. simply dereference the returned pointer (after checking for errors of course)
  67. to access legacy memory space.
  68. Supporting PCI access on new platforms
  69. In order to support PCI resource mapping as described above, Linux platform
  70. code must define HAVE_PCI_MMAP and provide a pci_mmap_page_range function.
  71. Platforms are free to only support subsets of the mmap functionality, but
  72. useful return codes should be provided.
  73. Legacy resources are protected by the HAVE_PCI_LEGACY define. Platforms
  74. wishing to support legacy functionality should define it and provide
  75. pci_legacy_read, pci_legacy_write and pci_mmap_legacy_page_range functions.