sysfs-pci.txt 3.4 KB

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