blob: 9f8740ca3f3bc514d9f5426168eb5b2273b96d42 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001Accessing PCI device resources through sysfs
Jesse Barnes5d135dff2005-12-09 11:55:03 -08002--------------------------------------------
Linus Torvalds1da177e2005-04-16 15:20:36 -07003
4sysfs, usually mounted at /sys, provides access to PCI resources on platforms
5that support it. For example, a given bus might look like this:
6
7 /sys/devices/pci0000:17
8 |-- 0000:17:00.0
9 | |-- class
10 | |-- config
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 | |-- device
Timothy S. Nelson97c44832009-01-30 06:12:47 +110012 | |-- enable
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 | |-- irq
14 | |-- local_cpus
15 | |-- resource
16 | |-- resource0
17 | |-- resource1
18 | |-- resource2
19 | |-- rom
20 | |-- subsystem_device
21 | |-- subsystem_vendor
22 | `-- vendor
David Brownell0b405a02005-05-12 12:06:27 -070023 `-- ...
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25The topmost element describes the PCI domain and bus number. In this case,
26the domain number is 0000 and the bus number is 17 (both values are in hex).
27This bus contains a single function device in slot 0. The domain and bus
28numbers are reproduced for convenience. Under the device directory are several
29files, each with their own function.
30
31 file function
32 ---- --------
33 class PCI class (ascii, ro)
34 config PCI config space (binary, rw)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 device PCI device (ascii, ro)
Timothy S. Nelson97c44832009-01-30 06:12:47 +110036 enable Whether the device is enabled (ascii, rw)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 irq IRQ number (ascii, ro)
38 local_cpus nearby CPU mask (cpumask, ro)
39 resource PCI resource host addresses (ascii, ro)
40 resource0..N PCI resource N, if present (binary, mmap)
venkatesh.pallipadi@intel.com45aec1ae2008-03-18 17:00:22 -070041 resource0_wc..N_wc PCI WC map resource N, if prefetchable (binary, mmap)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 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
47 ro - read only file
48 rw - file is readable and writable
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
Jesse Barnes5d135dff2005-12-09 11:55:03 -080054The read only files are informational, writes to them will be ignored, with
55the exception of the 'rom' file. Writable files can be used to perform
56actions on the device (e.g. changing config space, detaching a device).
57mmapable files are available via an mmap of the file at offset 0 and can be
58used to do actual device programming from userspace. Note that some platforms
59don't support mmapping of certain resources, so be sure to check the return
60value from any attempted mmap.
61
Timothy S. Nelson97c44832009-01-30 06:12:47 +110062The 'enable' file provides a counter that indicates how many times the device
63has been enabled. If the 'enable' file currently returns '4', and a '1' is
64echoed into it, it will then return '5'. Echoing a '0' into it will decrease
65the count. Even when it returns to 0, though, some of the initialisation
66may not be reversed.
67
Jesse Barnes5d135dff2005-12-09 11:55:03 -080068The 'rom' file is special in that it provides read-only access to the device's
69ROM file, if available. It's disabled by default, however, so applications
70should write the string "1" to the file to enable it before attempting a read
Timothy S. Nelson97c44832009-01-30 06:12:47 +110071call, and disable it following the access by writing "0" to the file. Note
72that the device must be enabled for a rom read to return data succesfully.
73In the event a driver is not bound to the device, it can be enabled using the
74'enable' file, documented above.
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76Accessing legacy resources through sysfs
Jesse Barnes5d135dff2005-12-09 11:55:03 -080077----------------------------------------
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79Legacy I/O port and ISA memory resources are also provided in sysfs if the
Uwe Kleine-König1b3c3712007-02-17 19:23:03 +010080underlying platform supports them. They're located in the PCI class hierarchy,
Linus Torvalds1da177e2005-04-16 15:20:36 -070081e.g.
82
83 /sys/class/pci_bus/0000:17/
84 |-- bridge -> ../../../devices/pci0000:17
85 |-- cpuaffinity
86 |-- legacy_io
87 `-- legacy_mem
88
89The legacy_io file is a read/write file that can be used by applications to
90do legacy port I/O. The application should open the file, seek to the desired
91port (e.g. 0x3e8) and do a read or a write of 1, 2 or 4 bytes. The legacy_mem
92file should be mmapped with an offset corresponding to the memory offset
93desired, e.g. 0xa0000 for the VGA frame buffer. The application can then
94simply dereference the returned pointer (after checking for errors of course)
95to access legacy memory space.
96
97Supporting PCI access on new platforms
Jesse Barnes5d135dff2005-12-09 11:55:03 -080098--------------------------------------
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100In order to support PCI resource mapping as described above, Linux platform
101code must define HAVE_PCI_MMAP and provide a pci_mmap_page_range function.
102Platforms are free to only support subsets of the mmap functionality, but
103useful return codes should be provided.
104
105Legacy resources are protected by the HAVE_PCI_LEGACY define. Platforms
106wishing to support legacy functionality should define it and provide
David Brownell0b405a02005-05-12 12:06:27 -0700107pci_legacy_read, pci_legacy_write and pci_mmap_legacy_page_range functions.