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